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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_GLF_SIMPLE_SHADOW_ARRAY_H
8 #define PXR_IMAGING_GLF_SIMPLE_SHADOW_ARRAY_H
9 
10 /// \file glf/simpleShadowArray.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/imaging/glf/api.h"
15 #include "pxr/base/tf/refPtr.h"
16 #include "pxr/base/tf/weakPtr.h"
17 #include "pxr/base/gf/matrix4d.h"
18 #include "pxr/base/gf/vec2i.h"
19 #include "pxr/base/gf/vec4d.h"
21 
22 #include <vector>
23 
25 
26 
28  public TfWeakBase
29 {
30 public:
31  GLF_API
33  GLF_API
34  ~GlfSimpleShadowArray() override;
35 
36  // Disallow copies
37  GlfSimpleShadowArray(const GlfSimpleShadowArray&) = delete;
38  GlfSimpleShadowArray& operator=(const GlfSimpleShadowArray&) = delete;
39 
40  // Returns the GL texture id of the shadow texture.
41  GLF_API
42  GLuint GetShadowMapTexture(int shadowIndex) const;
43 
44  // Returns the GL sampler id of the sampler object used to read the raw
45  // depth values.
46  GLF_API
48 
49  // Returns the GL sampler id of the sampler object used for depth comparison
50  GLF_API
52 
53  // Set the resolutions of all the shadow maps necessary. The number of
54  // resolutions corresponds to the number of shadow map textures necessary,
55  // which is currently one per shadow casting light.
56  GLF_API
57  void SetShadowMapResolutions(std::vector<GfVec2i> const& resolutions);
58 
59  // Returns the number of shadow map generation passes required, which is
60  // currently one per shadow map (corresponding to a shadow casting light).
61  GLF_API
62  size_t GetNumShadowMapPasses() const;
63 
64  // Returns the shadow map resolution for a given pass.
65  // this returns the resolution of the corresponding shadow map,
66  GLF_API
67  GfVec2i GetShadowMapSize(size_t pass) const;
68 
69  // Get/Set the view (world to shadow camera) transform to use for a given
70  // shadow map generation pass.
71  GLF_API
72  GfMatrix4d GetViewMatrix(size_t index) const;
73  GLF_API
74  void SetViewMatrix(size_t index, GfMatrix4d const & matrix);
75 
76  // Get/Set the projection transform to use for a given shadow map generation
77  // pass.
78  GLF_API
79  GfMatrix4d GetProjectionMatrix(size_t index) const;
80  GLF_API
81  void SetProjectionMatrix(size_t index, GfMatrix4d const & matrix);
82 
83  GLF_API
84  GfMatrix4d GetWorldToShadowMatrix(size_t index) const;
85 
86  // Bind necessary resources for a given shadow map generation pass.
87  GLF_API
88  void BeginCapture(size_t index, bool clear);
89 
90  // Unbind necssary resources after a shadow map gneration pass.
91  GLF_API
92  void EndCapture(size_t index);
93 
94  // Sets the GL texture ids of the shadow textures, as opposed to creating
95  // them internally with _AllocTextures().
96  GLF_API
97  void SetTextures(std::vector<GLuint> textureIds);
98 
99  // Allocates the shadow samplers.
100  GLF_API
101  void AllocSamplers();
102 
103 private:
104  void _AllocResources();
105  void _AllocTextures();
106  void _FreeResources();
107  void _FreeTextures();
108  bool _ShadowMapExists() const;
109  void _BindFramebuffer(size_t index);
110  void _UnbindFramebuffer();
111 
112 private:
113  std::vector<GfVec2i> _resolutions;
114  std::vector<GLuint> _textures;
115 
116  std::vector<GfMatrix4d> _viewMatrix;
117  std::vector<GfMatrix4d> _projectionMatrix;
118 
119  GLuint _framebuffer;
120 
121  GLuint _shadowDepthSampler;
122  GLuint _shadowCompareSampler;
123 
124  GLuint _unbindRestoreDrawFramebuffer;
125  GLuint _unbindRestoreReadFramebuffer;
126 
127  GLint _unbindRestoreViewport[4];
128 
129  bool _texturesAllocatedExternally;
130 };
131 
132 
134 
135 #endif
int GLint
Definition: cl.hpp:165
#define GLF_API
Definition: api.h:23
Definition: vec2i.h:43
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:1425
GLuint index
Definition: glcorearb.h:786
GLF_API GLuint GetShadowMapCompareSampler() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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)