Loading...
Searching...
No Matches
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
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"
18#include "pxr/base/gf/vec2i.h"
19#include "pxr/base/gf/vec4d.h"
20#include "pxr/imaging/garch/glApi.h"
21
22#include <vector>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26
27class GlfSimpleShadowArray : public TfRefBase,
28 public TfWeakBase
29{
30public:
31 GLF_API
32 GlfSimpleShadowArray();
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
47 GLuint GetShadowMapDepthSampler() const;
48
49 // Returns the GL sampler id of the sampler object used for depth comparison
50 GLF_API
51 GLuint GetShadowMapCompareSampler() const;
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
103private:
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
112private:
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
133PXR_NAMESPACE_CLOSE_SCOPE
134
135#endif
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type for a vector of 2 int components.
Definition: vec2i.h:44
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:56
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
Standard pointer typedefs.
Reference counting.
Pointer storage with deletion detection.