ShadowVolume.h#

Contains an implementation of Shadow Volume generation.

Includes#

  • PVRAssets/Volume.h

  • PVRAssets/model/Mesh.h

Namespaces#

Classes#

Source Code#

#pragma once

#include "PVRAssets/model/Mesh.h"
#include "PVRAssets/Volume.h"

namespace pvr {

class ShadowVolume : public Volume
{
public:
    enum Flags
    {
        Visible = 0x01,
        Cap_front = 0x02,
        Cap_back = 0x04,
        Zfail = 0x08
    };

public:
    ~ShadowVolume();

    void alllocateShadowVolume(uint32_t volumeID);

    bool releaseVolume(uint32_t volumeID);

    uint32_t getNumIndices(uint32_t volumeID);

    char* getIndices(uint32_t volumeID);

    bool isIndexDataInternal(uint32_t volumeID);

    uint32_t isVisible(const glm::mat4x4 projection, const glm::vec3& lightModel, bool isPointLight, float cameraZProj, float extrudeLength);

    bool projectSilhouette(uint32_t volumeID, uint32_t flags, const glm::vec3& lightModel, bool isPointLight, char** externalIndexBuffer = NULL);

private:
    // A silhouette?
    struct ShadowVolumeData
    {
        char* indexData;
        uint32_t numIndices; // If the index count is greater than 0 and indexData is NULL then the data is handled externally

        ShadowVolumeData() : indexData(NULL), numIndices(0) {}
        ~ShadowVolumeData() { delete indexData; }
    };

    // Extrude
    template<typename INDEXTYPE>
    bool project(uint32_t volumeID, uint32_t flags, const glm::vec3& lightModel, bool isPointLight, INDEXTYPE** externalIndexBuffer);

    typedef std::map<uint32_t, ShadowVolumeData> ShadowVolumeMapType;
    std::map<uint32_t, ShadowVolumeData> _shadowVolumes;
};
} // namespace pvr