Louvre
v1.2.1-2
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.
Classes | |
struct | TextureParams |
Parameters required for bindTextureMode(). More... | |
Public Member Functions | |
void | bindTextureMode (const TextureParams ¶ms) |
Switches to texture mode. More... | |
void | bindColorMode () |
Switches to color mode. More... | |
void | drawBox (const LBox &box) |
Draws a texture or color box on the screen based on the current rendering mode. More... | |
void | drawRect (const LRect &rect) |
Draws a texture or color rect on the screen based on the current rendering mode. More... | |
void | drawRegion (const LRegion ®ion) |
Draws a texture or color region on the screen based on the current rendering mode. More... | |
void | enableCustomTextureColor (bool enabled) |
Enables or disables custom texture color. More... | |
bool | customTextureColorEnabled () const |
Checks if custom texture color is enabled. More... | |
void | setAlpha (Float32 alpha) |
Sets the alpha value. More... | |
void | setColor (const LRGBF &color) |
Sets the color. More... | |
void | setColorFactor (const LRGBAF &color) |
Sets the color factor. More... | |
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 | setClearColor (const LRGBAF &color) |
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 bindTextureMode | ( | const TextureParams & | params | ) |
Switches to texture mode.
This method maps a texture to the global compositor space, enabling subsequent drawing of specific parts using drawBox(), drawRect() or drawRegion().
params | Parameters required to map the texture. |
void bindColorMode | ( | ) |
Switches to color mode.
In color mode, drawBox() or drawRect() can be called to draw the specified color. The color is set using setColor() and setAlpha().
void drawBox | ( | const LBox & | box | ) |
Draws a texture or color box on the screen based on the current rendering mode.
box | The box to be drawn in global compositor coordinates. |
void drawRect | ( | const LRect & | rect | ) |
Draws a texture or color rect on the screen based on the current rendering mode.
rect | The rect to be drawn in global compositor coordinates. |
void drawRegion | ( | const LRegion & | region | ) |
Draws a texture or color region on the screen based on the current rendering mode.
region | The region to be drawn in global compositor coordinates. |
void enableCustomTextureColor | ( | bool | enabled | ) |
Enables or disables custom texture color.
When enabled, the texture RGB values are replaced by the color set with setColor().
bool customTextureColorEnabled | ( | ) | const |
Checks if custom texture color is enabled.
true
if custom texture color is enabled, otherwise false
. void setAlpha | ( | Float32 | alpha | ) |
Sets the alpha value.
In texture mode, the texture alpha value is multiplied by this value. In color mode, this value becomes the alpha value of the color.
alpha | The alpha value to be set. |
void setColor | ( | const LRGBF & | color | ) |
Sets the color.
If the current mode is texture mode and customTextureColorEnabled() is enabled, this value replaces the texture RGB values while keeping the alpha intact. If the current mode is color mode, this is the color to be drawn.
color | The color to be set. |
void setColorFactor | ( | const LRGBAF & | color | ) |
Sets the color factor.
This factor multiplies each component of the destination color. Setting all components to 1.0f disables it.
color | The color factor to be set. |
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]). |
void setClearColor | ( | const LRGBAF & | color | ) |
Set the clear color.
This method sets the clear color used when calling clearScreen().
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().