Louvre  v1.2.1-2
C++ library for Wayland compositors
List of all members | Classes | Public Member Functions
LPainter Class Reference

#include <LPainter.h>

Utility for Painting Operations. More...

Detailed Description

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().

Note
You are not obligated to use LPainter methods for rendering. You have the flexibility to use OpenGL functions and your custom shaders if preferred, or leverage the LScene and LView classes for efficient rendering.

Coordinate System

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.

Note
When rendering into an LRenderBuffer, you should also consider its position, similar to how you do with outputs.

Classes

struct  TextureParams
 Parameters required for bindTextureMode(). More...
 

Public Member Functions

void bindTextureMode (const TextureParams &params)
 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 &region)
 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...
 
LFramebufferboundFramebuffer () 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...
 

Member Function Documentation

◆ bindTextureMode()

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().

Parameters
paramsParameters required to map the texture.

◆ bindColorMode()

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().

◆ drawBox()

void drawBox ( const LBox box)

Draws a texture or color box on the screen based on the current rendering mode.

Parameters
boxThe box to be drawn in global compositor coordinates.

◆ drawRect()

void drawRect ( const LRect rect)

Draws a texture or color rect on the screen based on the current rendering mode.

Parameters
rectThe rect to be drawn in global compositor coordinates.

◆ drawRegion()

void drawRegion ( const LRegion region)

Draws a texture or color region on the screen based on the current rendering mode.

Parameters
regionThe region to be drawn in global compositor coordinates.

◆ enableCustomTextureColor()

void enableCustomTextureColor ( bool  enabled)

Enables or disables custom texture color.

When enabled, the texture RGB values are replaced by the color set with setColor().

◆ customTextureColorEnabled()

bool customTextureColorEnabled ( ) const

Checks if custom texture color is enabled.

Returns
true if custom texture color is enabled, otherwise false.

◆ setAlpha()

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.

Parameters
alphaThe alpha value to be set.

◆ setColor()

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.

Parameters
colorThe color to be set.

◆ setColorFactor() [1/2]

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.

Parameters
colorThe color factor to be set.

◆ bindFramebuffer()

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.

Note
Output framebuffers are automatically bound prior a LOutput::paintGL() event.
Parameters
framebufferThe framebuffer to be bound.

◆ boundFramebuffer()

LFramebuffer * boundFramebuffer ( ) const

Retrieve the currently bound framebuffer.

This method returns a pointer to the currently bound framebuffer for rendering.

Returns
A pointer to the currently bound framebuffer.

◆ drawTexture() [1/2]

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.

Note
Using 1 as the srcScale means that the src rect is in buffer coordinates.
Parameters
textureTexture to draw.
srcThe portion of the texture to draw specified in surface coordinates.
dstThe destination rect where the texture will be drawn specified in surface coordinates.
srcScaleScaling factor for the source texture (default is 1.0).
alphaAlpha value for blending the texture (range [0.0, 1.0]).

◆ drawTexture() [2/2]

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.

Note
Using 1 as the srcScale means that the src rect is in buffer coordinates.
Parameters
textureTexture to draw.
srcXX-coordinate of the source rect.
srcYY-coordinate of the source rect.
srcWWidth of the source rect.
srcHHeight of the source rect.
dstXX-coordinate of the destination rect.
dstYY-coordinate of the destination rect.
dstWWidth of the destination rect.
dstHHeight of the destination rect.
srcScaleScaling factor for the source texture (default is 1.0).
alphaAlpha value for blending the texture (range [0.0, 1.0]).

◆ drawColorTexture() [1/2]

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.

Note
Using 1 as the srcScale means that the src rect is in buffer coordinates.
Parameters
textureTexture to draw.
colorThe solid color that will replace the original texture color.
srcThe portion of the texture to draw specified in surface coordinates.
dstThe destination rect where the texture will be drawn specified in surface coordinates.
srcScaleScaling factor for the source texture (default is 1.0).
alphaAlpha value for blending the texture (range [0.0, 1.0]).

◆ drawColorTexture() [2/2]

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.

Note
Using 1 as the srcScale means that the src rect is in buffer coordinates.
Parameters
textureTexture to draw.
rThe red component of the solid color (0.0 to 1.0).
gThe green component of the solid color (0.0 to 1.0).
bThe blue component of the solid color (0.0 to 1.0).
srcXX-coordinate of the source rect.
srcYY-coordinate of the source rect.
srcWWidth of the source rect.
srcHHeight of the source rect.
dstXX-coordinate of the destination rect.
dstYY-coordinate of the destination rect.
dstWWidth of the destination rect.
dstHHeight of the destination rect.
srcScaleScaling factor for the source texture (default is 1.0).
alphaAlpha value for blending the texture (range [0.0, 1.0]).

◆ drawColor() [1/2]

void drawColor ( const LRect dst,
Float32  r,
Float32  g,
Float32  b,
Float32  a 
)

Draw a solid color rect.

This method draws a solid colored rect.

Parameters
dstThe destination rect where the color will be drawn specified in surface coordinates.
rRed component value (range [0.0, 1.0]).
gGreen component value (range [0.0, 1.0]).
bBlue component value (range [0.0, 1.0]).
aAlpha component value (range [0.0, 1.0]).

◆ drawColor() [2/2]

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.

Parameters
dstXX-coordinate of the destination rect.
dstYY-coordinate of the destination rect.
dstWWidth of the destination rect.
dstHHeight of the destination rect.
rRed component value (range [0.0, 1.0]).
gGreen component value (range [0.0, 1.0]).
bBlue component value (range [0.0, 1.0]).
aAlpha component value (range [0.0, 1.0]).

◆ setViewport() [1/2]

void setViewport ( const LRect rect)

Set the viewport.

Note
This method should be used if you are working with your own shaders/programs.

◆ setViewport() [2/2]

void setViewport ( Int32  x,
Int32  y,
Int32  w,
Int32  h 
)

Sets the viewport.

Note
This method should be used if you are working with your own shaders/programs.

◆ setClearColor() [1/2]

void setClearColor ( Float32  r,
Float32  g,
Float32  b,
Float32  a 
)

Set the clear color.

This method sets the clear color used when calling clearScreen().

Parameters
rValue of the red component (range [0.0, 1.0]).
gValue of the green component (range [0.0, 1.0]).
bValue of the blue component (range [0.0, 1.0]).
aValue of the alpha component (range [0.0, 1.0]).

◆ setClearColor() [2/2]

void setClearColor ( const LRGBAF color)

Set the clear color.

This method sets the clear color used when calling clearScreen().

◆ setColorFactor() [2/2]

void setColorFactor ( Float32  r,
Float32  g,
Float32  b,
Float32  a 
)

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.

Parameters
rValue of the red component (range [0.0, 1.0]).
gValue of the green component (range [0.0, 1.0]).
bValue of the blue component (range [0.0, 1.0]).
aValue of the alpha component (range [0.0, 1.0]).

◆ clearScreen()

void clearScreen ( )

Clear the framebuffer.

This method clears the bound framebuffer using the color set with setClearColor().

◆ bindProgram()

void bindProgram ( )

Bind the internal LPainter program.

Note
This method should be used if you are working with your own OpenGL programs and want to use the LPainter methods again.