All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
unitTestHelper.h
1 //
2 // Copyright 2017 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 HDST_UNIT_TEST_HELPER
25 #define HDST_UNIT_TEST_HELPER
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/lightingShader.h"
29 #include "pxr/imaging/hdSt/renderDelegate.h"
30 #include "pxr/imaging/hdSt/renderPassState.h"
31 #include "pxr/imaging/hdSt/unitTestDelegate.h"
32 
33 #include "pxr/imaging/hd/engine.h"
34 #include "pxr/imaging/hd/renderPass.h"
35 #include "pxr/imaging/hio/glslfx.h"
36 
37 #include "pxr/base/gf/vec4d.h"
38 #include "pxr/base/gf/matrix4d.h"
39 
40 #include <vector>
41 #include <boost/scoped_ptr.hpp>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
45 
54 class HdSt_TestDriver final {
55 public:
56  HdSt_TestDriver();
57  HdSt_TestDriver(TfToken const &reprName);
58  HdSt_TestDriver(HdReprSelector const &reprToken);
59  ~HdSt_TestDriver();
60 
62  void Draw(bool withGuides=false);
63 
65  void Draw(HdRenderPassSharedPtr const &renderPass, bool withGuides);
66 
68  void SetCamera(GfMatrix4d const &modelViewMatrix,
69  GfMatrix4d const &projectionMatrix,
70  GfVec4d const &viewport);
71 
72  void SetCameraClipPlanes(std::vector<GfVec4d> const& clipPlanes);
73 
75  void SetCullStyle(HdCullStyle cullStyle);
76 
78  HdRenderPassSharedPtr const &GetRenderPass();
79 
81  HdStRenderPassStateSharedPtr const &GetRenderPassState() const {
82  return _renderPassState;
83  }
84 
86  HdSt_UnitTestDelegate& GetDelegate() { return *_sceneDelegate; }
87 
89  void SetRepr(HdReprSelector const &reprToken);
90 
91 private:
92 
93  void _Init(HdReprSelector const &reprToken);
94 
95  HdEngine _engine;
96  HdStRenderDelegate _renderDelegate;
97  HdRenderIndex *_renderIndex;
98  HdSt_UnitTestDelegate *_sceneDelegate;
99 
100  SdfPath _cameraId;
101  HdReprSelector _reprToken;
102 
103  HdRenderPassSharedPtr _renderPass;
104  HdStRenderPassStateSharedPtr _renderPassState;
105  HdRprimCollection _collection;
106 };
107 
112 typedef boost::shared_ptr<class HdSt_TestLightingShader> HdSt_TestLightingShaderSharedPtr;
113 
114 class HdSt_TestLightingShader : public HdStLightingShader {
115 public:
116  HdSt_TestLightingShader();
117  virtual ~HdSt_TestLightingShader();
118 
120  virtual ID ComputeHash() const;
121  virtual std::string GetSource(TfToken const &shaderStageKey) const;
122  virtual void BindResources(HdSt_ResourceBinder const &binder, int program);
123  virtual void UnbindResources(HdSt_ResourceBinder const &binder, int program);
124  virtual void AddBindings(HdBindingRequestVector *customBindings);
125 
127  virtual void SetCamera(GfMatrix4d const &worldToViewMatrix,
128  GfMatrix4d const &projectionMatrix);
129 
130  void SetSceneAmbient(GfVec3f const &color);
131  void SetLight(int light, GfVec3f const &dir, GfVec3f const &color);
132 
133 private:
134  struct Light {
135  GfVec3f dir;
136  GfVec3f eyeDir;
137  GfVec3f color;
138  };
139  Light _lights[2];
140  GfVec3f _sceneAmbient;
141  boost::scoped_ptr<HioGlslfx> _glslfx;
142 };
143 
144 
145 PXR_NAMESPACE_CLOSE_SCOPE
146 
147 #endif // HDST_UNIT_TEST_HELPER
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:119
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
virtual std::string GetSource(TfToken const &shaderStageKey) const =0
Returns the shader source provided by this shader for shaderStageKey.
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
virtual void AddBindings(HdBindingRequestVector *customBindings)=0
Add custom bindings (used by codegen)
virtual void UnbindResources(HdSt_ResourceBinder const &binder, int program)=0
Unbinds shader-specific resources.
HdStRenderDelegate.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
The application-facing entry point top-level entry point for accessing Hydra.
Definition: engine.h:48
virtual void BindResources(HdSt_ResourceBinder const &binder, int program)=0
Binds shader-specific resources to program XXX: this interface is meant to be used for bridging the G...
virtual void SetCamera(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix)=0
Sets camera state.
A named, semantic collection of objects.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
virtual ID ComputeHash() const =0
Returns the hash value of this shader.
Describes one or more authored display representations for an rprim.
Definition: repr.h:48
A lighting shader base class.