SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
ResourceManager.cpp
Go to the documentation of this file.
1
#include "
../../include/private/Graphics/Common/ResourceManager.hpp
"
2
#include <
Core/Logger.hpp
>
3
4
namespace
Sleak
{
5
namespace
RenderEngine
{
6
7
IMPLEMENT_RESOURCE_MANAGER
8
9
BufferBase
*
ResourceManager::CreateBuffer
(
BufferType
Type, uint32_t Size,
void
* Data) {
10
std::lock_guard<std::mutex> lock(threadManager);
11
if
(BufferCreationFunc) {
12
std::any result = BufferCreationFunc(Type, Size, Data);
13
try
{
14
if
(result.has_value()) {
15
BufferBase
* buffer = std::any_cast<BufferBase*>(result);
16
return
buffer;
17
}
18
}
catch
(
const
std::exception& e) {
19
SLEAK_ERROR
(
"Failed to cast object to Buffer object: {}"
, e.what());
20
}
21
}
else
{
22
SLEAK_ERROR
(
"No buffer creation function registered!"
);
23
}
24
return
nullptr
;
25
}
26
27
Shader
*
ResourceManager::CreateShader
(
const
std::string& ShaderPath) {
28
std::lock_guard<std::mutex> lock(threadManager);
29
if
(ShaderCreateFunc) {
30
std::any result = ShaderCreateFunc(ShaderPath);
31
try
{
32
if
(result.has_value()) {
33
Shader
* shader = std::any_cast<Shader*>(result);
34
return
shader;
35
}
36
}
catch
(
const
std::exception& e) {
37
SLEAK_ERROR
(
"Failed to cast object to Shader object: {}"
, e.what());
38
}
39
}
else
{
40
SLEAK_ERROR
(
"No shader creation function registered!"
);
41
}
42
return
nullptr
;
43
}
44
45
Sleak::Texture
*
ResourceManager::CreateTexture
(
const
std::string& TexturePath) {
46
std::lock_guard<std::mutex> lock(threadManager);
47
if
(TextureCreateFunc) {
48
std::any result = TextureCreateFunc(TexturePath);
49
try
{
50
if
(result.has_value()) {
51
Texture
* texture = std::any_cast<Texture*>(result);
52
return
texture;
53
}
54
}
catch
(
const
std::exception& e) {
55
SLEAK_ERROR
(
"Failed to cast object to Texture object: {}"
,
56
e.what());
57
}
58
}
else
{
59
SLEAK_ERROR
(
"No texture creation function registered!"
);
60
}
61
return
nullptr
;
62
}
63
64
Sleak::Texture
*
ResourceManager::CreateTextureFromMemory
(
const
void
* data, uint32_t
width
, uint32_t
height
,
TextureFormat
format, uint32_t maxMipLevels) {
65
std::lock_guard<std::mutex> lock(threadManager);
66
if
(TextureFromMemoryCreateFunc) {
67
std::any result = TextureFromMemoryCreateFunc(data,
width
,
height
, format, maxMipLevels);
68
try
{
69
if
(result.has_value()) {
70
Texture
* texture = std::any_cast<Texture*>(result);
71
return
texture;
72
}
73
}
catch
(
const
std::exception& e) {
74
SLEAK_ERROR
(
"Failed to cast object to Texture (from memory) object: {}"
,
75
e.what());
76
}
77
}
else
{
78
SLEAK_ERROR
(
"No texture-from-memory creation function registered!"
);
79
}
80
return
nullptr
;
81
}
82
83
Sleak::Texture
*
ResourceManager::CreateCubemapTexture
(
const
std::array<std::string, 6>& FacePaths) {
84
std::lock_guard<std::mutex> lock(threadManager);
85
if
(CubemapTextureCreateFunc) {
86
std::any result = CubemapTextureCreateFunc(FacePaths);
87
try
{
88
if
(result.has_value()) {
89
Texture
* texture = std::any_cast<Texture*>(result);
90
return
texture;
91
}
92
}
catch
(
const
std::exception& e) {
93
SLEAK_ERROR
(
"Failed to cast object to CubemapTexture object: {}"
,
94
e.what());
95
}
96
}
else
{
97
SLEAK_ERROR
(
"No cubemap texture creation function registered!"
);
98
}
99
return
nullptr
;
100
}
101
102
Sleak::Texture
*
ResourceManager::CreateCubemapTextureFromPanorama
(
const
std::string& PanoramaPath) {
103
std::lock_guard<std::mutex> lock(threadManager);
104
if
(CubemapPanoramaCreateFunc) {
105
std::any result = CubemapPanoramaCreateFunc(PanoramaPath);
106
try
{
107
if
(result.has_value()) {
108
Texture
* texture = std::any_cast<Texture*>(result);
109
return
texture;
110
}
111
}
catch
(
const
std::exception& e) {
112
SLEAK_ERROR
(
"Failed to cast object to CubemapTexture (panorama) object: {}"
,
113
e.what());
114
}
115
}
else
{
116
SLEAK_ERROR
(
"No cubemap panorama creation function registered!"
);
117
}
118
return
nullptr
;
119
}
120
121
};
122
}
width
int width
Definition
Application.cpp:40
height
int height
Definition
Application.cpp:41
Logger.hpp
SLEAK_ERROR
#define SLEAK_ERROR(...)
Definition
Logger.hpp:22
ResourceManager.hpp
IMPLEMENT_RESOURCE_MANAGER
#define IMPLEMENT_RESOURCE_MANAGER
Definition
ResourceManager.hpp:14
Sleak::RenderEngine::BufferBase
Backend-agnostic GPU buffer: vertex, index, constant, or resource view target.
Definition
BufferBase.hpp:16
Sleak::RenderEngine::ResourceManager::CreateCubemapTextureFromPanorama
static Sleak::Texture * CreateCubemapTextureFromPanorama(const std::string &PanoramaPath)
Loads a cubemap from a single equirectangular panorama via the currently registered backend factory.
Definition
ResourceManager.cpp:102
Sleak::RenderEngine::ResourceManager::CreateShader
static Shader * CreateShader(const std::string &ShaderPath)
Compiles a shader via the currently registered backend factory.
Definition
ResourceManager.cpp:27
Sleak::RenderEngine::ResourceManager::CreateTexture
static Sleak::Texture * CreateTexture(const std::string &TexturePath)
Loads a texture via the currently registered backend factory.
Definition
ResourceManager.cpp:45
Sleak::RenderEngine::ResourceManager::CreateBuffer
static BufferBase * CreateBuffer(BufferType Type, uint32_t Size, void *Data)
Creates a buffer via the currently registered backend factory.
Definition
ResourceManager.cpp:9
Sleak::RenderEngine::ResourceManager::CreateTextureFromMemory
static Sleak::Texture * CreateTextureFromMemory(const void *data, uint32_t width, uint32_t height, TextureFormat format, uint32_t maxMipLevels=0)
Creates a texture from raw pixel data via the currently registered backend factory.
Definition
ResourceManager.cpp:64
Sleak::RenderEngine::ResourceManager::CreateCubemapTexture
static Sleak::Texture * CreateCubemapTexture(const std::array< std::string, 6 > &FacePaths)
Loads a cubemap from six face image paths via the currently registered backend factory.
Definition
ResourceManager.cpp:83
Sleak::RenderEngine::Shader
Backend-agnostic compiled shader program.
Definition
Shader.hpp:11
Sleak::Texture
Definition
Texture.hpp:78
Sleak::TextureFormat
TextureFormat
Definition
Texture.hpp:10
Sleak::RenderEngine
Backend-facing rendering layer shared by the four graphics backends.
Definition
Application.hpp:60
Sleak::RenderEngine::BufferType
BufferType
GPU buffer usage kind, drives backend binding flags and layout.
Definition
BufferBase.hpp:13
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
src
Graphics
Common
ResourceManager.cpp
Generated on
for SleakEngine by
1.18.0