Pyrogenesis  trunk
Public Member Functions | Private Attributes | List of all members
ShadowMap Class Reference

Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup, including matrix calculations. More...

#include <ShadowMap.h>

Collaboration diagram for ShadowMap:
Collaboration graph
[legend]

Public Member Functions

 ShadowMap ()
 
 ~ShadowMap ()
 
void RecreateTexture ()
 RecreateTexture: Destroy the current shadow texture and force creation of a new one. More...
 
int GetDepthTextureBits () const
 GetDepthTextureBits: Return the number of bits to use for depth textures when enabled. More...
 
void SetDepthTextureBits (int bits)
 SetDepthTextureBits: Sets the number of bits to use for depth textures when enabled. More...
 
int GetWidth () const
 GetWidth: Return the width of the depth texture. More...
 
int GetHeight () const
 GetHeight: Return the height of the depth texture. More...
 
void SetupFrame (const CCamera &camera, const CVector3D &lightdir)
 SetupFrame: Configure light space for the given camera and light direction, create the shadow texture if necessary, etc. More...
 
void AddShadowCasterBound (const CBoundingBoxAligned &bounds)
 Add the bounding box of an object that will cast a shadow. More...
 
void AddShadowReceiverBound (const CBoundingBoxAligned &bounds)
 Add the bounding box of an object that will receive a shadow. More...
 
CFrustum GetShadowCasterCullFrustum ()
 Compute the frustum originating at the light source, that encompasses all the objects passed into AddShadowReceiverBound so far. More...
 
void BeginRender ()
 BeginRender: Set OpenGL state for rendering into the shadow map texture. More...
 
void EndRender ()
 EndRender: Finish rendering into the shadow map. More...
 
GLuint GetTexture () const
 GetTexture: Retrieve the OpenGL texture object name that contains the shadow map. More...
 
const CMatrix3DGetTextureMatrix () const
 GetTextureMatrix: Retrieve the world-space to shadow map texture coordinates transformation matrix. More...
 
void RenderDebugBounds ()
 Visualize shadow mapping calculations to help in debugging and optimal shadow map usage. More...
 
void RenderDebugTexture ()
 Visualize shadow map texture to help in debugging. More...
 

Private Attributes

ShadowMapInternalsm
 

Detailed Description

Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup, including matrix calculations.

The class will automatically generate a texture the first time the shadow map is rendered into. The texture will not be resized afterwards.

Constructor & Destructor Documentation

ShadowMap::ShadowMap ( )
ShadowMap::~ShadowMap ( )

Member Function Documentation

void ShadowMap::AddShadowCasterBound ( const CBoundingBoxAligned bounds)

Add the bounding box of an object that will cast a shadow.

This is used to calculate the bounds for the shadow map.

Parameters
boundsworld space bounding box
void ShadowMap::AddShadowReceiverBound ( const CBoundingBoxAligned bounds)

Add the bounding box of an object that will receive a shadow.

This is used to calculate the bounds for the shadow map.

Parameters
boundsworld space bounding box
void ShadowMap::BeginRender ( )

BeginRender: Set OpenGL state for rendering into the shadow map texture.

Todo:
this depends in non-obvious ways on the behaviour of the call-site
void ShadowMap::EndRender ( )

EndRender: Finish rendering into the shadow map.

Todo:
this depends in non-obvious ways on the behaviour of the call-site
int ShadowMap::GetDepthTextureBits ( ) const

GetDepthTextureBits: Return the number of bits to use for depth textures when enabled.

Returns
depth texture bit depth
int ShadowMap::GetHeight ( ) const

GetHeight: Return the height of the depth texture.

Returns
depth texture height
CFrustum ShadowMap::GetShadowCasterCullFrustum ( )

Compute the frustum originating at the light source, that encompasses all the objects passed into AddShadowReceiverBound so far.

This frustum can be used to determine which objects might cast a visible shadow. Those objects should be passed to AddShadowCasterBound and then should be rendered into the shadow map.

GLuint ShadowMap::GetTexture ( ) const

GetTexture: Retrieve the OpenGL texture object name that contains the shadow map.

Returns
the texture name of the shadow map texture
const CMatrix3D & ShadowMap::GetTextureMatrix ( ) const

GetTextureMatrix: Retrieve the world-space to shadow map texture coordinates transformation matrix.

Returns
the matrix that transforms world-space coordinates into homogenous shadow map texture coordinates
int ShadowMap::GetWidth ( ) const

GetWidth: Return the width of the depth texture.

Returns
depth texture width
void ShadowMap::RecreateTexture ( )

RecreateTexture: Destroy the current shadow texture and force creation of a new one.

Useful when the renderer's size has changed and the texture should be resized too.

void ShadowMap::RenderDebugBounds ( )

Visualize shadow mapping calculations to help in debugging and optimal shadow map usage.

void ShadowMap::RenderDebugTexture ( )

Visualize shadow map texture to help in debugging.

void ShadowMap::SetDepthTextureBits ( int  bits)

SetDepthTextureBits: Sets the number of bits to use for depth textures when enabled.

Possible values are 16, 24, 32 and 0 (= use default)

Parameters
bitsnumber of bits
void ShadowMap::SetupFrame ( const CCamera camera,
const CVector3D lightdir 
)

SetupFrame: Configure light space for the given camera and light direction, create the shadow texture if necessary, etc.

Parameters
camerathe camera that will be used for world rendering
lightdirthe direction of the (directional) sunlight

Member Data Documentation

ShadowMapInternals* ShadowMap::m
private

The documentation for this class was generated from the following files: