Loading...
Searching...
No Matches
simpleLightingContext.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_GLF_SIMPLE_LIGHTING_CONTEXT_H
8#define PXR_IMAGING_GLF_SIMPLE_LIGHTING_CONTEXT_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/imaging/glf/api.h"
17
19#include "pxr/base/gf/vec4f.h"
20
22#include "pxr/base/tf/refBase.h"
24#include "pxr/base/tf/token.h"
25
26#include <memory>
27
28PXR_NAMESPACE_OPEN_SCOPE
29
30
31TF_DECLARE_WEAK_AND_REF_PTRS(GlfBindingMap);
33TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleLightingContext);
34TF_DECLARE_WEAK_AND_REF_PTRS(GlfSimpleShadowArray);
35
36class GlfSimpleLightingContext : public TfRefBase, public TfWeakBase {
37public:
38 typedef GlfSimpleLightingContext This;
39
40 GLF_API
41 static GlfSimpleLightingContextRefPtr New();
42
43 GLF_API
44 void SetLights(GlfSimpleLightVector const & lights);
45 GLF_API
46 GlfSimpleLightVector const & GetLights() const;
47
48 // returns the effective number of lights taken into account
49 // in composable/compatible shader constraints
50 GLF_API
51 int GetNumLightsUsed() const;
52
53 // returns the number of shadow maps needed, by summing shadow maps
54 // allocated to each light.
55 GLF_API
56 int ComputeNumShadowsUsed() const;
57
58 GLF_API
59 void SetShadows(GlfSimpleShadowArrayRefPtr const & shadows);
60 GLF_API
61 GlfSimpleShadowArrayRefPtr const & GetShadows() const;
62
63 GLF_API
64 void SetMaterial(GlfSimpleMaterial const & material);
65 GLF_API
66 GlfSimpleMaterial const & GetMaterial() const;
67
68 GLF_API
69 void SetSceneAmbient(GfVec4f const & sceneAmbient);
70 GLF_API
71 GfVec4f const & GetSceneAmbient() const;
72
73 GLF_API
74 void SetCamera(GfMatrix4d const &worldToViewMatrix,
75 GfMatrix4d const &projectionMatrix);
76
77 GLF_API
78 void SetUseLighting(bool val);
79 GLF_API
80 bool GetUseLighting() const;
81
82 // returns true if any light has shadow enabled.
83 GLF_API
84 bool GetUseShadows() const;
85
86 GLF_API
87 void SetUseColorMaterialDiffuse(bool val);
88 GLF_API
89 bool GetUseColorMaterialDiffuse() const;
90
91 GLF_API
92 void InitUniformBlockBindings(GlfBindingMapPtr const &bindingMap) const;
93 GLF_API
94 void InitSamplerUnitBindings(GlfBindingMapPtr const &bindingMap) const;
95
96 GLF_API
97 void BindUniformBlocks(GlfBindingMapPtr const &bindingMap);
98 GLF_API
99 void BindSamplers(GlfBindingMapPtr const &bindingMap);
100
101 GLF_API
102 void UnbindSamplers(GlfBindingMapPtr const &bindingMap);
103
104 GLF_API
105 void SetStateFromOpenGL();
106
114
115 GLF_API
116 size_t ComputeShaderSourceHash();
117
118 GLF_API
119 std::string const & ComputeShaderSource(TfToken const &shaderStageKey);
120
122
123protected:
124 GLF_API
125 GlfSimpleLightingContext();
126 GLF_API
127 ~GlfSimpleLightingContext();
128
129 void _ComputePostSurfaceShaderState();
130 void _BindPostSurfaceShaderParams(GlfBindingMapPtr const &bindingMap);
131
132private:
133 GlfSimpleLightVector _lights;
134 GlfSimpleShadowArrayRefPtr _shadows;
135
136 GfMatrix4d _worldToViewMatrix;
137 GfMatrix4d _projectionMatrix;
138
139 GlfSimpleMaterial _material;
140 GfVec4f _sceneAmbient;
141
142 bool _useLighting;
143 bool _useShadows;
144 bool _useColorMaterialDiffuse;
145
146 GlfUniformBlockRefPtr _lightingUniformBlock;
147 GlfUniformBlockRefPtr _shadowUniformBlock;
148 GlfUniformBlockRefPtr _materialUniformBlock;
149 GlfUniformBlockRefPtr _bindlessShadowlUniformBlock;
150
151 class _PostSurfaceShaderState;
152 std::unique_ptr<_PostSurfaceShaderState> _postSurfaceShaderState;
153
154 bool _lightingUniformBlockValid;
155 bool _shadowUniformBlockValid;
156 bool _materialUniformBlockValid;
157 bool _postSurfaceShaderStateValid;
158};
159
160
161PXR_NAMESPACE_CLOSE_SCOPE
162
163#endif
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
Manages a GL uniform buffer object.
Definition: uniformBlock.h:30
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:56
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
Standard pointer typedefs.
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
Definition: declarePtrs.h:72
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...