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 "texture.h"
5#include "cubemap.h"
6
7#include <map>
8#include <memory>
9#include <string>
10#include <glm/vec3.hpp>
11
12namespace oe::io
13{
14 class FileSystem;
15}
16
17namespace oe::render
18{
23 {
27 glm::vec3 color1 = glm::vec3(0.0f, 0.0f, 0.0f);
28
32 glm::vec3 color2 = glm::vec3(1.0f, 0.0f, 1.0f);
33 };
34
39 {
40 CheckerboardTextureInfo default_texture_info;
41 };
42
43 class Shader;
44
49 {
50 public:
57
63 {
64 return &_dummy_texture;
65 }
66
74 {
75 return &_dummy_texture;
76 }
77
81 bool hasTexture(const std::string& name) const;
82
87 const Texture* getTexture(const std::string& name) const;
88
93 Texture* getTexture(const std::string& name);
94
100 template <typename T = Texture, typename... Args>
101 Texture* registerTexture(const std::string& name, Args&&... args)
102 {
103 if (name.length() == 0)
104 {
105 throw std::invalid_argument("Texture name is missing!");
106 }
107
108 if (hasTexture(name))
109 {
110 throw std::invalid_argument("Texture " + name + "already exists!");
111 }
112
113 _textures[name] = std::make_unique<T>(std::forward<Args>(args)...);
114
115 return _textures[name].get();
116 }
117
121 bool removeTexture(const std::string& name);
122
126 bool hasCubemap(const std::string& name) const;
127
132 const Cubemap* getCubemap(const std::string& name) const;
133
138 Cubemap* getCubemap(const std::string& name);
139
145 {
146 return &_dummy_cubemap;
147 }
148
156 {
157 return &_dummy_cubemap;
158 }
159
164 template <typename T = Cubemap, typename... Args>
165 Cubemap* registerCubemap(const std::string& name, Args&&... args)
166 {
167 if (name.length() == 0)
168 {
169 throw std::invalid_argument("Cubemap name is missing!");
170 }
171
172 if (hasCubemap(name))
173 {
174 throw std::invalid_argument("Cubemap " + name + "already exists!");
175 }
176
177 _cubemaps[name] = std::make_unique<T>(std::forward<Args>(args)...);
178
179 return _cubemaps[name].get();
180 }
181
185 bool removeCubemap(const std::string& name);
186
190 static void setVerticalFlipOnLoad(const bool flip);
191
192 private:
193 Texture _dummy_texture;
194 Cubemap _dummy_cubemap;
195
196 std::map<std::string, std::unique_ptr<Texture>> _textures;
197 std::map<std::string, std::unique_ptr<Cubemap>> _cubemaps;
198 };
199}
200
201#endif
Definition cubemap.h:9
Standard shader class.
Definition shader.h:23
handles the load and deletion of textures/cubemaps
Definition texture_manager.h:49
bool hasCubemap(const std::string &name) const
Check if a cubemap is registered.
Texture * getDefaultTexture()
Get dummy texture.
Definition texture_manager.h:73
TextureManager(const TextureManagerCreateInfo &={})
Constructor.
Cubemap * getCubemap(const std::string &name)
Get a cubemap by name.
Texture * registerTexture(const std::string &name, Args &&... args)
Generate and register a texture by calling texture constructor.
Definition texture_manager.h:101
Cubemap * registerCubemap(const std::string &name, Args &&... args)
Generate and register a cubemap by calling cubemap constructor.
Definition texture_manager.h:165
bool hasTexture(const std::string &name) const
Check if a texture is registered.
const Texture * getDefaultTexture() const
Get dummy texture.
Definition texture_manager.h:62
Texture * getTexture(const std::string &name)
Get a texture by name.
Cubemap * getDefaultCubemap()
Get dummy cubemap.
Definition texture_manager.h:155
const Texture * getTexture(const std::string &name) const
Get a texture by name.
bool removeTexture(const std::string &name)
Remove a registered texture.
const Cubemap * getCubemap(const std::string &name) const
Get a cubemap by name.
static void setVerticalFlipOnLoad(const bool flip)
Set if textures should be flipped upon image load.
const Cubemap * getDefaultCubemap() const
Get dummy cubemap.
Definition texture_manager.h:144
bool removeCubemap(const std::string &name)
Remove a registered cubemap.
Definition texture.h:31
Input/Output abstractions (Filesystem, Network, ...)
Definition file.h:10
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures)
Definition opengl.h:10
Settings to create a checkerboard texture.
Definition texture_manager.h:23
glm::vec3 color2
Second color of the default texture checkerboard pattern, magenta by default.
Definition texture_manager.h:32
glm::vec3 color1
First color of the default texture checkerboard pattern, black by default.
Definition texture_manager.h:27
Settings to create the texture manager.
Definition texture_manager.h:39