From d49018df63186b0779b71e075a40f184bf0c8843 Mon Sep 17 00:00:00 2001 From: LuisAntonRebollo Date: Fri, 5 Dec 2014 22:56:22 +0100 Subject: [PATCH] Fix GLCircularVolatileBuffer incorrect binding. --- .../gfx/gl/gfxGLCircularVolatileBuffer.h | 18 +++++++++--------- Engine/source/gfx/gl/gfxGLUtils.h | 7 +++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Engine/source/gfx/gl/gfxGLCircularVolatileBuffer.h b/Engine/source/gfx/gl/gfxGLCircularVolatileBuffer.h index b2749fe2e..6524a75f5 100644 --- a/Engine/source/gfx/gl/gfxGLCircularVolatileBuffer.h +++ b/Engine/source/gfx/gl/gfxGLCircularVolatileBuffer.h @@ -143,7 +143,7 @@ public: { glGenBuffers(1, &mBufferName); - PRESERVE_VERTEX_BUFFER(); + PRESERVE_BUFFER( mBinding ); glBindBuffer(mBinding, mBufferName); const U32 cSizeInMB = 10; @@ -195,11 +195,11 @@ public: } else if( GFXGL->glUseMap() ) { - PRESERVE_VERTEX_BUFFER(); - glBindBuffer(GL_ARRAY_BUFFER, mBufferName); + PRESERVE_BUFFER( mBinding ); + glBindBuffer(mBinding, mBufferName); const GLbitfield access = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT; - outPtr = glMapBufferRange(GL_ARRAY_BUFFER, outOffset, size, access); + outPtr = glMapBufferRange(mBinding, outOffset, size, access); } else { @@ -224,15 +224,15 @@ public: } else if( GFXGL->glUseMap() ) { - PRESERVE_VERTEX_BUFFER(); - glBindBuffer(GL_ARRAY_BUFFER, mBufferName); + PRESERVE_BUFFER( mBinding ); + glBindBuffer(mBinding, mBufferName); - glUnmapBuffer(GL_ARRAY_BUFFER); + glUnmapBuffer(mBinding); } else { - PRESERVE_VERTEX_BUFFER(); - glBindBuffer(GL_ARRAY_BUFFER, mBufferName); + PRESERVE_BUFFER( mBinding ); + glBindBuffer(mBinding, mBufferName); glBufferSubData( mBinding, _getBufferData.mOffset, _getBufferData.mSize, mFrameAllocator.getlockedPtr() ); diff --git a/Engine/source/gfx/gl/gfxGLUtils.h b/Engine/source/gfx/gl/gfxGLUtils.h index 881348043..d1cec52a8 100644 --- a/Engine/source/gfx/gl/gfxGLUtils.h +++ b/Engine/source/gfx/gl/gfxGLUtils.h @@ -182,6 +182,13 @@ GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_ARRAY_BUFFER, GL_ARR #define PRESERVE_INDEX_BUFFER() \ GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (GL_ELEMENT_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER_BINDING, (GFXGLPreserveInteger::BindFn)glBindBuffer) +#define _GET_BUFFER_BINDING( BINDING ) \ +BINDING == GL_ARRAY_BUFFER ? GL_ARRAY_BUFFER_BINDING : ( BINDING == GL_ELEMENT_ARRAY_BUFFER ? GL_ELEMENT_ARRAY_BUFFER_BINDING : 0 ) + +/// Helper macro to preserve the current element array binding. +#define PRESERVE_BUFFER( BINDING ) \ +GFXGLPreserveInteger TORQUE_CONCAT(preserve_, __LINE__) (BINDING, _GET_BUFFER_BINDING(BINDING), (GFXGLPreserveInteger::BindFn)glBindBuffer) + /// ASSERT: Never call glActiveTexture for a "bind to modify" or in a PRESERVER_TEXTURE MACRO scope. /// Helper macro to preserve the current 1D texture binding.