Skip to content

Commit

Permalink
GRAPHICS: Update GL state binding in RenderQueue::render
Browse files Browse the repository at this point in the history
  • Loading branch information
mirv-sillyfish authored and DrMcCoy committed Nov 17, 2018
1 parent 2ebdd4a commit 177f11a
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/graphics/render/renderqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ void RenderQueue::render() {
currentProgram = _nodeArray[i].program;
glUseProgram(currentProgram->glid);

if (currentSurface != 0) {
currentSurface->unbindGLState();
}
if (currentMaterial != 0) {
currentMaterial->unbindGLState();
}
Expand All @@ -132,39 +135,53 @@ void RenderQueue::render() {
currentMaterial->unbindGLState();
}
currentMaterial = _nodeArray[i].material;
currentMaterial->bindProgram(currentProgram);
currentMaterial->bindProgramNoFade(currentProgram);
currentMaterial->bindGLState();
}

assert(_nodeArray[i].surface);
assert(_nodeArray[i].mesh);

if (currentSurface != _nodeArray[i].surface) {
if (currentSurface != 0) {
currentSurface->unbindGLState();
}
currentSurface = _nodeArray[i].surface;
currentSurface->bindGLState();
}

currentSurface = _nodeArray[i].surface;
currentMesh = _nodeArray[i].mesh;
currentMesh->renderBind(); // Binds VAO ready for rendering.

// There's at least one mesh to be rendering here.
assert(_nodeArray[i].transform);
currentSurface->bindProgram(currentProgram, _nodeArray[i].transform);
//currentSurface->bindObjectModelview(currentProgram, _nodeArray[i].transform);
currentMaterial->bindFade(currentProgram, _nodeArray[i].alpha);
currentMesh->render();

++i; // Move to next object.
while ((i < limit) && (_nodeArray[i].mesh == currentMesh) && (_nodeArray[i].material == currentMaterial) && (_nodeArray[i].surface == currentSurface)) {
// Next object is basically the same, but will have a different object modelview transform. So rebind that, and render again.
assert(_nodeArray[i].transform);
currentSurface->bindObjectModelview(currentProgram, _nodeArray[i].transform);
currentMaterial->bindFade(currentProgram, _nodeArray[i].alpha);
currentMesh->render();
++i;
}
// Done rendering, unbind the mesh, and onwards into the queue.
currentMesh->renderUnbind();
}
if (currentMaterial) {
currentMaterial->unbindGLState();
}
if (currentSurface) {
currentSurface->unbindGLState();
}

// Restore OpenGL state on exit.
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glUseProgram(0);
glActiveTexture(GL_TEXTURE0);
}

void RenderQueue::clear() {
Expand Down

0 comments on commit 177f11a

Please sign in to comment.