Louvre  v2.4.0-1
C++ library for Wayland compositors
Public Types | Public Member Functions | Static Public Member Functions | List of all members
LTexture Class Referencefinal

OpenGL texture abstraction. More...

+ Inheritance diagram for LTexture:

Public Types

enum  BufferSourceType
 Texture source enumeration indicating the origin of the texture data. More...
 

Public Member Functions

 LTexture (bool premultipliedAlpha=false) noexcept
 Creates an empty texture. More...
 
 ~LTexture () noexcept
 The LTexture class destructor. More...
 
bool setDataFromMainMemory (const LSize &size, UInt32 stride, UInt32 format, const void *buffer) noexcept
 Set the data of the texture from a buffer in main memory. More...
 
bool setDataFromWaylandDRM (wl_resource *buffer) noexcept
 Set the data of the texture from a wl_drm buffer. More...
 
bool setDataFromDMA (const LDMAPlanes &planes) noexcept
 Set the data of the texture from DMA planes. More...
 
bool updateRect (const LRect &rect, UInt32 stride, const void *buffer) noexcept
 Update a specific area of the texture with the provided buffer. More...
 
LTexturecopy (const LSize &dst=LSize(), const LRect &src=LRect(), bool highQualityScaling=true) const noexcept
 Creates a copy of the texture. More...
 
bool save (const std::filesystem::path &name) const noexcept
 Save the texture as a PNG file. More...
 
const LSizesizeB () const noexcept
 Gets the size of the texture in buffer coordinates. More...
 
bool initialized () const noexcept
 Check if the texture has been initialized. More...
 
GLuint id (LOutput *output) const noexcept
 Gets the OpenGL texture ID for a specific output. More...
 
GLenum target () const noexcept
 Gets the OpenGL texture target. More...
 
BufferSourceType sourceType () const noexcept
 Gets the texture source type. More...
 
UInt32 format () const noexcept
 Gets the DRM format of the texture. More...
 
UInt32 serial () const noexcept
 Gets the serial number of the texture. More...
 
bool premultipliedAlpha () const noexcept
 Indicates whether the RGB components are pre-multiplied by the alpha component. More...
 
void setPremultipliedAlpha (bool premultipledAlpha) const noexcept
 Sets a hint indicating whether the RGB components are pre-multiplied by the alpha component. More...
 
- Public Member Functions inherited from LObject
 LObject (const LObject &) noexcept
 Copy constructor. More...
 
LObjectoperator= (const LObject &) noexcept
 Assignment operator (each object has its own individual LWeak reference count). More...
 
void setUserData (UIntPtr data) const noexcept
 Store an unsigned integer value/pointer. More...
 
UIntPtr userData () const noexcept
 Retrieves the stored unsigned integer value/pointer. More...
 

Static Public Member Functions

static UInt32 waylandFormatToDRM (UInt32 waylandFormat) noexcept
 Gets the equivalent DRM buffer format from a Wayland SHM buffer format. More...
 
static UInt32 formatBytesPerPixel (UInt32 format) noexcept
 Gets the number of bytes (not bits) per pixel of a DRM format. More...
 
static UInt32 formatPlanes (UInt32 format) noexcept
 Gets the number of planes of a DRM format. More...
 
static const std::vector< LDMAFormat > & supportedDMAFormats () noexcept
 Retrieves the DMA formats supported by the graphics backend. More...
 

Additional Inherited Members

- Protected Member Functions inherited from LObject
 LObject () noexcept=default
 Constructor of the LObject class. More...
 
virtual ~LObject () noexcept
 Destructor of the LObject class. More...
 
void notifyDestruction () noexcept
 Notifies the object destruction. More...
 

Detailed Description

OpenGL texture abstraction.

The LTexture class is an abstraction of an OpenGL texture.
It provides a unified interface for generating and updating textures from buffers in main memory, wl_drm buffers, and DMA buffers.

Warning
The texture internal buffer storage is destroyed and replaced every time any of the setData() variants is used.
See also
To create a texture from an image file use LOpenGL::loadTexture().

Member Enumeration Documentation

◆ BufferSourceType

Texture source enumeration indicating the origin of the texture data.

Enumerator
CPU 

Buffer sourced from main memory.

WL_DRM 

Buffer sourced from wl_drm buffers.

DMA 

Buffer sourced from DMA planes.

Framebuffer 

Indicates the texture is from an LFramebuffer.

Native 

Sourced from a native OpenGL ES 2.0 texture.

Constructor & Destructor Documentation

◆ LTexture()

LTexture ( bool  premultipliedAlpha = false)
noexcept

Creates an empty texture.

◆ ~LTexture()

~LTexture ( )
noexcept

The LTexture class destructor.

Member Function Documentation

◆ waylandFormatToDRM()

UInt32 waylandFormatToDRM ( UInt32  waylandFormat)
staticnoexcept

Gets the equivalent DRM buffer format from a Wayland SHM buffer format.

DRM formats are listed in drm_fourcc.h.

Parameters
waylandFormatThe Wayland buffer format to convert.
Returns
The equivalent DRM buffer format.

◆ formatBytesPerPixel()

UInt32 formatBytesPerPixel ( UInt32  format)
staticnoexcept

Gets the number of bytes (not bits) per pixel of a DRM format.

Parameters
formatThe DRM format to get the bytes per pixel for.
Returns
The number of bytes per pixel.

◆ formatPlanes()

UInt32 formatPlanes ( UInt32  format)
staticnoexcept

Gets the number of planes of a DRM format.

Parameters
formatThe DRM format.
Returns
The number of planes of the format.

◆ supportedDMAFormats()

const std::vector< LDMAFormat > & supportedDMAFormats ( )
staticnoexcept

Retrieves the DMA formats supported by the graphics backend.

◆ setDataFromMainMemory()

bool setDataFromMainMemory ( const LSize size,
UInt32  stride,
UInt32  format,
const void *  buffer 
)
noexcept

Set the data of the texture from a buffer in main memory.

Parameters
sizeWidth and height of the source buffer.
strideThe stride of the source buffer.
formatThe DRM format of the buffer (defined in drm_fourcc.h).
bufferThe pointer to the source main memory buffer.
Returns
true if the data was successfully set, false otherwise.

◆ setDataFromWaylandDRM()

bool setDataFromWaylandDRM ( wl_resource *  buffer)
noexcept

Set the data of the texture from a wl_drm buffer.

Parameters
bufferThe pointer to the wl_drm buffer.
Returns
true if the data was successfully set, false otherwise.

◆ setDataFromDMA()

bool setDataFromDMA ( const LDMAPlanes planes)
noexcept

Set the data of the texture from DMA planes.

Parameters
planesThe pointer to the DMA planes struct.
Returns
true if the data was successfully set, false otherwise.

◆ updateRect()

bool updateRect ( const LRect rect,
UInt32  stride,
const void *  buffer 
)
noexcept

Update a specific area of the texture with the provided buffer.

The provided buffer must have the same format as the texture.
If invalid parameters are passed or if the texture cannot be modified, this method returns false.

Parameters
rectThe rect within the texture to update, specified in buffer coordinates with the top-left corner as the origin.
strideThe stride of the source main memory buffer.
bufferA pointer to the origin of the source main memory buffer.
Returns
true if the update was successful; otherwise, false.

◆ copy()

LTexture * copy ( const LSize dst = LSize(),
const LRect src = LRect(),
bool  highQualityScaling = true 
) const
noexcept

Creates a copy of the texture.

Note
The resulting texture is independent of the original and must be freed manually when no longer used.
Parameters
dstThe destination size of the copied texture. Pass (0,0) to use the same size as the original texture.
srcThe rectangular area within the source texture to be copied. Pass (0,0,0,0) to copy the entire texture.
highQualityScalingSet this parameter to true to enable high-quality scaling, which produces better results when resizing to a significantly different size from the original.
Returns
A pointer to the copied LTexture object or nullptr on failure.

◆ save()

bool save ( const std::filesystem::path &  name) const
noexcept

Save the texture as a PNG file.

This method allows you to save the texture as a PNG image file at the specified name.

Parameters
nameFull path and file name where the PNG image will be saved.
Returns
true if the save operation is successful, false otherwise.

◆ sizeB()

const LSize& sizeB ( ) const
inlinenoexcept

Gets the size of the texture in buffer coordinates.

Returns
The size of the texture.

◆ initialized()

bool initialized ( ) const
inlinenoexcept

Check if the texture has been initialized.

A texture is considered initialized when content has been assigned to it using any of the setDataXXX() variants.

Returns
true if the texture has been initialized, false otherwise.

◆ id()

GLuint id ( LOutput output) const
noexcept

Gets the OpenGL texture ID for a specific output.

If nullptr is passed as output, a texture for the main thread is returned.

Parameters
outputThe specific output for which to get the texture ID.
Returns
The OpenGL texture ID or 0 if fails.

◆ target()

GLenum target ( ) const
inlinenoexcept

Gets the OpenGL texture target.

Returns
The OpenGL texture target.

◆ sourceType()

BufferSourceType sourceType ( ) const
inlinenoexcept

Gets the texture source type.

Returns
The texture source type as an LTexture::BufferSourceType enum value.

◆ format()

UInt32 format ( ) const
inlinenoexcept

Gets the DRM format of the texture.

See also
drm_fourcc.h for more information on DRM formats.
Returns
The DRM format of the texture.

◆ serial()

UInt32 serial ( ) const
inlinenoexcept

Gets the serial number of the texture.

The serial number is incremented each time the texture's backing storage, or its pixel data changes.

Returns
The serial number of the texture.

◆ premultipliedAlpha()

bool premultipliedAlpha ( ) const
inlinenoexcept

Indicates whether the RGB components are pre-multiplied by the alpha component.

This flag is crucial for proper blending of textures within LPainter and LScene.
By default, Wayland clients typically use pre-multiplied alpha, but user-defined textures may not adhere to this convention.

To modify this value, use setPremultipliedAlpha().

Returns
true if the RGB components are pre-multiplied by the alpha component, false otherwise.

◆ setPremultipliedAlpha()

void setPremultipliedAlpha ( bool  premultipledAlpha) const
inlinenoexcept

Sets a hint indicating whether the RGB components are pre-multiplied by the alpha component.

This function allows you to modify the pre-multiplied alpha flag.

Parameters
premultipledAlphatrue to indicate pre-multiplied alpha, false otherwise.