jubilant-funicular
ContextData.h
1 #ifndef NTA_CONTEXTDATA_H_INCLUDED
2 #define NTA_CONTEXTDATA_H_INCLUDED
3 
4 #include <map>
5 
6 #include "nta/GLSLProgram.h"
7 #include "nta/GLTexture.h"
8 #include "nta/SpriteFont.h"
9 #include "nta/Path.h"
10 
11 namespace nta {
16  // \question Should these things have a unique ID for logging purposes?
17  class ContextData {
18  private:
20  std::map<std::string, GLSLProgram> m_glslMap;
22  std::map<utils::Path, GLTexture> m_textureMap;
24  std::map<GLTexture, utils::Path> m_textureFiles;
26  std::map<std::pair<utils::Path, int>, SpriteFont> m_fontMap;
33  public:
38  GLSLProgram* getGLSLProgram(const utils::Path& progPath);
43  GLSLProgram* getGLSLProgram(crstring name, const utils::Path& vert, const utils::Path& frag);
45  Result<GLTexture> getTexture(const utils::Path& path, crvec2 dimensions = glm::vec2(0));
49  Result<SpriteFont*> getSpriteFont(const utils::Path& fontPath, int fontSize = 32);
51  void reloadShaders();
53  void reloadTextures();
57  void setTextureFolder(const utils::Path& fldr) { m_texture_folder = fldr; }
59  void setGLSLFolder(const utils::Path& fldr) { m_glsl_folder = fldr; }
61  void setFontFolder(const utils::Path& fldr) { m_font_folder = fldr; }
63  void destroy();
64  };
65 }
66 
67 #endif // NTA_CONTEXTDATA_H_INCLUDED
nta::GLSLProgram
represents a program written in GLSL comprised of a vertex shader and a fragment shader
Definition: GLSLProgram.h:14
nta::ContextData::setFontFolder
void setFontFolder(const utils::Path &fldr)
Sets the font folder.
Definition: ContextData.h:61
nta::ContextData::destroy
void destroy()
Deletes all data (does not reset folder paths)
Definition: ContextData.cpp:65
nta::ContextData::setGLSLFolder
void setGLSLFolder(const utils::Path &fldr)
Sets the shader folder.
Definition: ContextData.h:59
nta::ContextData
Definition: ContextData.h:17
utils::Path
A (case-sensitive) Path in a file system.
Definition: Path.h:16
nta::ContextData::reloadShaders
void reloadShaders()
Reloads all known shaders.
Definition: ContextData.cpp:53
nta::ContextData::m_textureMap
std::map< utils::Path, GLTexture > m_textureMap
a map file names to textures
Definition: ContextData.h:22
nta::Result
Definition: Errors.h:74
nta::ContextData::m_texture_folder
utils::Path m_texture_folder
Folder containing textures.
Definition: ContextData.h:28
nta
Definition: Animation2D.h:6
nta::ContextData::setTextureFolder
void setTextureFolder(const utils::Path &fldr)
Sets the texture folder.
Definition: ContextData.h:57
nta::ContextData::getTextureFile
Result< utils::Path > getTextureFile(GLTexture tex)
Gets the name of the file used the create tex.
Definition: ContextData.cpp:35
nta::ContextData::m_glslMap
std::map< std::string, GLSLProgram > m_glslMap
Collection of GLSLProgram.
Definition: ContextData.h:20
nta::GLTexture
represents a texture (tied to a specific GL context)
Definition: GLTexture.h:24
nta::ContextData::getTexture
Result< GLTexture > getTexture(const utils::Path &path, crvec2 dimensions=glm::vec2(0))
Gets a GLTexture representing the image at the given path.
Definition: ContextData.cpp:22
nta::ContextData::m_textureFiles
std::map< GLTexture, utils::Path > m_textureFiles
Inverse map to m_textureMap.
Definition: ContextData.h:24
nta::ContextData::getSpriteFont
Result< SpriteFont * > getSpriteFont(const utils::Path &fontPath, int fontSize=32)
Gets SpriteFont created from the given font with the given size.
Definition: ContextData.cpp:42
nta::ContextData::m_glsl_folder
utils::Path m_glsl_folder
Folder containing shaders.
Definition: ContextData.h:30
nta::ContextData::reload
void reload()
Reloads everything.
Definition: ContextData.h:55
nta::ContextData::getGLSLProgram
GLSLProgram * getGLSLProgram(const utils::Path &progPath)
Definition: ContextData.cpp:6
nta::ContextData::m_font_folder
utils::Path m_font_folder
Folder containing fonts.
Definition: ContextData.h:32
nta::SpriteFont
Loads in a .ttf file, creates a font texture from it which is then used to render text.
Definition: SpriteFont.h:55
nta::ContextData::m_fontMap
std::map< std::pair< utils::Path, int >, SpriteFont > m_fontMap
Map front (font name, font size) -> SpriteFont.
Definition: ContextData.h:26
nta::ContextData::reloadTextures
void reloadTextures()
Reloads all known texture.
Definition: ContextData.cpp:62