SolarSim
Loading...
Searching...
No Matches
asset_manager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_map>
4#include <string>
5#include <memory>
6#include <vector>
7
8namespace solarsim {
9 struct Mesh;
10 struct Material;
11 struct Shader;
12
14 const std::vector<float> cube = {
15 // positions // normals
16 // Front face
17 -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
18 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
19 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
20 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
21 -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
22 -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
23
24 // Back face
25 -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
26 -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
27 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
28 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
29 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
30 -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
31
32 // Left face
33 -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
34 -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
35 -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
36 -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
37 -0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
38 -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
39
40 // Right face
41 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
42 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
43 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
44 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
45 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
46 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
47
48 // Top face
49 -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
50 -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
51 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
52 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
53 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
54 -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
55
56 // Bottom face
57 -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
58 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
59 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
60 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
61 -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
62 -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f
63 };
64
72 public:
73 AssetManager(const AssetManager&) = delete;
75
80 static AssetManager& get();
81
90 std::shared_ptr<Mesh> LoadMesh(const std::string& meshID);
91
100 std::shared_ptr<Material> LoadMaterial(const std::string& materialID);
101
110 std::shared_ptr<Shader> LoadShader(const std::string& shaderID);
111
112 private:
114 std::unordered_map<std::string, std::shared_ptr<Material>> loadedMaterials;
116 std::unordered_map<std::string, std::shared_ptr<Mesh>> loadedMeshes;
118 std::unordered_map<std::string, std::shared_ptr<Shader>> loadedShaders;
119
127 void generateSphere(std::vector<float>& vertices, std::vector<uint32_t>& indices, float radius=1.0f, int resolution=100);
128
136 void generateGrid(std::vector<float>& vertices, std::vector<uint32_t>& indices, float spacing=20.0f, int extent=100);
137
140 };
141}
std::unordered_map< std::string, std::shared_ptr< Mesh > > loadedMeshes
Definition asset_manager.hpp:116
std::shared_ptr< Mesh > LoadMesh(const std::string &meshID)
Load or retrieve a cached mesh by ID.
Definition asset_manager.cpp:16
AssetManager()
Definition asset_manager.hpp:138
static AssetManager & get()
Get the singleton AssetManager instance.
Definition asset_manager.cpp:11
AssetManager(const AssetManager &)=delete
std::unordered_map< std::string, std::shared_ptr< Material > > loadedMaterials
Definition asset_manager.hpp:114
std::shared_ptr< Material > LoadMaterial(const std::string &materialID)
Load or retrieve a cached material by ID.
Definition asset_manager.cpp:45
std::unordered_map< std::string, std::shared_ptr< Shader > > loadedShaders
Definition asset_manager.hpp:118
AssetManager & operator=(const AssetManager &)=delete
void generateGrid(std::vector< float > &vertices, std::vector< uint32_t > &indices, float spacing=20.0f, int extent=100)
Generate grid mesh geometry.
Definition asset_manager.cpp:165
std::shared_ptr< Shader > LoadShader(const std::string &shaderID)
Load or retrieve a cached shader by ID.
Definition asset_manager.cpp:83
~AssetManager()
Definition asset_manager.hpp:139
void generateSphere(std::vector< float > &vertices, std::vector< uint32_t > &indices, float radius=1.0f, int resolution=100)
Generate sphere mesh geometry.
Definition asset_manager.cpp:105
Definition engine.cpp:23
const std::vector< float > cube
Definition asset_manager.hpp:14
Defines surface appearance properties for rendering.
Definition material.hpp:13
Represents 3D geometry with OpenGL buffers.
Definition mesh.hpp:14
Manages OpenGL shader program compilation and uniform setting.
Definition shader.hpp:19