GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::graphics::Texture Class Reference

Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configuration that defines how to sample the stored data in shaders while rendering. More...

#include <GREM/graphics/Texture.hpp>

Inheritance diagram for grem::graphics::Texture:

Public Member Functions

 Texture () noexcept=default
 Construct an empty texture without a value.
 Texture (Device &device, const resource::ImageView &image, const TextureImageUploadOptions &options={}, Optional< TextureSamplerOptions > samplerOptions=TextureSamplerOptions{})
 Construct a new texture and allocate GPU memory for storing a copy of an image.
 operator bool () const noexcept
 Check if the texture has a value.
void pasteImage (Extent3D imageSize, const void *pixels, Offset3D destinationOffset, Region3D sourceRegion)
 Copy all or part of an array of layers of 2D image data into the texture at a specific position.
void pasteImage (Extent3D imageSize, const void *pixels, Offset3D destinationOffset={.x=0,.y=0,.z=0}, Offset3D sourceOffset={.x=0,.y=0,.z=0})
 Copy all of an array of layers of 2D image data into the texture at a specific position.
void pasteTexture (const Texture &texture, Offset3D destinationOffset, Region3D sourceRegion)
 Copy all or part of the image data of another 2D or 2D array texture into the texture at a specific position.
void pasteTexture (const Texture &texture, Offset3D destinationOffset={.x=0,.y=0,.z=0}, Offset3D sourceOffset={.x=0,.y=0,.z=0})
 Copy all of the image data of another 2D or 2D array texture into the texture at a specific position.
void fill (const ClearValues &values={})
 Fill all allocated texture data with specific values.
void fill (TextureSubresource subresource, const ClearValues &values={})
 Fill a subresource of the texture with specific values.
void generateMipmap ()
 Generate a mipmap, with the maximum possible number of mip levels, for the texture based on the highest quality mip level.
Texture copy () const
 Create a new texture object, allocate GPU memory and copy the image data of this texture onto it.
Texture copyWithSamplerOptions (Optional< TextureSamplerOptions > newSamplerOptions) const
 Create a new texture object with new sampler options, allocate GPU memory and copy the image data of this texture onto it.
resource::Image downloadImage (const TextureImageDownloadOptions &downloadOptions={}) const
 Download a copy of all or part of the image stored in the texture.
 operator TextureSubresourceReference () noexcept
 Get a reference to the first subresource of the texture.
 operator TextureSubresourceConstReference () const noexcept
 Get a read-only reference to the first subresource of the texture.
TextureSubresourceReference getSubresource (TextureSubresource subresource) noexcept
 Get a reference to a subresource of the texture.
TextureSubresourceConstReference getSubresource (TextureSubresource subresource) const noexcept
 Get a read-only reference to a subresource of the texture.
 operator TextureRegion2DReference () noexcept
 Get a reference to the first 2D layer region of the texture.
 operator TextureRegion2DConstReference () const noexcept
 Get a read-only reference to the first 2D layer region of the texture.
TextureRegion2DReference getRegion2D (TextureRegion2D region) noexcept
 Get a reference to a 2D region of the texture.
TextureRegion2DConstReference getRegion2D (TextureRegion2D region) const noexcept
 Get a read-only reference to a 2D region of the texture.
TextureRegion3DReference getRegion3D (TextureRegion3D region) noexcept
 Get a reference to a 3D region of the texture.
TextureRegion3DConstReference getRegion3D (TextureRegion3D region) const noexcept
 Get a read-only reference to a 3D region of the texture.
TextureType getType () const noexcept
 Get the type of the texture.
TextureFormat getInternalFormat () const noexcept
 Get the internal texture format of this texture.
Extent2D getSize2D () const noexcept
 Get the size, in texels, of the 2D image data stored in this texture.
Extent3D getSize3D () const noexcept
 Get the size, in texels, and the depth, in layers, of the 3D image data stored in this texture.
uint32_t getWidth () const noexcept
 Get the width, in texels, of the image data stored in this texture.
uint32_t getHeight () const noexcept
 Get the height, in texels, of the image data stored in this texture.
uint32_t getDepth () const noexcept
 Get the depth, in layers, of the image data stored in this texture.
uint32_t getMipLevelCount () const noexcept
 Get the number of mip levels of the texture.
uint32_t getMaxMultisampleCount () const noexcept
 Get the maximum multisample count of the texture.
Optional< TextureSamplerOptions > getSamplerOptions () const noexcept
 Get the configuration options of this texture's associated sampler.
SharedPointer< TextureImplementation > lock () const noexcept
 Get a lock for the underlying resource implementation.
TextureImplementation * get () noexcept
 Get a pointer to the underlying resource implementation.
const TextureImplementation * get () const noexcept
 Get a pointer to the underlying resource implementation.

Static Public Member Functions

static constexpr TextureAspects getFormatAspects (TextureFormat internalFormat)
 Get the set of texture aspects of an internal texture format.
static constexpr resource::ImageType getImageType (TextureType type)
 Get the image type corresponding to a texture type.
static constexpr resource::ImageFormat getImageFormat (TextureFormat internalFormat)
 Get the image format corresponding to an internal texture format.
static constexpr TextureType getType (resource::ImageType type) noexcept
 Get the texture type corresponding to an image type.
static constexpr bool hasInternalSRGBFormat (resource::ImageFormat format) noexcept
 Check if an image format has a corresponding internal texture format that uses the sRGB transfer function.
static constexpr Color::TransferFunction getTransferFunction (TextureFormat internalFormat) noexcept
 Get the transfer function of an internal texture format.
static constexpr TextureFormat getInternalFormat (resource::ImageFormat format, Color::TransferFunction transferFunction) noexcept
 Get the internal texture format corresponding to an image format.
static constexpr TextureFormat getRawFormat (TextureFormat internalFormat) noexcept
 Get the raw format corresponding to a specific internal texture format.
static constexpr TextureFormat getUncompressedFormat (TextureFormat internalFormat) noexcept
 Get the uncompressed format corresponding to a specific internal texture format.
static constexpr bool isCompatibleFormat (TextureFormat internalFormat, resource::ImageFormat format) noexcept
 Check if a specific image format is directly compatible with an internal texture format.
static constexpr bool isRGBAColorFormat (TextureFormat internalFormat) noexcept
 Check if a specific internal texture format is an RGBA color format with an alpha channel.
static constexpr bool isRawFormat (TextureFormat internalFormat) noexcept
 Check if a specific internal texture format is a raw format.
static constexpr bool isPackedFormat (TextureFormat internalFormat) noexcept
 Check if a specific internal texture format is a bit-packed format.
static constexpr bool isCompressedFormat (TextureFormat internalFormat) noexcept
 Check if a specific internal texture format is a compressed format.
static constexpr bool isFramebufferCompatibleFormat (TextureFormat internalFormat) noexcept
 Check if a specific internal texture format is framebuffer-compatible.
static Texture create (Device &device, TextureType type, TextureFormat internalFormat, Extent3D size, uint32_t mipLevelCount, const void *pixels, Optional< TextureSamplerOptions > samplerOptions=TextureSamplerOptions{})
 Create a new texture object and allocate GPU memory for storing image data.
static Texture create (Device &device, TextureType type, TextureFormat internalFormat, Extent3D size, uint32_t mipLevelCount, const UndefinedClearValues &values, Optional< TextureSamplerOptions > samplerOptions=TextureSamplerOptions{})
 Create a new texture object and allocate uninitialized GPU memory for storing image data.
static Texture create (Device &device, TextureType type, TextureFormat internalFormat, Extent3D size, uint32_t mipLevelCount, const ClearValues &values, Optional< TextureSamplerOptions > samplerOptions=TextureSamplerOptions{})
 Create a new texture object and allocate GPU memory for storing image data, initialized to specific values.
static Texture createRenderbuffer (Device &device, TextureFormat internalFormat, Extent2D size, uint32_t maxMultisampleCount, const UndefinedClearValues &values)
 Create a new unsampled texture object and allocate uninitialized GPU memory for storing potentially multisampled 2D image data.
static Texture createRenderbuffer (Device &device, TextureFormat internalFormat, Extent2D size, uint32_t maxMultisampleCount, const ClearValues &values)
 Create a new unsampled texture object and allocate GPU memory for storing potentially multisampled 2D image data, initialized to specific values.

Detailed Description

Storage for multidimensional data, such as 2D images, on the GPU, combined with a sampler configuration that defines how to sample the stored data in shaders while rendering.

Constructor & Destructor Documentation

◆ Texture() [1/2]

grem::graphics::Texture::Texture ( )
defaultnoexcept

Construct an empty texture without a value.

◆ Texture() [2/2]

grem::graphics::Texture::Texture ( Device & device,
const resource::ImageView & image,
const TextureImageUploadOptions & options = {},
Optional< TextureSamplerOptions > samplerOptions = TextureSamplerOptions{} )

Construct a new texture and allocate GPU memory for storing a copy of an image.

Parameters
devicedevice to create the texture for. Must outlive the texture.
imagenon-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.
optionsimage upload options, see TextureImageUploadOptions.
samplerOptionssampler options, see TextureSamplerOptions. Set to an empty optional to create an unsampled texture.
Exceptions
graphics::Errorif resource creation failed, or on failure to choose an appropriate internal texture format for the given image.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly.
Note
A suitable texture type and internal texture format is chosen automatically based on the type and format of the image. To choose the type and internal format manually, use one of the static texture creation functions instead.

Member Function Documentation

◆ getFormatAspects()

constexpr TextureAspects grem::graphics::Texture::getFormatAspects ( TextureFormat internalFormat)
inlinestaticnodiscardconstexpr

Get the set of texture aspects of an internal texture format.

Parameters
internalFormatformat to get the aspects of.
Returns
a set containing all texture aspects of the given format.
Exceptions
graphics::Errorif the format aspects cannot be determined.

◆ getImageType()

constexpr resource::ImageType grem::graphics::Texture::getImageType ( TextureType type)
inlinestaticnodiscardconstexpr

Get the image type corresponding to a texture type.

Parameters
typetexture type to get the image type of.
Returns
the corresponding image type.
Exceptions
graphics::Errorif a corresponding image type cannot be determined.

◆ getImageFormat()

constexpr resource::ImageFormat grem::graphics::Texture::getImageFormat ( TextureFormat internalFormat)
inlinestaticnodiscardconstexpr

Get the image format corresponding to an internal texture format.

Parameters
internalFormatinternal texture format to get the image format of.
Returns
the corresponding image format.
Exceptions
graphics::Errorif a corresponding image format cannot be determined.

◆ getType() [1/2]

constexpr TextureType grem::graphics::Texture::getType ( resource::ImageType type)
inlinestaticnodiscardconstexprnoexcept

Get the texture type corresponding to an image type.

Parameters
typeimage type to get the texture type of.
Returns
the corresponding texture type.

◆ hasInternalSRGBFormat()

constexpr bool grem::graphics::Texture::hasInternalSRGBFormat ( resource::ImageFormat format)
inlinestaticnodiscardconstexprnoexcept

Check if an image format has a corresponding internal texture format that uses the sRGB transfer function.

Parameters
formatimage format to check.
Returns
true if there exists an sRGB texture format that the given image format corresponds to, false otherwise.
Note
This function does not guarantee that the sRGB texture format in question is supported by the current graphics backend. Use Device::getSupportedFeatures() to query this information.

◆ getTransferFunction()

constexpr Color::TransferFunction grem::graphics::Texture::getTransferFunction ( TextureFormat internalFormat)
inlinestaticnodiscardconstexprnoexcept

Get the transfer function of an internal texture format.

Parameters
internalFormatinternal texture format to get the transfer function of.
Returns
the transfer function of the internal format if it is known, Color::TransferFunction::LINEAR otherwise.

◆ getInternalFormat() [1/2]

constexpr TextureFormat grem::graphics::Texture::getInternalFormat ( resource::ImageFormat format,
Color::TransferFunction transferFunction )
inlinestaticnodiscardconstexprnoexcept

Get the internal texture format corresponding to an image format.

Parameters
formatimage format to get the internal texture format of.
transferFunctionpreferred transfer function to use. Only applies to image formats where the corresponding texture format has both sRGB and non-sRGB variants.
Returns
the corresponding internal texture format, or TextureFormat::UNKNOWN if a corresponding internal texture format cannot be determined.
See also
hasInternalSRGBFormat()

◆ getRawFormat()

constexpr TextureFormat grem::graphics::Texture::getRawFormat ( TextureFormat internalFormat)
inlinestaticnodiscardconstexprnoexcept

Get the raw format corresponding to a specific internal texture format.

Parameters
internalFormatinternal texture format to get the raw internal texture format of.
Returns
the corresponding raw internal texture format.

◆ getUncompressedFormat()

constexpr TextureFormat grem::graphics::Texture::getUncompressedFormat ( TextureFormat internalFormat)
inlinestaticnodiscardconstexprnoexcept

Get the uncompressed format corresponding to a specific internal texture format.

Parameters
internalFormatinternal texture format to get the uncompressed internal texture format of.
Returns
the corresponding uncompressed internal texture format.
Note
The corresponding uncompressed format may still be packed. To get the raw format, use getRawFormat() instead.

◆ isCompatibleFormat()

constexpr bool grem::graphics::Texture::isCompatibleFormat ( TextureFormat internalFormat,
resource::ImageFormat format )
inlinestaticnodiscardconstexprnoexcept

Check if a specific image format is directly compatible with an internal texture format.

Parameters
internalFormatinternal texture format to check.
formatimage format to check.
Returns
true if the image format is definitely directly compatible with the internal texture format, false otherwise.

◆ isRGBAColorFormat()

constexpr bool grem::graphics::Texture::isRGBAColorFormat ( TextureFormat internalFormat)
inlinestaticnodiscardconstexprnoexcept

Check if a specific internal texture format is an RGBA color format with an alpha channel.

Parameters
internalFormatinternal texture format to check.
Returns
true if the texture format is an RGBA color format with an alpha channel, false otherwise.

◆ isRawFormat()

constexpr bool grem::graphics::Texture::isRawFormat ( TextureFormat internalFormat)
inlinestaticnodiscardconstexprnoexcept

Check if a specific internal texture format is a raw format.

Parameters
internalFormatinternal texture format to check.
Returns
true if the internal texture format is raw, false otherwise.

◆ isPackedFormat()

constexpr bool grem::graphics::Texture::isPackedFormat ( TextureFormat internalFormat)
inlinestaticnodiscardconstexprnoexcept

Check if a specific internal texture format is a bit-packed format.

Parameters
internalFormatinternal texture format to check.
Returns
true if the internal texture format is packed, false otherwise.
Note
Compressed formats without any further bit-packing do not count as packed formats.

◆ isCompressedFormat()

constexpr bool grem::graphics::Texture::isCompressedFormat ( TextureFormat internalFormat)
inlinestaticnodiscardconstexprnoexcept

Check if a specific internal texture format is a compressed format.

Parameters
internalFormatinternal texture format to check.
Returns
true if the internal texture format is compressed, false otherwise.
Note
Bit-packed formats without any further compression do not count as compressed formats.

◆ isFramebufferCompatibleFormat()

constexpr bool grem::graphics::Texture::isFramebufferCompatibleFormat ( TextureFormat internalFormat)
inlinestaticnodiscardconstexprnoexcept

Check if a specific internal texture format is framebuffer-compatible.

Parameters
internalFormatinternal texture format to check.
Returns
true if the internal texture format is framebuffer-compatible, false otherwise.
Note
Even if this function returns true, the specified format may not be supported on all users' graphics drivers.

◆ create() [1/3]

Texture grem::graphics::Texture::create ( Device & device,
TextureType type,
TextureFormat internalFormat,
Extent3D size,
uint32_t mipLevelCount,
const void * pixels,
Optional< TextureSamplerOptions > samplerOptions = TextureSamplerOptions{} )
staticnodiscard

Create a new texture object and allocate GPU memory for storing image data.

Parameters
devicedevice to create the texture for. Must outlive the texture.
typetype of texture object to create.
internalFormatinternal texture format of the new texture. Must not be TextureFormat::UNKNOWN.
sizesize of the image data to allocate, in texels. Must fit in the maximum texture size specified in device.getSupportedFeatures() corresponding to the given texture type.
mipLevelCountnumber of mip levels to allocate.
pixelsnon-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.
samplerOptionssampler options, see TextureSamplerOptions. Set to an empty optional to create an unsampled texture.
Returns
the newly created texture.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly.
Warning
If not nullptr, the pixel data pointed to by the pixels parameter must be of the exact shape and format described by the size and internalFormat parameters.

◆ create() [2/3]

Texture grem::graphics::Texture::create ( Device & device,
TextureType type,
TextureFormat internalFormat,
Extent3D size,
uint32_t mipLevelCount,
const UndefinedClearValues & values,
Optional< TextureSamplerOptions > samplerOptions = TextureSamplerOptions{} )
inlinestaticnodiscard

Create a new texture object and allocate uninitialized GPU memory for storing image data.

Parameters
devicedevice to create the texture for. Must outlive the texture.
typetype of texture object to create.
internalFormatinternal texture format of the new texture. Must not be TextureFormat::UNKNOWN.
sizesize of the image data to allocate, in texels. Must fit in the maximum texture size specified in device.getSupportedFeatures() corresponding to the given texture type.
mipLevelCountnumber of mip levels to allocate.
valuesundefined clear value tag.
samplerOptionssampler options, see TextureSamplerOptions. Set to an empty optional to create an unsampled texture.
Returns
the newly created texture.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon 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() [3/3]

Texture grem::graphics::Texture::create ( Device & device,
TextureType type,
TextureFormat internalFormat,
Extent3D size,
uint32_t mipLevelCount,
const ClearValues & values,
Optional< TextureSamplerOptions > samplerOptions = TextureSamplerOptions{} )
inlinestaticnodiscard

Create a new texture object and allocate GPU memory for storing image data, initialized to specific values.

Parameters
devicedevice to create the texture for. Must outlive the texture.
typetype of texture object to create.
internalFormatinternal texture format of the new texture. Must not be TextureFormat::UNKNOWN.
sizesize of the image data to allocate, in texels. Must fit in the maximum texture size specified in device.getSupportedFeatures() corresponding to the given texture type.
mipLevelCountnumber of mip levels to allocate.
valuesinitial values to fill the texture with.
samplerOptionssampler options, see TextureSamplerOptions. Set to an empty optional to create an unsampled texture.
Returns
the newly created texture.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly.

◆ createRenderbuffer() [1/2]

Texture grem::graphics::Texture::createRenderbuffer ( Device & device,
TextureFormat internalFormat,
Extent2D size,
uint32_t maxMultisampleCount,
const UndefinedClearValues & values )
staticnodiscard

Create a new unsampled texture object and allocate uninitialized GPU memory for storing potentially multisampled 2D image data.

Parameters
devicedevice to create the texture for. Must outlive the texture.
internalFormatinternal texture format of the new texture. Must not be TextureFormat::UNKNOWN.
sizesize of the 2D image data to allocate, in texels. Must fit in the maximum 2D texture size specified in device.getSupportedFeatures().
maxMultisampleCountmaximum number of samples to use for the texels. The actual sample count may be lower than requested due to implementation-specific limitations. Set to 0 or 1 to disable multisampling.
valuesundefined clear value tag.
Returns
the newly created texture.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly.

◆ createRenderbuffer() [2/2]

Texture grem::graphics::Texture::createRenderbuffer ( Device & device,
TextureFormat internalFormat,
Extent2D size,
uint32_t maxMultisampleCount,
const ClearValues & values )
inlinestaticnodiscard

Create a new unsampled texture object and allocate GPU memory for storing potentially multisampled 2D image data, initialized to specific values.

Parameters
devicedevice to create the texture for. Must outlive the texture.
internalFormatinternal texture format of the new texture. Must not be TextureFormat::UNKNOWN.
sizesize of the 2D image data to allocate, in texels. Must fit in the maximum 2D texture size specified in device.getSupportedFeatures().
maxMultisampleCountmaximum number of samples to use for the texels. The actual sample count may be lower than requested due to implementation-specific limitations. Set to 0 or 1 to disable multisampling.
valuesinitial values to fill the texture with.
Returns
the newly created texture.
Exceptions
graphics::Errorif resource creation failed.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly.

◆ operator bool()

grem::graphics::Texture::operator bool ( ) const
inlineexplicitnoexcept

Check if the texture has a value.

Returns
true if the texture has a value, false otherwise.

◆ pasteImage() [1/2]

void grem::graphics::Texture::pasteImage ( Extent3D imageSize,
const void * pixels,
Offset3D destinationOffset,
Region3D sourceRegion )

Copy all or part of an array of layers of 2D image data into the texture at a specific position.

Parameters
imageSizefull size of the input image, in pixels.
pixelsnon-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.
destinationOffsetoffset, in texels, from the bottom left corner of the first layer of the destination texture to start pasting at, where the bottom left corner of the first layer of the pasted image region will begin.
sourceRegionregion, in texels, relative to the top left corner of the first layer of the source image, to copy.
Exceptions
graphics::Errorif resource creation failed or on failure to paste the given image data.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
This function must only be called on 2D or 2D array textures.
The pixel data pointed to by the pixels parameter must have the exact shape described by the imageSize parameter, and the same format as the internal format of the texture.
Enough space must be allocated in the texture for the copied image region to fit at the given position.
The internal texture format must be framebuffer-compatible.

◆ pasteImage() [2/2]

void grem::graphics::Texture::pasteImage ( Extent3D imageSize,
const void * pixels,
Offset3D destinationOffset = {.x = 0, .y = 0, .z = 0},
Offset3D sourceOffset = {.x = 0, .y = 0, .z = 0} )
inline

Copy all of an array of layers of 2D image data into the texture at a specific position.

Parameters
imageSizefull size of the input image to copy, in pixels.
pixelsnon-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.
destinationOffsetoffset, in texels, from the bottom left corner of the first layer of the destination texture to start pasting at, where the bottom left corner of the first layer of the pasted image region will begin.
sourceOffsetoffset, in texels, from the top left corner of the first layer of the source image to start copying from.
Exceptions
graphics::Errorif resource creation failed or on failure to paste the given image data.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
This function must only be called on 2D or 2D array textures.
The pixel data pointed to by the pixels parameter must have the exact shape described by the imageSize parameter, and the same format as the internal format of the texture.
Enough space must be allocated in the texture for the copied image region to fit at the given position.
The internal texture format must be framebuffer-compatible.

◆ pasteTexture() [1/2]

void grem::graphics::Texture::pasteTexture ( const Texture & texture,
Offset3D destinationOffset,
Region3D sourceRegion )

Copy all or part of the image data of another 2D or 2D array texture into the texture at a specific position.

Parameters
textureother texture to copy into the existing texture data storage of this texture. Must be a 2D or 2D array texture.
destinationOffsetoffset, in texels, from the bottom left corner of the first layer of the destination texture to start pasting at, where the bottom left corner of the first layer of the pasted image region will begin.
sourceRegionregion, in texels, relative to the bottom left corner of the first layer of the source texture, to copy.
Exceptions
graphics::Errorif resource creation failed or on failure to paste the given image data.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
This function must only be called on 2D or 2D array textures.
Enough space must be allocated in the texture for the copied image region to fit at the given position.
Both textures must have the same internal texture format.
The internal texture format must be framebuffer-compatible.

◆ pasteTexture() [2/2]

void grem::graphics::Texture::pasteTexture ( const Texture & texture,
Offset3D destinationOffset = {.x = 0, .y = 0, .z = 0},
Offset3D sourceOffset = {.x = 0, .y = 0, .z = 0} )
inline

Copy all of the image data of another 2D or 2D array texture into the texture at a specific position.

Parameters
textureother texture to copy into the existing texture data storage of this texture. Must be a 2D or 2D array texture.
destinationOffsetoffset, in texels, from the bottom left corner of the first layer of the destination texture to start pasting at, where the bottom left corner of the first layer of the pasted image region will begin.
sourceOffsetoffset, in texels, from the bottom left corner of the first layer of the source texture to start copying from.
Exceptions
graphics::Errorif resource creation failed or on failure to paste the given image data.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
This function must only be called on 2D or 2D array textures.
Enough space must be allocated in the texture for the copied image region to fit at the given position.
Both textures must have the same internal texture format.
The internal texture format must be framebuffer-compatible.

◆ fill() [1/2]

void grem::graphics::Texture::fill ( const ClearValues & values = {})

Fill all allocated texture data with specific values.

Parameters
valuesvalues to fill the texture with.
Exceptions
graphics::Errorif resource creation failed or on failure to fill the texture.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
The internal texture format must be framebuffer-compatible.

◆ fill() [2/2]

void grem::graphics::Texture::fill ( TextureSubresource subresource,
const ClearValues & values = {} )

Fill a subresource of the texture with specific values.

Parameters
subresourcetexture subresource to fill. Must be a valid subresource of this texture.
valuesvalues to fill the subresource with.
Exceptions
graphics::Errorif resource creation failed or on failure to fill the texture.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
The internal texture format must be framebuffer-compatible.

◆ generateMipmap()

void grem::graphics::Texture::generateMipmap ( )

Generate a mipmap, with the maximum possible number of mip levels, for the texture based on the highest quality mip level.

Exceptions
graphics::Errorif resource creation failed or on failure to regenerate the mipmap.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Note
Mipmaps are automatically regenerated without having to call this function if the texture was modified using one of its member functions, but not if the texture was rendered to.

◆ copy()

Texture grem::graphics::Texture::copy ( ) const
nodiscard

Create a new texture object, allocate GPU memory and copy the image data of this texture onto it.

Returns
the new copy of this texture, or an empty texture if this texture is empty.
Warning
The internal texture format must be framebuffer-compatible.
Exceptions
graphics::Errorif resource creation failed or on failure to copy the texture.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly.

◆ copyWithSamplerOptions()

Texture grem::graphics::Texture::copyWithSamplerOptions ( Optional< TextureSamplerOptions > newSamplerOptions) const
nodiscard

Create a new texture object with new sampler options, allocate GPU memory and copy the image data of this texture onto it.

Parameters
newSamplerOptionssampler options of the new texture.
Returns
the new copy of this texture, with the given sampler options, or an empty texture if this texture is empty.
Warning
The internal texture format must be framebuffer-compatible.
Exceptions
graphics::Errorif resource creation failed or on failure to copy the texture.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure. Note: this pertains only to CPU memory allocations. Failure to allocate GPU memory for the texture data might not be reported directly.

◆ downloadImage()

resource::Image grem::graphics::Texture::downloadImage ( const TextureImageDownloadOptions & downloadOptions = {}) const
nodiscard

Download a copy of all or part of the image stored in the texture.

Parameters
downloadOptionstexture download options, see TextureImageDownloadOptions.
Returns
an image containing a copy of the specified pixels stored in the texture.
Exceptions
graphics::Erroron failure to download the image data.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
This function must only be called on 2D, 2D array, cubemap or cubemap array textures.
Downloading data from the GPU tends to be very slow since the CPU needs to wait to make sure that the transfer has completed before resuming control. As such, this function should only be used sparingly, such as for saving screenshots.

◆ operator TextureSubresourceReference()

grem::graphics::Texture::operator TextureSubresourceReference ( )
inlinenoexcept

Get a reference to the first subresource of the texture.

Returns
a reference to the first subresource of the texture.

◆ operator TextureSubresourceConstReference()

grem::graphics::Texture::operator TextureSubresourceConstReference ( ) const
inlinenoexcept

Get a read-only reference to the first subresource of the texture.

Returns
a read-only reference to the first subresource of the texture.

◆ getSubresource() [1/2]

TextureSubresourceReference grem::graphics::Texture::getSubresource ( TextureSubresource subresource)
inlinenodiscardnoexcept

Get a reference to a subresource of the texture.

Parameters
subresourcesubresource to get a reference to. Must be a valid subresource of this texture.
Returns
a reference to the given subresource.

◆ getSubresource() [2/2]

TextureSubresourceConstReference grem::graphics::Texture::getSubresource ( TextureSubresource subresource) const
inlinenodiscardnoexcept

Get a read-only reference to a subresource of the texture.

Parameters
subresourcesubresource to get a reference to. Must be a valid subresource of this texture.
Returns
a read-only reference to the given subresource.

◆ operator TextureRegion2DReference()

grem::graphics::Texture::operator TextureRegion2DReference ( )
inlinenoexcept

Get a reference to the first 2D layer region of the texture.

Returns
a reference to the first 2D layer region of the texture.

◆ operator TextureRegion2DConstReference()

grem::graphics::Texture::operator TextureRegion2DConstReference ( ) const
inlinenoexcept

Get a read-only reference to the first 2D layer region of the texture.

Returns
a read-only reference to the first 2D layer region of the texture.

◆ getRegion2D() [1/2]

TextureRegion2DReference grem::graphics::Texture::getRegion2D ( TextureRegion2D region)
inlinenodiscardnoexcept

Get a reference to a 2D region of the texture.

Parameters
regionregion to get a reference to. Must be a valid region of this texture.
Returns
a reference to the given region.

◆ getRegion2D() [2/2]

TextureRegion2DConstReference grem::graphics::Texture::getRegion2D ( TextureRegion2D region) const
inlinenodiscardnoexcept

Get a read-only reference to a 2D region of the texture.

Parameters
regionregion to get a reference to. Must be a valid region of this texture.
Returns
a read-only reference to the given region.

◆ getRegion3D() [1/2]

TextureRegion3DReference grem::graphics::Texture::getRegion3D ( TextureRegion3D region)
inlinenodiscardnoexcept

Get a reference to a 3D region of the texture.

Parameters
regionregion to get a reference to. Must be a valid region of this texture.
Returns
a reference to the given region.

◆ getRegion3D() [2/2]

TextureRegion3DConstReference grem::graphics::Texture::getRegion3D ( TextureRegion3D region) const
inlinenodiscardnoexcept

Get a read-only reference to a 3D region of the texture.

Parameters
regionregion to get a reference to. Must be a valid region of this texture.
Returns
a read-only reference to the given region.

◆ getType() [2/2]

TextureType grem::graphics::Texture::getType ( ) const
nodiscardnoexcept

Get the type of the texture.

Returns
the texture type.

◆ getInternalFormat() [2/2]

TextureFormat grem::graphics::Texture::getInternalFormat ( ) const
nodiscardnoexcept

Get the internal texture format of this texture.

Returns
the internal texture format, or TextureFormat::UNKNOWN if the texture does not have a value.

◆ getSize2D()

Extent2D grem::graphics::Texture::getSize2D ( ) const
inlinenodiscardnoexcept

Get the size, in texels, of the 2D image data stored in this texture.

Returns
the size of the texture, in texels, or (0, 0) if the texture does not have a value.
Note
For 2D array textures, this function returns the width and height of a single image layer in the array.
For cube textures, this function returns the size of a single side of the cubemap.
See also
getSize3D()
getWidth()
getHeight()

◆ getSize3D()

Extent3D grem::graphics::Texture::getSize3D ( ) const
nodiscardnoexcept

Get the size, in texels, and the depth, in layers, of the 3D image data stored in this texture.

Returns
the size of the texture, in texels, or (0, 0, 0) if the texture does not have a value.
See also
getSize2D()
getWidth()
getHeight()
getDepth()

◆ getWidth()

uint32_t grem::graphics::Texture::getWidth ( ) const
inlinenodiscardnoexcept

Get the width, in texels, of the image data stored in this texture.

Returns
the width of the texture, in texels, or 0 if the texture does not have a value.
Note
For 2D array textures, this function returns the width of a single image layer in the array.
For cube textures, this function returns the width of a single side of the cubemap.
See also
getSize2D()
getSize3D()
getHeight()
getDepth()

◆ getHeight()

uint32_t grem::graphics::Texture::getHeight ( ) const
inlinenodiscardnoexcept

Get the height, in texels, of the image data stored in this texture.

Returns
the height of the texture, in texels, or 0 if the texture does not have a value.
Note
For 2D array textures, this function returns the height of a single image layer in the array.
For cube textures, this function returns the height of a single side of the cubemap.
See also
getSize2D()
getSize3D()
getWidth()
getDepth()

◆ getDepth()

uint32_t grem::graphics::Texture::getDepth ( ) const
inlinenodiscardnoexcept

Get the depth, in layers, of the image data stored in this texture.

Returns
the depth of the texture, in layers, or 0 if the texture does not have a value.
Note
For 2D textures, this function always returns 1. For 2D array textures, this function returns the number of image layers in the array. For cube textures, this function always returns 6. For cube array textures, this function returns the number of cube layers in the array times 6.
See also
getSize3D()
getWidth()
getHeight()

◆ getMipLevelCount()

uint32_t grem::graphics::Texture::getMipLevelCount ( ) const
nodiscardnoexcept

Get the number of mip levels of the texture.

Returns
the number of mip levels of each image layer in the texture, or 0 if the texture does not have a value.

◆ getMaxMultisampleCount()

uint32_t grem::graphics::Texture::getMaxMultisampleCount ( ) const
nodiscardnoexcept

Get the maximum multisample count of the texture.

Returns
the maximum number of samples requested to be used for the texels (1 if the texture is not multisampled), or 0 if the texture does not have a value.

◆ getSamplerOptions()

Optional< TextureSamplerOptions > grem::graphics::Texture::getSamplerOptions ( ) const
nodiscardnoexcept

Get the configuration options of this texture's associated sampler.

Returns
the current sampler options of the texture, or an empty optional if the texture does not have a value or is an unsampled texture.

◆ lock()

SharedPointer< TextureImplementation > grem::graphics::Texture::lock ( ) const
inlinenodiscardnoexcept

Get a lock for the underlying resource implementation.

Returns
a shared resource handle to the underlying resource.
Note
The type of the returned resource is backend-specific and has no meaning to application code.

◆ get() [1/2]

TextureImplementation * grem::graphics::Texture::get ( )
inlinenodiscardnoexcept

Get a pointer to the underlying resource implementation.

Returns
a non-owning pointer to the underlying resource.
Note
The type of the returned resource is backend-specific and has no meaning to application code.

◆ get() [2/2]

const TextureImplementation * grem::graphics::Texture::get ( ) const
inlinenodiscardnoexcept

Get a pointer to the underlying resource implementation.

Returns
a non-owning read-only pointer to the underlying resource.
Note
The type of the returned resource is backend-specific and has no meaning to application code.

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