Louvre  v2.3.2-1
C++ library for Wayland compositors
Classes | Public Member Functions | List of all members
LPainter Class Referencefinal

Basic 2D rendering utility. More...

+ Inheritance diagram for LPainter:

Classes

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

Public Member Functions

void bindTextureMode (const TextureParams &params) noexcept
 Switches to texture mode. More...
 
void bindColorMode () noexcept
 Switches to color mode. More...
 
void drawBox (const LBox &box) noexcept
 Draws a texture or color box on the screen based on the current rendering mode. More...
 
void drawRect (const LRect &rect) noexcept
 Draws a texture or color rect on the screen based on the current rendering mode. More...
 
void drawRegion (const LRegion &region) noexcept
 Draws a texture or color region on the screen based on the current rendering mode. More...
 
void enableCustomTextureColor (bool enabled) noexcept
 Enables or disables a custom texture color. More...
 
bool customTextureColorEnabled () const noexcept
 Checks if custom texture color is enabled. More...
 
bool autoBlendFuncEnabled () const noexcept
 Checks if automatic blending function selection is enabled. More...
 
void enableAutoBlendFunc (bool enabled) const noexcept
 Toggles automatic blending function selection. More...
 
void setBlendFunc (const LBlendFunc &blendFunc) const noexcept
 Sets a custom blend function. More...
 
void setAlpha (Float32 alpha) noexcept
 Sets the alpha value. More...
 
void setColor (const LRGBF &color) noexcept
 Sets the color. More...
 
void setColorFactor (Float32 r, Float32 g, Float32 b, Float32 a) noexcept
 Sets the color factor. More...
 
void setColorFactor (const LRGBAF &factor) noexcept
 Sets the color factor. More...
 
void setClearColor (Float32 r, Float32 g, Float32 b, Float32 a) noexcept
 Sets the clear color. More...
 
void setClearColor (const LRGBAF &color) noexcept
 Set the clear color. More...
 
void clearScreen () noexcept
 Clear the framebuffer. More...
 
void setViewport (const LRect &rect) noexcept
 Sets the viewport. More...
 
void setViewport (Int32 x, Int32 y, Int32 w, Int32 h) noexcept
 Sets the viewport. More...
 
void bindFramebuffer (LFramebuffer *framebuffer) noexcept
 Binds the specified framebuffer for rendering. More...
 
LFramebufferboundFramebuffer () const noexcept
 Retrieves the currently bound framebuffer. More...
 
void bindProgram () noexcept
 Bind the internal LPainter program. More...
 

Detailed Description

Basic 2D rendering utility.

The LPainter class offers essential methods for 2D rendering without the need to use OpenGL functions directly.
It can draw solid colors and textures with custom clipping, scaling, blending effects, and transforms.

Each LOutput has its own LPainter, accessible via LOutput::painter().

Note
While LPainter provides convenience, it's not mandatory. You have the flexibility to use OpenGL functions and your custom shaders if preferred, or leverage the efficiency of rendering provided by the LScene and LView classes.

Coordinate System

When specifying the destination rectangle for your painting operations, use compositor-global coordinates, which operate with surface units.
LPainter automatically scales and transforms the content for you, considering the scale factor/transform of the texture you are drawing and the scale factor/transform of the destination framebuffer.

The coordinate space in which the content is rendered aligns with that used to arrange outputs.
For example, to paint something in the upper-left corner of an LOutput, consider the LOutput::pos().

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

Class Documentation

◆ Louvre::LPainter::TextureParams

struct Louvre::LPainter::TextureParams

Parameters required for bindTextureMode().

This struct provides all the necessary parameters to map a texture into the current destination framebuffer.

Class Members
LTexture * texture Texture to be drawn.
LPoint pos Position of the texture (destination rect) in compositor-global coordinates.
LRectF srcRect Subrect of the texture to be mapped in surface units.

Coordinates should be specified in the space generated after applying the scale factor and transformation to the texture buffer.

LSize dstSize Destination size of the source rect in surface units.
LTransform srcTransform Transform already applied to the texture.

For example, if the texture is rotated 90 degrees counterclockwise and you want to display it in a normal orientation, use LTransform::Rotated90 and LPainter will apply the inverse transform (LTransform::Rotated270).
If you don't want to apply any transform use LTransform::Normal.

Float32 srcScale Scale factor of the texture.

Member Function Documentation

◆ bindTextureMode()

void bindTextureMode ( const TextureParams params)
noexcept

Switches to texture mode.

This method maps a texture to the compositor-global space, enabling subsequent drawing of specific sub-rectangles using drawBox(), drawRect() or drawRegion().

Parameters
paramsParameters required to map the texture.

◆ bindColorMode()

void bindColorMode ( )
noexcept

Switches to color mode.

In color mode, drawBox(), drawRect() and drawRegion() can be used to draw rectagles of the specified color.

The color is set using setColor() and setAlpha().

◆ drawBox()

void drawBox ( const LBox box)
noexcept

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

Parameters
boxThe box to be drawn in compositor-global coordinates.

◆ drawRect()

void drawRect ( const LRect rect)
noexcept

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

Parameters
rectThe rect to be drawn in compositor-global coordinates.

◆ drawRegion()

void drawRegion ( const LRegion region)
noexcept

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

Parameters
regionThe region to be drawn in compositor-global coordinates.

◆ enableCustomTextureColor()

void enableCustomTextureColor ( bool  enabled)
noexcept

Enables or disables a custom texture color.

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

◆ customTextureColorEnabled()

bool customTextureColorEnabled ( ) const
noexcept

Checks if custom texture color is enabled.

See also
enableCustomTextureColor().
Returns
true if custom texture color is enabled, otherwise false.

◆ autoBlendFuncEnabled()

bool autoBlendFuncEnabled ( ) const
noexcept

Checks if automatic blending function selection is enabled.

See also
enable enableAutoBlendFunc().

◆ enableAutoBlendFunc()

void enableAutoBlendFunc ( bool  enabled) const
noexcept

Toggles automatic blending function selection.

When enabled, LPainter will automatically select the appropriate OpenGL blend function mode based on whether the bound texture uses premultiplied alpha or not (see LTexture::premultipliedAlpha()).

When disabled, LPainter will use the blend function set with setBlendFunc().

Enabled by default.

◆ setBlendFunc()

void setBlendFunc ( const LBlendFunc blendFunc) const
noexcept

Sets a custom blend function.

Setting a custom blend function can be useful for masking or other sophisticated blending effects.

To make LPainter use this blend function, the auto blend function must be disabled, see enableAutoBlendFunc().

◆ setAlpha()

void setAlpha ( Float32  alpha)
noexcept

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)
noexcept

Sets the color.

  • In texture mode and if customTextureColorEnabled() is enabled, this value replaces the texture RGB values while keeping the alpha intact.
  • If color mode, this is the color to be drawn. See setAlpha().
Parameters
colorThe color to be set.

◆ setColorFactor() [1/2]

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

Sets the color factor.

This method multiplies each component of the source color by the specified factor.

Note
Setting all components to 1.0 disables the effect.
Parameters
rThe value of the red component (range: [0.0, 1.0]).
gThe value of the green component (range: [0.0, 1.0]).
bThe value of the blue component (range: [0.0, 1.0]).
aThe value of the alpha component (range: [0.0, 1.0]).

◆ setColorFactor() [2/2]

void setColorFactor ( const LRGBAF factor)
noexcept

Sets the color factor.

This method multiplies each component of the source color by the specified factor.

Note
Setting all components to 1.0 disables the effect.
Parameters
factorThe color factor to be set.

◆ setClearColor() [1/2]

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

Sets 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)
noexcept

Set the clear color.

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

◆ clearScreen()

void clearScreen ( )
noexcept

Clear the framebuffer.

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

◆ setViewport() [1/2]

void setViewport ( const LRect rect)
noexcept

Sets the viewport.

Note
Do not use this method unless you are working with your own shaders/programs.

◆ setViewport() [2/2]

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

Sets the viewport.

Note
Do not use this method unless you are working with your own shaders/programs.

◆ bindFramebuffer()

void bindFramebuffer ( LFramebuffer framebuffer)
noexcept

Binds 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
noexcept

Retrieves the currently bound framebuffer.

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

Returns
A pointer to the currently bound framebuffer.

◆ bindProgram()

void bindProgram ( )
noexcept

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.