libdonut
2.3.2
Application framework for cross-platform game development in C++20
|
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configuration that defines how to render the stored data. More...
#include <donut/graphics/Texture.hpp>
Public Member Functions | |
Texture () noexcept=default | |
Construct an empty texture without a value. More... | |
Texture (TextureFormat internalFormat, std::size_t width, std::size_t height, PixelFormat pixelFormat, PixelComponentType pixelComponentType, const void *pixels, const TextureOptions &options={}) | |
Create a new texture object and allocate GPU memory for storing 2D image data. More... | |
Texture (TextureFormat internalFormat, std::size_t width, std::size_t height, std::size_t depth, PixelFormat pixelFormat, PixelComponentType pixelComponentType, const void *pixels, const TextureOptions &options={}) | |
Create a new texture object and allocate GPU memory for storing an array of layers of 2D image data. More... | |
Texture (TextureFormat internalFormat, std::size_t width, std::size_t height, const TextureOptions &options={}) | |
Create a new texture object and allocate uninitialized GPU memory for storing 2D image data. More... | |
Texture (TextureFormat internalFormat, std::size_t width, std::size_t height, std::size_t depth, const TextureOptions &options={}) | |
Create a new texture object and allocate uninitialized GPU memory for storing an array of layers of 2D image data. More... | |
Texture (const ImageView &image, const TextureOptions &options={}) | |
Create a new texture object and allocate GPU memory for storing 2D image data loaded from an image. More... | |
operator bool () const noexcept | |
Check if the texture has a value. More... | |
void | setOptions2D (const TextureOptions &newOptions) |
Apply a new configuration of texture/sampler options to the 2D texture. More... | |
void | setOptions2DArray (const TextureOptions &newOptions) |
Apply a new configuration of texture/sampler options to the 2D array texture. More... | |
void | pasteImage2D (std::size_t width, std::size_t height, PixelFormat pixelFormat, PixelComponentType pixelComponentType, const void *pixels, std::size_t x, std::size_t y) |
Copy 2D image data into the 2D texture at a specific position. More... | |
void | pasteImage2D (const ImageView &image, std::size_t x, std::size_t y) |
Copy a 2D image into the 2D texture at a specific position. More... | |
void | pasteImage2DArray (std::size_t width, std::size_t height, std::size_t depth, PixelFormat pixelFormat, PixelComponentType pixelComponentType, const void *pixels, std::size_t x, std::size_t y, std::size_t z) |
Copy an array of layers of 2D image data into the 2D array texture at a specific position. More... | |
void | pasteImage2DArray (const ImageView &image, std::size_t x, std::size_t y, std::size_t z) |
Copy a 2D image into the 2D array texture at a specific position. More... | |
void | fill2D (Renderer &renderer, Color color) |
Fill the entire allocated 2D texture data with pixels of the given color. More... | |
void | grow2D (Renderer &renderer, std::size_t newWidth, std::size_t newHeight, std::optional< Color > backgroundColor={}) |
Expand the allocated 2D texture data by allocating larger texture storage and copying the old texture image onto the bottom left corner of the new texture. More... | |
Texture | copy2D (Renderer &renderer) const |
Create a new texture object and allocate GPU memory onto which the 2D image data of this 2D texture is copied. More... | |
Texture | copyGrow2D (Renderer &renderer, std::size_t newWidth, std::size_t newHeight, std::optional< Color > backgroundColor={}) const |
Create a new texture object and allocate GPU memory in an expanded version of this texture onto which the 2D texture data of this 2D texture is copied. More... | |
vec2 | getSize2D () const noexcept |
Get the floating-point size, in texels, of the 2D image data stored in this texture. More... | |
TextureFormat | getInternalFormat () const noexcept |
Get the internal texel format of this texture. More... | |
std::size_t | getWidth () const noexcept |
Get the width, in texels, of the 2D image data stored in this texture. More... | |
std::size_t | getHeight () const noexcept |
Get the height, in texels, of the 2D image data stored in this texture. More... | |
const TextureOptions & | getOptions () const noexcept |
Get the configuration options of this texture and its associated sampler. More... | |
Handle | get () const noexcept |
Get an opaque handle to the GPU representation of the texture. More... | |
Static Public Member Functions | |
static std::size_t | getChannelCount (TextureFormat internalFormat) noexcept |
Get the number of texel component channels defined by an internal texel format. More... | |
static PixelFormat | getPixelFormat (TextureFormat internalFormat) noexcept |
Get a description of the pixel format that corresponds to the texel format of an internal texture format. More... | |
static PixelComponentType | getPixelComponentType (TextureFormat internalFormat) noexcept |
Get a description of the pixel component type that corresponds to the texel component type of an internal texture format. More... | |
static TextureFormat | getInternalFormat (PixelFormat pixelFormat, PixelComponentType pixelComponentType) noexcept |
Get the internal texture format that correspons to an image format. More... | |
Static Public Attributes | |
static const Texture *const | TRANSPARENT |
Pointer to the statically allocated storage for the built-in transparent 2D texture. More... | |
static const Texture *const | BLACK |
Pointer to the statically allocated storage for the built-in black 2D texture. More... | |
static const Texture *const | WHITE |
Pointer to the statically allocated storage for the built-in white 2D texture. More... | |
static const Texture *const | DEFAULT_SPECULAR |
Pointer to the statically allocated storage for the built-in default specular-map 2D texture. More... | |
static const Texture *const | DEFAULT_NORMAL |
Pointer to the statically allocated storage for the built-in default normal-map 2D texture. More... | |
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configuration that defines how to render the stored data.
|
defaultnoexcept |
Construct an empty texture without a value.
donut::graphics::Texture::Texture | ( | TextureFormat | internalFormat, |
std::size_t | width, | ||
std::size_t | height, | ||
PixelFormat | pixelFormat, | ||
PixelComponentType | pixelComponentType, | ||
const void * | pixels, | ||
const TextureOptions & | options = {} |
||
) |
Create a new texture object and allocate GPU memory for storing 2D image data.
internalFormat | internal texel format of the new texture. |
width | width of the 2D image data to allocate, in texels. |
height | height of the 2D image data to allocate, in texels. |
pixelFormat | pixel format of the input image. |
pixelComponentType | pixel component type of the input image. |
pixels | non-owning read-only pointer to the pixel data of the input image to copy into the new texture data storage, or nullptr to leave the data uninitialized. |
options | texture/sampler options, see TextureOptions. |
graphics::Error | on failure to create the texture object. |
std::bad_alloc | on allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly. |
donut::graphics::Texture::Texture | ( | TextureFormat | internalFormat, |
std::size_t | width, | ||
std::size_t | height, | ||
std::size_t | depth, | ||
PixelFormat | pixelFormat, | ||
PixelComponentType | pixelComponentType, | ||
const void * | pixels, | ||
const TextureOptions & | options = {} |
||
) |
Create a new texture object and allocate GPU memory for storing an array of layers of 2D image data.
internalFormat | internal texel format of the new texture. |
width | width of the 2D image data to allocate, in texels. |
height | height of the 2D image data to allocate, in texels. |
depth | number of 2D image layers to allocate for the array. |
pixelFormat | pixel format of the input image array. |
pixelComponentType | pixel component type of the input image array. |
pixels | non-owning read-only pointer to the pixel data of the input image array to copy into the new texture data storage, or nullptr to leave the data uninitialized. |
options | texture/sampler options, see TextureOptions. |
graphics::Error | on failure to create the texture object. |
std::bad_alloc | on allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly. |
donut::graphics::Texture::Texture | ( | TextureFormat | internalFormat, |
std::size_t | width, | ||
std::size_t | height, | ||
const TextureOptions & | options = {} |
||
) |
Create a new texture object and allocate uninitialized GPU memory for storing 2D image data.
internalFormat | internal texel format of the new texture. |
width | width of the 2D image data to allocate, in texels. |
height | height of the 2D image data to allocate, in texels. |
options | texture/sampler options, see TextureOptions. |
graphics::Error | on failure to create the texture object. |
std::bad_alloc | on allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly. |
donut::graphics::Texture::Texture | ( | TextureFormat | internalFormat, |
std::size_t | width, | ||
std::size_t | height, | ||
std::size_t | depth, | ||
const TextureOptions & | options = {} |
||
) |
Create a new texture object and allocate uninitialized GPU memory for storing an array of layers of 2D image data.
internalFormat | internal texel format of the new texture. |
width | width of the 2D image data to allocate, in texels. |
height | height of the 2D image data to allocate, in texels. |
depth | number of 2D image layers to allocate for the array. |
options | texture/sampler options, see TextureOptions. |
graphics::Error | on failure to create the texture object. |
std::bad_alloc | on allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly. |
donut::graphics::Texture::Texture | ( | const ImageView & | image, |
const TextureOptions & | options = {} |
||
) |
Create a new texture object and allocate GPU memory for storing 2D image data loaded from an image.
image | non-owning read-only view over the image to copy into the new texture data storage. The allocated storage will be sized to fit the image. |
options | texture/sampler options, see TextureOptions. |
graphics::Error | on failure to create the texture object, or on failure to choose an appropriate internal texel format for the given image. |
std::bad_alloc | on allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly. |
|
staticnoexcept |
Get the number of texel component channels defined by an internal texel format.
internalFormat | the format to get the number of channels of. |
|
staticnoexcept |
Get a description of the pixel format that corresponds to the texel format of an internal texture format.
internalFormat | the internal texel format to get the pixel format of. |
|
staticnoexcept |
Get a description of the pixel component type that corresponds to the texel component type of an internal texture format.
internalFormat | the internal texel format to get the component type of. |
|
staticnoexcept |
Get the internal texture format that correspons to an image format.
pixelFormat | the pixel format of the image format. |
pixelComponentType | the pixel component type of the image format. |
|
inlineexplicitnoexcept |
Check if the texture has a value.
void donut::graphics::Texture::setOptions2D | ( | const TextureOptions & | newOptions | ) |
Apply a new configuration of texture/sampler options to the 2D texture.
newOptions | the new options to apply. |
void donut::graphics::Texture::setOptions2DArray | ( | const TextureOptions & | newOptions | ) |
Apply a new configuration of texture/sampler options to the 2D array texture.
newOptions | the new options to apply. |
void donut::graphics::Texture::pasteImage2D | ( | std::size_t | width, |
std::size_t | height, | ||
PixelFormat | pixelFormat, | ||
PixelComponentType | pixelComponentType, | ||
const void * | pixels, | ||
std::size_t | x, | ||
std::size_t | y | ||
) |
Copy 2D image data into the 2D texture at a specific position.
width | width of the 2D image data to copy, in pixels. |
height | height of the 2D image data to copy, in pixels. |
pixelFormat | pixel format of the input image. |
pixelComponentType | pixel component type of the input image. |
pixels | non-owning read-only pointer to the pixel data of the input image to copy into the existing texture data storage. Must not be nullptr. |
x | the horizontal offset, in texels, from the left edge of the texture at which to paste the image, where the left edge of the pasted image will begin. |
y | the vertical offset, in texels, from the bottom edge of the texture at which to paste the image, where the bottom edge of the pasted image will begin. |
void donut::graphics::Texture::pasteImage2D | ( | const ImageView & | image, |
std::size_t | x, | ||
std::size_t | y | ||
) |
Copy a 2D image into the 2D texture at a specific position.
image | non-owning read-only view over the image to copy into the existing texture data storage. |
x | the horizontal offset, in texels, from the left edge of the texture at which to paste the image, where the left edge of the pasted image will begin. |
y | the vertical offset, in texels, from the bottom edge of the texture at which to paste the image, where the bottom edge of the pasted image will begin. |
void donut::graphics::Texture::pasteImage2DArray | ( | std::size_t | width, |
std::size_t | height, | ||
std::size_t | depth, | ||
PixelFormat | pixelFormat, | ||
PixelComponentType | pixelComponentType, | ||
const void * | pixels, | ||
std::size_t | x, | ||
std::size_t | y, | ||
std::size_t | z | ||
) |
Copy an array of layers of 2D image data into the 2D array texture at a specific position.
width | width of the 2D image data to copy, in pixels. |
height | height of the 2D image data to copy, in pixels. |
depth | number of 2D image layers in the array to copy. |
pixelFormat | pixel format of the input image. |
pixelComponentType | pixel component type of the input image. |
pixels | non-owning read-only pointer to the pixel data of the input image array to copy into the existing texture data storage. Must not be nullptr. |
x | the horizontal offset, in texels, from the left edge of the texture at which to paste the image array, where the left edge of the pasted image array will begin. |
y | the vertical offset, in texels, from the bottom edge of the texture at which to paste the image array, where the bottom edge of the pasted image array will begin. |
z | the depth offset, in texels, from the first layer of the texture at which to paste the image array, where the first pasted image will begin. |
void donut::graphics::Texture::pasteImage2DArray | ( | const ImageView & | image, |
std::size_t | x, | ||
std::size_t | y, | ||
std::size_t | z | ||
) |
Copy a 2D image into the 2D array texture at a specific position.
image | non-owning read-only view over the image to copy into the existing texture data storage. |
x | the horizontal offset, in texels, from the left edge of the texture at which to paste the image, where the left edge of the pasted image will begin. |
y | the vertical offset, in texels, from the bottom edge of the texture at which to paste the image, where the bottom edge of the pasted image will begin. |
z | the depth offset, in texels, from the first layer of the texture at which to paste the image. |
Fill the entire allocated 2D texture data with pixels of the given color.
renderer | renderer to use for filling the texture. |
color | color to fill the texture with. |
void donut::graphics::Texture::grow2D | ( | Renderer & | renderer, |
std::size_t | newWidth, | ||
std::size_t | newHeight, | ||
std::optional< Color > | backgroundColor = {} |
||
) |
Expand the allocated 2D texture data by allocating larger texture storage and copying the old texture image onto the bottom left corner of the new texture.
renderer | renderer to use for copying the texture data. |
newWidth | new width of the 2D image data to allocate, in texels. Must be greater than or equal to the old width. |
newHeight | new height of the 2D image data to allocate, in texels. Must be greater than or equal to the old height. |
backgroundColor | if set, the new texture data is cleared to this color before copying the old data onto it. |
std::bad_alloc | on allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly. |
Create a new texture object and allocate GPU memory onto which the 2D image data of this 2D texture is copied.
renderer | renderer to use for copying the texture data. |
std::bad_alloc | on allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly. |
Texture donut::graphics::Texture::copyGrow2D | ( | Renderer & | renderer, |
std::size_t | newWidth, | ||
std::size_t | newHeight, | ||
std::optional< Color > | backgroundColor = {} |
||
) | const |
Create a new texture object and allocate GPU memory in an expanded version of this texture onto which the 2D texture data of this 2D texture is copied.
renderer | renderer to use for copying the texture data. |
newWidth | new width of the 2D image data to allocate, in texels. Must be greater than or equal to the old width. |
newHeight | new height of the 2D image data to allocate, in texels. Must be greater than or equal to the old height. |
backgroundColor | if set, the new texture data is cleared to this color before copying the old data onto it. |
std::bad_alloc | on allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly. |
|
inlinenoexcept |
Get the floating-point size, in texels, of the 2D image data stored in this texture.
|
inlinenoexcept |
Get the internal texel format of this texture.
|
inlinenoexcept |
Get the width, in texels, of the 2D image data stored in this texture.
|
inlinenoexcept |
Get the height, in texels, of the 2D image data stored in this texture.
|
inlinenoexcept |
Get the configuration options of this texture and its associated sampler.
|
inlinenoexcept |
Get an opaque handle to the GPU representation of the texture.
|
static |
Pointer to the statically allocated storage for the built-in transparent 2D texture.
|
static |
Pointer to the statically allocated storage for the built-in black 2D texture.
|
static |
Pointer to the statically allocated storage for the built-in white 2D texture.
|
static |
Pointer to the statically allocated storage for the built-in default specular-map 2D texture.
|
static |
Pointer to the statically allocated storage for the built-in default normal-map 2D texture.