From 1d0dab45daa8c0ea430cd269ff1d2335cd41a6e7 Mon Sep 17 00:00:00 2001 From: BearOso Date: Wed, 22 Feb 2023 19:14:05 -0600 Subject: [PATCH] win32: Flush message queue between driver changes. --- win32/COpenGL.cpp | 14 +++++++++----- win32/win32_display.cpp | 14 +++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/win32/COpenGL.cpp b/win32/COpenGL.cpp index 152eceb4..9e3ec394 100644 --- a/win32/COpenGL.cpp +++ b/win32/COpenGL.cpp @@ -104,7 +104,7 @@ bool COpenGL::Initialize(HWND hWnd) LoadPBOFunctions(); wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress( "wglSwapIntervalEXT" ); - + glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_BLEND); @@ -113,7 +113,7 @@ bool COpenGL::Initialize(HWND hWnd) glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho (0.0, 1.0, 0.0, 1.0, -1, 1); - + glVertexPointer(2, GL_FLOAT, 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, texcoords); @@ -147,7 +147,11 @@ void COpenGL::DeInitialize() wglDeleteContext(hRC); hRC = NULL; } - hDC = NULL; + if (hDC) + { + ReleaseDC(hWnd, hDC); + hDC = NULL; + } hWnd = NULL; afterRenderWidth = 0; afterRenderHeight = 0; @@ -446,7 +450,7 @@ bool COpenGL::SetFullscreen(bool fullscreen) ChangeDisplaySettings(NULL,0); } - + return true; } @@ -510,7 +514,7 @@ bool COpenGL::LoadPBOFunctions() if(glGenBuffers && glBindBuffer && glBufferData && glDeleteBuffers && glMapBuffer) { pboFunctionsLoaded = true; } - + } return pboFunctionsLoaded; } diff --git a/win32/win32_display.cpp b/win32/win32_display.cpp index 12324697..f8b363b0 100644 --- a/win32/win32_display.cpp +++ b/win32/win32_display.cpp @@ -98,6 +98,15 @@ void WinChangeWindowSize(unsigned int newWidth, unsigned int newHeight) S9xDisplayOutput->ChangeRenderSize(newWidth,newHeight); } +static void FlushMessageQueue() +{ + for (MSG msg; PeekMessage(&msg, GUI.hWnd, 0, 0, PM_NOREMOVE);) + { + GetMessage(&msg, GUI.hWnd, 0, 0); + DispatchMessage(&msg); + } +} + /* WinDisplayReset initializes the currently selected display output and reinitializes the core graphics rendering @@ -107,8 +116,7 @@ returns true if successful, false otherwise bool WinDisplayReset(void) { S9xDisplayOutput->DeInitialize(); - if (S9xDisplayOutput == (IS9xDisplayOutput *)&VulkanDriver && GUI.outputMethod == OPENGL) - Sleep(500); + FlushMessageQueue(); switch(GUI.outputMethod) { default: @@ -238,7 +246,7 @@ bool8 S9xInitUpdate (void) bool8 S9xContinueUpdate(int Width, int Height) { // called every other frame during interlace - + Src.Width = Width; if(Height%SNES_HEIGHT) Src.Height = Height;