Loading...
Searching...
No Matches
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"
34
36#include "pxr/base/gf/vec4f.h"
37
39#include "pxr/base/tf/refBase.h"
41#include "pxr/base/tf/token.h"
42
43#include <memory>
44
45PXR_NAMESPACE_OPEN_SCOPE
46
47
48TF_DECLARE_WEAK_AND_REF_PTRS(GlfBindingMap);
50TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleLightingContext);
51TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleShadowArray);
52
53class GlfSimpleLightingContext : public TfRefBase, public TfWeakBase {
54public:
55 typedef GlfSimpleLightingContext This;
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
131
132 GLF_API
133 size_t ComputeShaderSourceHash();
134
135 GLF_API
136 std::string const & ComputeShaderSource(TfToken const &shaderStageKey);
137
139
140protected:
141 GLF_API
142 GlfSimpleLightingContext();
143 GLF_API
144 ~GlfSimpleLightingContext();
145
146 void _ComputePostSurfaceShaderState();
147 void _BindPostSurfaceShaderParams(GlfBindingMapPtr const &bindingMap);
148
149private:
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
178PXR_NAMESPACE_CLOSE_SCOPE
179
180#endif
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 TfRefPtr.
Definition: refBase.h:73
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:89
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...