3D Graphics Engine for ESP32
 
Loading...
Searching...
No Matches
Ragot::Rasterizer< Color > Class Template Reference

Class for rasterizing polygons in a frame buffer. More...

#include <Rasterizer.hpp>

Inheritance diagram for Ragot::Rasterizer< Color >:
Inheritance graph
Collaboration diagram for Ragot::Rasterizer< Color >:
Collaboration graph

Public Member Functions

 Rasterizer (FrameBuffer< Color > &frame)
 Constructs a Rasterizer with a given frame buffer.
 
 Rasterizer ()=default
 Default constructor for the Rasterizer class (Default).
 
 ~Rasterizer ()=default
 Default destructor for the Rasterizer class.
 
const FrameBuffer< Color > & get_frame_buffer () const
 Gets the frame buffer associated with this rasterizer.
 
void set_color (const Color &new_color)
 Gets the current color used for drawing polygons.
 
void clear ()
 Gets the current color used for clearing the frame buffer.
 
void fill_convex_polygon (const glm::ivec4 *const vertices, const int *const indices_begin, const int *const indices_end)
 Fills a convex polygon defined by its vertices and indices.
 
void fill_convex_polygon (const glm::ivec4 *const vertices, const face_t *const face)
 Fills a convex polygon defined by its vertices and face structure.
 
void fill_convex_polygon_z_buffer (const glm::ivec4 *const vertices, const face_t *const face)
 Fills a convex polygon in the Z-buffer.
 
void fill_convex_polygon_z_buffer (const glm::ivec4 *const vertices, const int *const indices_begin, const int *const indices_end)
 Fills a convex polygon in the Z-buffer using vertex indices.
 

Public Attributes

bool debug_enabled = true
 

Private Member Functions

template<typename VALUE_TYPE, size_t SHIFT>
void interpolate (int *cache, int v0, int v1, int y_min, int y_max)
 < Enable or disable debug logging for rasterization operations.
 
template<unsigned COLOR_SIZE>
void fill_row (Color *start, unsigned left_offset, unsigned right_offset, const Color &color)
 Fills a row of pixels in the frame buffer with a specified color.
 
template<unsigned COLOR_SIZE>
void fill_row_zbuffer (Color *start, int *zbuffer, unsigned left_offset, unsigned right_offset, int z_start, int dz, const Color &color)
 Fills a row of pixels in the frame buffer with a specified color using Z-buffering.
 
void fill_row (RGB565 *start, unsigned left_offset, unsigned right_offset, const RGB565 &color)
 
void fill_row_zbuffer (RGB565 *start, int *zbuffer, unsigned left_offset, unsigned right_offset, int z_start, int dz, const RGB565 &color)
 

Private Attributes

FrameBuffer< Color > & frame_buffer
 Reference to the frame buffer where polygons will be drawn.
 
std::vector< int > z_buffer
 Z-buffer for depth testing, used when painter's algorithm is disabled.
 
Color color
 Current color to be used for drawing polygons.
 
Color clear_color
 Color used to clear the frame buffer, default is black.
 

Static Private Attributes

static int offset_cache0 [1024]
 Cache for left offsets of scanlines >
 
static int offset_cache1 [1024]
 Cache for right offsets of scanlines.
 
static int z_cache0 [1024]
 Cache for Z-buffer values for left offsets.
 
static int z_cache1 [1024]
 Cache for Z-buffer values for right offsets.
 
static constexpr const char * RASTER_TAG = "Rasterizer"
 

Detailed Description

template<typename Color>
class Ragot::Rasterizer< Color >

Class for rasterizing polygons in a frame buffer.

This class provides methods to fill convex polygons in a frame buffer with a specified color. It supports both standard rasterization and Z-buffering techniques.

Template Parameters
ColorThe color type used for the frame buffer (e.g., RGB565).

Constructor & Destructor Documentation

◆ Rasterizer() [1/2]

template<typename Color>
Ragot::Rasterizer< Color >::Rasterizer ( FrameBuffer< Color > & frame)
inline

Constructs a Rasterizer with a given frame buffer.

Initializes the rasterizer with the specified frame buffer and prepares the Z-buffer if needed.

Parameters
frameReference to the frame buffer where polygons will be drawn.

◆ Rasterizer() [2/2]

template<typename Color>
Ragot::Rasterizer< Color >::Rasterizer ( )
default

Default constructor for the Rasterizer class (Default).

◆ ~Rasterizer()

template<typename Color>
Ragot::Rasterizer< Color >::~Rasterizer ( )
default

Default destructor for the Rasterizer class.

Cleans up resources used by the rasterizer.

Member Function Documentation

◆ clear()

template<typename Color>
void Ragot::Rasterizer< Color >::clear ( )
inline

Gets the current color used for clearing the frame buffer.

This method returns the color that will be used to clear the frame buffer.

Returns
const Color& Reference to the clear color.

◆ fill_convex_polygon() [1/2]

template<typename COLOR>
void Ragot::Rasterizer< COLOR >::fill_convex_polygon ( const glm::ivec4 *const vertices,
const face_t *const face )

Fills a convex polygon defined by its vertices and face structure.

This method fills a convex polygon in the frame buffer using the specified vertices and face structure.

Parameters
verticesPointer to an array of vertices defining the polygon.
facePointer to the face structure containing vertex indices.

◆ fill_convex_polygon() [2/2]

template<typename COLOR>
void Ragot::Rasterizer< COLOR >::fill_convex_polygon ( const glm::ivec4 *const vertices,
const int *const indices_begin,
const int *const indices_end )

Fills a convex polygon defined by its vertices and indices.

This method fills a convex polygon in the frame buffer using the specified vertices and indices.

Parameters
verticesPointer to an array of vertices defining the polygon.
indices_beginPointer to the beginning of the indices array.
indices_endPointer to the end of the indices array.
Here is the call graph for this function:

◆ fill_convex_polygon_z_buffer() [1/2]

template<typename COLOR>
template void Ragot::Rasterizer< Color >::fill_convex_polygon_z_buffer ( const glm::ivec4 *const vertices,
const face_t *const face )

Fills a convex polygon in the Z-buffer.

This method fills a convex polygon in the Z-buffer using the specified vertices and face structure. It performs depth testing to ensure correct rendering order.

Parameters
verticesPointer to an array of vertices defining the polygon.
facePointer to the face structure containing vertex indices.

◆ fill_convex_polygon_z_buffer() [2/2]

template<typename COLOR>
template void Ragot::Rasterizer< Color >::fill_convex_polygon_z_buffer ( const glm::ivec4 *const vertices,
const int *const indices_begin,
const int *const indices_end )

Fills a convex polygon in the Z-buffer using vertex indices.

  • This method fills a convex polygon in the Z-buffer using the specified vertices and indices. It performs depth testing to ensure correct rendering order.
    Parameters
    verticesPointer to an array of vertices defining the polygon.
    indices_beginPointer to the beginning of the indices array.
    indices_endPointer to the end of the indices array.
Here is the call graph for this function:

◆ fill_row() [1/2]

template<typename Color>
template<unsigned COLOR_SIZE>
void Ragot::Rasterizer< Color >::fill_row ( Color * start,
unsigned left_offset,
unsigned right_offset,
const Color & color )
inlineprivate

Fills a row of pixels in the frame buffer with a specified color.

This method fills a row of pixels in the frame buffer with the specified color, from left_offset to right_offset.

Template Parameters
COLOR_SIZEThe size of the color type in bytes.
Parameters
startPointer to the first pixel of the scanline.
left_offsetThe starting offset (inclusive).
right_offsetThe ending offset (exclusive).
colorThe color to fill the row with.

◆ fill_row() [2/2]

void Ragot::Rasterizer< RGB565 >::fill_row< 2 > ( RGB565 * start,
unsigned left_offset,
unsigned right_offset,
const RGB565 & color )
private

◆ fill_row_zbuffer() [1/2]

template<typename Color>
template<unsigned COLOR_SIZE>
void Ragot::Rasterizer< Color >::fill_row_zbuffer ( Color * start,
int * zbuffer,
unsigned left_offset,
unsigned right_offset,
int z_start,
int dz,
const Color & color )
inlineprivate

Fills a row of pixels in the frame buffer with a specified color using Z-buffering.

This method fills a row of pixels in the frame buffer with the specified color, from left_offset to right_offset, while performing depth testing using the Z-buffer.

Template Parameters
COLOR_SIZEThe size of the color type in bytes.
Parameters
startPointer to the first pixel of the scanline.
zbufferPointer to the first element of the Z-buffer.
left_offsetThe starting offset (inclusive).
right_offsetThe ending offset (exclusive).
z_startThe initial depth value at left_offset.
dzThe increment of depth per pixel.
colorThe color to fill the row with.

◆ fill_row_zbuffer() [2/2]

void Ragot::Rasterizer< RGB565 >::fill_row_zbuffer< 2 > ( RGB565 * start,
int * zbuffer,
unsigned left_offset,
unsigned right_offset,
int z_start,
int dz,
const RGB565 & color )
private

◆ get_frame_buffer()

template<typename Color>
const FrameBuffer< Color > & Ragot::Rasterizer< Color >::get_frame_buffer ( ) const
inline

Gets the frame buffer associated with this rasterizer.

This method returns a reference to the frame buffer where polygons will be drawn.

Returns
const FrameBuffer<Color>& Reference to the frame buffer.

◆ interpolate()

template<typename COLOR>
template<typename VALUE_TYPE, size_t SHIFT>
void Ragot::Rasterizer< COLOR >::interpolate ( int * cache,
int v0,
int v1,
int y_min,
int y_max )
private

< Enable or disable debug logging for rasterization operations.

Interpolates pixel offsets for a scanline.

This method interpolates pixel offsets for a scanline based on the provided vertex values and Y range. It fills the offset cache with calculated pixel offsets.

Template Parameters
VALUE_TYPEThe type of value used for interpolation (e.g., int32_t).
SHIFTThe bit shift value used for scaling the interpolation.
Parameters
cachePointer to the cache where interpolated offsets will be stored.
v0The starting vertex value.
v1The ending vertex value.
y_minThe minimum Y coordinate of the scanline.
y_maxThe maximum Y coordinate of the scanline.
Here is the caller graph for this function:

◆ set_color()

template<typename Color>
void Ragot::Rasterizer< Color >::set_color ( const Color & new_color)
inline

Gets the current color used for drawing polygons.

This method returns the current color that will be used to fill polygons.

Returns
const Color& Reference to the current color.

Member Data Documentation

◆ clear_color

template<typename Color>
Color Ragot::Rasterizer< Color >::clear_color
private

Color used to clear the frame buffer, default is black.

◆ color

template<typename Color>
Color Ragot::Rasterizer< Color >::color
private

Current color to be used for drawing polygons.

◆ debug_enabled

template<typename Color>
bool Ragot::Rasterizer< Color >::debug_enabled = true

◆ frame_buffer

template<typename Color>
FrameBuffer< Color >& Ragot::Rasterizer< Color >::frame_buffer
private

Reference to the frame buffer where polygons will be drawn.

◆ offset_cache0

template<typename Color>
int Ragot::Rasterizer< Color >::offset_cache0[1024]
staticprivate

Cache for left offsets of scanlines >

◆ offset_cache1

template<typename Color>
int Ragot::Rasterizer< Color >::offset_cache1[1024]
staticprivate

Cache for right offsets of scanlines.

◆ RASTER_TAG

template<typename Color>
const char* Ragot::Rasterizer< Color >::RASTER_TAG = "Rasterizer"
staticconstexprprivate

◆ z_buffer

template<typename Color>
std::vector< int > Ragot::Rasterizer< Color >::z_buffer
private

Z-buffer for depth testing, used when painter's algorithm is disabled.

◆ z_cache0

template<typename Color>
int Ragot::Rasterizer< Color >::z_cache0[1024]
staticprivate

Cache for Z-buffer values for left offsets.

◆ z_cache1

template<typename Color>
int Ragot::Rasterizer< Color >::z_cache1[1024]
staticprivate

Cache for Z-buffer values for right offsets.


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