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

#include <LTexture.h>

OpenGL texture abstraction. 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. The current texture buffer content 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().

Public Types

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

Public Member Functions

 LTexture ()
 Create an empty texture. More...
 
 ~LTexture ()
 The LTexture class destructor. More...
 
bool setDataB (const LSize &size, UInt32 stride, UInt32 format, const void *buffer)
 Set the data of the texture from a buffer in main memory. More...
 
bool setData (void *wlDRMBuffer)
 Set the data of the texture from a wl_drm buffer. More...
 
bool setDataB (const LDMAPlanes *planes)
 Set the data of the texture from DMA planes. More...
 
bool updateRect (const LRect &rect, UInt32 stride, const void *buffer)
 Update a specific area of the texture with the provided buffer. More...
 
LTexturecopyB (const LSize &dst=LSize(), const LRect &src=LRect(), bool highQualityScaling=true) const
 Create a copy of the texture. More...
 
bool save (const std::filesystem::path &name) const
 Save the texture as a PNG file. More...
 
const LSizesizeB () const
 Get the size of the texture in buffer coordinates. More...
 
bool initialized () const
 Check if the texture has been initialized. More...
 
GLuint id (LOutput *output) const
 Get the OpenGL texture ID for a specific output. More...
 
GLenum target () const
 Get the OpenGL texture target. More...
 
BufferSourceType sourceType () const
 Get the texture source type. More...
 
UInt32 format () const
 Get the DRM format of the texture. More...
 
- Public Member Functions inherited from LObject
 LObject ()=default
 Constructor of the LObject class. More...
 
 ~LObject ()
 Destructor of the LObject class. More...
 
std::shared_ptr< const bool > isAlive () const
 Object's liveness status. More...
 

Static Public Member Functions

static UInt32 waylandFormatToDRM (UInt32 waylandFormat)
 Get the equivalent DRM buffer format from a Wayland buffer format. More...
 
static UInt32 formatBytesPerPixel (UInt32 format)
 Get the number of bytes (not bits) per pixel of a DRM format. More...
 
static UInt32 formatPlanes (UInt32 format)
 Get the number of planes of a DRM format. More...
 
- Static Public Member Functions inherited from LObject
static LCompositorcompositor ()
 Quick access to the global compositor instance. More...
 
static LSeatseat ()
 Quick access to the global seat instance. More...
 
static LCursorcursor ()
 Quick access to the global cursor instance. More...
 

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

Create an empty texture.

◆ ~LTexture()

~LTexture ( )

The LTexture class destructor.

Member Function Documentation

◆ waylandFormatToDRM()

UInt32 waylandFormatToDRM ( UInt32  waylandFormat)
static

Get the equivalent DRM buffer format from a Wayland 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)
static

Get 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)
static

Get the number of planes of a DRM format.

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

◆ setDataB() [1/2]

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

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

Parameters
sizeThe size of the texture in buffer coordinates.
strideThe stride of the buffer.
formatThe DRM format of the buffer (defined in drm_fourcc.h).
bufferThe pointer to the main memory buffer.
Returns
true if the data was successfully set, false otherwise.

◆ setData()

bool setData ( void *  wlDRMBuffer)

Set the data of the texture from a wl_drm buffer.

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

◆ setDataB() [2/2]

bool setDataB ( const LDMAPlanes planes)

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 
)

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

To successfully update the texture, 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 main memory buffer.
bufferA pointer to the main memory buffer.
Returns
true if the update was successful; otherwise, false.

◆ copyB()

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

Create a copy of the texture.

The destination size (dst) is the size of the copied texture, and the source (src) is the rectangular area within the texture to be copied. Using both parameters, a clipped and scaled copy version can be created from the texture.
Using negative values for the source rect size (srcW and srcH) causes the texture to be mirrored along the given axis.

Note
The resulting texture is independent of the original and must be freed separately.
Parameters
dstThe destination size of the copied texture. Passing an empty Louvre::LSize means the same texture size is used.
srcThe rectangular area within the texture to be copied. Passing an empty Louvre::LRect means the entire texture is used.
highQualityScalingSet this value 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.

◆ save()

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

Save the texture as a PNG file.

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

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

◆ sizeB()

const LSize & sizeB ( ) const

Get the size of the texture in buffer coordinates.

Returns
The size of the texture.

◆ initialized()

bool initialized ( ) const

Check if the texture has been initialized.

A texture is considered initialized when content has been assigned to it using any setData() variant.

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

◆ id()

GLuint id ( LOutput output) const

Get 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

Get the OpenGL texture target.

Returns
The OpenGL texture target.

◆ sourceType()

LTexture::BufferSourceType sourceType ( ) const

Get the texture source type.

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

◆ format()

UInt32 format ( ) const

Get the DRM format of the texture.

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