23#ifndef VCL_BGFX_TEXTURE_H
24#define VCL_BGFX_TEXTURE_H
26#include <vclib/base.h>
27#include <vclib/space/core.h>
81 if (bgfx::isValid(mTextureHandle))
82 bgfx::destroy(mTextureHandle);
116 swap(mTextureHandle,
other.mTextureHandle);
131 bool isValid()
const {
return bgfx::isValid(mTextureHandle); }
161 bimg::TextureFormat::RGBA8);
166 bgfx::TextureFormat::RGBA8,
187 const bgfx::Memory* texture,
191 bgfx::TextureFormat::Enum format = bgfx::TextureFormat::RGBA8,
194 if (bgfx::isValid(mTextureHandle))
195 bgfx::destroy(mTextureHandle);
197 mTextureHandle = bgfx::createTexture2D(
218 if (bgfx::isValid(mTextureHandle) && bgfx::isValid(
samplerHandle)) {
240 if (
tex.minFilter() == NEAREST ||
241 tex.minFilter() == NEAREST_MIPMAP_LINEAR ||
242 tex.minFilter() == NEAREST_MIPMAP_NEAREST)
246 if (
tex.minFilter() == NEAREST_MIPMAP_NEAREST ||
247 tex.minFilter() == LINEAR_MIPMAP_NEAREST)
255 if (
tex.wrapU() == CLAMP_TO_EDGE)
257 else if (
tex.wrapU() == MIRRORED_REPEAT)
260 if (
tex.wrapV() == CLAMP_TO_EDGE)
262 else if (
tex.wrapV() == MIRRORED_REPEAT)
A class representing a box in N-dimensional space.
Definition box.h:46
The Point class represents an N-dimensional point containing N scalar values.
Definition point.h:55
ScalarType & x()
Returns a reference to the x-component of the Point object.
Definition point.h:128
ScalarType & y()
Returns a reference to the y-component of the Point object.
Definition point.h:150
Describes the properties of a texture, such as its source path and rendering parameters.
Definition texture_descriptor.h:42
MinificationFilter
Defines the texture minification filter modes, following the glTF 2.0 specification....
Definition texture_descriptor.h:50
@ NEAREST
Nearest neighbor filtering.
WrapMode
Defines the texture wrapping modes for S (U) and T (V) coordinates, following the glTF 2....
Definition texture_descriptor.h:81
Manages a BGFX texture.
Definition texture.h:43
bool isValid() const
Checks if the Texture holds valid BGFX texture handle.
Definition texture.h:131
Texture(const Texture &other)=delete
Deleted copy constructor.
Texture & operator=(Texture &&other) noexcept
Move assignment operator.
Definition texture.h:102
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.
Definition texture.h:186
friend void swap(Texture &a, Texture &b)
Swaps two Texture objects.
Definition texture.h:124
Texture & operator=(const Texture &other)=delete
Deleted copy assignment operator.
Texture()=default
Default constructor.
static uint samplerFlagsFromTexture(const TextureDescriptor &tex)
Generates BGFX sampler flags based on the texture's filtering and wrapping modes.
Definition texture.h:232
void swap(Texture &other)
Swaps the content of this object with another Texture.
Definition texture.h:113
Texture(Texture &&other) noexcept
Move constructor.
Definition texture.h:71
~Texture()
Destructor.
Definition texture.h:79
void bind(uint stage, bgfx::UniformHandle samplerHandle, uint samplerFlags=UINT32_MAX) const
Binds the texture to a texture stage for rendering.
Definition texture.h:213
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.
Definition texture.h:146