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 GLF_SIMPLE_LIGHTING_CONTEXT_H
25 #define 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  GLF_API
68  void SetShadows(GlfSimpleShadowArrayRefPtr const & shadows);
69  GLF_API
70  GlfSimpleShadowArrayRefPtr const & GetShadows();
71 
72  GLF_API
73  void SetMaterial(GlfSimpleMaterial const & material);
74  GLF_API
75  GlfSimpleMaterial const & GetMaterial() const;
76 
77  GLF_API
78  void SetSceneAmbient(GfVec4f const & sceneAmbient);
79  GLF_API
80  GfVec4f const & GetSceneAmbient() const;
81 
82  GLF_API
83  void SetCamera(GfMatrix4d const &worldToViewMatrix,
84  GfMatrix4d const &projectionMatrix);
85 
86  GLF_API
87  void SetUseLighting(bool val);
88  GLF_API
89  bool GetUseLighting() const;
90 
91  // returns true if any light has shadow enabled.
92  GLF_API
93  bool GetUseShadows() const;
94 
95  GLF_API
96  void SetUseColorMaterialDiffuse(bool val);
97  GLF_API
98  bool GetUseColorMaterialDiffuse() const;
99 
100  GLF_API
101  void InitUniformBlockBindings(GlfBindingMapPtr const &bindingMap) const;
102  GLF_API
103  void InitSamplerUnitBindings(GlfBindingMapPtr const &bindingMap) const;
104 
105  GLF_API
106  void BindUniformBlocks(GlfBindingMapPtr const &bindingMap);
107  GLF_API
108  void BindSamplers(GlfBindingMapPtr const &bindingMap);
109 
110  GLF_API
111  void UnbindSamplers(GlfBindingMapPtr const &bindingMap);
112 
113  GLF_API
114  void SetStateFromOpenGL();
115 
116 protected:
117  GLF_API
118  GlfSimpleLightingContext();
119  GLF_API
120  ~GlfSimpleLightingContext();
121 
122 private:
123  GlfSimpleLightVector _lights;
124  GlfSimpleShadowArrayRefPtr _shadows;
125 
126  GfMatrix4d _worldToViewMatrix;
127  GfMatrix4d _projectionMatrix;
128 
129  GlfSimpleMaterial _material;
130  GfVec4f _sceneAmbient;
131 
132  bool _useLighting;
133  bool _useShadows;
134  bool _useColorMaterialDiffuse;
135 
136  GlfUniformBlockRefPtr _lightingUniformBlock;
137  GlfUniformBlockRefPtr _shadowUniformBlock;
138  GlfUniformBlockRefPtr _materialUniformBlock;
139 
140  bool _lightingUniformBlockValid;
141  bool _shadowUniformBlockValid;
142  bool _materialUniformBlockValid;
143 };
144 
145 
146 PXR_NAMESPACE_CLOSE_SCOPE
147 
148 #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:72
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:142