Skip to content

Commit 7f25ca0

Browse files
committed
GPU Display: Add vsync support for GLUT frontend
1 parent 2683fbb commit 7f25ca0

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontend.cxx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ void GPUDisplayFrontend::applyInitialWindowState()
226226
}
227227
}
228228

229+
bool GPUDisplayFrontend::vsyncEnabled() const
230+
{
231+
return mDisplay->cfgR().drawQualityVSync;
232+
}
233+
229234
int32_t& GPUDisplayFrontend::drawTextFontSize()
230235
{
231236
return mDisplay->drawTextFontSize();

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontend.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
155155
int32_t InitDisplay(bool initFailure = false); // Callback to initialize the GL Display (to be called in StartDisplay)
156156
void ExitDisplay(); // Callback to clean up the GL Display
157157
int32_t& drawTextFontSize();
158+
bool vsyncEnabled() const; // VSync setting (drawQualityVSync)
158159
void setWindowState(bool fullScreen, bool maximized); // Sync the settings if the window manager changed the window state
159160
void focusLost(); // Release all keys and mouse buttons when the window loses focus, since the release events go to another window
160161
void applyInitialWindowState(); // Switch to fullscreen / maximize at startup according to the settings

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendGlut.cxx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include <cstring>
2222
#include <GL/freeglut.h>
2323
#include <unistd.h>
24+
#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
25+
#include <GL/glx.h>
26+
#include <GL/glxext.h>
27+
#endif
2428

2529
#include <pthread.h>
2630
using namespace o2::gpu;
@@ -264,6 +268,7 @@ int32_t GPUDisplayFrontendGlut::FrontendMain()
264268
glutPassiveMotionFunc(mouseMoveFunc);
265269
glutMouseWheelFunc(mMouseWheelFunc);
266270
applyInitialWindowState();
271+
SetVSync(vsyncEnabled());
267272

268273
{
269274
std::lock_guard lock(mExitStateMutex);
@@ -308,4 +313,12 @@ void GPUDisplayFrontendGlut::SwitchFullscreen(bool set)
308313
}
309314

310315
void GPUDisplayFrontendGlut::ToggleMaximized(bool set) {}
311-
void GPUDisplayFrontendGlut::SetVSync(bool enable) {}
316+
void GPUDisplayFrontendGlut::SetVSync(bool enable) // GLUT has no swap interval API, set it via GLX directly (no-op if freeglut does not use GLX)
317+
{
318+
#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
319+
auto swapInterval = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
320+
if (swapInterval && glXGetCurrentDisplay()) {
321+
swapInterval(glXGetCurrentDisplay(), glXGetCurrentDrawable(), enable);
322+
}
323+
#endif
324+
}

0 commit comments

Comments
 (0)