Visual Computing Library  devel
Loading...
Searching...
No Matches
vcl::Texture Class Reference

Manages a BGFX texture. More...

#include <vclib/bgfx/texture.h>

Public Member Functions

void bind (uint stage, bgfx::UniformHandle samplerHandle, uint samplerFlags=UINT32_MAX) const
 Binds the texture to a texture stage for rendering.
 
bool isValid () const
 Checks if the Texture holds valid BGFX texture handle.
 
Textureoperator= (const Texture &other)=delete
 Deleted copy assignment operator.
 
Textureoperator= (Texture &&other) noexcept
 Move assignment operator.
 
void set (const bgfx::Memory *texture, const vcl::Point2i &size, bool hasMips, uint nLayers, bgfx::TextureFormat::Enum format=bgfx::TextureFormat::RGBA8, uint64_t flags=BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE)
 Creates a 2D texture from a bgfx::Memory reference.
 
void set (const void *data, const vcl::Point2i &size, bool hasMips=false, uint64_t flags=BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE, bgfx::ReleaseFn releaseFn=nullptr)
 Creates a 2D texture from raw pixel data.
 
void swap (Texture &other)
 Swaps the content of this object with another Texture.
 
 Texture ()=default
 Default constructor.
 
 Texture (const Texture &other)=delete
 Deleted copy constructor.
 
 Texture (Texture &&other) noexcept
 Move constructor.
 
 ~Texture ()
 Destructor.
 

Static Public Member Functions

static uint samplerFlagsFromTexture (const TextureDescriptor &tex)
 Generates BGFX sampler flags based on the texture's filtering and wrapping modes.
 

Private Attributes

bgfx::TextureHandle mTextureHandle = BGFX_INVALID_HANDLE
 

Friends

void swap (Texture &a, Texture &b)
 Swaps two Texture objects.
 

Detailed Description

Manages a BGFX texture.

This class is a RAII wrapper for a bgfx::TextureHandle. It handles the creation, destruction, and binding of a texture.

This class is move-only, as it represents a unique GPU resource.

Constructor & Destructor Documentation

◆ Texture() [1/3]

vcl::Texture::Texture ( )
default

Default constructor.

Creates an empty and invalid Texture object. A call to set() is required before the object can be used.

◆ Texture() [2/3]

vcl::Texture::Texture ( const Texture other)
delete

Deleted copy constructor.

Copying a Texture is disallowed to prevent duplicate ownership of a single GPU resource.

◆ Texture() [3/3]

vcl::Texture::Texture ( Texture &&  other)
inlinenoexcept

Move constructor.

Transfers ownership of the texture resources from another Texture. The other Texture is left in an invalid state.

Parameters
[in]otherThe Texture object to move from.

◆ ~Texture()

vcl::Texture::~Texture ( )
inline

Destructor.

Destroys the managed BGFX texture if it is valid, releasing the associated GPU resource.

Member Function Documentation

◆ bind()

void vcl::Texture::bind ( uint  stage,
bgfx::UniformHandle  samplerHandle,
uint  samplerFlags = UINT32_MAX 
) const
inline

Binds the texture to a texture stage for rendering.

This method should be called within the rendering loop before submitting a draw call that uses this texture.

Parameters
[in]stageThe texture stage (sampler index) to bind to.
[in]samplerHandleThe sampler uniform handle in the shader.
[in]samplerFlagsOptional BGFX sampler flags to override the flags set during creation. If set to UINT32_MAX, the creation flags are used.

◆ isValid()

bool vcl::Texture::isValid ( ) const
inline

Checks if the Texture holds valid BGFX texture handle.

Returns
true if the texture handle is valid, false otherwise.

◆ operator=() [1/2]

Texture & vcl::Texture::operator= ( const Texture other)
delete

Deleted copy assignment operator.

Copy-assigning a Texture is disallowed to prevent duplicate ownership of a single GPU resource.

◆ operator=() [2/2]

Texture & vcl::Texture::operator= ( Texture &&  other)
inlinenoexcept

Move assignment operator.

Transfers ownership of the texture resources from another Texture. The other Texture is left in an invalid state.

Parameters
[in]otherThe Texture object to move from.
Returns
A reference to this object.

◆ samplerFlagsFromTexture()

static uint vcl::Texture::samplerFlagsFromTexture ( const TextureDescriptor tex)
inlinestatic

Generates BGFX sampler flags based on the texture's filtering and wrapping modes.

Parameters
[in]texThe TextureDescriptor object to derive sampler flags from.
Returns
The generated BGFX sampler flags.

◆ set() [1/2]

void vcl::Texture::set ( const bgfx::Memory *  texture,
const vcl::Point2i size,
bool  hasMips,
uint  nLayers,
bgfx::TextureFormat::Enum  format = bgfx::TextureFormat::RGBA8,
uint64_t  flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE 
)
inline

Creates a 2D texture from a bgfx::Memory reference.

This is the primary method for texture creation, offering full control over format, layers, and mipmaps. Any existing texture data in this object will be destroyed.

Parameters
[in]texturePointer to a bgfx::Memory object containing the texture data.
[in]sizeThe width and height of the texture.
[in]hasMipsIndicates if the provided data includes mipmaps.
[in]nLayersThe number of layers for a texture array. Use 1 for a standard 2D texture.
[in]formatThe format of the texture data.
[in]flagsBGFX texture and sampler creation flags.

◆ set() [2/2]

void vcl::Texture::set ( const void data,
const vcl::Point2i size,
bool  hasMips = false,
uint64_t  flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE,
bgfx::ReleaseFn  releaseFn = nullptr 
)
inline

Creates a 2D texture from raw pixel data.

This is a convenience method that creates a standard 2D RGBA8 texture. Any existing texture data in this object will be destroyed.

Parameters
[in]dataPointer to the raw texture data.
[in]sizeThe width and height of the texture.
[in]hasMipsIndicates if the provided data includes mipmaps.
[in]flagsBGFX texture and sampler creation flags.
[in]releaseFnOptional callback function to release the data pointer when BGFX is finished with it.

◆ swap()

void vcl::Texture::swap ( Texture other)
inline

Swaps the content of this object with another Texture.

Parameters
[in]otherThe other Texture object to swap with.

Friends And Related Symbol Documentation

◆ swap

void swap ( Texture a,
Texture b 
)
friend

Swaps two Texture objects.

Parameters
[in]aThe first Texture.
[in]bThe second Texture.

The documentation for this class was generated from the following file: