From 8c78a40703e59b2c0793a98b39bdd2cefd9d6d93 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 17 Jan 2006 01:27:29 +0000 Subject: [PATCH] Implement concurrent rendering in OpenGL in Windows. (D3D already worked.) It's still off by default. --- .../LowLevelWindow/LowLevelWindow_Win32.cpp | 43 +++++++++++++++++++ .../LowLevelWindow/LowLevelWindow_Win32.h | 3 ++ 2 files changed, 46 insertions(+) diff --git a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp index 8df095c278..2d4a141b06 100644 --- a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp +++ b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp @@ -9,6 +9,7 @@ static PIXELFORMATDESCRIPTOR g_CurrentPixelFormat; static HGLRC g_HGLRC = NULL; +static HGLRC g_HGLRC_Background = NULL; void DestroyGraphicsWindowAndOpenGLContext() { @@ -19,6 +20,12 @@ void DestroyGraphicsWindowAndOpenGLContext() g_HGLRC = NULL; } + if( g_HGLRC_Background != NULL ) + { + wglDeleteContext( g_HGLRC_Background ); + g_HGLRC_Background = NULL; + } + ZERO( g_CurrentPixelFormat ); GraphicsWindow::DestroyGraphicsWindow(); @@ -36,6 +43,7 @@ void *LowLevelWindow_Win32::GetProcAddress( CString s ) LowLevelWindow_Win32::LowLevelWindow_Win32() { ASSERT( g_HGLRC == NULL ); + ASSERT( g_HGLRC_Background == NULL ); GraphicsWindow::Initialize( false ); } @@ -173,6 +181,8 @@ CString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNew wglMakeCurrent( NULL, NULL ); wglDeleteContext( g_HGLRC ); g_HGLRC = NULL; + wglDeleteContext( g_HGLRC_Background ); + g_HGLRC_Background = NULL; } bNewDeviceOut = true; @@ -207,6 +217,20 @@ CString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNew return hr_ssprintf( GetLastError(), "wglCreateContext" ); } + g_HGLRC_Background = wglCreateContext( GraphicsWindow::GetHDC() ); + if( g_HGLRC_Background == NULL ) + { + DestroyGraphicsWindowAndOpenGLContext(); + return hr_ssprintf( GetLastError(), "wglCreateContext" ); + } + + if( !wglShareLists(g_HGLRC, g_HGLRC_Background) ) + { + LOG->Warn( werr_ssprintf(GetLastError(), "wglShareLists failed") ); + wglDeleteContext( g_HGLRC_Background ); + g_HGLRC_Background = NULL; + } + if( !wglMakeCurrent( GraphicsWindow::GetHDC(), g_HGLRC ) ) { DestroyGraphicsWindowAndOpenGLContext(); @@ -216,6 +240,25 @@ CString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNew return CString(); // we set the video mode successfully } +bool LowLevelWindow_Win32::SupportsThreadedRendering() +{ + return g_HGLRC_Background != NULL; +} + +void LowLevelWindow_Win32::BeginConcurrentRendering() +{ + if( !wglMakeCurrent( GraphicsWindow::GetHDC(), g_HGLRC_Background ) ) + { + LOG->Warn( hr_ssprintf(GetLastError(), "wglMakeCurrent") ); + FAIL_M( hr_ssprintf(GetLastError(), "wglMakeCurrent") ); + } +} + +void LowLevelWindow_Win32::EndConcurrentRendering() +{ + wglMakeCurrent( NULL, NULL ); +} + bool LowLevelWindow_Win32::IsSoftwareRenderer( CString &sError ) { if( strcmp((const char*)glGetString(GL_VENDOR),"Microsoft Corporation") && diff --git a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.h b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.h index b39d45e6db..3eb501c720 100644 --- a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.h +++ b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.h @@ -14,6 +14,9 @@ public: bool IsSoftwareRenderer( CString &sError ); void SwapBuffers(); void Update(); + bool SupportsThreadedRendering(); + void BeginConcurrentRendering(); + void EndConcurrentRendering(); VideoModeParams GetActualVideoModeParams() const; };