diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 08a9a39d68..b0b017a826 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -76,10 +76,12 @@ GLBackend::GLBackend() : _output() { initTransform(); + initInput(); } GLBackend::~GLBackend() { killTransform(); + killInput(); } void GLBackend::render(Batch& batch) { diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index 3551953998..dc6c3b64ed 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -200,7 +200,9 @@ protected: void do_setInputFormat(Batch& batch, uint32 paramOffset); void do_setInputBuffer(Batch& batch, uint32 paramOffset); void do_setIndexBuffer(Batch& batch, uint32 paramOffset); - + + void initInput(); + void killInput(); void updateInput(); struct InputStageState { bool _invalidFormat; @@ -238,7 +240,7 @@ protected: void do_setModelTransform(Batch& batch, uint32 paramOffset); void do_setViewTransform(Batch& batch, uint32 paramOffset); void do_setProjectionTransform(Batch& batch, uint32 paramOffset); - + void initTransform(); void killTransform(); void updateTransform(); diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index fcaa28aaaa..8ae4f9cf0a 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -46,6 +46,18 @@ static const GLenum attributeSlotToClassicAttribName[NUM_CLASSIC_ATTRIBS] = { }; #endif +void GLBackend::initInput() { + killInput(); +} + +void GLBackend::killInput() { + // Disable client states and set buffers to 0 + _input._format = Stream::FormatPointer(new Stream::Format()); + _input._attributeActivation.set(); + updateInput(); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} + void GLBackend::updateInput() { if (_input._invalidFormat || _input._buffersState.any()) { @@ -69,8 +81,7 @@ void GLBackend::updateInput() { if (i < NUM_CLASSIC_ATTRIBS) { if (newState) { glEnableClientState(attributeSlotToClassicAttribName[i]); - } - else { + } else { glDisableClientState(attributeSlotToClassicAttribName[i]); } } else { @@ -147,6 +158,9 @@ void GLBackend::updateInput() { } } } + } else { + glBindBuffer(GL_ARRAY_BUFFER, 0); + (void) CHECK_GL_ERROR(); } // everything format related should be in sync now _input._invalidFormat = false; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 83301b6a6f..f7280fc0ec 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -296,12 +296,6 @@ void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, in } else { batch.drawIndexed(gpu::LINES, indices); } - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); - batch._glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderCone(float base, float height, int slices, int stacks) { @@ -483,11 +477,6 @@ void GeometryCache::renderGrid(gpu::Batch& batch, int xDivisions, int yDivisions batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.draw(gpu::LINES, vertices, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { @@ -595,11 +584,6 @@ void GeometryCache::renderGrid(gpu::Batch& batch, int x, int y, int width, int h batch.setInputBuffer(VERTICES_SLOT, verticesView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.draw(gpu::LINES, vertices, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { @@ -809,11 +793,6 @@ void GeometryCache::renderVertices(gpu::Batch& batch, gpu::Primitive primitiveTy batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(primitiveType, details.vertices, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } } @@ -935,12 +914,6 @@ void GeometryCache::renderSolidCube(gpu::Batch& batch, float size, const glm::ve batch.setInputBuffer(COLOR_SLOT, colorView); batch.setIndexBuffer(gpu::UINT8, _solidCubeIndexBuffer, 0); batch.drawIndexed(gpu::TRIANGLES, indices); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); - batch._glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderWireCube(float size, const glm::vec4& color) { @@ -1024,12 +997,6 @@ void GeometryCache::renderWireCube(gpu::Batch& batch, float size, const glm::vec batch.setInputBuffer(COLOR_SLOT, colorView); batch.setIndexBuffer(gpu::UINT8, _wireCubeIndexBuffer, 0); batch.drawIndexed(gpu::LINES, indices); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); - batch._glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { @@ -1134,11 +1101,6 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { @@ -1216,11 +1178,6 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, @@ -1309,12 +1266,6 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, co batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_TEXTURE_COORD_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { @@ -1392,11 +1343,6 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, co batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, @@ -1497,18 +1443,10 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, cons details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer); details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); } - - batch._glEnable(GL_TEXTURE_2D); batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::QUADS, 4, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_TEXTURE_COORD_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { @@ -1620,11 +1558,6 @@ void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, details.vertices, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } @@ -1765,11 +1698,6 @@ void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, 2, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { @@ -1860,11 +1788,6 @@ void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); batch.draw(gpu::LINES, 2, 0); - - batch._glDisableClientState(GL_VERTEX_ARRAY); - batch._glDisableClientState(GL_COLOR_ARRAY); - - batch._glBindBuffer(GL_ARRAY_BUFFER, 0); }