From 34d692330e381cef5d82c8223ec0e546267221d2 Mon Sep 17 00:00:00 2001 From: Michael Rennie Date: Wed, 26 Apr 2017 10:47:08 +0100 Subject: [PATCH] Only create client memory VBOs the first time context is activated. Also added corresponding deletion code in WrappedOpenGL::DeleteContext. --- renderdoc/driver/gl/gl_driver.cpp | 27 ++++++++++++++++++--------- renderdoc/driver/gl/gl_driver.h | 1 + 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/renderdoc/driver/gl/gl_driver.cpp b/renderdoc/driver/gl/gl_driver.cpp index b7e5156ec..a84ad15e1 100644 --- a/renderdoc/driver/gl/gl_driver.cpp +++ b/renderdoc/driver/gl/gl_driver.cpp @@ -1099,6 +1099,9 @@ void WrappedOpenGL::DeleteContext(void *contextHandle) m_Real.glDeleteTextures(1, &ctxdata.GlyphTexture); } + if(ctxdata.m_ClientMemoryVBOs[0]) + glDeleteBuffers(ARRAY_COUNT(ctxdata.m_ClientMemoryVBOs), ctxdata.m_ClientMemoryVBOs); + for(auto it = m_LastContexts.begin(); it != m_LastContexts.end(); ++it) { if(it->ctx == contextHandle) @@ -1471,6 +1474,21 @@ void WrappedOpenGL::ActivateContext(GLWindowingData winData) DoVendorChecks(gl, m_Platform, winData); } } + + if(m_State >= WRITING) + { + GLuint prevArrayBuffer = 0; + glGetIntegerv(eGL_ARRAY_BUFFER_BINDING, (GLint *)&prevArrayBuffer); + + // Initialize VBOs used in case we copy from client memory. + glGenBuffers(ARRAY_COUNT(ctxdata.m_ClientMemoryVBOs), ctxdata.m_ClientMemoryVBOs); + for(size_t i = 0; i < ARRAY_COUNT(ctxdata.m_ClientMemoryVBOs); i++) + { + glBindBuffer(eGL_ARRAY_BUFFER, ctxdata.m_ClientMemoryVBOs[i]); + glBufferData(eGL_ARRAY_BUFFER, 64, NULL, eGL_DYNAMIC_DRAW); + } + glBindBuffer(eGL_ARRAY_BUFFER, prevArrayBuffer); + } } if(m_State >= WRITING) @@ -1478,15 +1496,6 @@ void WrappedOpenGL::ActivateContext(GLWindowingData winData) m_Internal = m_Real; glEmulate::EmulateRequiredExtensions(&m_Real, &m_Internal); - - // Initialize VBOs used in case we copy from client memory. - glGenBuffers(ARRAY_COUNT(ctxdata.m_ClientMemoryVBOs), ctxdata.m_ClientMemoryVBOs); - for(size_t i = 0; i < ARRAY_COUNT(ctxdata.m_ClientMemoryVBOs); i++) - { - glBindBuffer(eGL_ARRAY_BUFFER, ctxdata.m_ClientMemoryVBOs[i]); - glBufferData(eGL_ARRAY_BUFFER, 64, NULL, eGL_DYNAMIC_DRAW); - } - glBindBuffer(eGL_ARRAY_BUFFER, 0); } } } diff --git a/renderdoc/driver/gl/gl_driver.h b/renderdoc/driver/gl/gl_driver.h index 2ef74f672..e3dc2bbab 100644 --- a/renderdoc/driver/gl/gl_driver.h +++ b/renderdoc/driver/gl/gl_driver.h @@ -389,6 +389,7 @@ private: m_Renderbuffer = ResourceId(); m_TextureUnit = 0; m_ProgramPipeline = m_Program = 0; + RDCEraseEl(m_ClientMemoryVBOs); } void *ctx;