Implement concurrent rendering in OpenGL in Windows. (D3D already

worked.)  It's still off by default.
This commit is contained in:
Glenn Maynard
2006-01-17 01:27:29 +00:00
parent a96b8fa350
commit 8c78a40703
2 changed files with 46 additions and 0 deletions
@@ -9,6 +9,7 @@
static PIXELFORMATDESCRIPTOR g_CurrentPixelFormat; static PIXELFORMATDESCRIPTOR g_CurrentPixelFormat;
static HGLRC g_HGLRC = NULL; static HGLRC g_HGLRC = NULL;
static HGLRC g_HGLRC_Background = NULL;
void DestroyGraphicsWindowAndOpenGLContext() void DestroyGraphicsWindowAndOpenGLContext()
{ {
@@ -19,6 +20,12 @@ void DestroyGraphicsWindowAndOpenGLContext()
g_HGLRC = NULL; g_HGLRC = NULL;
} }
if( g_HGLRC_Background != NULL )
{
wglDeleteContext( g_HGLRC_Background );
g_HGLRC_Background = NULL;
}
ZERO( g_CurrentPixelFormat ); ZERO( g_CurrentPixelFormat );
GraphicsWindow::DestroyGraphicsWindow(); GraphicsWindow::DestroyGraphicsWindow();
@@ -36,6 +43,7 @@ void *LowLevelWindow_Win32::GetProcAddress( CString s )
LowLevelWindow_Win32::LowLevelWindow_Win32() LowLevelWindow_Win32::LowLevelWindow_Win32()
{ {
ASSERT( g_HGLRC == NULL ); ASSERT( g_HGLRC == NULL );
ASSERT( g_HGLRC_Background == NULL );
GraphicsWindow::Initialize( false ); GraphicsWindow::Initialize( false );
} }
@@ -173,6 +181,8 @@ CString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNew
wglMakeCurrent( NULL, NULL ); wglMakeCurrent( NULL, NULL );
wglDeleteContext( g_HGLRC ); wglDeleteContext( g_HGLRC );
g_HGLRC = NULL; g_HGLRC = NULL;
wglDeleteContext( g_HGLRC_Background );
g_HGLRC_Background = NULL;
} }
bNewDeviceOut = true; bNewDeviceOut = true;
@@ -207,6 +217,20 @@ CString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNew
return hr_ssprintf( GetLastError(), "wglCreateContext" ); 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 ) ) if( !wglMakeCurrent( GraphicsWindow::GetHDC(), g_HGLRC ) )
{ {
DestroyGraphicsWindowAndOpenGLContext(); DestroyGraphicsWindowAndOpenGLContext();
@@ -216,6 +240,25 @@ CString LowLevelWindow_Win32::TryVideoMode( const VideoModeParams &p, bool &bNew
return CString(); // we set the video mode successfully 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 ) bool LowLevelWindow_Win32::IsSoftwareRenderer( CString &sError )
{ {
if( strcmp((const char*)glGetString(GL_VENDOR),"Microsoft Corporation") && if( strcmp((const char*)glGetString(GL_VENDOR),"Microsoft Corporation") &&
@@ -14,6 +14,9 @@ public:
bool IsSoftwareRenderer( CString &sError ); bool IsSoftwareRenderer( CString &sError );
void SwapBuffers(); void SwapBuffers();
void Update(); void Update();
bool SupportsThreadedRendering();
void BeginConcurrentRendering();
void EndConcurrentRendering();
VideoModeParams GetActualVideoModeParams() const; VideoModeParams GetActualVideoModeParams() const;
}; };