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 GLF_SIMPLE_SHADOW_ARRAY_H
25 #define GLF_SIMPLE_SHADOW_ARRAY_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
31 #include "pxr/base/tf/declarePtrs.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"
37 #include "pxr/imaging/garch/gl.h"
38 
39 #include <boost/noncopyable.hpp>
40 #include <vector>
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
44 
45 class GlfSimpleShadowArray : public TfRefBase,
46  public TfWeakBase,
47  boost::noncopyable {
48 public:
49  GLF_API
50  GlfSimpleShadowArray(GfVec2i const & size, size_t numLayers);
51  GLF_API
52  virtual ~GlfSimpleShadowArray();
53 
54  GLF_API
55  GfVec2i GetSize() const;
56  GLF_API
57  void SetSize(GfVec2i const & size);
58 
59  GLF_API
60  size_t GetNumLayers() const;
61  GLF_API
62  void SetNumLayers(size_t numLayers);
63 
64  GLF_API
65  GfMatrix4d GetViewMatrix(size_t index) const;
66  GLF_API
67  void SetViewMatrix(size_t index, GfMatrix4d const & matrix);
68 
69  GLF_API
70  GfMatrix4d GetProjectionMatrix(size_t index) const;
71  GLF_API
72  void SetProjectionMatrix(size_t index, GfMatrix4d const & matrix);
73 
74  GLF_API
75  GfMatrix4d GetWorldToShadowMatrix(size_t index) const;
76 
77  GLF_API
78  GLuint GetShadowMapTexture() const;
79  GLF_API
80  GLuint GetShadowMapDepthSampler() const;
81  GLF_API
82  GLuint GetShadowMapCompareSampler() const;
83 
84  GLF_API
85  void BeginCapture(size_t index, bool clear);
86  GLF_API
87  void EndCapture(size_t index);
88 
89 private:
90  void _AllocTextureArray();
91  void _FreeTextureArray();
92 
93  void _BindFramebuffer(size_t index);
94  void _UnbindFramebuffer();
95 
96 private:
97  GfVec2i _size;
98  size_t _numLayers;
99 
100  std::vector<GfMatrix4d> _viewMatrix;
101  std::vector<GfMatrix4d> _projectionMatrix;
102 
103  GLuint _texture;
104  GLuint _framebuffer;
105 
106  GLuint _shadowDepthSampler;
107  GLuint _shadowCompareSampler;
108 
109  GLuint _unbindRestoreDrawFramebuffer;
110  GLuint _unbindRestoreReadFramebuffer;
111 
112  GLint _unbindRestoreViewport[4];
113 };
114 
115 
116 PXR_NAMESPACE_CLOSE_SCOPE
117 
118 #endif
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:72
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:142