Skip to content

Commit

Permalink
[UsdImagingGL] Removed more GL specific code from unit tests
Browse files Browse the repository at this point in the history
Updated most of these tests to generate output images
directly from the engine's AOVs.

The remaining exceptions are when testing presentation
output, in which case the output images are still
generated from a client draw target.

This allowed most GL specific code to be removed from
these tests.

The "-clearOnce" option to testUsdImagingGLBasicDrawing
has been renamed to "-presentComposite".

(Internal change: 2256810)
  • Loading branch information
davidgyu authored and pixar-oss committed Dec 8, 2022
1 parent ade8c29 commit ec96089
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 344 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include "pxr/pxr.h"

#include "pxr/imaging/garch/glApi.h"

#include "pxr/usdImaging/usdImagingGL/unitTestGLDrawing.h"

#include "pxr/base/arch/systemInfo.h"
Expand Down Expand Up @@ -90,8 +88,6 @@ class My_TestGLDrawing : public UsdImagingGL_UnitTestGLDrawing {
bool _mouseButton[3];
};

GLuint vao;

void
My_TestGLDrawing::InitTest()
{
Expand Down Expand Up @@ -120,10 +116,6 @@ My_TestGLDrawing::InitTest()
renderSetting.second);
}

std::cout << glGetString(GL_VENDOR) << "\n";
std::cout << glGetString(GL_RENDERER) << "\n";
std::cout << glGetString(GL_VERSION) << "\n";

if (_ShouldFrameAll()) {
TfTokenVector purposes;
purposes.push_back(UsdGeomTokens->default_);
Expand Down Expand Up @@ -257,12 +249,6 @@ My_TestGLDrawing::DrawTest(bool offscreen)
_engine->SetRenderViewport(viewport);
}

bool const useAovs = !GetRendererAov().IsEmpty();
GfVec4f fboClearColor = useAovs? GfVec4f(0.0f) : GetClearColor();
GLfloat clearDepth[1] = { 1.0f };
bool const clearOnlyOnce = ShouldClearOnce();
bool cleared = false;

UsdImagingGLRenderParams params;
params.drawMode = GetDrawMode();
params.enableLighting = IsEnabledTestLighting();
Expand All @@ -279,13 +265,7 @@ My_TestGLDrawing::DrawTest(bool offscreen)
_SetDisplayUnloadedPrimsWithBounds(_engine.get(), true);
}

glViewport(0, 0, width, height);

glEnable(GL_DEPTH_TEST);

if (useAovs) {
_engine->SetRendererAov(GetRendererAov());
}
_engine->SetRendererAov(GetRendererAov());

if(IsEnabledTestLighting()) {
_engine->SetLightingState(_lightingContext);
Expand All @@ -295,12 +275,7 @@ My_TestGLDrawing::DrawTest(bool offscreen)
_engine->SetEnablePresentation(false);
}

if (!GetClipPlanes().empty()) {
params.clipPlanes = GetClipPlanes();
for (size_t i=0; i<GetClipPlanes().size(); ++i) {
glEnable(GL_CLIP_PLANE0 + i);
}
}
params.clipPlanes = GetClipPlanes();

for (double const &t : GetTimes()) {
UsdTimeCode time = t;
Expand All @@ -324,15 +299,6 @@ My_TestGLDrawing::DrawTest(bool offscreen)

convergenceIterations++;

if (cleared && clearOnlyOnce) {
// Don't clear the FBO
} else {
glClearBufferfv(GL_COLOR, 0, fboClearColor.data());
glClearBufferfv(GL_DEPTH, 0, clearDepth);

cleared = true;
}

_engine->Render(_stage->GetPseudoRoot(), params);
} while (!_engine->IsConverged());

Expand All @@ -358,7 +324,7 @@ My_TestGLDrawing::DrawTest(bool offscreen)
imageFilePath = TfStringReplace(imageFilePath, ".png", suffix.str());
}
std::cout << imageFilePath << "\n";
WriteToFile("color", imageFilePath);
WriteToFile(_engine.get(), HdAovTokens->color, imageFilePath);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
// language governing permissions and limitations under the Apache License.
//

#include "pxr/imaging/garch/glApi.h"

#include "pxr/usdImaging/usdImagingGL/unitTestGLDrawing.h"

#include "pxr/base/arch/systemInfo.h"
Expand Down Expand Up @@ -95,8 +93,6 @@ class My_TestGLDrawing : public UsdImagingGL_UnitTestGLDrawing {
double _time;
};

GLuint vao;

static
UsdStageRefPtr
_CreateStage(std::string const& primName) {
Expand All @@ -117,10 +113,6 @@ _CreateStage(std::string const& primName) {
void
My_TestGLDrawing::InitTest()
{
std::cout << glGetString(GL_VENDOR) << "\n";
std::cout << glGetString(GL_RENDERER) << "\n";
std::cout << glGetString(GL_VERSION) << "\n";

WorkSetMaximumConcurrencyLimit();

HdPerfLog& perfLog = HdPerfLog::GetInstance();
Expand Down Expand Up @@ -178,11 +170,6 @@ My_TestGLDrawing::InitTest()
path.GetText());
}

if(IsEnabledTestLighting()) {
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}

_translate[0] = 0.0;
_translate[1] = -1000.0;
_translate[2] = -2500.0;
Expand Down Expand Up @@ -243,17 +230,7 @@ My_TestGLDrawing::DrawTest(bool offscreen)
params.drawMode = UsdImagingGLDrawMode::DRAW_SHADED_SMOOTH;
params.enableLighting = IsEnabledTestLighting();
params.cullStyle = GetCullStyle();

glViewport(0, 0, width, height);

GLfloat clearColor[4] = { .25f, .25f, 0.25f, 1.0f };
glClearBufferfv(GL_COLOR, 0, clearColor);

GLfloat clearDepth[1] = { 1.0f };
glClearBufferfv(GL_DEPTH, 0, clearDepth);

glEnable(GL_DEPTH_TEST);

params.clearColor = GetClearColor();

if(IsEnabledTestLighting()) {
GlfSimpleLightingContextRefPtr lightingContext = GlfSimpleLightingContext::New();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 8 additions & 29 deletions pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLHdGp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#include "pxr/imaging/garch/glApi.h"

#include "pxr/base/gf/bbox3d.h"
#include "pxr/base/gf/frustum.h"
Expand All @@ -31,9 +30,6 @@
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/tf/getenv.h"

#include "pxr/imaging/glf/contextCaps.h"
#include "pxr/imaging/glf/drawTarget.h"
#include "pxr/imaging/glf/glContext.h"
#include "pxr/imaging/garch/glDebugWindow.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdGeom/bboxCache.h"
Expand Down Expand Up @@ -142,19 +138,6 @@ int main(int argc, char *argv[])
// prepare GL context
GarchGLDebugWindow window("UsdImagingGL Test", 512, 512);
window.Init();
GarchGLApiLoad();

// wrap into GlfGLContext so that GlfDrawTarget works
GlfGLContextSharedPtr ctx = GlfGLContext::GetCurrentGLContext();
GlfContextCaps::InitInstance();

// prep draw target
int width = 512, height = 512;
GlfDrawTargetRefPtr drawTarget = GlfDrawTarget::New(GfVec2i(width, height));
drawTarget->Bind();
drawTarget->AddAttachment("color", GL_RGBA, GL_FLOAT, GL_RGBA);
drawTarget->Unbind();


// open stage
UsdStageRefPtr stage = UsdStage::Open(stageFilePath);
Expand All @@ -174,14 +157,10 @@ int main(int argc, char *argv[])
new UsdImagingGLEngine(stage->GetPseudoRoot().GetPath(),
excludedPaths));

#define _Render() \
drawTarget->Bind(); \
engine->Render(stage->GetPseudoRoot(), params); \
drawTarget->Unbind(); \

engine->SetRendererAov(HdAovTokens->color);

//-------------------------------------------------------------------------
_Render();
engine->Render(stage->GetPseudoRoot(), params);

// NOTE: this makes assumptions based on scene index emulation and will
// need to be updated when UsdImagingGLEngine no longer uses the
Expand Down Expand Up @@ -241,7 +220,7 @@ int main(int argc, char *argv[])
srcMeshRel.SetTargets({SdfPath("/World/myMesh")});
}

_Render();
engine->Render(stage->GetPseudoRoot(), params);

std::cout << "Checking adjusted child count of: "
<< cubePerMeshProcPrimPath << "..." << std::endl;
Expand Down Expand Up @@ -272,7 +251,7 @@ int main(int argc, char *argv[])
{
observer.Clear();
params.frame = 2;
_Render();
engine->Render(stage->GetPseudoRoot(), params);

std::cout << "changing frame to 2" << std::endl;

Expand All @@ -292,7 +271,7 @@ int main(int argc, char *argv[])
srcMeshRel.SetTargets({SdfPath("/World/myMesh2")});
}

_Render();
engine->Render(stage->GetPseudoRoot(), params);

std::cout << "Checking restored child count of: "
<< cubePerMeshProcPrimPath << "..." << std::endl;
Expand All @@ -308,7 +287,7 @@ int main(int argc, char *argv[])
{
observer.Clear();
params.frame = 1;
_Render();
engine->Render(stage->GetPseudoRoot(), params);

std::cout << "changing frame to 1" << std::endl;\
std::cout << "confirming no child prims with dirtied xforms..."
Expand All @@ -326,7 +305,7 @@ int main(int argc, char *argv[])
observer.Clear();
cubePerMeshProcPrim.GetAttribute(
TfToken("primvars:scale")).Set(VtValue(1.25f));
_Render();
engine->Render(stage->GetPseudoRoot(), params);

std::cout << "setting 'primvars:scale' of "
<< cubePerMeshProcPrimPath << std::endl;
Expand Down Expand Up @@ -366,7 +345,7 @@ int main(int argc, char *argv[])
UsdPrim procPrim = stage->GetPrimAtPath(makeSomeStuffProcPrimPath);
procPrim.GetAttribute(TfToken("primvars:myDepth")).Set(VtValue(2));

_Render();
engine->Render(stage->GetPseudoRoot(), params);

std::cout << "confirming child and grandchild types "
<< makeSomeStuffProcPrimPath << "..." << std::endl;
Expand Down
33 changes: 2 additions & 31 deletions pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLHighlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
// language governing permissions and limitations under the Apache License.
//

#include "pxr/imaging/garch/glApi.h"

#include "pxr/usdImaging/usdImagingGL/unitTestGLDrawing.h"

#include "pxr/base/arch/systemInfo.h"
Expand Down Expand Up @@ -108,17 +106,6 @@ My_TestGLDrawing::InitTest()

_engine->SetSelectionColor(GfVec4f(1, 1, 0, 1));

std::cout << glGetString(GL_VENDOR) << "\n";
std::cout << glGetString(GL_RENDERER) << "\n";
std::cout << glGetString(GL_VERSION) << "\n";

if(IsEnabledTestLighting()) {
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
float position[4] = {0,-.5,.5,0};
glLightfv(GL_LIGHT0, GL_POSITION, position);
}

if (_ShouldFrameAll()) {
TfTokenVector purposes;
purposes.push_back(UsdGeomTokens->default_);
Expand Down Expand Up @@ -279,29 +266,13 @@ My_TestGLDrawing::Draw()
params.highlight = true;
params.clearColor = GetClearColor();

glViewport(0, 0, width, height);

GLfloat clearColor[4] = { 1.0f, .5f, 0.1f, 1.0f };
glClearBufferfv(GL_COLOR, 0, clearColor);

GLfloat clearDepth[1] = { 1.0f };
glClearBufferfv(GL_DEPTH, 0, clearDepth);

glEnable(GL_DEPTH_TEST);


if(IsEnabledTestLighting()) {
GlfSimpleLightingContextRefPtr lightingContext = GlfSimpleLightingContext::New();
lightingContext->SetStateFromOpenGL();
_engine->SetLightingState(lightingContext);
}

if (!GetClipPlanes().empty()) {
params.clipPlanes = GetClipPlanes();
for (size_t i=0; i<GetClipPlanes().size(); ++i) {
glEnable(GL_CLIP_PLANE0 + i);
}
}
params.clipPlanes = GetClipPlanes();

_engine->Render(_stage->GetPseudoRoot(), params);

Expand All @@ -313,7 +284,7 @@ My_TestGLDrawing::Draw()
suffix << "_" << std::setw(3) << std::setfill('0') << i << ".png";
imageFilePath = TfStringReplace(imageFilePath, ".png", suffix.str());
std::cout << imageFilePath << "\n";
WriteToFile("color", imageFilePath);
WriteToFile(_engine.get(), HdAovTokens->color, imageFilePath);

i++;
}
Expand Down
Loading

0 comments on commit ec96089

Please sign in to comment.