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_IMAGING_HD_UNIT_TEST_HELPER_H
25 #define PXR_IMAGING_HD_UNIT_TEST_HELPER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/engine.h"
30 #include "pxr/imaging/hd/renderPass.h"
31 #include "pxr/imaging/hd/renderPassState.h"
32 #include "pxr/imaging/hd/unitTestDelegate.h"
33 #include "pxr/imaging/hd/unitTestNullRenderDelegate.h"
34 
35 #include "pxr/base/gf/vec4d.h"
36 #include "pxr/base/gf/matrix4d.h"
37 
38 #include <vector>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 
43 /// \class Hd_TestDriver
44 ///
45 /// A unit test driver that exercises the core engine.
46 ///
47 /// \note This test driver does NOT assume OpenGL is available; in the even
48 /// that is is not available, all OpenGL calls become no-ops, but all other work
49 /// is performed as usual.
50 ///
51 class Hd_TestDriver final {
52 public:
53     HD_API
54     Hd_TestDriver();
55     HD_API
56     Hd_TestDriver(HdReprSelector const &reprToken);
57     HD_API
58     ~Hd_TestDriver();
59 
60     /// Draw
61     HD_API
62     void Draw(bool withGuides=false);
63 
64     /// Draw with external renderPass
65     HD_API
66     void Draw(HdRenderPassSharedPtr const &renderPass, bool withGuides);
67 
68     /// Set camera to renderpass
69     HD_API
70     void SetCamera(GfMatrix4d const &modelViewMatrix,
71                    GfMatrix4d const &projectionMatrix,
72                    GfVec4d const &viewport);
73 
74     /// Set cull style
75     HD_API
76     void SetCullStyle(HdCullStyle cullStyle);
77 
78     /// Returns the renderpass
79     HD_API
80     HdRenderPassSharedPtr const &GetRenderPass();
81 
82     /// Returns the renderPassState
GetRenderPassState()83     HdRenderPassStateSharedPtr const &GetRenderPassState() const {
84         return _renderPassState;
85     }
86 
87     /// Returns the UnitTest delegate
GetDelegate()88     HdUnitTestDelegate& GetDelegate() { return *_sceneDelegate; }
89 
90     /// Switch repr
91     HD_API
92     void SetRepr(HdReprSelector const &reprSelector);
93 
94 private:
95 
96     void _Init(HdReprSelector const &reprSelector);
97 
98     HdEngine _engine;
99     Hd_UnitTestNullRenderDelegate _renderDelegate;
100     HdRenderIndex       *_renderIndex;
101     HdUnitTestDelegate *_sceneDelegate;
102 	SdfPath _cameraId;
103     HdRenderPassSharedPtr _renderPass;
104     HdRenderPassStateSharedPtr _renderPassState;
105     HdRprimCollection          _collection;
106 };
107 
108 PXR_NAMESPACE_CLOSE_SCOPE
109 
110 #endif  // PXR_IMAGING_HD_UNIT_TEST_HELPER_H
111