|
Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
|
2D texture for GPU rendering More...
#include <Texture.hpp>
Public Member Functions | |
| Texture ()=default | |
| virtual | ~Texture () |
| Texture (const Texture &)=delete | |
| Texture & | operator= (const Texture &)=delete |
| Texture (Texture &&other) noexcept | |
| Texture & | operator= (Texture &&other) noexcept |
| bool | adoptContent (Texture &from) |
Takes from's pixels behind this texture's handle; from is empty afterwards. | |
| void | bind (u32 slot=0) const |
| Binds the texture to a texture unit. | |
| void | unbind () const |
| Unbinds the texture. | |
| void | setData (std::span< const u8 > pixels) |
| Updates texture pixel data from span. | |
| void | setData (const std::vector< u8 > &pixels) |
| Updates texture pixel data from vector. | |
| void | updateSubRegion (u32 xoffset, u32 yoffset, u32 width, u32 height, const void *data, u32 sizeBytes, bool flipY=false) |
| Uploads pixel data to a sub-rectangle of the texture. | |
| TextureHandle | handle () const |
| Gets the device texture handle. | |
| u32 | getId () const |
| Gets the texture handle's raw value, for command payloads and the WASM boundary. | |
| u32 | getWidth () const |
| Gets the texture width in pixels. | |
| u32 | getHeight () const |
| Gets the texture height in pixels. | |
| TextureFormat | getFormat () const |
| Gets the pixel format. | |
| bool | operator== (const Texture &other) const |
| Compares textures by GPU ID. | |
| void | setDataRaw (const void *data, u32 sizeBytes, bool flipY=false) |
| Updates texture pixel data from raw pointer (internal use). | |
Static Public Member Functions | |
| static Unique< Texture > | create (GfxDevice &device, GfxContent content, const TextureSpecification &spec) |
| Creates an empty texture from specification. | |
| static Unique< Texture > | create (GfxDevice &device, GfxContent content, u32 width, u32 height, std::span< const u8 > pixels, TextureFormat format=TextureFormat::RGBA8, bool flipY=false) |
| Creates a texture from a span of pixel data. | |
| static Unique< Texture > | create (GfxDevice &device, GfxContent content, u32 width, u32 height, const std::vector< u8 > &pixels, TextureFormat format=TextureFormat::RGBA8, bool flipY=false) |
| Creates a texture from pixel vector. | |
| static Unique< Texture > | borrow (GfxDevice &device, TextureHandle texture, u32 width, u32 height) |
| Names a texture the device already holds for another owner (a render target's colour plane), without taking it over. | |
| static Unique< Texture > | createArray (GfxDevice &device, GfxContent content, const TextureSpecification &spec, const void *pixels) |
| Creates a 2D texture array from spec.layers layers of spec.width x spec.height. | |
| static Unique< Texture > | createRaw (GfxDevice &device, GfxContent content, u32 width, u32 height, const void *data, TextureFormat format=TextureFormat::RGBA8, bool flipY=false) |
| Creates a texture from raw pixel pointer (internal use). | |
| static Unique< Texture > | createVolume (GfxDevice &device, GfxContent content, u32 width, u32 height, u32 depth, const void *data, TextureFormat format) |
| A 3D texture, linearly filtered across all three axes and clamped at every edge. | |
| static Unique< Texture > | createCompressed (GfxDevice &device, GfxContent content, u32 width, u32 height, GfxCompressedFormat format, std::span< const u8 > data, u32 mipLevels=1) |
| Creates a block-compressed texture (KTX2 → ETC2/ASTC/BC), uploading the pre-compressed blocks in one shot. No setDataRaw afterward — compressed data is immutable here. | |
| static Unique< Texture > | createFromExternalId (GfxDevice &device, GfxContent content, u32 glTextureId, u32 width, u32 height, TextureFormat format=TextureFormat::RGBA8) |
| Hands the device a texture the host made with its own API; the device owns it from here. | |
2D texture for GPU rendering
Encapsulates an OpenGL/WebGL texture object. Supports creation from pixel data, files, or empty specifications.
Definition at line 116 of file Texture.hpp.
|
default |
Referenced by Texture(), Texture(), adoptContent(), operator=(), operator=(), and operator==().
|
virtual |
Definition at line 45 of file Texture.cpp.
References esengine::Invalid.
|
delete |
References Texture().
|
noexcept |
Definition at line 51 of file Texture.cpp.
References Texture(), esengine::Invalid, and esengine::None.
| bool esengine::Texture::adoptContent | ( | Texture & | from | ) |
Takes from's pixels behind this texture's handle; from is empty afterwards.
How owed content is paid: the provider loads it the ordinary way and hands the result over, so nothing that names this texture changes.
Definition at line 207 of file Texture.cpp.
References Texture(), and esengine::Invalid.
Referenced by esengine::resource::ResourceManager::adoptTextureContent().
| void esengine::Texture::bind | ( | u32 | slot = 0 | ) | const |
Binds the texture to a texture unit.
| slot | Texture unit index (0-7 typical for WebGL) |
Definition at line 248 of file Texture.cpp.
|
static |
Names a texture the device already holds for another owner (a render target's colour plane), without taking it over.
Definition at line 195 of file Texture.cpp.
References handle(), esengine::makeUnique(), esengine::RGBA8, and esengine::GfxDevice::textureDesc().
Referenced by esengine::resource::ResourceManager::wrapDeviceTexture().
|
static |
Creates an empty texture from specification.
| spec | Texture parameters |
Creates a texture with uninitialized pixel data. Use setData() to upload pixels later.
Definition at line 83 of file Texture.cpp.
References esengine::makeUnique().
Referenced by create(), esengine::resource::ResourceManager::createTexture(), and esengine::resource::ResourceManager::createTexture().
|
static |
Creates a texture from pixel vector.
| width | Texture width in pixels |
| height | Texture height in pixels |
| pixels | Pixel data (size must match width*height*channels) |
| format | Pixel format (default RGBA8) |
| flipY | Flip vertically on upload (for web image data) |
Definition at line 109 of file Texture.cpp.
References create().
|
static |
Creates a texture from a span of pixel data.
| width | Texture width in pixels |
| height | Texture height in pixels |
| pixels | Pixel data (size must match width*height*channels) |
| format | Pixel format (default RGBA8) |
Definition at line 102 of file Texture.cpp.
References createRaw(), and ES_ASSERT.
|
static |
Creates a 2D texture array from spec.layers layers of spec.width x spec.height.
| pixels | The layers back to back, layer 0 first, rows bottom-up as the engine samples them; spec.width * spec.height * bpp * spec.layers bytes. Its contents are fixed: setData is refused. |
Definition at line 92 of file Texture.cpp.
References esengine::makeUnique().
Referenced by esengine::resource::ResourceManager::createTextureArray().
|
static |
Creates a block-compressed texture (KTX2 → ETC2/ASTC/BC), uploading the pre-compressed blocks in one shot. No setDataRaw afterward — compressed data is immutable here.
| data | Compressed block data for mip level 0. |
Definition at line 152 of file Texture.cpp.
References esengine::ClampToEdge, esengine::GfxDevice::createCompressedTexture(), ES_LOG_ERROR, esengine::TextureDesc::height, esengine::Invalid, esengine::Linear, esengine::TextureDesc::magFilter, esengine::makeUnique(), esengine::TextureDesc::minFilter, esengine::TextureDesc::mipmaps, esengine::RGBA8, esengine::TextureDesc::width, esengine::TextureDesc::wrapS, and esengine::TextureDesc::wrapT.
Referenced by esengine::resource::ResourceManager::createCompressedTexture().
|
static |
Hands the device a texture the host made with its own API; the device owns it from here.
| glTextureId | The host's id for it (a WebGL texture registered with the GL layer) |
Definition at line 179 of file Texture.cpp.
References esengine::TextureDesc::format, esengine::TextureDesc::height, esengine::GfxDevice::importExternalTexture(), esengine::makeUnique(), and esengine::TextureDesc::width.
Referenced by esengine::resource::ResourceManager::registerExternalTexture().
|
static |
Creates a texture from raw pixel pointer (internal use).
| width | Texture width in pixels |
| height | Texture height in pixels |
| data | Pointer to pixel data |
| format | Pixel format (default RGBA8) |
Definition at line 114 of file Texture.cpp.
References esengine::ClampToEdge, esengine::TextureSpecification::format, esengine::TextureSpecification::generateMips, esengine::TextureSpecification::height, esengine::makeUnique(), esengine::TextureSpecification::width, esengine::TextureSpecification::wrapS, and esengine::TextureSpecification::wrapT.
Referenced by create().
|
static |
A 3D texture, linearly filtered across all three axes and clamped at every edge.
| data | Its slices back to back, slice 0 first: width * height * depth texels. |
Definition at line 132 of file Texture.cpp.
References esengine::ClampToEdge, esengine::TextureSpecification::format, esengine::TextureSpecification::generateMips, esengine::TextureSpecification::height, esengine::TextureSpecification::layers, esengine::makeUnique(), esengine::TextureSpecification::volume, esengine::TextureSpecification::width, esengine::TextureSpecification::wrapS, and esengine::TextureSpecification::wrapT.
|
inline |
Gets the pixel format.
Definition at line 245 of file Texture.hpp.
|
inline |
Gets the texture height in pixels.
Definition at line 242 of file Texture.hpp.
Referenced by esengine::SpritePlugin::collect(), and esengine::UIElementPlugin::collect().
|
inline |
Gets the texture handle's raw value, for command payloads and the WASM boundary.
Definition at line 236 of file Texture.hpp.
Referenced by esengine::resource::ResourceManager::acquireTextureByPath(), esengine::ParticlePlugin::collect(), esengine::SpritePlugin::collect(), esengine::UIElementPlugin::collect(), esengine::resource::ResourceManager::forgoTextureContent(), esengine::resource::ResourceManager::restoreTextureContent(), esengine::rm_getTextureGLId(), and esengine::resource::ResourceManager::texturesAwaitingReupload().
|
inline |
Gets the texture width in pixels.
Definition at line 239 of file Texture.hpp.
Referenced by esengine::SpritePlugin::collect(), and esengine::UIElementPlugin::collect().
|
inline |
Gets the device texture handle.
Definition at line 233 of file Texture.hpp.
Referenced by borrow(), esengine::draw_meshWithUniforms(), and esengine::resource::ResourceManager::textureNativeId().
References Texture(), and esengine::RGBA8.
Definition at line 64 of file Texture.cpp.
References Texture(), esengine::Invalid, and esengine::None.
|
inline |
Compares textures by GPU ID.
| other | Texture to compare with |
Definition at line 252 of file Texture.hpp.
References Texture().
| void esengine::Texture::setData | ( | const std::vector< u8 > & | pixels | ) |
Updates texture pixel data from vector.
| pixels | New pixel data |
Definition at line 262 of file Texture.cpp.
References setData().
| void esengine::Texture::setData | ( | std::span< const u8 > | pixels | ) |
Updates texture pixel data from span.
| pixels | New pixel data |
Definition at line 256 of file Texture.cpp.
References ES_ASSERT, and setDataRaw().
Referenced by setData().
| void esengine::Texture::setDataRaw | ( | const void * | data, |
| u32 | sizeBytes, | ||
| bool | flipY = false ) |
Updates texture pixel data from raw pointer (internal use).
| data | Pointer to pixel data |
| sizeBytes | Size of data in bytes |
Definition at line 266 of file Texture.cpp.
References ES_LOG_ERROR.
Referenced by setData().
| void esengine::Texture::unbind | ( | ) | const |
| void esengine::Texture::updateSubRegion | ( | u32 | xoffset, |
| u32 | yoffset, | ||
| u32 | width, | ||
| u32 | height, | ||
| const void * | data, | ||
| u32 | sizeBytes, | ||
| bool | flipY = false ) |
Uploads pixel data to a sub-rectangle of the texture.
Lets the dynamic glyph atlas pack glyphs one-by-one without re-uploading the whole atlas. The sub-rect must lie fully inside the texture and data must be tightly packed in this texture's format.
| xoffset,yoffset | top-left of the sub-rect, in texels |
| width,height | sub-rect size, in texels |
| data,sizeBytes | pixel buffer matching the texture's format |
Definition at line 280 of file Texture.cpp.
References ES_LOG_ERROR.