Hymn to Beauty
C++ 3D Engine
ResourceManager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <string>
5
6namespace Video {
7class Renderer;
8class LowLevelRenderer;
9class Texture2D;
10namespace Geometry {
11class Rectangle;
12}
13} // namespace Video
14namespace Geometry {
15class Cube;
16class Model;
17} // namespace Geometry
18
19class TextureAsset;
20class ScriptFile;
21
24 friend class Hub;
25
26 public:
28
32
35
37
41 Geometry::Model* CreateModel(const std::string& name);
42
44
47 void FreeModel(Geometry::Model* model);
48
50
55 Video::Texture2D* CreateTexture2D(const char* data, int dataLength);
56
58
62 void FreeTexture2D(Video::Texture2D* texture);
63
65
69 TextureAsset* CreateTextureAsset(const std::string& name);
70
72
76 void FreeTextureAsset(TextureAsset* textureAsset);
77
79
84
86
90 ScriptFile* CreateScriptFile(const std::string& name);
91
93
97 void FreeScriptFile(ScriptFile* scriptFile);
98
100
104
106
110
112
116
117 private:
118 ResourceManager(ResourceManager const&) = delete;
119 void operator=(ResourceManager const&) = delete;
120
121 Video::LowLevelRenderer* lowLevelRenderer;
122
123 // Rectangle
124 Video::Geometry::Rectangle* rectangle = nullptr;
125 int rectangleCount = 0;
126
127 // Cube
128 Geometry::Cube* cube = nullptr;
129
130 int cubeCount = 0;
131
132 // Model.
133 struct ModelInstance {
134 Geometry::Model* model;
135 int count;
136 };
137 std::map<std::string, ModelInstance> models;
138 std::map<Geometry::Model*, std::string> modelsInverse;
139
140 // Texture2D.
141 struct Texture2DInstance {
142 Video::Texture2D* texture;
143 int count;
144 };
145 std::map<const char*, Texture2DInstance> textures;
146 std::map<Video::Texture2D*, const char*> texturesInverse;
147
148 // Texture asset.
149 struct TextureAssetInstance {
150 TextureAsset* textureAsset;
151 int count;
152 };
153 std::map<std::string, TextureAssetInstance> textureAssets;
154 std::map<TextureAsset*, std::string> textureAssetsInverse;
155
156 // ScriptFile.
157 struct ScriptFileInstance {
158 ScriptFile* scriptFile;
159 int count;
160 };
161 std::map<std::string, ScriptFileInstance> scriptFiles;
162 std::map<ScriptFile*, std::string> scriptFilesInverse;
163
164 TextureAsset* defaultAlbedo;
165 TextureAsset* defaultNormal;
166 TextureAsset* defaultRoughnessMetallic;
167};
A cube.
Definition: Cube.hpp:8
Interface of a model loaded from a file.
Definition: Model.hpp:8
Singleton class that holds all subsystems.
Definition: Managers.hpp:16
Video::Renderer * renderer
Definition: Managers.hpp:21
Handles all resources.
Definition: ResourceManager.hpp:23
void FreeModel(Geometry::Model *model)
Free the reference to the model.
Definition: ResourceManager.cpp:42
TextureAsset * CreateTextureAsset(const std::string &name)
Create a texture asset if it doesn't already exist.
Definition: ResourceManager.cpp:73
void FreeTextureAsset(TextureAsset *textureAsset)
Free the reference to the texture asset.
Definition: ResourceManager.cpp:86
ScriptFile * CreateScriptFile(const std::string &name)
Create a script file if it doesn't already exist.
Definition: ResourceManager.cpp:101
TextureAsset * GetDefaultRoughnessMetallic()
Get the default roughness-metallic texture.
Definition: ResourceManager.cpp:132
TextureAsset * GetDefaultNormal()
Get the default normal map.
Definition: ResourceManager.cpp:128
~ResourceManager()
Destructor.
Definition: ResourceManager.cpp:23
TextureAsset * GetDefaultAlbedo()
Get the default albedo texture.
Definition: ResourceManager.cpp:124
Geometry::Model * CreateModel(const std::string &name)
Create a model if it doesn't already exist.
Definition: ResourceManager.cpp:29
int GetTextureAssetInstanceCount(TextureAsset *textureAsset)
Get the number of instances of a texture asset.
Definition: ResourceManager.cpp:96
void FreeScriptFile(ScriptFile *scriptFile)
Free the reference to the script file.
Definition: ResourceManager.cpp:114
ResourceManager(Video::Renderer *renderer)
Constructor.
Definition: ResourceManager.cpp:14
Video::Texture2D * CreateTexture2D(const char *data, int dataLength)
Create a 2D texture if it doesn't already exist.
Definition: ResourceManager.cpp:52
void FreeTexture2D(Video::Texture2D *texture)
Free the reference to the 2D texture.
Definition: ResourceManager.cpp:63
Information about a file containing a script.
Definition: ScriptFile.hpp:8
A texture used in a hymn.
Definition: TextureAsset.hpp:12
A renderable 2D rectangle.
Definition: Rectangle.hpp:8
Low level renderer abstracting the underlaying graphics API (OpenGL or Vulkan).
Definition: LowLevelRenderer.hpp:27
Handles rendering using a low-level renderer.
Definition: Renderer.hpp:32
A two-dimensional texture.
Definition: Texture2D.hpp:10
Definition: AssetEditor.hpp:5
Definition: Editor.hpp:18