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 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
31 #include "pxr/imaging/glf/simpleLight.h"
32 #include "pxr/imaging/glf/simpleMaterial.h"
33 #include "pxr/imaging/glf/simpleShadowArray.h"
34 
35 #include "pxr/base/gf/matrix4d.h"
36 #include "pxr/base/gf/vec4f.h"
37 
38 #include "pxr/base/tf/declarePtrs.h"
39 #include "pxr/base/tf/refBase.h"
40 #include "pxr/base/tf/weakBase.h"
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
44 
45 TF_DECLARE_WEAK_AND_REF_PTRS(GlfBindingMap);
47 TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleLightingContext);
48 TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleShadowArray);
49 
50 class GlfSimpleLightingContext : public TfRefBase, public TfWeakBase {
51 public:
52  typedef GlfSimpleLightingContext This;
53 
54  GLF_API
55  static GlfSimpleLightingContextRefPtr New();
56 
57  GLF_API
58  void SetLights(GlfSimpleLightVector const & lights);
59  GLF_API
60  GlfSimpleLightVector & GetLights();
61 
62  // returns the effective number of lights taken into account
63  // in composable/compatible shader constraints
64  GLF_API
65  int GetNumLightsUsed() const;
66 
67  // returns the number of shadow maps needed, by summing shadow maps
68  // allocated to each light.
69  GLF_API
70  int ComputeNumShadowsUsed() const;
71 
72  GLF_API
73  void SetShadows(GlfSimpleShadowArrayRefPtr const & shadows);
74  GLF_API
75  GlfSimpleShadowArrayRefPtr const & GetShadows();
76 
77  GLF_API
78  void SetMaterial(GlfSimpleMaterial const & material);
79  GLF_API
80  GlfSimpleMaterial const & GetMaterial() const;
81 
82  GLF_API
83  void SetSceneAmbient(GfVec4f const & sceneAmbient);
84  GLF_API
85  GfVec4f const & GetSceneAmbient() const;
86 
87  GLF_API
88  void SetCamera(GfMatrix4d const &worldToViewMatrix,
89  GfMatrix4d const &projectionMatrix);
90 
91  GLF_API
92  void SetUseLighting(bool val);
93  GLF_API
94  bool GetUseLighting() const;
95 
96  // returns true if any light has shadow enabled.
97  GLF_API
98  bool GetUseShadows() const;
99 
100  GLF_API
101  void SetUseColorMaterialDiffuse(bool val);
102  GLF_API
103  bool GetUseColorMaterialDiffuse() const;
104 
105  GLF_API
106  void InitUniformBlockBindings(GlfBindingMapPtr const &bindingMap) const;
107  GLF_API
108  void InitSamplerUnitBindings(GlfBindingMapPtr const &bindingMap) const;
109 
110  GLF_API
111  void BindUniformBlocks(GlfBindingMapPtr const &bindingMap);
112  GLF_API
113  void BindSamplers(GlfBindingMapPtr const &bindingMap);
114 
115  GLF_API
116  void UnbindSamplers(GlfBindingMapPtr const &bindingMap);
117 
118  GLF_API
119  void SetStateFromOpenGL();
120 
121 protected:
122  GLF_API
123  GlfSimpleLightingContext();
124  GLF_API
125  ~GlfSimpleLightingContext();
126 
127 private:
128  GlfSimpleLightVector _lights;
129  GlfSimpleShadowArrayRefPtr _shadows;
130 
131  GfMatrix4d _worldToViewMatrix;
132  GfMatrix4d _projectionMatrix;
133 
134  GlfSimpleMaterial _material;
135  GfVec4f _sceneAmbient;
136 
137  bool _useLighting;
138  bool _useShadows;
139  bool _useColorMaterialDiffuse;
140 
141  GlfUniformBlockRefPtr _lightingUniformBlock;
142  GlfUniformBlockRefPtr _shadowUniformBlock;
143  GlfUniformBlockRefPtr _materialUniformBlock;
144  GlfUniformBlockRefPtr _bindlessShadowlUniformBlock;
145 
146  bool _lightingUniformBlockValid;
147  bool _shadowUniformBlockValid;
148  bool _materialUniformBlockValid;
149 };
150 
151 
152 PXR_NAMESPACE_CLOSE_SCOPE
153 
154 #endif
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:71
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
Manages a GL uniform buffer object.
Definition: uniformBlock.h:47
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141