Skip to content

Commit

Permalink
use UBOBindingsSaver when rendering in Pixar's batch renderer
Browse files Browse the repository at this point in the history
With UBOBindingsSaver now available from px_vp20/utils, this change uses that
class to wrap the Hydra Execute() call made during rendering.
  • Loading branch information
mattyjams committed Feb 20, 2020
1 parent 32def62 commit 35a6a0f
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions lib/render/pxrUsdMayaGL/batchRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "./debugCodes.h"
#include "./userData.h"

#include "../px_vp20/utils.h"
#include "../px_vp20/utils_legacy.h"
#include "mayaUsd/render/px_vp20/utils.h"
#include "mayaUsd/render/px_vp20/utils_legacy.h"

#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/vec2i.h"
Expand Down Expand Up @@ -1294,27 +1294,7 @@ UsdMayaGLBatchRenderer::_Render(
GL_DEPTH_BUFFER_BIT |
GL_VIEWPORT_BIT);

// XXX: When Maya is using OpenGL Core Profile as the rendering engine (in
// either compatibility or strict mode), batch renders like those done in
// the "Render View" window or through the ogsRender command do not
// properly track uniform buffer binding state. This was causing issues
// where the first batch render performed would look correct, but then all
// subsequent renders done in that Maya session would be completely black
// (no alpha), even if the frame contained only Maya-native geometry or if
// a new scene was created/opened.
//
// To avoid this problem, we need to save and restore Maya's bindings
// across Hydra calls. We try not to bog down performance by saving and
// restoring *all* GL_MAX_UNIFORM_BUFFER_BINDINGS possible bindings, so
// instead we only do just enough to avoid issues. Empirically, the
// problematic binding has been the material binding at index 4.
static constexpr size_t _UNIFORM_BINDINGS_TO_SAVE = 5u;
std::vector<GLint> uniformBufferBindings(_UNIFORM_BINDINGS_TO_SAVE, 0);
for (size_t i = 0u; i < uniformBufferBindings.size(); ++i) {
glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING,
(GLuint)i,
&uniformBufferBindings[i]);
}
UBOBindingsSaver bindingsSaver;

// hydra orients all geometry during topological processing so that
// front faces have ccw winding. We disable culling because culling
Expand Down Expand Up @@ -1374,13 +1354,6 @@ UsdMayaGLBatchRenderer::_Render(

glDisable(GL_FRAMEBUFFER_SRGB_EXT);

// XXX: Restore Maya's uniform buffer binding state. See above for details.
for (size_t i = 0u; i < uniformBufferBindings.size(); ++i) {
glBindBufferBase(GL_UNIFORM_BUFFER,
(GLuint)i,
uniformBufferBindings[i]);
}

glPopAttrib(); // GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT |
// GL_DEPTH_BUFFER_BIT | GL_VIEWPORT_BIT
}
Expand Down

0 comments on commit 35a6a0f

Please sign in to comment.