Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sandbox/src/Test3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ void Test3D::OnInit(Renderer3D& renderer, Scene& scene)
// m_Materials[i]->SetUniform("u_ShadowMap", 6);
}

m_Window->SetVsync(VSYNC_DISABLED);

SP_INFO("Init took ", timer.ElapsedMillis(), " ms");
}

Expand Down
7 changes: 4 additions & 3 deletions Sparky-core/src/sp/app/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "sp/sp.h"
#include "Window.h"

#include "sp/graphics/API/Context.h"
#include "sp/graphics/Renderer.h"

#include "sp/utils/Log.h"
Expand Down Expand Up @@ -57,10 +58,10 @@ namespace sp {
return true;
}

void Window::SetVsync(bool enabled)
void Window::SetVsync(uint syncInterval)
{
// TODO: Not implemented
m_Vsync = enabled;
m_Vsync = syncInterval;
graphics::API::Context::SetVsync(m_Vsync);
}

void Window::Clear() const
Expand Down
9 changes: 6 additions & 3 deletions Sparky-core/src/sp/app/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

#include "sp/app/Input.h"

#define VSYNC_DISABLED 0
#define VSYNC_ENABLED 1

namespace sp {

typedef std::function<void(events::Event& event)> WindowEventCallback;
Expand All @@ -32,7 +35,7 @@ namespace sp {
bool m_Closed;
void* m_Handle;

bool m_Vsync;
uint m_Vsync;
WindowEventCallback m_EventCallback;
InputManager* m_InputManager;
public:
Expand All @@ -47,8 +50,8 @@ namespace sp {
inline uint GetWidth() const { return m_Properties.width; }
inline uint GetHeight() const { return m_Properties.height; }

void SetVsync(bool enabled);
inline bool IsVsync() const { return m_Vsync; }
void SetVsync(uint syncInterval);
inline bool IsVsync() const { return m_Vsync != 0; }

inline InputManager* GetInputManager() const { return m_InputManager; }

Expand Down
9 changes: 9 additions & 0 deletions Sparky-core/src/sp/graphics/API/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ namespace sp { namespace graphics { namespace API {
}
}

void Context::SetVsync(const uint& syncInterval)
{
switch ( s_RenderAPI )
{
case RenderAPI::OPENGL: GLContext::SetVsync(syncInterval); break;
case RenderAPI::DIRECT3D: D3DContext::SetVsync(syncInterval); break;
}
}

} } }
1 change: 1 addition & 0 deletions Sparky-core/src/sp/graphics/API/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace sp { namespace graphics { namespace API {

static RenderAPI GetRenderAPI() { return s_RenderAPI; }
static void SetRenderAPI(RenderAPI api) { s_RenderAPI = api; }
static void SetVsync(const uint& syncInterval);
};

} } }
2 changes: 1 addition & 1 deletion Sparky-core/src/sp/platform/directx/DXContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace sp { namespace graphics { namespace API {

void D3DContext::Present()
{
swapchain->Present(0, 0);
swapchain->Present(m_SyncInterval, 0);
}

String D3DContext::GetD3DVersionStringInternal() const
Expand Down
3 changes: 3 additions & 0 deletions Sparky-core/src/sp/platform/directx/DXContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace sp { namespace graphics { namespace API {
D3D_FEATURE_LEVEL m_D3DFeatureLevel;
uint m_MSAAQuality;
bool m_MSAAEnabled;
uint m_SyncInterval;

ID3D11RenderTargetView* m_RenderTargetView;
ID3D11DepthStencilView* m_DepthStencilView;
Expand All @@ -38,6 +39,8 @@ namespace sp { namespace graphics { namespace API {

String GetD3DVersionStringInternal() const;
public:
inline static void SetVsync(const uint& syncInter) { Get()->m_SyncInterval = syncInter; }

inline static D3DContext* GetContext() { return (D3DContext*)s_Context; }

inline static IDXGISwapChain* GetSwapChain() { return GetContext()->swapchain; }
Expand Down
6 changes: 6 additions & 0 deletions Sparky-core/src/sp/platform/opengl/GLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sp/utils/Log.h"

#include <GL/glew.h>
#include <GL/wglew.h>

namespace sp { namespace graphics { namespace API {

Expand Down Expand Up @@ -42,4 +43,9 @@ namespace sp { namespace graphics { namespace API {
SwapBuffers(hDc);
}

void GLContext::SetVsync(const uint& syncInterval)
{
wglSwapIntervalEXT(syncInterval);

@Shimmen Shimmen Apr 6, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the GL backend is intended to work on Windows, Mac, and Linux. This would only work on Windows.

Edit: on the other hand, there is a Windows handle right above. I'm not sure.

}

} } }
1 change: 1 addition & 0 deletions Sparky-core/src/sp/platform/opengl/GLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace sp { namespace graphics { namespace API {
void Present();
public:
inline static GLContext* Get() { return (GLContext*)s_Context; }
static void SetVsync(const uint& syncInterval);
};

} } }