struct render::TextureUtility

Utility class for working with textures, providing helper methods for staging buffer operations and data transfer.

Public

Methods

staticCreateStagingBuffer

static SPtr<GpuBuffer> CreateStagingBuffer(const SPtr<Texture> &texture, u32 mipLevel, bool readable)

Creates a staging buffer sized appropriately for texture data transfer.

texture
Texture for which to create the staging buffer.
mipLevel
Mip level of the texture subresource.
readable
True if the buffer needs to be CPU-readable (for readback), false if CPU-writeable (for upload).

Returns: Newly created staging buffer sized for the specified texture subresource.

staticCreateStagingBuffer

static SPtr<GpuBuffer> CreateStagingBuffer(const SPtr<Texture> &texture, const PixelData &pixelData, bool readable)

Creates a staging buffer with the specified size.

texture
Texture for which to create the staging buffer.
pixelData
Pixel data structure with initialized row/depth pitch, used to determine buffer size.
readable
True if the buffer needs to be CPU-readable (for readback), false if CPU-writeable (for upload).

Returns: Newly created staging buffer.

staticWrite

static void Write(const SPtr<Texture> &texture, const PixelData &source, u32 mipLevel = 0, u32 arrayLayer = 0, TextureWriteFlags flags = TextureWriteFlag::Normal, SPtr<GpuCommandBuffer> commandBuffer = nullptr)

Writes pixel data to a texture subresource.

This method automatically chooses the optimal path:

  • For directly mappable textures: Uses Map() + BulkPixelConversion
  • For non-mappable textures: Uses staging buffer + CopyBufferToTexture
texture
Texture to write data to.
source
Pixel data to write. Must be compatible with texture format and dimensions.
mipLevel
Destination mipmap level.
arrayLayer
Destination array layer (or cubemap face or depth slice).
flags
Optional flags controlling write behavior.
commandBuffer
Command buffer for staging operations. If null, uses internal transfer buffer.

staticRead

static void Read(const SPtr<Texture> &texture, PixelData &destination, u32 mipLevel = 0, u32 arrayLayer = 0, const SPtr<GpuQueue> &gpuQueue = nullptr)

Reads data from the texture subresource into the provided buffer.

This method automatically chooses the optimal path:

  • For directly mappable textures: Uses Map() + BulkPixelConversion
  • For non-mappable textures: Uses staging buffer + CopyTextureToBuffer
  • If the texture is currently being used by the GPU, this method will block until the GPU is done executing.
texture
Texture to read the data from.
destination
Previously allocated buffer to read data into.
mipLevel
Mipmap level to read from.
arrayLayer
Array layer (or cubemap face or depth slice) to read from.
gpuQueue
GPU queue on which to perform the read. If not specified the default transfer queue will be used.

staticReadAsync

static TAsyncOp<SPtr<PixelData>> ReadAsync(const SPtr<Texture> &texture, GpuCommandBuffer &commandBuffer, u32 mipLevel = 0, u32 arrayLayer = 0)

Performs a non-blocking read operation.

The GPU will execute the read when the command buffer reaches the execution point and the asynchronous operation will be signaled with the return value.

commandBuffer
Command buffer to queue the operation on.
mipLevel
Mipmap level to read from.
arrayLayer
Texture array layer (or cubemap face or depth slice) to read from.

Returns: Operation that will be signaled when the data is ready to be read.

staticClear

static void Clear(const SPtr<Texture> &texture, const Color &value, u32 mipLevel = 0, u32 arrayLayer = 0, const SPtr<GpuCommandBuffer> &commandBuffer = nullptr)

Sets all the pixels of the specified face and mip level to the provided value.

texture
Texture to write data to.
value
Color to clear the pixels to.
mipLevel
Mip level to clear.
arrayLayer
Array layer (or cubemap face or depth slice) to clear.
commandBuffer
Command buffer on which to encode the staging texture copy, in case the texture is not directly writeable. If not provided the operation will be queued on an internal command buffer that will be submitted before any regular command buffer submission.