HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
simpleLightingContext.h
Go to the documentation of this file.
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_GLF_SIMPLE_LIGHTING_CONTEXT_H
25 #define PXR_IMAGING_GLF_SIMPLE_LIGHTING_CONTEXT_H
26 
27 /// \file glf/simpleLightingContext.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
34 
35 #include "pxr/base/gf/matrix4d.h"
36 #include "pxr/base/gf/vec4f.h"
37 
39 #include "pxr/base/tf/refBase.h"
40 #include "pxr/base/tf/weakBase.h"
41 #include "pxr/base/tf/token.h"
42 
43 #include <memory>
44 
46 
47 
52 
54 public:
56 
57  GLF_API
58  static GlfSimpleLightingContextRefPtr New();
59 
60  GLF_API
61  void SetLights(GlfSimpleLightVector const & lights);
62  GLF_API
63  GlfSimpleLightVector const & GetLights() const;
64 
65  // returns the effective number of lights taken into account
66  // in composable/compatible shader constraints
67  GLF_API
68  int GetNumLightsUsed() const;
69 
70  // returns the number of shadow maps needed, by summing shadow maps
71  // allocated to each light.
72  GLF_API
73  int ComputeNumShadowsUsed() const;
74 
75  GLF_API
76  void SetShadows(GlfSimpleShadowArrayRefPtr const & shadows);
77  GLF_API
78  GlfSimpleShadowArrayRefPtr const & GetShadows() const;
79 
80  GLF_API
81  void SetMaterial(GlfSimpleMaterial const & material);
82  GLF_API
83  GlfSimpleMaterial const & GetMaterial() const;
84 
85  GLF_API
86  void SetSceneAmbient(GfVec4f const & sceneAmbient);
87  GLF_API
88  GfVec4f const & GetSceneAmbient() const;
89 
90  GLF_API
91  void SetCamera(GfMatrix4d const &worldToViewMatrix,
92  GfMatrix4d const &projectionMatrix);
93 
94  GLF_API
95  void SetUseLighting(bool val);
96  GLF_API
97  bool GetUseLighting() const;
98 
99  // returns true if any light has shadow enabled.
100  GLF_API
101  bool GetUseShadows() const;
102 
103  GLF_API
104  void SetUseColorMaterialDiffuse(bool val);
105  GLF_API
106  bool GetUseColorMaterialDiffuse() const;
107 
108  GLF_API
109  void InitUniformBlockBindings(GlfBindingMapPtr const &bindingMap) const;
110  GLF_API
111  void InitSamplerUnitBindings(GlfBindingMapPtr const &bindingMap) const;
112 
113  GLF_API
114  void BindUniformBlocks(GlfBindingMapPtr const &bindingMap);
115  GLF_API
116  void BindSamplers(GlfBindingMapPtr const &bindingMap);
117 
118  GLF_API
119  void UnbindSamplers(GlfBindingMapPtr const &bindingMap);
120 
121  GLF_API
122  void SetStateFromOpenGL();
123 
124  /// \name Post Surface Lighting
125  ///
126  /// This context can provide additional shader source, currently
127  /// used to implement post surface lighting, along with a hash
128  /// to help de-duplicate use by client shader programs.
129  ///
130  /// @{
131 
132  GLF_API
133  size_t ComputeShaderSourceHash();
134 
135  GLF_API
136  std::string const & ComputeShaderSource(TfToken const &shaderStageKey);
137 
138  /// @}
139 
140 protected:
141  GLF_API
143  GLF_API
145 
147  void _BindPostSurfaceShaderParams(GlfBindingMapPtr const &bindingMap);
148 
149 private:
150  GlfSimpleLightVector _lights;
151  GlfSimpleShadowArrayRefPtr _shadows;
152 
153  GfMatrix4d _worldToViewMatrix;
154  GfMatrix4d _projectionMatrix;
155 
156  GlfSimpleMaterial _material;
157  GfVec4f _sceneAmbient;
158 
159  bool _useLighting;
160  bool _useShadows;
161  bool _useColorMaterialDiffuse;
162 
163  GlfUniformBlockRefPtr _lightingUniformBlock;
164  GlfUniformBlockRefPtr _shadowUniformBlock;
165  GlfUniformBlockRefPtr _materialUniformBlock;
166  GlfUniformBlockRefPtr _bindlessShadowlUniformBlock;
167 
168  class _PostSurfaceShaderState;
169  std::unique_ptr<_PostSurfaceShaderState> _postSurfaceShaderState;
170 
171  bool _lightingUniformBlockValid;
172  bool _shadowUniformBlockValid;
173  bool _materialUniformBlockValid;
174  bool _postSurfaceShaderStateValid;
175 };
176 
177 
179 
180 #endif
GLF_API bool GetUseColorMaterialDiffuse() const
#define GLF_API
Definition: api.h:40
GLF_API std::string const & ComputeShaderSource(TfToken const &shaderStageKey)
GLF_API void SetStateFromOpenGL()
GLF_API void BindSamplers(GlfBindingMapPtr const &bindingMap)
GLF_API void InitUniformBlockBindings(GlfBindingMapPtr const &bindingMap) const
GLF_API void SetLights(GlfSimpleLightVector const &lights)
GLF_API void SetMaterial(GlfSimpleMaterial const &material)
GLF_API void SetSceneAmbient(GfVec4f const &sceneAmbient)
GLF_API GfVec4f const & GetSceneAmbient() const
GLF_API int ComputeNumShadowsUsed() const
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_AND_REF_PTRS(GlfBindingMap)
Definition: token.h:87
GLF_API GlfSimpleLightingContext()
GLF_API size_t ComputeShaderSourceHash()
GlfSimpleLightingContext This
void _BindPostSurfaceShaderParams(GlfBindingMapPtr const &bindingMap)
GLF_API GlfSimpleLightVector const & GetLights() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
GLF_API GlfSimpleShadowArrayRefPtr const & GetShadows() const
GLF_API GlfSimpleMaterial const & GetMaterial() const
GLF_API void InitSamplerUnitBindings(GlfBindingMapPtr const &bindingMap) const
GLF_API bool GetUseLighting() const
GLF_API int GetNumLightsUsed() const
GLF_API void SetUseLighting(bool val)
GLF_API bool GetUseShadows() const
Definition: vec4f.h:63
GLuint GLfloat * val
Definition: glcorearb.h:1607
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
GLF_API void UnbindSamplers(GlfBindingMapPtr const &bindingMap)
GLF_API ~GlfSimpleLightingContext()
GLF_API void BindUniformBlocks(GlfBindingMapPtr const &bindingMap)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
static GLF_API GlfSimpleLightingContextRefPtr New()
GLF_API void SetShadows(GlfSimpleShadowArrayRefPtr const &shadows)
GLF_API void SetUseColorMaterialDiffuse(bool val)
GLF_API void SetCamera(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix)
std::vector< class GlfSimpleLight > GlfSimpleLightVector
Definition: simpleLight.h:231