HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
simpleShadowArray.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_SHADOW_ARRAY_H
25 #define PXR_IMAGING_GLF_SIMPLE_SHADOW_ARRAY_H
26 
27 /// \file glf/simpleShadowArray.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
32 #include "pxr/base/tf/refPtr.h"
33 #include "pxr/base/tf/weakPtr.h"
34 #include "pxr/base/gf/matrix4d.h"
35 #include "pxr/base/gf/vec2i.h"
36 #include "pxr/base/gf/vec4d.h"
38 
39 #include <vector>
40 
42 
43 
45  public TfWeakBase
46 {
47 public:
48  GLF_API
50  GLF_API
51  ~GlfSimpleShadowArray() override;
52 
53  // Disallow copies
54  GlfSimpleShadowArray(const GlfSimpleShadowArray&) = delete;
55  GlfSimpleShadowArray& operator=(const GlfSimpleShadowArray&) = delete;
56 
57  // Returns the GL texture id of the shadow texture.
58  GLF_API
59  GLuint GetShadowMapTexture(int shadowIndex) const;
60 
61  // Returns the GL sampler id of the sampler object used to read the raw
62  // depth values.
63  GLF_API
65 
66  // Returns the GL sampler id of the sampler object used for depth comparison
67  GLF_API
69 
70  // Set the resolutions of all the shadow maps necessary. The number of
71  // resolutions corresponds to the number of shadow map textures necessary,
72  // which is currently one per shadow casting light.
73  GLF_API
74  void SetShadowMapResolutions(std::vector<GfVec2i> const& resolutions);
75 
76  // Returns the number of shadow map generation passes required, which is
77  // currently one per shadow map (corresponding to a shadow casting light).
78  GLF_API
79  size_t GetNumShadowMapPasses() const;
80 
81  // Returns the shadow map resolution for a given pass.
82  // this returns the resolution of the corresponding shadow map,
83  GLF_API
84  GfVec2i GetShadowMapSize(size_t pass) const;
85 
86  // Get/Set the view (world to shadow camera) transform to use for a given
87  // shadow map generation pass.
88  GLF_API
89  GfMatrix4d GetViewMatrix(size_t index) const;
90  GLF_API
91  void SetViewMatrix(size_t index, GfMatrix4d const & matrix);
92 
93  // Get/Set the projection transform to use for a given shadow map generation
94  // pass.
95  GLF_API
96  GfMatrix4d GetProjectionMatrix(size_t index) const;
97  GLF_API
98  void SetProjectionMatrix(size_t index, GfMatrix4d const & matrix);
99 
100  GLF_API
101  GfMatrix4d GetWorldToShadowMatrix(size_t index) const;
102 
103  // Bind necessary resources for a given shadow map generation pass.
104  GLF_API
105  void BeginCapture(size_t index, bool clear);
106 
107  // Unbind necssary resources after a shadow map gneration pass.
108  GLF_API
109  void EndCapture(size_t index);
110 
111  // Sets the GL texture ids of the shadow textures, as opposed to creating
112  // them internally with _AllocTextures().
113  GLF_API
114  void SetTextures(std::vector<GLuint> textureIds);
115 
116  // Allocates the shadow samplers.
117  GLF_API
118  void AllocSamplers();
119 
120 private:
121  void _AllocResources();
122  void _AllocTextures();
123  void _FreeResources();
124  void _FreeTextures();
125  bool _ShadowMapExists() const;
126  void _BindFramebuffer(size_t index);
127  void _UnbindFramebuffer();
128 
129 private:
130  std::vector<GfVec2i> _resolutions;
131  std::vector<GLuint> _textures;
132 
133  std::vector<GfMatrix4d> _viewMatrix;
134  std::vector<GfMatrix4d> _projectionMatrix;
135 
136  GLuint _framebuffer;
137 
138  GLuint _shadowDepthSampler;
139  GLuint _shadowCompareSampler;
140 
141  GLuint _unbindRestoreDrawFramebuffer;
142  GLuint _unbindRestoreReadFramebuffer;
143 
144  GLint _unbindRestoreViewport[4];
145 
146  bool _texturesAllocatedExternally;
147 };
148 
149 
151 
152 #endif
int GLint
Definition: cl.hpp:165
#define GLF_API
Definition: api.h:40
Definition: vec2i.h:60
GLF_API GfVec2i GetShadowMapSize(size_t pass) const
unsigned int GLuint
Definition: cl.hpp:167
GLF_API size_t GetNumShadowMapPasses() const
GLF_API GLuint GetShadowMapDepthSampler() const
GLF_API GLuint GetShadowMapTexture(int shadowIndex) const
GLF_API GlfSimpleShadowArray()
GLF_API void SetShadowMapResolutions(std::vector< GfVec2i > const &resolutions)
GLF_API void SetTextures(std::vector< GLuint > textureIds)
GLF_API GfMatrix4d GetProjectionMatrix(size_t index) const
GLF_API ~GlfSimpleShadowArray() override
GLF_API GfMatrix4d GetWorldToShadowMatrix(size_t index) const
GLF_API void SetViewMatrix(size_t index, GfMatrix4d const &matrix)
GLF_API void AllocSamplers()
GLF_API void SetProjectionMatrix(size_t index, GfMatrix4d const &matrix)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
GLuint index
Definition: glcorearb.h:786
GLF_API GLuint GetShadowMapCompareSampler() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GLF_API GfMatrix4d GetViewMatrix(size_t index) const
GLF_API void EndCapture(size_t index)
GlfSimpleShadowArray & operator=(const GlfSimpleShadowArray &)=delete
GLF_API void BeginCapture(size_t index, bool clear)