Skip to content

Commit

Permalink
Linux+OpenGL: Implement GUI vsync setting (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 authored Nov 13, 2022
1 parent 2842615 commit e9d10a9
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 19 deletions.
25 changes: 10 additions & 15 deletions src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#define STRINGIFY(X) STRINGIFY2(X)

#define GLFUNC(__type, __name) __type __name;
#define EGLFUNC(__type, __name) __type __name;
#include "Common/GLInclude/glFunctions.h"
#undef GLFUNC
#undef EGLFUNC

#include "config/ActiveSettings.h"
#include "config/LaunchSettings.h"
Expand Down Expand Up @@ -229,9 +231,17 @@ void LoadOpenGLImports()
_glXGetProcAddress = (PFNGLXGETPROCADDRESSPROC)dlsym(libGL, "glXGetProcAddressARB");
}

void* libEGL = dlopen("libEGL.so.1", RTLD_NOW | RTLD_GLOBAL);
if(!libEGL)
{
libGL = dlopen("libEGL.so", RTLD_NOW | RTLD_GLOBAL);
}

#define GLFUNC(__type, __name) __name = (__type)_GetOpenGLFunction(libGL, _glXGetProcAddress, STRINGIFY(__name));
#define EGLFUNC(__type, __name) __name = (__type)dlsym(libEGL, STRINGIFY(__name));
#include "Common/GLInclude/glFunctions.h"
#undef GLFUNC
#undef EGLFUNC
}
#elif BOOST_OS_MACOS
void LoadOpenGLImports()
Expand Down Expand Up @@ -352,20 +362,6 @@ void OpenGLRenderer::NotifyLatteCommandProcessorIdle()
glFlush();
}

void OpenGLRenderer::UpdateVSyncState()
{
int configValue = GetConfig().vsync.GetValue();
if(m_activeVSyncState != configValue)
{
#if BOOST_OS_WINDOWS
if(wglSwapIntervalEXT)
wglSwapIntervalEXT(configValue); // 1 = enabled, 0 = disabled
#else
cemuLog_log(LogType::Force, "OpenGL vsync not implemented");
#endif
m_activeVSyncState = configValue;
}
}

bool IsRunningInWine();

Expand Down Expand Up @@ -443,7 +439,6 @@ void OpenGLRenderer::EnableDebugMode()
void OpenGLRenderer::SwapBuffers(bool swapTV, bool swapDRC)
{
GLCanvas_SwapBuffers(swapTV, swapDRC);
UpdateVSyncState();

if (swapTV)
cleanupAfterFrame();
Expand Down
1 change: 0 additions & 1 deletion src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ class OpenGLRenderer : public Renderer
GLuint m_defaultFramebufferId;
GLuint m_pipeline = 0;

int m_activeVSyncState{};
bool m_isPadViewContext{};

// rendertarget viewport
Expand Down
7 changes: 6 additions & 1 deletion src/Common/GLInclude/GLInclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ typedef XID GLXFBConfigID;
typedef struct __GLXcontextRec *GLXContext;
typedef struct __GLXFBConfigRec *GLXFBConfig;

#define EGL_EGL_PROTOTYPES 0
#include "egl.h"
#undef EGL_EGL_PROTOTYPES
#include "glxext.h"

#undef Bool
Expand All @@ -34,9 +37,11 @@ typedef struct __GLXFBConfigRec *GLXFBConfig;
#endif

#define GLFUNC(__type, __name) extern __type __name;
#define EGLFUNC(__type, __name) extern __type __name;
#include "glFunctions.h"
#undef GLFUNC
#undef EGLFUNC

// this prevents Windows GL.h from being included:
#define __gl_h_
#define __GL_H__
#define __GL_H__
Loading

0 comments on commit e9d10a9

Please sign in to comment.