lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
lmgl::renderer::ShadowMap Class Reference

Manages a 2D depth texture for rendering shadows from directional lights. More...

#include <shadow_map.hpp>

Public Member Functions

 ShadowMap (unsigned int width=2048, unsigned int height=2048)
 Constructs a ShadowMap with the specified width and height.
 
 ~ShadowMap ()
 Destructor for ShadowMap.
 
void bind ()
 Binds the framebuffer object for rendering to the shadow map.
 
void unbind ()
 Unbinds the framebuffer object, returning to the default framebuffer.
 
void bind_texture (unsigned int slot=0) const
 Binds the depth texture to the specified texture slot for use in shaders.
 
unsigned int get_texture_id () const
 Returns the OpenGL texture ID of the depth texture.
 
unsigned int get_width () const
 Returns the width of the shadow map texture.
 
unsigned int get_height () const
 Returns the height of the shadow map texture.
 
void resize (unsigned int width, unsigned int height)
 Resizes the shadow map texture to the specified width and height.
 

Detailed Description

Manages a 2D depth texture for rendering shadows from directional lights.

This class encapsulates the creation and management of a framebuffer object (FBO) and a depth texture used for shadow mapping. It provides methods to bind and unbind the FBO, bind the depth texture for use in shaders, and resize the shadow map.

Note
The default resolution is set to 2048x2048 pixels.

Constructor & Destructor Documentation

◆ ShadowMap()

lmgl::renderer::ShadowMap::ShadowMap ( unsigned int width = 2048,
unsigned int height = 2048 )

Constructs a ShadowMap with the specified width and height.

Creates a framebuffer object and a depth texture for shadow mapping.

Parameters
widthThe width of the shadow map texture. Default is 2048.
heightThe height of the shadow map texture. Default is 2048.

Member Function Documentation

◆ bind()

void lmgl::renderer::ShadowMap::bind ( )

Binds the framebuffer object for rendering to the shadow map.

This method binds the FBO so that subsequent rendering commands will write depth information to the shadow map texture.

Note
Make sure to unbind the FBO after rendering using the unbind method.

◆ bind_texture()

void lmgl::renderer::ShadowMap::bind_texture ( unsigned int slot = 0) const

Binds the depth texture to the specified texture slot for use in shaders.

This method binds the depth texture so that it can be sampled in shaders for shadow calculations.

Parameters
slotThe texture slot to bind the depth texture to. Default is 0.

◆ get_height()

unsigned int lmgl::renderer::ShadowMap::get_height ( ) const
inline

Returns the height of the shadow map texture.

Returns
The height of the shadow map texture in pixels.

◆ get_texture_id()

unsigned int lmgl::renderer::ShadowMap::get_texture_id ( ) const
inline

Returns the OpenGL texture ID of the depth texture.

Returns
The texture ID of the depth texture.

◆ get_width()

unsigned int lmgl::renderer::ShadowMap::get_width ( ) const
inline

Returns the width of the shadow map texture.

Returns
The width of the shadow map texture in pixels.

◆ resize()

void lmgl::renderer::ShadowMap::resize ( unsigned int width,
unsigned int height )

Resizes the shadow map texture to the specified width and height.

This method recreates the depth texture with the new dimensions.

Parameters
widthThe new width of the shadow map texture.
heightThe new height of the shadow map texture.

◆ unbind()

void lmgl::renderer::ShadowMap::unbind ( )

Unbinds the framebuffer object, returning to the default framebuffer.

This method should be called after rendering to the shadow map is complete. It restores rendering to the default framebuffer.


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