Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
image_data_gpu.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Alexander Obzherin � Licensed under the zlib License. See LICENSE.md.
2
3#include "image_data_gpu.hpp"
4#include "image_data.hpp"
5#include "i_renderer.hpp"
7
8using namespace rendering_engine;
9
10ImageDataGpu::ImageDataGpu(std::string path, IRenderer* renderer)
11 :
12 mPath{path},
13 mRenderer{renderer},
14 mImageData{nullptr},
15 mGpuHandle{nullptr}
16{
17 mImageData = std::make_unique<ImageData>(path);
18}
19
20ImageDataGpu::ImageDataGpu(std::vector<uint8_t> const& fileBytes, IRenderer* renderer)
21 :
22 mPath{},
23 mRenderer{ renderer },
24 mImageData{ nullptr },
25 mGpuHandle{ nullptr }
26{
27 mImageData = std::make_unique<ImageData>(fileBytes);
28}
29
31 :
32 mPath{},
33 mRenderer{ renderer },
34 mImageData{ nullptr },
35 mGpuHandle{ nullptr }
36{
37 mImageData = std::make_unique<ImageData>(imageData);
38}
39
41{
42}
43
45{
46 if (!mRenderer)
47 {
48 return;
49 }
50
51 if (mGpuHandle)
52 {
53 if (mGpuHandle->IsTextureLoadedInGPU())
54 {
56 }
57 }
58 mGpuHandle = std::unique_ptr<ITextureRenderResources>(mRenderer->ProvideTextureRenderResources());
59 if (!mGpuHandle)
60 {
61 return;
62 }
63 mGpuHandle->LoadToGPU(*mImageData);
64}
65
67{
68 if (!mRenderer)
69 {
70 return;
71 }
72 if (!mGpuHandle)
73 {
74 return;
75 }
76
77 mGpuHandle->ReleaseFromGPU();
78 mGpuHandle.release();
79 mGpuHandle = nullptr;
80}
81
83{
84 if (!mGpuHandle)
85 {
86 return false;
87 }
88 return mGpuHandle->IsTextureLoadedInGPU();
89}
90
92{
93 if (!mImageData)
94 {
95 return 0;
96 }
97
98 return mImageData->GetSizeInBytes();
99}
100
102{
103 if (!mGpuHandle)
104 {
105 return 0;
106 }
107
108 return mGpuHandle->GetSizeInGPUBytes();
109}
110
112{
113 return *mImageData;
114}
115
117{
118 return *mImageData;
119}
120
122{
123 return mGpuHandle.get();
124}
Defines an abstract interface for rendering backends.
Definition: i_renderer.hpp:29
virtual ITextureRenderResources * ProvideTextureRenderResources() const =0
Provides access to texture-related GPU resources.
Interface for backend-specific GPU texture resource management.
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).
ITextureRenderResources * GetTextureRenderResources() const
Returns a pointer to the GPU texture resource interface.
~ImageDataGpu()
Destructor. Frees GPU memory if allocated.
size_t GetSizeInGPU() const
Gets the size of the texture in GPU memory (in bytes).
void UploadToGPU()
Uploads the texture data to GPU if not already uploaded.
ImageData const & GetCpuImageData() const
Returns a const reference to the CPU-side image data.
void ReleaseFromGPU()
Releases the GPU resources (image, sampler, view).
ImageDataGpu(std::string path, IRenderer *renderer)
Constructs an ImageDataGpu object from an image file path.
Represents raw 2D image data stored in memory.
Definition: image_data.hpp:80