1 #ifndef DONUT_GRAPHICS_TEXTURE_HPP
2 #define DONUT_GRAPHICS_TEXTURE_HPP
294 explicit operator bool() const noexcept {
295 return static_cast<bool>(texture);
396 std::size_t x, std::size_t y, std::size_t z);
455 void grow2D(
Renderer& renderer, std::size_t newWidth, std::size_t newHeight, std::optional<Color> backgroundColor = {});
504 [[nodiscard]]
Texture copyGrow2D(
Renderer& renderer, std::size_t newWidth, std::size_t newHeight, std::optional<Color> backgroundColor = {})
const;
520 return {
static_cast<float>(width),
static_cast<float>(height)};
530 return internalFormat;
545 [[nodiscard]] std::size_t
getWidth() const noexcept {
586 return texture.
get();
592 static void createSharedTextures();
593 static void destroySharedTextures() noexcept;
595 struct TextureDeleter {
596 void operator()(
Handle handle)
const noexcept;
600 std::size_t width = 0;
601 std::size_t height = 0;
603 TextureOptions options{};
Normalized floating-point RGBA color type with 32 bits per component.
Definition: Color.hpp:11
constexpr Handle get() const noexcept
Get the value of the underlying resource handle.
Definition: UniqueHandle.hpp:152
Read-only non-owning view over a 2D image.
Definition: Image.hpp:40
Persistent system for rendering the batched draw commands of a RenderPass onto a Framebuffer,...
Definition: Renderer.hpp:38
Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configurati...
Definition: Texture.hpp:75
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.
const TextureOptions & getOptions() const noexcept
Get the configuration options of this texture and its associated sampler.
Definition: Texture.hpp:571
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 2...
vec2 getSize2D() const noexcept
Get the floating-point size, in texels, of the 2D image data stored in this texture.
Definition: Texture.hpp:519
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...
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.
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.
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.
static PixelComponentType getPixelComponentType(TextureFormat internalFormat) noexcept
Get a description of the pixel component type that corresponds to the texel component type of an inte...
static const Texture *const DEFAULT_SPECULAR
Pointer to the statically allocated storage for the built-in default specular-map 2D texture.
Definition: Texture.hpp:115
std::size_t getHeight() const noexcept
Get the height, in texels, of the 2D image data stored in this texture.
Definition: Texture.hpp:561
static TextureFormat getInternalFormat(PixelFormat pixelFormat, PixelComponentType pixelComponentType) noexcept
Get the internal texture format that correspons to an image format.
static std::size_t getChannelCount(TextureFormat internalFormat) noexcept
Get the number of texel component channels defined by an internal texel format.
static PixelFormat getPixelFormat(TextureFormat internalFormat) noexcept
Get a description of the pixel format that corresponds to the texel format of an internal texture for...
static const Texture *const BLACK
Pointer to the statically allocated storage for the built-in black 2D texture.
Definition: Texture.hpp:95
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.
void setOptions2DArray(const TextureOptions &newOptions)
Apply a new configuration of texture/sampler options to the 2D array texture.
TextureFormat getInternalFormat() const noexcept
Get the internal texel format of this texture.
Definition: Texture.hpp:529
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.
void setOptions2D(const TextureOptions &newOptions)
Apply a new configuration of texture/sampler options to the 2D texture.
static const Texture *const WHITE
Pointer to the statically allocated storage for the built-in white 2D texture.
Definition: Texture.hpp:105
std::size_t getWidth() const noexcept
Get the width, in texels, of the 2D image data stored in this texture.
Definition: Texture.hpp:545
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...
Handle get() const noexcept
Get an opaque handle to the GPU representation of the texture.
Definition: Texture.hpp:585
Texture() noexcept=default
Construct an empty texture without a value.
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.
static const Texture *const TRANSPARENT
Pointer to the statically allocated storage for the built-in transparent 2D texture.
Definition: Texture.hpp:85
void fill2D(Renderer &renderer, Color color)
Fill the entire allocated 2D texture data with pixels of the given color.
Texture copy2D(Renderer &renderer) const
Create a new texture object and allocate GPU memory onto which the 2D image data of this 2D texture i...
static const Texture *const DEFAULT_NORMAL
Pointer to the statically allocated storage for the built-in default normal-map 2D texture.
Definition: Texture.hpp:125
TextureFormat
Description of the internal texel format of a Texture, including the number of component channels,...
Definition: Texture.hpp:22
@ R32G32_FLOAT
Each texel comprises 2 32-bit floating-point components: red, green.
@ R16_FLOAT
Each texel comprises 1 16-bit floating-point component: red.
@ R32_FLOAT
Each texel comprises 1 32-bit floating-point component: red.
@ R16G16B16_FLOAT
Each texel comprises 3 16-bit floating-point components: red, green, blue.
@ R16G16_FLOAT
Each texel comprises 2 16-bit floating-point components: red, green.
@ R8G8B8_UNORM
Each texel comprises 3 normalized 8-bit unsigned integer components: red, green, blue.
@ R8_UNORM
Each texel comprises 1 normalized 8-bit unsigned integer component: red.
@ R8G8_UNORM
Each texel comprises 2 normalized 8-bit unsigned integer components: red, green.
@ R32G32B32A32_FLOAT
Each texel comprises 4 32-bit floating-point components: red, green, blue, alpha.
@ R16G16B16A16_FLOAT
Each texel comprises 4 16-bit floating-point components: red, green, blue, alpha.
@ R32G32B32_FLOAT
Each texel comprises 3 32-bit floating-point components: red, green, blue.
@ R8G8B8A8_UNORM
Each texel comprises 4 normalized 8-bit unsigned integer components: red, green, blue,...
std::uint32_t Handle
Generic GPU resource handle.
Definition: Handle.hpp:11
PixelComponentType
Description of the data type of the pixel components of an image.
Definition: Image.hpp:29
PixelFormat
Description of the number and meaning of the pixel component channels of an image.
Definition: Image.hpp:19
Configuration options for a Texture and its assocated sampler.
Definition: Texture.hpp:40
bool useMipmap
Generate a mipmap of different levels of detail for the texture and use it when sampling the texture ...
Definition: Texture.hpp:68
bool useLinearFiltering
Use bilinear filtering rather than nearest-neighbor interpolation when sampling the texture at coordi...
Definition: Texture.hpp:57
bool repeat
Treat the texture as repeating when sampling it outside of the 0-1 texture coordinate range.
Definition: Texture.hpp:47