sKit  0.0.9
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
sKit::SDL::TextureDownloader Class Reference

An SDL_GPUTexture download helper. Can be used to download a texture from the gpu and get as raw data. More...

#include <TextureDownloader.hpp>

Public Member Functions

 TextureDownloader ()=default
 
 TextureDownloader (SDL_GPUDevice *device, SDL_GPUCopyPass *pass, SDL_GPUTexture *sourceTexture, Uint32 width, Uint32 height)
 
 ~TextureDownloader ()
 Unmaps and releases the SDL_GPUTransferBuffer. More...
 
auto getData () -> unsigned char *
 

Public Attributes

SDL_GPUTransferBuffer * buffer
 

Detailed Description

An SDL_GPUTexture download helper. Can be used to download a texture from the gpu and get as raw data.

Example usage:

auto cmd = SDL_AcquireGPUCommandBuffer(device);
auto pass = SDL_BeginGPUCopyPass(cmd);
sKit::SDL::TextureDownloader d(device,pass, tex, w, h);
SDL_EndGPUCopyPass(pass);
auto fence = SDL_SubmitGPUCommandBufferAndAcquireFence(cmd);
SDL_WaitForGPUFences(gpu, true, &fence, 1);
SDL_ReleaseGPUFence(gpu, fence);
unsigned char * data = d.getData();

Definition at line 22 of file TextureDownloader.hpp.

Constructor & Destructor Documentation

◆ TextureDownloader() [1/2]

sKit::SDL::TextureDownloader::TextureDownloader ( )
default

◆ TextureDownloader() [2/2]

sKit::SDL::TextureDownloader::TextureDownloader ( SDL_GPUDevice *  device,
SDL_GPUCopyPass *  pass,
SDL_GPUTexture *  sourceTexture,
Uint32  width,
Uint32  height 
)

On construction, creates an SDL_GPUTransferBuffer and downloads sourceTexture into it. Must be called within a copy pass.

Definition at line 8 of file TextureDownloader.cpp.

References buffer.

◆ ~TextureDownloader()

sKit::SDL::TextureDownloader::~TextureDownloader ( )

Unmaps and releases the SDL_GPUTransferBuffer.

Definition at line 32 of file TextureDownloader.cpp.

References buffer.

Member Function Documentation

◆ getData()

auto sKit::SDL::TextureDownloader::getData ( ) -> unsigned char*

Maps the SDL_GPUTransferBuffer as raw data. The data must be used before the TextureDownloaded is destroyed because the unsigned char* will be invalidated.

Definition at line 37 of file TextureDownloader.cpp.

Member Data Documentation

◆ buffer

SDL_GPUTransferBuffer* sKit::SDL::TextureDownloader::buffer

Definition at line 24 of file TextureDownloader.hpp.

Referenced by TextureDownloader(), and ~TextureDownloader().


The documentation for this class was generated from the following files:
sKit::SDL::TextureDownloader
An SDL_GPUTexture download helper. Can be used to download a texture from the gpu and get as raw data...
Definition: TextureDownloader.hpp:22