Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
image_data_gpu.cpp
Go to the documentation of this file.
1// Copyright (c) 2025 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
33
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}
55
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}
71
73{
74 if (!mGpuHandle)
75 {
76 return false;
77 }
78 mGpuHandle->IsTextureLoadedInGPU();
79}
80
82{
83 if (!mImageData)
84 {
85 return 0;
86 }
87
88 return mImageData->GetSizeInBytes();
89}
90
92{
93 if (!mGpuHandle)
94 {
95 return 0;
96 }
97
98 return mGpuHandle->GetSizeInGPUBytes();
99}
100
102{
103 return *mImageData;
104}
105
107{
108 return *mImageData;
109}
110
112{
113 return mGpuHandle.get();
114}
Defines an abstract interface for rendering backends.
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.