Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
rendering_engine::ImageDataGpu Class Reference

Combines CPU-side and GPU-side texture representations, managing both lifetimes and transitions. More...

#include <image_data_gpu.hpp>

Public Member Functions

 ImageDataGpu (std::string path, IRenderer *renderer)
 Constructs an ImageDataGpu object from an image file path.
 ImageDataGpu (std::vector< uint8_t > const &fileBytes, IRenderer *renderer)
 Constructs an ImageDataGpu object from raw image file bytes.
 ~ImageDataGpu ()
 Destructor. Frees GPU memory if allocated.
void UploadToGPU ()
 Uploads the texture data to GPU if not already uploaded.
void ReleaseFromGPU ()
 Releases the GPU resources (image, sampler, view).
bool IsOnGPU () const
 Checks whether the texture is currently loaded in GPU memory.
size_t GetSizeInRAM () const
 Gets the size of the texture in RAM (in bytes).
size_t GetSizeInGPU () const
 Gets the size of the texture in GPU memory (in bytes).
ImageData const & GetCpuImageData () const
 Returns a const reference to the CPU-side image data.
ImageDataGetCpuImageData ()
 Returns a modifiable reference to the CPU-side image data.
ITextureRenderResourcesGetTextureRenderResources () const
 Returns a pointer to the GPU texture resource interface.

Detailed Description

Combines CPU-side and GPU-side texture representations, managing both lifetimes and transitions.

This class owns the image data in RAM (via ImageData) and optionally uploads/releases the corresponding GPU-side representation. It provides accessors for both and tracks memory usage.

Definition at line 25 of file image_data_gpu.hpp.

Constructor & Destructor Documentation

◆ ImageDataGpu() [1/2]

ImageDataGpu::ImageDataGpu ( std::string path,
IRenderer * renderer )

Constructs an ImageDataGpu object from an image file path.

Parameters
pathPath to the image file (must be supported format such as .png or .jpg).
rendererPointer to the rendering engine interface (IRenderer).

Definition at line 10 of file image_data_gpu.cpp.

11 :
12 mPath{path},
13 mRenderer{renderer},
14 mImageData{nullptr},
15 mGpuHandle{nullptr}
16{
17 mImageData = std::make_unique<ImageData>(path);
18}

◆ ImageDataGpu() [2/2]

ImageDataGpu::ImageDataGpu ( std::vector< uint8_t > const & fileBytes,
IRenderer * renderer )

Constructs an ImageDataGpu object from raw image file bytes.

This constructor allows loading GPU-ready image data directly from a memory buffer rather than from disk. The input is interpreted as an encoded image (PNG or JPEG). After decoding via ImageData, the pixel data is uploaded to GPU memory through the provided IRenderer interface.

Parameters
fileBytesRaw binary contents of an image file (PNG or JPEG).
rendererPointer to the rendering engine interface responsible for uploading the texture to GPU memory.

Definition at line 20 of file image_data_gpu.cpp.

21 :
22 mPath{},
23 mRenderer{ renderer },
24 mImageData{ nullptr },
25 mGpuHandle{ nullptr }
26{
27 mImageData = std::make_unique<ImageData>(fileBytes);
28}

◆ ~ImageDataGpu()

rendering_engine::ImageDataGpu::~ImageDataGpu ( )

Destructor. Frees GPU memory if allocated.

Definition at line 30 of file image_data_gpu.cpp.

31{
32}

Member Function Documentation

◆ GetCpuImageData() [1/2]

ImageData & ImageDataGpu::GetCpuImageData ( )

Returns a modifiable reference to the CPU-side image data.

Returns
Reference to the underlying ImageData.

Definition at line 106 of file image_data_gpu.cpp.

107{
108 return *mImageData;
109}

◆ GetCpuImageData() [2/2]

ImageData const & ImageDataGpu::GetCpuImageData ( ) const

Returns a const reference to the CPU-side image data.

Returns
Const reference to the underlying ImageData.

Definition at line 101 of file image_data_gpu.cpp.

102{
103 return *mImageData;
104}

◆ GetSizeInGPU()

size_t rendering_engine::ImageDataGpu::GetSizeInGPU ( ) const

Gets the size of the texture in GPU memory (in bytes).

Returns
Estimated GPU memory usage if uploaded, 0 otherwise.

Definition at line 91 of file image_data_gpu.cpp.

92{
93 if (!mGpuHandle)
94 {
95 return 0;
96 }
97
98 return mGpuHandle->GetSizeInGPUBytes();
99}

◆ GetSizeInRAM()

size_t rendering_engine::ImageDataGpu::GetSizeInRAM ( ) const

Gets the size of the texture in RAM (in bytes).

Returns
Estimated RAM usage of the image data.

Definition at line 81 of file image_data_gpu.cpp.

82{
83 if (!mImageData)
84 {
85 return 0;
86 }
87
88 return mImageData->GetSizeInBytes();
89}

◆ GetTextureRenderResources()

ITextureRenderResources * ImageDataGpu::GetTextureRenderResources ( ) const

Returns a pointer to the GPU texture resource interface.

Returns
Pointer to ITextureRenderResources if uploaded, nullptr otherwise.

Definition at line 111 of file image_data_gpu.cpp.

112{
113 return mGpuHandle.get();
114}

◆ IsOnGPU()

bool ImageDataGpu::IsOnGPU ( ) const

Checks whether the texture is currently loaded in GPU memory.

Returns
true if texture has been uploaded to GPU, false otherwise.

Definition at line 72 of file image_data_gpu.cpp.

73{
74 if (!mGpuHandle)
75 {
76 return false;
77 }
78 mGpuHandle->IsTextureLoadedInGPU();
79}

◆ ReleaseFromGPU()

void ImageDataGpu::ReleaseFromGPU ( )

Releases the GPU resources (image, sampler, view).

After this call, the texture will be stored in RAM only.

Definition at line 56 of file image_data_gpu.cpp.

57{
58 if (!mRenderer)
59 {
60 return;
61 }
62 if (!mGpuHandle)
63 {
64 return;
65 }
66
67 mGpuHandle->ReleaseFromGPU();
68 mGpuHandle.release();
69 mGpuHandle = nullptr;
70}

◆ UploadToGPU()

void ImageDataGpu::UploadToGPU ( )

Uploads the texture data to GPU if not already uploaded.

This function instantiates GPU resource handlers and invokes texture uploading routines.

Definition at line 34 of file image_data_gpu.cpp.

35{
36 if (!mRenderer)
37 {
38 return;
39 }
40
41 if (mGpuHandle)
42 {
43 if (mGpuHandle->IsTextureLoadedInGPU())
44 {
46 }
47 }
48 mGpuHandle = std::unique_ptr<ITextureRenderResources>(mRenderer->ProvideTextureRenderResources());
49 if (!mGpuHandle)
50 {
51 return;
52 }
53 mGpuHandle->LoadToGPU(*mImageData);
54}
void ReleaseFromGPU()
Releases the GPU resources (image, sampler, view).

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