TDME2  1.9.200
ShadowMap.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
7 #include <tdme/engine/fwd-tdme.h>
10 #include <tdme/math/fwd-tdme.h>
11 #include <tdme/math/Matrix4x4.h>
12 #include <tdme/math/Vector3.h>
14 
15 using std::unique_ptr;
16 using std::vector;
17 
25 
26 /**
27  * Shadow map
28  * @author Andreas Drewke
29  */
31 {
32  friend class ShadowMapping;
33 
34 private:
35  vector<Object*> visibleObjects;
37  unique_ptr<Camera> lightCamera;
38  unique_ptr<FrameBuffer> frameBuffer;
41 
42  /**
43  * Initialize shadow map
44  */
45  void initialize();
46 
47  /**
48  * Reshape frame buffer
49  * @param width width
50  * @param height height
51  */
52  void reshape(int32_t width, int32_t height);
53 
54  /**
55  * Disposes this shadow map
56  */
57  void dispose();
58 
59  /**
60  * Binds frame buffer depth texture
61  * @param contextIdx context index
62  */
63  void bindDepthBufferTexture(int contextIdx);
64 
65  /**
66  * @return light camera
67  */
68  Camera* getCamera();
69 
70  /**
71  * Create shadow map
72  * @param light light
73  */
74  void createShadowMap(Light* light);
75 
76  /**
77  * Computes shadow texture matrix and stores it
78  */
80 
81  /**
82  * Set up shadow texture matrix computed and stored before
83  * @param contextIdx context index
84  */
85  void updateDepthBiasMVPMatrix(int contextIdx);
86 
87 public:
88  static constexpr int32_t TEXTUREUNIT { 9 };
89 
90  // forbid class copy
92 
93  /**
94  * Public constructor
95  * @param shadowMapping shadow mapping
96  * @param width width
97  * @param height height
98  */
99  ShadowMap(ShadowMapping* shadowMapping, int32_t width, int32_t height);
100 
101  /**
102  * Destructor
103  */
104  ~ShadowMap();
105 
106  /**
107  * @return width
108  */
109  inline int32_t getWidth() {
110  return frameBuffer->getWidth();
111  }
112 
113  /**
114  * @return height
115  */
116  inline int32_t getHeight() {
117  return frameBuffer->getWidth();
118  }
119 
120  /**
121  * @return frame buffer
122  */
124  return frameBuffer.get();
125  }
126 
127 };
Frame buffer class.
Definition: FrameBuffer.h:22
Light representation.
Definition: Light.h:33
Object to be used with engine class.
Definition: Object.h:60
void reshape(int32_t width, int32_t height)
Reshape frame buffer.
Definition: ShadowMap.cpp:89
void updateDepthBiasMVPMatrix(int contextIdx)
Set up shadow texture matrix computed and stored before.
Definition: ShadowMap.cpp:321
ShadowMap(ShadowMapping *shadowMapping, int32_t width, int32_t height)
Public constructor.
Definition: ShadowMap.cpp:57
void dispose()
Disposes this shadow map.
Definition: ShadowMap.cpp:93
void computeDepthBiasMVPMatrix()
Computes shadow texture matrix and stores it.
Definition: ShadowMap.cpp:312
void createShadowMap(Light *light)
Create shadow map.
Definition: ShadowMap.cpp:108
void bindDepthBufferTexture(int contextIdx)
Binds frame buffer depth texture.
Definition: ShadowMap.cpp:98
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6