-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows: Pause the rendering thread while switching to full screen
- Loading branch information
Showing
3 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ | |
static HDC hDC; // Private GDI Device Context | ||
static HGLRC hRC; // Permanent Rendering Context | ||
static HWND hWnd; // Holds Our Window Handle | ||
static volatile bool pauseRequested; | ||
static volatile bool resumeRequested; | ||
static HANDLE pauseEvent; | ||
static HANDLE resumeEvent; | ||
|
||
static int xres, yres; | ||
|
||
|
@@ -42,11 +46,47 @@ static bool enableGLDebug = false; | |
void GL_SwapBuffers() { | ||
SwapBuffers(hDC); | ||
|
||
if (pauseRequested) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
hrydgard
Author
Owner
|
||
SetEvent(pauseEvent); | ||
resumeRequested = true; | ||
DWORD result = WaitForSingleObject(resumeEvent, INFINITE); | ||
if (result == WAIT_TIMEOUT) { | ||
ERROR_LOG(G3D, "Wait for resume timed out. Resuming rendering"); | ||
} | ||
pauseRequested = false; | ||
} | ||
|
||
// According to some sources, doing this *after* swapbuffers can reduce frame latency | ||
// at a large performance cost. | ||
// at a large performance cost. So let's not. | ||
// glFinish(); | ||
} | ||
|
||
void GL_Pause() { | ||
if (!hRC) { | ||
return; | ||
} | ||
|
||
pauseRequested = true; | ||
DWORD result = WaitForSingleObject(pauseEvent, INFINITE); | ||
if (result == WAIT_TIMEOUT) { | ||
ERROR_LOG(G3D, "Wait for pause timed out"); | ||
} | ||
// OK, we now know the rendering thread is paused. | ||
} | ||
|
||
void GL_Resume() { | ||
if (!hRC) { | ||
return; | ||
} | ||
|
||
if (!resumeRequested) { | ||
ERROR_LOG(G3D, "Not waiting to get resumed"); | ||
} else { | ||
SetEvent(resumeEvent); | ||
} | ||
resumeRequested = false; | ||
} | ||
|
||
void FormatDebugOutputARB(char outStr[], size_t outStrSize, GLenum source, GLenum type, | ||
GLuint id, GLenum severity, const char *msg) { | ||
char sourceStr[32]; | ||
|
@@ -270,6 +310,14 @@ bool GL_Init(HWND window, std::string *error_message) { | |
glDebugMessageCallbackARB((GLDEBUGPROCARB)&DebugCallbackARB, 0); // print debug output to stderr | ||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); | ||
} | ||
|
||
pauseRequested = false; | ||
resumeRequested = false; | ||
|
||
// These are auto-reset events. | ||
pauseEvent = CreateEvent(NULL, FALSE, FALSE, NULL); | ||
resumeEvent = CreateEvent(NULL, FALSE, FALSE, NULL); | ||
|
||
return true; // Success | ||
} | ||
|
||
|
@@ -280,6 +328,8 @@ void GL_SwapInterval(int interval) { | |
} | ||
|
||
void GL_Shutdown() { | ||
CloseHandle(pauseEvent); | ||
CloseHandle(resumeEvent); | ||
if (hRC) { | ||
// Are we able to release the DC and RC contexts? | ||
if (!wglMakeCurrent(NULL,NULL)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Should probably add a comment here so someone doesn't come along in a few years and say, "who added pausing during rendering? let's delete that nonsense."
-[Unknown]