Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
texture_manager.h
1#ifndef OE_RENDER_TEXTURE_MANAGER_H
2#define OE_RENDER_TEXTURE_MANAGER_H
3
4#include "../common.h"
5
6#include "texture.h"
7#include "cubemap.h"
8
9#include <map>
10#include <memory>
11#include <string>
12#include <glm/vec3.hpp>
13
14namespace oe::io
15{
16 class FileSystem;
17}
18
19namespace oe::render
20{
25 {
29 glm::vec3 color1 = glm::vec3(0.0f, 0.0f, 0.0f);
30
34 glm::vec3 color2 = glm::vec3(1.0f, 0.0f, 1.0f);
35 };
36
41 {
42 CheckerboardTextureInfo default_texture_info;
43 };
44
45 class Shader;
46
51 {
52 public:
59
64 std::shared_ptr<Texture> getDefaultTexture() const
65 {
66 return _dummy_texture;
67 }
68
72 bool hasTexture(const std::string& name) const;
73
78 std::shared_ptr<Texture> getTexture(const std::string& name) const;
79
85 template <typename T = Texture, typename... Args>
86 std::shared_ptr<Texture> registerTexture(const std::string& name, Args&&... args)
87 {
88 if (name.length() == 0)
89 {
90 throw std::invalid_argument("Texture name is missing!");
91 }
92
93 if (hasTexture(name))
94 {
95 throw std::invalid_argument("Texture " + name + "already exists!");
96 }
97
98 std::shared_ptr<Texture> result = std::make_shared<T>(std::forward<Args>(args)...);
99
100 if (result)
101 {
102 _textures[name] = result;
103 }
104
105 return result;
106 }
107
111 bool removeTexture(const std::string& name);
112
116 bool hasCubemap(const std::string& name) const;
117
122 std::shared_ptr<Cubemap> getCubemap(const std::string& name) const;
123
128 std::shared_ptr<Cubemap> getDefaultCubemap() const
129 {
130 return _dummy_cubemap;
131 }
132
137 template <typename T = Cubemap, typename... Args>
138 std::shared_ptr<Cubemap> generateCubemap(const std::string& name, Args&&... args)
139 {
140 if (name.length() == 0)
141 {
142 throw std::invalid_argument("Cubemap name is missing!");
143 }
144
145 if (hasCubemap(name))
146 {
147 throw std::invalid_argument("Cubemap " + name + "already exists!");
148 }
149
150 std::shared_ptr<Cubemap> result = std::make_shared<T>(std::forward<Args>(args)...);
151
152 if (result)
153 {
154 _cubemaps[name] = result;
155 }
156
157 return result;
158 }
159
163 bool removeCubemap(const std::string& name);
164
168 static void setVerticalFlipOnLoad(const bool flip);
169
170 private:
171 std::map<std::string, std::shared_ptr<Texture>> _textures;
172 std::map<std::string, std::shared_ptr<Cubemap>> _cubemaps;
173 std::shared_ptr<Texture> _dummy_texture;
174 std::shared_ptr<Cubemap> _dummy_cubemap;
175
176 };
177}
178
179#endif
Definition cubemap.h:9
Standard shader class.
Definition shader.h:26
handles the load and deletion of textures/cubemaps
Definition texture_manager.h:51
std::shared_ptr< Cubemap > getDefaultCubemap() const
Get dummy cubemap.
Definition texture_manager.h:128
bool hasCubemap(const std::string &name) const
Check if a cubemap is registered.
std::shared_ptr< Texture > getDefaultTexture() const
Get dummy texture.
Definition texture_manager.h:64
TextureManager(const TextureManagerCreateInfo &={})
Constructor.
std::shared_ptr< Cubemap > generateCubemap(const std::string &name, Args &&... args)
Generate and register a cubemap by calling cubemap constructor.
Definition texture_manager.h:138
bool hasTexture(const std::string &name) const
Check if a texture is registered.
std::shared_ptr< Texture > getTexture(const std::string &name) const
Get a texture by name.
bool removeTexture(const std::string &name)
Remove a registered texture.
static void setVerticalFlipOnLoad(const bool flip)
Set if textures should be flipped upon image load.
std::shared_ptr< Cubemap > getCubemap(const std::string &name) const
Get a cubemap by name.
bool removeCubemap(const std::string &name)
Remove a registered cubemap.
std::shared_ptr< Texture > registerTexture(const std::string &name, Args &&... args)
Generate and register a texture by calling texture constructor.
Definition texture_manager.h:86
Definition texture.h:27
Input/Output abstractions (Filesystem, Network, ...)
Definition file.h:14
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures)
Definition opengl.h:10
Settings to create a checkerboard texture.
Definition texture_manager.h:25
glm::vec3 color2
Second color of the default texture checkerboard pattern, magenta by default.
Definition texture_manager.h:34
glm::vec3 color1
First color of the default texture checkerboard pattern, black by default.
Definition texture_manager.h:29
Settings to create the texture manager.
Definition texture_manager.h:41