2017-03-01 03:05:54 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-03-08 12:31:19 +00:00
|
|
|
#include "gl/dynlights/gl_aabbtree.h"
|
2017-03-02 17:07:47 +00:00
|
|
|
#include "tarray.h"
|
2017-03-08 12:31:19 +00:00
|
|
|
#include <memory>
|
2017-03-02 17:07:47 +00:00
|
|
|
|
|
|
|
class ADynamicLight;
|
2017-03-01 03:05:54 +00:00
|
|
|
|
|
|
|
class FShadowMap
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FShadowMap() { }
|
|
|
|
~FShadowMap() { Clear(); }
|
|
|
|
|
2017-03-08 13:12:59 +00:00
|
|
|
// Release resources
|
2017-03-01 03:05:54 +00:00
|
|
|
void Clear();
|
2017-03-08 13:12:59 +00:00
|
|
|
|
|
|
|
// Update shadow map texture
|
2017-03-01 03:05:54 +00:00
|
|
|
void Update();
|
|
|
|
|
2017-03-08 13:12:59 +00:00
|
|
|
// Return the assigned shadow map index for a given light
|
2017-03-10 18:10:40 +00:00
|
|
|
int ShadowMapIndex(ADynamicLight *light);
|
2017-03-02 17:07:47 +00:00
|
|
|
|
2017-03-08 13:12:59 +00:00
|
|
|
// Test if a world position is in shadow relative to the specified light and returns false if it is
|
2017-03-07 23:34:08 +00:00
|
|
|
bool ShadowTest(ADynamicLight *light, const DVector3 &pos);
|
|
|
|
|
2017-03-10 18:10:40 +00:00
|
|
|
// Returns true if gl_light_shadowmap is enabled and supported by the hardware
|
|
|
|
bool IsEnabled() const;
|
|
|
|
|
2017-03-01 03:05:54 +00:00
|
|
|
private:
|
2017-03-08 13:12:59 +00:00
|
|
|
// Upload the AABB-tree to the GPU
|
2017-03-08 12:31:19 +00:00
|
|
|
void UploadAABBTree();
|
2017-03-08 13:12:59 +00:00
|
|
|
|
|
|
|
// Upload light list to the GPU
|
2017-03-01 16:17:33 +00:00
|
|
|
void UploadLights();
|
|
|
|
|
2017-03-08 13:12:59 +00:00
|
|
|
// OpenGL storage buffer with the list of lights in the shadow map texture
|
2017-03-01 16:17:33 +00:00
|
|
|
int mLightList = 0;
|
2017-03-08 13:12:59 +00:00
|
|
|
|
|
|
|
// Working buffer for creating the list of lights. Stored here to avoid allocating memory each frame
|
2017-03-02 17:07:47 +00:00
|
|
|
TArray<float> mLights;
|
2017-03-08 13:12:59 +00:00
|
|
|
|
|
|
|
// The assigned shadow map index for each light
|
2017-03-02 17:07:47 +00:00
|
|
|
TMap<ADynamicLight*, int> mLightToShadowmap;
|
2017-03-01 03:05:54 +00:00
|
|
|
|
2017-03-08 13:12:59 +00:00
|
|
|
// OpenGL storage buffers for the AABB tree
|
2017-03-08 12:31:19 +00:00
|
|
|
int mNodesBuffer = 0;
|
|
|
|
int mLinesBuffer = 0;
|
|
|
|
|
2017-03-08 13:12:59 +00:00
|
|
|
// Used to detect when a level change requires the AABB tree to be regenerated
|
2017-03-08 12:31:19 +00:00
|
|
|
int mLastNumNodes = 0;
|
|
|
|
int mLastNumSegs = 0;
|
|
|
|
|
2017-03-08 13:12:59 +00:00
|
|
|
// AABB-tree of the level, used for ray tests
|
2017-03-08 12:31:19 +00:00
|
|
|
std::unique_ptr<LevelAABBTree> mAABBTree;
|
|
|
|
|
2017-03-01 03:05:54 +00:00
|
|
|
FShadowMap(const FShadowMap &) = delete;
|
|
|
|
FShadowMap &operator=(FShadowMap &) = delete;
|
|
|
|
};
|