OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
TextureManager.h
Go to the documentation of this file.
1 
9 #ifndef _TEXTURE_MANAGER_H
10 #define _TEXTURE_MANAGER_H
11 
12 #include <array>
13 #include <tuple>
14 #include <vector>
15 
16 // These are loaded into TextureStorage::SYSTEM by initialize()!
17 #define TEXTURE_WHITE 0
18 #define TEXTURE_SPLASH 1
19 
21  public:
22  TextureTileVertex(int xc, int xp, int yc, int yp)
23  : xCoordinate(xc), xPixel(xp), yCoordinate(yc), yPixel(yp) { }
24 
27 };
28 
29 class TextureTile {
30  public:
31  TextureTile(unsigned int a, unsigned int t) : attribute(a), texture(t) { }
32  void add(TextureTileVertex t) { vertices.push_back(t); }
33 
34  unsigned int getTexture() { return texture; }
35  glm::vec2 getUV(unsigned int i);
36 
37  private:
38  unsigned int attribute;
39  unsigned int texture;
40  std::vector<TextureTileVertex> vertices;
41 };
42 
43 enum class ColorMode {
44  RGB,
45  RGBA,
46  ARGB,
47  BGR,
48  BGRA
49 };
50 
51 enum class TextureStorage {
52  GAME,
53  SYSTEM
54 };
55 
57  public:
59  int getTextureID() { return texture; }
61 
62  private:
63  int texture;
65 };
66 
68  public:
69  static int initialize();
70  static int initializeSplash();
71  static void shutdown();
72  static void clear();
73  static void prepare();
74 
76 
83  static int bindTexture(unsigned int n, TextureStorage s);
84 
97  static int loadBufferSlot(unsigned char* image = nullptr,
98  unsigned int width = 256, unsigned int height = 256,
99  ColorMode mode = ColorMode::RGBA, unsigned int bpp = 32,
101  int slot = -1, bool filter = true);
102 
103  static int loadImage(std::string filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
104 
105  static void addTile(TextureTile* t);
106  static int numTiles();
107  static TextureTile& getTile(int index);
108 
109  static void addAnimatedTile(int index, int tile);
110  static int numAnimatedTiles();
111  static int getFirstTileAnimation(int index);
112  static int getNextTileAnimation(int index, int tile);
113 
114  static BufferManager* getBufferManager(int tex, TextureStorage store);
115 
116  static void display();
117 
118  static unsigned int getTextureID(int n, TextureStorage s);
119 
120  static void setPalette(int index, glm::vec4 color);
121  static glm::vec4 getPalette(int index);
122 
123  static void addIndexedTexture(unsigned char* image, unsigned int width, unsigned int height);
124 
125  private:
126  static std::vector<unsigned int>& getIds(TextureStorage s);
127  static std::vector<int>& getUnits(TextureStorage s);
128 
129  static void bindTextureId(unsigned int n, TextureStorage s, unsigned int unit);
130  static int loadPCX(std::string filename, TextureStorage s, int slot);
131 
132  static std::vector<unsigned int> mTextureIdsGame;
133  static std::vector<unsigned int> mTextureIdsSystem;
134 
135  static std::vector<TextureTile*> tiles;
136  static std::vector<std::vector<int>> animations;
137 
138  static std::vector<int> gameUnits;
139  static std::vector<int> systemUnits;
140  static unsigned int nextFreeTextureUnit;
141 
142  static std::vector<BufferManager> gameBuffers;
143  static std::vector<BufferManager> systemBuffers;
144 
145  static std::array<glm::vec4, 256> colorPalette;
146  static std::vector<std::tuple<unsigned char*, unsigned int, unsigned int>> indexedTextures;
147 };
148 
149 #endif
150 
static std::vector< unsigned int > mTextureIdsSystem
static int initializeSplash()
static std::vector< unsigned int > mTextureIdsGame
BufferManager(int t, TextureStorage s)
static int numAnimatedTiles()
std::vector< TextureTileVertex > vertices
static std::vector< std::vector< int > > animations
static void addAnimatedTile(int index, int tile)
static void display()
static TextureTile & getTile(int index)
static std::vector< TextureTile * > tiles
static void addTile(TextureTile *t)
TextureTileVertex(int xc, int xp, int yc, int yp)
static std::vector< BufferManager > systemBuffers
static std::vector< int > gameUnits
TextureTile(unsigned int a, unsigned int t)
static std::array< glm::vec4, 256 > colorPalette
static int loadImage(std::string filename, TextureStorage s=TextureStorage::GAME, int slot=-1)
static int getFirstTileAnimation(int index)
static std::vector< unsigned int > & getIds(TextureStorage s)
static int numTextures(TextureStorage s=TextureStorage::GAME)
static void addIndexedTexture(unsigned char *image, unsigned int width, unsigned int height)
static int bindTexture(unsigned int n, TextureStorage s)
Bind texture to next free texture unit.
TextureStorage getTextureStorage()
unsigned int getTexture()
static unsigned int getTextureID(int n, TextureStorage s)
static void prepare()
static BufferManager * getBufferManager(int tex, TextureStorage store)
static unsigned int nextFreeTextureUnit
static std::vector< int > systemUnits
static int numTiles()
static std::vector< int > & getUnits(TextureStorage s)
TextureStorage
static void shutdown()
void add(TextureTileVertex t)
glm::vec2 getUV(unsigned int i)
static void clear()
static void setPalette(int index, glm::vec4 color)
static int loadPCX(std::string filename, TextureStorage s, int slot)
TextureStorage storage
static glm::vec4 getPalette(int index)
static int getNextTileAnimation(int index, int tile)
static std::vector< BufferManager > gameBuffers
static int loadBufferSlot(unsigned char *image=nullptr, unsigned int width=256, unsigned int height=256, ColorMode mode=ColorMode::RGBA, unsigned int bpp=32, TextureStorage s=TextureStorage::GAME, int slot=-1, bool filter=true)
Loads Buffer as texture.
ColorMode
static std::vector< std::tuple< unsigned char *, unsigned int, unsigned int > > indexedTextures
unsigned int texture
static int initialize()
unsigned int attribute
static void bindTextureId(unsigned int n, TextureStorage s, unsigned int unit)