From 5dafea7c06acc876024252ad0a62355244019223 Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Wed, 9 Apr 2014 21:23:22 -0700 Subject: [PATCH] avoid allocations in renderer (messes up AMD buggy OpenGL driver) add missing file in cmake build system (BroadphaseCollision/b3GpuParallelLinearBvhBroadphase.cpp and BroadphaseCollision/b3GpuParallelLinearBvh.cpp) --- .../opengl_fontstashcallbacks.cpp | 1 + btgui/OpenGLWindow/GLInstancingRenderer.cpp | 14 ++++++++++++-- btgui/OpenGLWindow/GLPrimitiveRenderer.cpp | 4 ++-- src/Bullet3OpenCL/CMakeLists.txt | 2 ++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/btgui/OpenGLTrueTypeFont/opengl_fontstashcallbacks.cpp b/btgui/OpenGLTrueTypeFont/opengl_fontstashcallbacks.cpp index e1554bf08..1ef12906f 100644 --- a/btgui/OpenGLTrueTypeFont/opengl_fontstashcallbacks.cpp +++ b/btgui/OpenGLTrueTypeFont/opengl_fontstashcallbacks.cpp @@ -220,6 +220,7 @@ void InternalOpenGL2RenderCallbacks::render(sth_texture* texture) glBindBuffer(GL_ARRAY_BUFFER, s_vertexBuffer); glBindVertexArray(s_vertexArrayObject); glBufferData(GL_ARRAY_BUFFER, texture->nverts * sizeof(Vertex), &texture->newverts[0].position.p[0], GL_DYNAMIC_DRAW); + err = glGetError(); assert(err==GL_NO_ERROR); diff --git a/btgui/OpenGLWindow/GLInstancingRenderer.cpp b/btgui/OpenGLWindow/GLInstancingRenderer.cpp index ecf66c6a8..6097a9f88 100644 --- a/btgui/OpenGLWindow/GLInstancingRenderer.cpp +++ b/btgui/OpenGLWindow/GLInstancingRenderer.cpp @@ -742,6 +742,12 @@ void GLInstancingRenderer::InitShaders() glGenBuffers(1, &lineVertexBufferObject); glGenBuffers(1, &lineIndexVbo); + + int sz = 8*sizeof(float); + glBindVertexArray(lineVertexArrayObject); + glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject); + glBufferData(GL_ARRAY_BUFFER, sz, 0, GL_DYNAMIC_DRAW); + glBindVertexArray(0); @@ -1456,8 +1462,12 @@ void GLInstancingRenderer::drawLine(const float from[4], const float to[4], cons err = glGetError(); b3Assert(err==GL_NO_ERROR); - glBufferData(GL_ARRAY_BUFFER, sz, vertexPositions, GL_STATIC_DRAW); - + + { + glBufferSubData(GL_ARRAY_BUFFER, 0,sz, vertexPositions); + } + + err = glGetError(); b3Assert(err==GL_NO_ERROR); diff --git a/btgui/OpenGLWindow/GLPrimitiveRenderer.cpp b/btgui/OpenGLWindow/GLPrimitiveRenderer.cpp index a3024a21e..e1c424659 100644 --- a/btgui/OpenGLWindow/GLPrimitiveRenderer.cpp +++ b/btgui/OpenGLWindow/GLPrimitiveRenderer.cpp @@ -130,7 +130,7 @@ void GLPrimitiveRenderer::loadBufferData() glGenBuffers(1, &m_data->m_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vertexBuffer); - glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(Vertex), vertexData, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(Vertex), vertexData, GL_DYNAMIC_DRAW); GLuint err = glGetError(); assert(err==GL_NO_ERROR); @@ -269,7 +269,7 @@ void GLPrimitiveRenderer::drawTexturedRect(float x0, float y0, float x1, float y { vec4( -1.+2.*x1/float(m_screenWidth), 1.-2.*y0/float(m_screenHeight), 1, 0 ), vec4( color[0], color[1], color[2], color[3] ) ,vec2(u1,v0)} }; - glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(Vertex), vertexData, GL_STATIC_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0,4 * sizeof(Vertex), vertexData); diff --git a/src/Bullet3OpenCL/CMakeLists.txt b/src/Bullet3OpenCL/CMakeLists.txt index d7d43df04..286822272 100644 --- a/src/Bullet3OpenCL/CMakeLists.txt +++ b/src/Bullet3OpenCL/CMakeLists.txt @@ -6,6 +6,8 @@ SET(Bullet3OpenCL_clew_SRCS ../clew/clew.c BroadphaseCollision/b3GpuGridBroadphase.cpp BroadphaseCollision/b3GpuSapBroadphase.cpp + BroadphaseCollision/b3GpuParallelLinearBvhBroadphase.cpp + BroadphaseCollision/b3GpuParallelLinearBvh.cpp Initialize/b3OpenCLUtils.cpp NarrowphaseCollision/b3ContactCache.cpp NarrowphaseCollision/b3ConvexHullContact.cpp