Class to manage a frame buffer for rendering graphics. More...
#include <FrameBuffer.hpp>
Public Types | |
using | TYPE = Color |
using | ColorVector = std::vector < Color > |
Public Member Functions | |
FrameBuffer (size_t width, size_t height, bool double_buffer) | |
Constructor for the FrameBuffer class. | |
FrameBuffer ()=delete | |
Default constructor for the FrameBuffer class (Deleted). | |
~FrameBuffer ()=default | |
Default destructor for the FrameBuffer class. | |
FrameBuffer (const FrameBuffer &)=delete | |
Construct a new Frame Buffer object (Deleted). | |
FrameBuffer (const FrameBuffer &&)=delete | |
Construct a new Frame Buffer object (Deleted). | |
FrameBuffer & | operator= (const FrameBuffer &)=delete |
Assignment operator for the FrameBuffer class (Deleted). | |
FrameBuffer & | operator= (const FrameBuffer &&)=delete |
Assignment operator for the FrameBuffer class (Deleted). | |
void | swap_buffers () |
Swaps the current buffer with the next buffer. | |
void | clear_buffer (Buffer buffer_to_clear=NEXT_BUFFER) |
Clears the specified buffer by filling it with the default color. | |
void | fill (Color color=0, Buffer buffer_to_fill=NEXT_BUFFER) |
Fills the specified buffer with the given color. | |
void | set_pixel (size_t x, size_t y, Color color) |
Sets a pixel at the specified coordinates to the given color. | |
void | set_pixel (size_t offset, Color color) |
Sets a pixel at the specified offset in the buffer to the given color. | |
void | set_pixel (size_t offset) |
Sets a pixel at the specified offset in the buffer to the default color. | |
void | set_color (Color color) |
Sets the default color for the frame buffer. | |
Color | get_pixel (size_t x, size_t y) const |
Gets the color of a pixel at the specified coordinates. | |
size_t | get_width () |
Gets the color of a pixel at the specified offset in the buffer. | |
size_t | get_width () const |
Gets the width of the frame buffer. | |
size_t | get_height () |
Gets the height of the frame buffer. | |
size_t | get_height () const |
Gets the height of the frame buffer. | |
const Color * | get_buffer () const |
Gets the current buffer being used. | |
Color * | get_buffer () |
Get the buffer object. | |
void | blit_to_window () const |
Blits the current buffer to the window. This method copies the contents of the current buffer to the next buffer, effectively preparing the next frame for rendering. | |
void | initGLTexture () |
Initializes the OpenGL texture for the frame buffer. | |
void | sendGL () const |
Clears the OpenGL texture associated with the frame buffer. | |
GLuint | getGLTex () const |
Gets the OpenGL texture ID for the frame buffer. | |
Static Public Member Functions | |
static GLenum | getGLFormat () |
Sets the OpenGL texture for the frame buffer. | |
static GLenum | getGLType () |
Gets the OpenGL type for the frame buffer. | |
Private Attributes | |
bool | double_buffer |
Flag to indicate if double buffering is enabled. | |
size_t | width |
Width of the frame buffer in pixels. | |
size_t | height |
Height of the frame buffer in pixels. | |
Color | color |
Default color for filling the buffer. | |
ColorVector | buffer_1 |
First buffer for single or double buffering. | |
ColorVector | buffer_2 |
Second buffer for double buffering (if enabled) | |
ColorVector * | current_buffer |
Pointer to the current buffer being used. | |
ColorVector * | next_buffer |
Pointer to the next buffer to be used (for double buffering) | |
GLuint | gl_tex = 0 |
OpenGL texture ID for the frame buffer. | |
Class to manage a frame buffer for rendering graphics.
This class provides methods to create a frame buffer, swap buffers, clear the buffer, fill it with a color, set and get pixels, and manage OpenGL textures. It supports both single and double buffering modes.
using Ragot::FrameBuffer< Color >::ColorVector = std::vector < Color > |
using Ragot::FrameBuffer< Color >::TYPE = Color |
Ragot::FrameBuffer< Color >::FrameBuffer | ( | size_t | width, |
size_t | height, | ||
bool | double_buffer ) |
Constructor for the FrameBuffer class.
Initializes the frame buffer with the specified width, height, and double buffering option. Allocates memory for the buffers and fills them with the default color.
width | Width of the frame buffer in pixels. |
height | Height of the frame buffer in pixels. |
double_buffer | Flag to indicate if double buffering is enabled. |
|
delete |
Default constructor for the FrameBuffer class (Deleted).
|
default |
Default destructor for the FrameBuffer class.
Cleans up resources used by the frame buffer.
|
delete |
|
delete |
|
inline |
Blits the current buffer to the window. This method copies the contents of the current buffer to the next buffer, effectively preparing the next frame for rendering.
void Ragot::FrameBuffer< Color >::clear_buffer | ( | Buffer | buffer_to_clear = NEXT_BUFFER | ) |
Clears the specified buffer by filling it with the default color.
buffer_to_clear | The buffer to clear (CURRENT_BUFFER, NEXT_BUFFER, or MAX_BUFFER). |
void Ragot::FrameBuffer< Color >::fill | ( | Color | color = 0, |
Buffer | buffer_to_fill = NEXT_BUFFER ) |
Fills the specified buffer with the given color.
color | The color to fill the buffer with (default is 0). |
buffer_to_fill | The buffer to fill (CURRENT_BUFFER, NEXT_BUFFER, or MAX_BUFFER). |
|
inline |
Get the buffer object.
|
inline |
Gets the current buffer being used.
|
inline |
Gets the height of the frame buffer.
|
inline |
Gets the height of the frame buffer.
Color Ragot::FrameBuffer< Color >::get_pixel | ( | size_t | x, |
size_t | y ) const |
Gets the color of a pixel at the specified coordinates.
x | X coordinate of the pixel. |
y | Y coordinate of the pixel. |
|
inline |
Gets the color of a pixel at the specified offset in the buffer.
offset | Offset in the buffer (calculated as y * width + x). |
|
inline |
Gets the width of the frame buffer.
|
static |
Sets the OpenGL texture for the frame buffer.
This method binds the OpenGL texture to the current context.
|
inline |
Gets the OpenGL texture ID for the frame buffer.
|
static |
Gets the OpenGL type for the frame buffer.
This method returns the OpenGL type corresponding to the color format used in the frame buffer.
void Ragot::FrameBuffer< Color >::initGLTexture | ( | ) |
Initializes the OpenGL texture for the frame buffer.
This method creates an OpenGL texture and binds it to the frame buffer.
|
delete |
Assignment operator for the FrameBuffer class (Deleted).
Prevents assignment of FrameBuffer objects.
|
delete |
Assignment operator for the FrameBuffer class (Deleted).
Prevents assignment of FrameBuffer objects.
void Ragot::FrameBuffer< Color >::sendGL | ( | ) | const |
Clears the OpenGL texture associated with the frame buffer.
This method deletes the OpenGL texture to free up resources.
void Ragot::FrameBuffer< Color >::set_color | ( | Color | color | ) |
Sets the default color for the frame buffer.
color | The color to set as the default. |
void Ragot::FrameBuffer< Color >::set_pixel | ( | size_t | offset | ) |
Sets a pixel at the specified offset in the buffer to the default color.
offset | Offset in the buffer (calculated as y * width + x). |
void Ragot::FrameBuffer< Color >::set_pixel | ( | size_t | offset, |
Color | color ) |
Sets a pixel at the specified offset in the buffer to the given color.
offset | Offset in the buffer (calculated as y * width + x). |
color | Color value for the pixel. |
void Ragot::FrameBuffer< Color >::set_pixel | ( | size_t | x, |
size_t | y, | ||
Color | color ) |
Sets a pixel at the specified coordinates to the given color.
x | X coordinate of the pixel. |
y | Y coordinate of the pixel. |
color | Color value for the pixel. |
void Ragot::FrameBuffer< Color >::swap_buffers | ( | ) |
Swaps the current buffer with the next buffer.
This method is used in double buffering to switch between the buffers for rendering.
|
private |
First buffer for single or double buffering.
|
private |
Second buffer for double buffering (if enabled)
|
private |
Default color for filling the buffer.
|
private |
Pointer to the current buffer being used.
|
private |
Flag to indicate if double buffering is enabled.
|
private |
OpenGL texture ID for the frame buffer.
This variable holds the OpenGL texture ID used for rendering the frame buffer.
|
private |
Height of the frame buffer in pixels.
|
private |
Pointer to the next buffer to be used (for double buffering)
|
private |
Width of the frame buffer in pixels.