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.
This commit is contained in:
baldurk
2015-02-24 23:03:55 +00:00
parent 07d65b8f9a
commit cf24cb4ff5
2 changed files with 19 additions and 0 deletions
+15
View File
@@ -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);
}
}
+4
View File
@@ -131,6 +131,10 @@ class WrappedOpenGL
map<uint64_t, GLWindowingData> m_ActiveContexts;
// we use this context if we need one e.g. for fetching initial states
// if no context is current
map<uint64_t, GLWindowingData> m_DefaultContexts;
bool m_ActiveQueries[8][8]; // first index type, second index (for some, always 0)
bool m_ActiveConditional;
bool m_ActiveFeedback;