1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 //    names, trademarks, service marks, or product names of the Licensor
11 //    and its affiliates, except as required to comply with Section 4(c) of
12 //    the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_IMAGING_USD_IMAGING_GL_UNIT_TEST_GLDRAWING_H
25 #define PXR_USD_IMAGING_USD_IMAGING_GL_UNIT_TEST_GLDRAWING_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/gf/vec4d.h"
29 #include "pxr/base/vt/dictionary.h"
30 
31 #include "pxr/base/tf/declarePtrs.h"
32 
33 #include "pxr/usdImaging/usdImagingGL/engine.h"
34 
35 #include <string>
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 
41 class UsdImagingGL_UnitTestWindow;
42 
43 /// \class UsdImagingGL_UnitTestGLDrawing
44 ///
45 /// A helper class for unit tests which need to perform GL drawing.
46 ///
47 class UsdImagingGL_UnitTestGLDrawing {
48 public:
49     UsdImagingGL_UnitTestGLDrawing();
50     virtual ~UsdImagingGL_UnitTestGLDrawing();
51 
52     int GetWidth() const;
53     int GetHeight() const;
54 
IsEnabledTestLighting()55     bool IsEnabledTestLighting() const { return _testLighting; }
IsEnabledSceneLights()56     bool IsEnabledSceneLights() const { return _sceneLights; }
IsEnabledCameraLight()57     bool IsEnabledCameraLight() const { return _cameraLight; }
IsEnabledIdRender()58     bool IsEnabledIdRender() const { return _testIdRender; }
IsEnabledSceneMaterials()59     bool IsEnabledSceneMaterials() const { return _enableSceneMaterials; }
60 
IsShowGuides()61     bool IsShowGuides() const { return _showGuides; }
IsShowRender()62     bool IsShowRender() const { return _showRender; }
IsShowProxy()63     bool IsShowProxy() const { return _showProxy; }
ShouldClearOnce()64     bool ShouldClearOnce() const { return _clearOnce; }
PresentDisabled()65     bool PresentDisabled() const { return _presentDisabled; }
66 
GetDrawMode()67     UsdImagingGLDrawMode GetDrawMode() const { return _drawMode; }
68 
GetStageFilePath()69     std::string const & GetStageFilePath() const { return _stageFilePath; }
GetOutputFilePath()70     std::string const & GetOutputFilePath() const { return _outputFilePath; }
71 
GetCameraPath()72     std::string const & GetCameraPath() const { return _cameraPath; }
GetClipPlanes()73     std::vector<GfVec4d> const & GetClipPlanes() const { return _clipPlanes; }
GetTimes()74     std::vector<double> const& GetTimes() const { return _times; }
GetClearColor()75     GfVec4f const & GetClearColor() const { return _clearColor; }
GetTranslate()76     GfVec3f const & GetTranslate() const { return _translate; }
GetRenderSettings()77     VtDictionary const &GetRenderSettings() const { return _renderSettings; }
GetRendererAov()78     TfToken const & GetRendererAov() const { return _rendererAov; }
GetPerfStatsFile()79     std::string const &GetPerfStatsFile() const { return _perfStatsFile; }
GetPixelAspectRatio()80     float GetPixelAspectRatio() const { return _pixelAspectRatio; }
GetDisplayWindow()81     GfRange2f const & GetDisplayWindow() const { return _displayWindow; }
GetDataWindow()82     GfRect2i const & GetDataWindow() const { return _dataWindow; }
GetCullStyle()83     UsdImagingGLCullStyle GetCullStyle() const { return _cullStyle; }
84 
85     void RunTest(int argc, char *argv[]);
86 
87     virtual void InitTest() = 0;
88     virtual void DrawTest(bool offscreen) = 0;
ShutdownTest()89     virtual void ShutdownTest() { }
90 
91     virtual void MousePress(int button, int x, int y, int modKeys);
92     virtual void MouseRelease(int button, int x, int y, int modKeys);
93     virtual void MouseMove(int x, int y, int modKeys);
94     virtual void KeyRelease(int key);
95 
96     bool WriteToFile(std::string const & attachment, std::string const & filename) const;
97 
98 protected:
_GetComplexity()99     float _GetComplexity() const { return _complexity; }
_ShouldFrameAll()100     bool _ShouldFrameAll() const { return _shouldFrameAll; }
_GetRenderer()101     TfToken _GetRenderer() const { return _renderer; }
102 
_GetRenderIndex(UsdImagingGLEngine * engine)103     HdRenderIndex *_GetRenderIndex(UsdImagingGLEngine *engine) {
104         return engine->_GetRenderIndex();
105     }
106 
_Render(UsdImagingGLEngine * engine,const UsdImagingGLRenderParams & params)107     void _Render(UsdImagingGLEngine *engine,
108                  const UsdImagingGLRenderParams &params) {
109         SdfPathVector roots(1, SdfPath::AbsoluteRootPath());
110         engine->RenderBatch(roots, params);
111     }
112 
113 private:
114     struct _Args;
115     void _Parse(int argc, char *argv[], _Args* args);
116 
117 private:
118     UsdImagingGL_UnitTestWindow *_widget;
119     bool _testLighting;
120     bool _sceneLights;
121     bool _cameraLight;
122     std::string _cameraPath;
123     bool _testIdRender;
124     bool _enableSceneMaterials;
125 
126     std::string _stageFilePath;
127     std::string _outputFilePath;
128 
129     float _complexity;
130     TfToken _renderer;
131 
132     std::vector<double> _times;
133 
134     std::vector<GfVec4d> _clipPlanes;
135 
136     UsdImagingGLDrawMode _drawMode;
137     bool _shouldFrameAll;
138     UsdImagingGLCullStyle _cullStyle;
139     GfVec4f _clearColor;
140     GfVec3f _translate;
141     float _pixelAspectRatio;
142     GfRange2f _displayWindow;
143     GfRect2i _dataWindow;
144     VtDictionary _renderSettings;
145     TfToken _rendererAov;
146     std::string _perfStatsFile;
147     std::string _traceFile;
148 
149     bool _showGuides;
150     bool _showRender;
151     bool _showProxy;
152     bool _clearOnce;
153     bool _presentDisabled;
154 };
155 
156 
157 PXR_NAMESPACE_CLOSE_SCOPE
158 
159 #endif // PXR_USD_IMAGING_USD_IMAGING_GL_UNIT_TEST_GLDRAWING_H
160