From cf24cb4ff52453df4dd5c68cbfa6134d06604070 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 24 Feb 2015 23:03:55 +0000 Subject: [PATCH] Semi-hack, make last known context current if NULL is current on cap * We need a context to be current when the frame capture happens so that we can fetch initial contents and such. This is a hack as there's no guarantee it's correct or will work, but we temporarily make the last context that was active on this thread active again, to fetch our data. * This could break if that context is active elsewhere, or isn't a valid context (ie. maybe it was a temporary context used to fetch func pointers). * A better fix would be to delay any GL work we need to do until the next time a good context becomes current, but that becomes dicey in itself. --- renderdoc/driver/gl/gl_driver.cpp | 15 +++++++++++++++ renderdoc/driver/gl/gl_driver.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/renderdoc/driver/gl/gl_driver.cpp b/renderdoc/driver/gl/gl_driver.cpp index 32c768079..ab120fd00 100644 --- a/renderdoc/driver/gl/gl_driver.cpp +++ b/renderdoc/driver/gl/gl_driver.cpp @@ -968,6 +968,9 @@ void WrappedOpenGL::CreateContext(GLWindowingData winData, void *shareContext, G void WrappedOpenGL::ActivateContext(GLWindowingData winData) { m_ActiveContexts[Threading::GetCurrentID()] = winData; + if(winData.ctx) + m_DefaultContexts[Threading::GetCurrentID()] = winData; + // TODO: support multiple GL contexts more explicitly Keyboard::AddInputWindow((void *)winData.wnd); @@ -1895,6 +1898,15 @@ void WrappedOpenGL::Present(void *windowHandle) { m_State = WRITING_CAPFRAME; + GLWindowingData &prevctx = m_ActiveContexts[Threading::GetCurrentID()]; + + bool switchedContext = false; + if(prevctx.ctx == NULL) + { + MakeContextCurrent(m_DefaultContexts[Threading::GetCurrentID()]); + switchedContext = true; + } + FetchFrameRecord record; record.frameInfo.frameNumber = m_FrameCounter+1; record.frameInfo.captureTime = Timing::GetUnixTimestamp(); @@ -1908,6 +1920,9 @@ void WrappedOpenGL::Present(void *windowHandle) AttemptCapture(); BeginCaptureFrame(); + if(switchedContext) + MakeContextCurrent(prevctx); + RDCLOG("Starting capture, frame %u", m_FrameCounter); } } diff --git a/renderdoc/driver/gl/gl_driver.h b/renderdoc/driver/gl/gl_driver.h index dbc6345dd..e9f7e9e85 100644 --- a/renderdoc/driver/gl/gl_driver.h +++ b/renderdoc/driver/gl/gl_driver.h @@ -131,6 +131,10 @@ class WrappedOpenGL map m_ActiveContexts; + // we use this context if we need one e.g. for fetching initial states + // if no context is current + map m_DefaultContexts; + bool m_ActiveQueries[8][8]; // first index type, second index (for some, always 0) bool m_ActiveConditional; bool m_ActiveFeedback;