diff --git a/renderdoc/driver/gl/gl_driver.cpp b/renderdoc/driver/gl/gl_driver.cpp index 192e01de9..cbb073a0a 100644 --- a/renderdoc/driver/gl/gl_driver.cpp +++ b/renderdoc/driver/gl/gl_driver.cpp @@ -705,6 +705,12 @@ WrappedOpenGL::WrappedOpenGL(const char *logfile, const GLHookSet &funcs) m_ContextRecord->NumSubResources = 0; m_ContextRecord->SpecialResource = true; m_ContextRecord->SubResources = NULL; + + // register VAO 0 as a special VAO, so that it can be tracked if the app uses it + // we immediately mark it dirty since the vertex array tracking functions expect a proper VAO + m_FakeVAOID = GetResourceManager()->RegisterResource(VertexArrayRes(NULL, 0)); + GetResourceManager()->AddResourceRecord(m_FakeVAOID); + GetResourceManager()->MarkDirtyResource(m_FakeVAOID); } else { @@ -1563,6 +1569,7 @@ void WrappedOpenGL::Present(void *windowHandle) SCOPED_SERIALISE_CONTEXT(DEVICE_INIT); SERIALISE_ELEMENT(ResourceId, immContextId, m_ContextResourceID); + SERIALISE_ELEMENT(ResourceId, vaoId, m_FakeVAOID); m_pFileSerialiser->Insert(scope.Get(true)); } @@ -2012,8 +2019,10 @@ void WrappedOpenGL::ProcessChunk(uint64_t offset, GLChunkType context) case DEVICE_INIT: { SERIALISE_ELEMENT(ResourceId, immContextId, ResourceId()); + SERIALISE_ELEMENT(ResourceId, vaoId, ResourceId()); - m_ResourceManager->AddLiveResource(immContextId, GLResource(NULL, eResSpecial, eSpecialResContext)); + GetResourceManager()->AddLiveResource(immContextId, GLResource(NULL, eResSpecial, eSpecialResContext)); + GetResourceManager()->AddLiveResource(vaoId, VertexArrayRes(NULL, 0)); break; } case GEN_TEXTURE: diff --git a/renderdoc/driver/gl/gl_driver.h b/renderdoc/driver/gl/gl_driver.h index 1c4043910..3bead2260 100644 --- a/renderdoc/driver/gl/gl_driver.h +++ b/renderdoc/driver/gl/gl_driver.h @@ -256,6 +256,8 @@ class WrappedOpenGL GLuint m_FakeBB_Color; GLuint m_FakeBB_DepthStencil; GLuint m_FakeVAO; + + ResourceId m_FakeVAOID; bool m_DoStateVerify; //GLRenderState *m_CurrentPipelineState; diff --git a/renderdoc/driver/gl/gl_manager.cpp b/renderdoc/driver/gl/gl_manager.cpp index ce0746513..d13e6a043 100644 --- a/renderdoc/driver/gl/gl_manager.cpp +++ b/renderdoc/driver/gl/gl_manager.cpp @@ -492,7 +492,7 @@ bool GLResourceManager::Prepare_InitialState(GLResource res) // need to be on the right context, as VAOs are never shared void *oldctx = NULL; - if(!VendorCheck[VendorCheck_EXT_vao_shared]) + if(!VendorCheck[VendorCheck_EXT_vao_shared] && res.Context) oldctx = m_GL->SwitchToContext(res.Context); GLuint prevVAO = 0; @@ -531,7 +531,7 @@ bool GLResourceManager::Prepare_InitialState(GLResource res) gl.glBindVertexArray(prevVAO); // restore the previous context - if(!VendorCheck[VendorCheck_EXT_vao_shared]) + if(!VendorCheck[VendorCheck_EXT_vao_shared] && res.Context) m_GL->SwitchToContext(oldctx); } else @@ -1325,11 +1325,14 @@ void GLResourceManager::Apply_InitialState(GLResource live, InitialContentData i { GLuint VAO = 0; gl.glGetIntegerv(eGL_VERTEX_ARRAY_BINDING, (GLint *)&VAO); - - gl.glBindVertexArray(live.name); - + VAOInitialData *initialdata = (VAOInitialData *)initial.blob; + if(live.name == 0) + gl.glBindVertexArray(m_GL->GetFakeVAO()); + else + gl.glBindVertexArray(live.name); + for(GLuint i=0; i < 16; i++) { VertexAttribInitialData &attrib = initialdata->VertexAttribs[i];