Loading...
Searching...
No Matches
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
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"
35#include "pxr/base/gf/vec2i.h"
36#include "pxr/base/gf/vec4d.h"
37#include "pxr/imaging/garch/glApi.h"
38
39#include <vector>
40
41PXR_NAMESPACE_OPEN_SCOPE
42
43
44class GlfSimpleShadowArray : public TfRefBase,
45 public TfWeakBase
46{
47public:
48 GLF_API
49 GlfSimpleShadowArray();
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
64 GLuint GetShadowMapDepthSampler() const;
65
66 // Returns the GL sampler id of the sampler object used for depth comparison
67 GLF_API
68 GLuint GetShadowMapCompareSampler() const;
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
120private:
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
129private:
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
150PXR_NAMESPACE_CLOSE_SCOPE
151
152#endif
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:73
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
Standard pointer typedefs.
Reference counting.
Pointer storage with deletion detection.