From 5f138be59ae7510968270ecea1fabf7339cf0ace Mon Sep 17 00:00:00 2001 From: cxgeorge <> Date: Tue, 21 May 2002 02:01:56 +0000 Subject: [PATCH] add gl-swapbuffer-framelock option --- panda/src/wgldisplay/config_wgldisplay.cxx | 3 +++ panda/src/wgldisplay/config_wgldisplay.h | 1 + panda/src/wgldisplay/wglGraphicsWindow.cxx | 25 ++++++++++++++++++++++ panda/src/wgldisplay/wglext.h | 15 +++++++++++++ 4 files changed, 44 insertions(+) diff --git a/panda/src/wgldisplay/config_wgldisplay.cxx b/panda/src/wgldisplay/config_wgldisplay.cxx index dca8c684a5..39d1ac553c 100644 --- a/panda/src/wgldisplay/config_wgldisplay.cxx +++ b/panda/src/wgldisplay/config_wgldisplay.cxx @@ -47,6 +47,9 @@ bool bResponsive_minimized_fullscreen_window = config_wgldisplay.GetBool("respon // will crab out WireGL. bool support_wiregl = config_wgldisplay.GetBool("support-wiregl", false); +// Set this true to enable HW swapbuffer frame-lock on 3dlabs cards +bool gl_swapbuffer_framelock = config_wgldisplay.GetBool("gl-swapbuffer-framelock", false); + // if true, use ddraw's GetAvailVidMem to fail if driver says it has too little video mem bool gl_do_vidmemsize_check = config_wgldisplay.GetBool("do-vidmemsize-check", true); diff --git a/panda/src/wgldisplay/config_wgldisplay.h b/panda/src/wgldisplay/config_wgldisplay.h index 0b41f1a268..b819a6271f 100644 --- a/panda/src/wgldisplay/config_wgldisplay.h +++ b/panda/src/wgldisplay/config_wgldisplay.h @@ -34,6 +34,7 @@ extern Filename get_mono_cursor_filename_2(); extern bool gl_show_fps_meter; extern float gl_fps_meter_update_interval; extern bool gl_sync_video; +extern bool gl_swapbuffer_framelock; extern int gl_forced_pixfmt; extern bool bResponsive_minimized_fullscreen_window; extern bool gl_do_vidmemsize_check; diff --git a/panda/src/wgldisplay/wglGraphicsWindow.cxx b/panda/src/wgldisplay/wglGraphicsWindow.cxx index 614cf00103..f01b2f1c9a 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.cxx +++ b/panda/src/wgldisplay/wglGraphicsWindow.cxx @@ -620,6 +620,31 @@ void wglGraphicsWindow::config() { if (wgldisplay_cat.is_spam()) wgldisplay_cat.spam() << "GL extensions: " << _extensions_str << endl; + if(gl_swapbuffer_framelock) { + // utilize HW-assisted framelocking if available (3dLabs ext) + WGLENABLEFRAMELOCKI3DFUNCPTR wglEnableFrameLock = (WGLENABLEFRAMELOCKI3DFUNCPTR) wglGetProcAddress("wglEnableFrameLockI3D"); + + if(wglEnableFrameLock==NULL) { + wgldisplay_cat.fatal() << "wglEnableFrameLockI3D not found in OpenGL ICD, cannot implement gl-swapbuffer-framelock!\n"; + exit(1); + } else { + BOOL result = wglEnableFrameLock(); + if(!result) { + wgldisplay_cat.fatal() << "wglEnableFrameLockI3D failed, error=" << GetLastError() << endl; + exit(1); + } + } + + if(wgldisplay_cat.is_debug()) { + WGLQUERYFRAMELOCKMASTERI3DFUNCPTR wglQueryFrameLockMasterI3D = (WGLQUERYFRAMELOCKMASTERI3DFUNCPTR) wglGetProcAddress("wglQueryFrameLockMasterI3D"); + BOOL bIsMaster; + if((wglQueryFrameLockMasterI3D!=NULL) && wglQueryFrameLockMasterI3D(&bIsMaster)) + wgldisplay_cat.debug() << "SwapBuffer Frame-locking Enabled, HW wired as framelock " << (bIsMaster ? "Master" : "Slave") << endl; + } + + gl_sync_video=true; // you want gl_sync_video if you want framelock, right? + } + if (gl_sync_video) { // set swapbuffers to swap no more than once per monitor refresh // note sometimes the ICD advertises this ext, but it still doesn't seem to work diff --git a/panda/src/wgldisplay/wglext.h b/panda/src/wgldisplay/wglext.h index e9ca423884..4d1fe5a6a0 100644 --- a/panda/src/wgldisplay/wglext.h +++ b/panda/src/wgldisplay/wglext.h @@ -391,6 +391,21 @@ typedef void * (APIENTRY * PFNWGLALLOCATEMEMORYNVPROC) (int size, float readfreq typedef void (APIENTRY * PFNWGLFREEMEMORYNVPROC) (void *pointer); #endif +// added from 3dlabs glext.h +/* + * Constants and typedefs for the WGL swap_frame_usage extension. + */ +typedef BOOL (APIENTRY *WGLGETFRAMEUSAGEI3DFUNCPTR)(float *); + + +/* + * Constants and typedefs for the WGL swap_frame_lock extension. + */ +typedef BOOL (APIENTRY *WGLENABLEFRAMELOCKI3DFUNCPTR)(VOID); +typedef BOOL (APIENTRY *WGLDISABLEFRAMELOCKI3DFUNCPTR)(VOID); +typedef BOOL (APIENTRY *WGLISENABLEDFRAMELOCKI3DFUNCPTR)(BOOL *); +typedef BOOL (APIENTRY *WGLQUERYFRAMELOCKMASTERI3DFUNCPTR)(BOOL *); + #ifdef __cplusplus }