![]() |
Louvre
v1.0.1-1
C++ library for Wayland compositors
|
#include <LPainter.h>
Utility for Painting Operations. More...
Utility for Painting Operations.
The LPainter class offers basic methods for 2D rendering without the need to use OpenGL functions directly. It can draw texture rects or solid colors, clear the screen and set the viewport.
Its goal is to abstract the rendering API, allowing for portable compositors, independent of the renderer used.
Currently, the library only offers the OpenGL ES 2.0 renderer, but in the future others such as Vulkan, Pixman, etc. could be incorporated.
Each LOutput has its own LPainter, which can be accessed from LOutput::painter().
When specifying the destination rect for your painting operations, you must use surface coordinates. LPainter automatically scales the content for you, taking into account the scale factor of the texture you are drawing and the scale factor of the destination framebuffer.
The coordinate space in which the content is rendered is the same as that used to arrange the outputs. For instance, if you want to paint something in the upper-left corner of an LOutput, you must consider the LOutput's position.
Public Member Functions | |
void | bindFramebuffer (LFramebuffer *framebuffer) |
Bind the specified framebuffer for rendering. More... | |
LFramebuffer * | boundFramebuffer () const |
Retrieve the currently bound framebuffer. More... | |
void | drawTexture (const LTexture *texture, const LRect &src, const LRect &dst, Float32 srcScale=1.0f, Float32 alpha=1.0f) |
Draw a texture. More... | |
void | drawTexture (const LTexture *texture, Int32 srcX, Int32 srcY, Int32 srcW, Int32 srcH, Int32 dstX, Int32 dstY, Int32 dstW, Int32 dstH, Float32 srcScale=1.0f, Float32 alpha=1.0f) |
Draw a texture. More... | |
void | drawColorTexture (const LTexture *texture, const LRGBF &color, const LRect &src, const LRect &dst, Float32 srcScale=1.0f, Float32 alpha=1.0f) |
Draw a texture with a custom solid color. More... | |
void | drawColorTexture (const LTexture *texture, Float32 r, Float32 g, Float32 b, Int32 srcX, Int32 srcY, Int32 srcW, Int32 srcH, Int32 dstX, Int32 dstY, Int32 dstW, Int32 dstH, Float32 srcScale=1.0f, Float32 alpha=1.0f) |
Draw a texture with a custom solid color. More... | |
void | drawColor (const LRect &dst, Float32 r, Float32 g, Float32 b, Float32 a) |
Draw a solid color rect. More... | |
void | drawColor (Int32 dstX, Int32 dstY, Int32 dstW, Int32 dstH, Float32 r, Float32 g, Float32 b, Float32 a) |
Draw a solid color rect. More... | |
void | setViewport (const LRect &rect) |
Set the viewport. More... | |
void | setViewport (Int32 x, Int32 y, Int32 w, Int32 h) |
Sets the viewport. More... | |
void | setClearColor (Float32 r, Float32 g, Float32 b, Float32 a) |
Set the clear color. More... | |
void | setColorFactor (Float32 r, Float32 g, Float32 b, Float32 a) |
Set the color factor. More... | |
void | clearScreen () |
Clear the framebuffer. More... | |
void | bindProgram () |
Bind the internal LPainter program. More... | |
void bindFramebuffer | ( | LFramebuffer * | framebuffer | ) |
Bind the specified framebuffer for rendering.
This method binds the provided framebuffer for rendering, allowing subsequent rendering operations to be performed on it.
framebuffer | The framebuffer to be bound. |
LFramebuffer * boundFramebuffer | ( | ) | const |
Retrieve the currently bound framebuffer.
This method returns a pointer to the currently bound framebuffer for rendering.
void drawTexture | ( | const LTexture * | texture, |
const LRect & | src, | ||
const LRect & | dst, | ||
Float32 | srcScale = 1.0f , |
||
Float32 | alpha = 1.0f |
||
) |
Draw a texture.
This method allows you to draw a texture or sub-rect of a texture on the bound frambuffer.
srcScale
means that the src
rect is in buffer coordinates.texture | Texture to draw. |
src | The portion of the texture to draw specified in surface coordinates. |
dst | The destination rect where the texture will be drawn specified in surface coordinates. |
srcScale | Scaling factor for the source texture (default is 1.0). |
alpha | Alpha value for blending the texture (range [0.0, 1.0]). |
void drawTexture | ( | const LTexture * | texture, |
Int32 | srcX, | ||
Int32 | srcY, | ||
Int32 | srcW, | ||
Int32 | srcH, | ||
Int32 | dstX, | ||
Int32 | dstY, | ||
Int32 | dstW, | ||
Int32 | dstH, | ||
Float32 | srcScale = 1.0f , |
||
Float32 | alpha = 1.0f |
||
) |
Draw a texture.
This method allows you to draw a texture or sub-rect of a texture on the bound frambuffer.
srcScale
means that the src
rect is in buffer coordinates.texture | Texture to draw. |
srcX | X-coordinate of the source rect. |
srcY | Y-coordinate of the source rect. |
srcW | Width of the source rect. |
srcH | Height of the source rect. |
dstX | X-coordinate of the destination rect. |
dstY | Y-coordinate of the destination rect. |
dstW | Width of the destination rect. |
dstH | Height of the destination rect. |
srcScale | Scaling factor for the source texture (default is 1.0). |
alpha | Alpha value for blending the texture (range [0.0, 1.0]). |
void drawColorTexture | ( | const LTexture * | texture, |
const LRGBF & | color, | ||
const LRect & | src, | ||
const LRect & | dst, | ||
Float32 | srcScale = 1.0f , |
||
Float32 | alpha = 1.0f |
||
) |
Draw a texture with a custom solid color.
This method draws a rect or sub-rect of a texture, replacing its original color while maintaining its alpha channel.
srcScale
means that the src
rect is in buffer coordinates.texture | Texture to draw. |
color | The solid color that will replace the original texture color. |
src | The portion of the texture to draw specified in surface coordinates. |
dst | The destination rect where the texture will be drawn specified in surface coordinates. |
srcScale | Scaling factor for the source texture (default is 1.0). |
alpha | Alpha value for blending the texture (range [0.0, 1.0]). |
void drawColorTexture | ( | const LTexture * | texture, |
Float32 | r, | ||
Float32 | g, | ||
Float32 | b, | ||
Int32 | srcX, | ||
Int32 | srcY, | ||
Int32 | srcW, | ||
Int32 | srcH, | ||
Int32 | dstX, | ||
Int32 | dstY, | ||
Int32 | dstW, | ||
Int32 | dstH, | ||
Float32 | srcScale = 1.0f , |
||
Float32 | alpha = 1.0f |
||
) |
Draw a texture with a custom solid color.
This method draws a rect or sub-rect of a texture, replacing its original color while maintaining its alpha channel.
srcScale
means that the src
rect is in buffer coordinates.texture | Texture to draw. |
r | The red component of the solid color (0.0 to 1.0). |
g | The green component of the solid color (0.0 to 1.0). |
b | The blue component of the solid color (0.0 to 1.0). |
srcX | X-coordinate of the source rect. |
srcY | Y-coordinate of the source rect. |
srcW | Width of the source rect. |
srcH | Height of the source rect. |
dstX | X-coordinate of the destination rect. |
dstY | Y-coordinate of the destination rect. |
dstW | Width of the destination rect. |
dstH | Height of the destination rect. |
srcScale | Scaling factor for the source texture (default is 1.0). |
alpha | Alpha value for blending the texture (range [0.0, 1.0]). |
Draw a solid color rect.
This method draws a solid colored rect.
dst | The destination rect where the color will be drawn specified in surface coordinates. |
r | Red component value (range [0.0, 1.0]). |
g | Green component value (range [0.0, 1.0]). |
b | Blue component value (range [0.0, 1.0]). |
a | Alpha component value (range [0.0, 1.0]). |
void drawColor | ( | Int32 | dstX, |
Int32 | dstY, | ||
Int32 | dstW, | ||
Int32 | dstH, | ||
Float32 | r, | ||
Float32 | g, | ||
Float32 | b, | ||
Float32 | a | ||
) |
Draw a solid color rect.
This method draws a solid colored rect.
dstX | X-coordinate of the destination rect. |
dstY | Y-coordinate of the destination rect. |
dstW | Width of the destination rect. |
dstH | Height of the destination rect. |
r | Red component value (range [0.0, 1.0]). |
g | Green component value (range [0.0, 1.0]). |
b | Blue component value (range [0.0, 1.0]). |
a | Alpha component value (range [0.0, 1.0]). |
void setViewport | ( | const LRect & | rect | ) |
Set the viewport.
Sets the viewport.
Set the clear color.
This method sets the clear color used when calling clearScreen().
r | Value of the red component (range [0.0, 1.0]). |
g | Value of the green component (range [0.0, 1.0]). |
b | Value of the blue component (range [0.0, 1.0]). |
a | Value of the alpha component (range [0.0, 1.0]). |
Set the color factor.
This method allows you to set a color factor that influences the resulting color of every painting operation. By default, the color factor is (1.0, 1.0, 1.0, 1.0), which has no effect on the colors.
r | Value of the red component (range [0.0, 1.0]). |
g | Value of the green component (range [0.0, 1.0]). |
b | Value of the blue component (range [0.0, 1.0]). |
a | Value of the alpha component (range [0.0, 1.0]). |
void clearScreen | ( | ) |
Clear the framebuffer.
This method clears the bound framebuffer using the color set with setClearColor().