Selaa lähdekoodia

TextureManager is now completely static.

Thomas Buck 10 vuotta sitten
vanhempi
commit
e2f3ea30ad

+ 1
- 0
ChangeLog.md Näytä tiedosto

@@ -8,6 +8,7 @@
8 8
     * Added ShaderBuffer class.
9 9
     * Level geometry now stored in GL buffers at level load.
10 10
         * Greatly improved level load times, more FPS.
11
+    * TextureManager is now completely static.
11 12
 
12 13
     [ 20141231 ]
13 14
     * No longer using Exceptions.

+ 1
- 1
include/Render.h Näytä tiedosto

@@ -37,7 +37,7 @@ class Render {
37 37
     static void screenShot(const char* filenameBase);
38 38
 
39 39
     static void drawTexture(float x, float y, float w, float h, glm::vec4 color,
40
-                            unsigned int texture, TextureManager::TextureStorage s);
40
+                            unsigned int texture, TextureStorage s);
41 41
 
42 42
     static void setDisplayViewFrustum(bool d) { displayViewFrustum = d; }
43 43
     static bool getDisplayViewFrustum() { return displayViewFrustum; }

+ 43
- 49
include/TextureManager.h Näytä tiedosto

@@ -40,34 +40,30 @@ class TextureTile {
40 40
     std::vector<TextureTileVertex> vertices;
41 41
 };
42 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
+
43 56
 /*!
44 57
  * \brief Texture registry
45 58
  */
46 59
 class TextureManager {
47 60
   public:
61
+    static int initialize();
62
+    static int initializeSplash();
63
+    static void shutdown();
64
+    static void clear();
48 65
 
49
-    enum class ColorMode {
50
-        RGB,
51
-        RGBA,
52
-        ARGB,
53
-        BGR,
54
-        BGRA
55
-    };
56
-
57
-    enum class TextureStorage {
58
-        GAME,
59
-        SYSTEM
60
-    };
61
-
62
-    TextureManager() : nextFreeTextureUnit(0) { }
63
-    ~TextureManager();
64
-
65
-    int initialize();
66
-    int initializeSplash();
67
-
68
-    void clear();
69
-
70
-    int numTextures(TextureStorage s = TextureStorage::GAME);
66
+    static int numTextures(TextureStorage s = TextureStorage::GAME);
71 67
 
72 68
     /*!
73 69
      * \brief Bind texture to next free texture unit.
@@ -75,7 +71,7 @@ class TextureManager {
75 71
      * \param s Place where texture is stored
76 72
      * \returns ID of GL texture unit to which this texture is bound.
77 73
      */
78
-    int bindTexture(unsigned int n, TextureStorage s);
74
+    static int bindTexture(unsigned int n, TextureStorage s);
79 75
 
80 76
     /*!
81 77
      * \brief Loads Buffer as texture
@@ -89,42 +85,40 @@ class TextureManager {
89 85
      * \param filter if the texture should be mipmap filtered
90 86
      * \returns texture ID or < 0 on error
91 87
      */
92
-    int loadBufferSlot(unsigned char* image = nullptr,
93
-                       unsigned int width = 256, unsigned int height = 256,
94
-                       ColorMode mode = ColorMode::RGBA, unsigned int bpp = 32,
95
-                       TextureStorage s = TextureStorage::GAME,
96
-                       int slot = -1, bool filter = true);
88
+    static int loadBufferSlot(unsigned char* image = nullptr,
89
+                              unsigned int width = 256, unsigned int height = 256,
90
+                              ColorMode mode = ColorMode::RGBA, unsigned int bpp = 32,
91
+                              TextureStorage s = TextureStorage::GAME,
92
+                              int slot = -1, bool filter = true);
97 93
 
98
-    int loadImage(std::string filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
94
+    static int loadImage(std::string filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
99 95
 
100
-    void addTile(TextureTile* t);
101
-    int numTiles();
102
-    TextureTile& getTile(int index);
96
+    static void addTile(TextureTile* t);
97
+    static int numTiles();
98
+    static TextureTile& getTile(int index);
103 99
 
104
-    void addAnimatedTile(int index, int tile);
105
-    int numAnimatedTiles();
106
-    int getFirstTileAnimation(int index);
107
-    int getNextTileAnimation(int tile);
100
+    static void addAnimatedTile(int index, int tile);
101
+    static int numAnimatedTiles();
102
+    static int getFirstTileAnimation(int index);
103
+    static int getNextTileAnimation(int tile);
108 104
 
109 105
   private:
110
-    std::vector<unsigned int>& getIds(TextureStorage s);
111
-    std::vector<int>& getUnits(TextureStorage s);
106
+    static std::vector<unsigned int>& getIds(TextureStorage s);
107
+    static std::vector<int>& getUnits(TextureStorage s);
112 108
 
113
-    void bindTextureId(unsigned int n, TextureStorage s, unsigned int unit);
114
-    int loadPCX(std::string filename, TextureStorage s, int slot);
109
+    static void bindTextureId(unsigned int n, TextureStorage s, unsigned int unit);
110
+    static int loadPCX(std::string filename, TextureStorage s, int slot);
115 111
 
116
-    std::vector<unsigned int> mTextureIdsGame;
117
-    std::vector<unsigned int> mTextureIdsSystem;
112
+    static std::vector<unsigned int> mTextureIdsGame;
113
+    static std::vector<unsigned int> mTextureIdsSystem;
118 114
 
119
-    std::vector<TextureTile*> tiles;
120
-    std::vector<std::vector<int>> animations;
115
+    static std::vector<TextureTile*> tiles;
116
+    static std::vector<std::vector<int>> animations;
121 117
 
122
-    std::vector<int> gameUnits;
123
-    std::vector<int> systemUnits;
124
-    unsigned int nextFreeTextureUnit;
118
+    static std::vector<int> gameUnits;
119
+    static std::vector<int> systemUnits;
120
+    static unsigned int nextFreeTextureUnit;
125 121
 };
126 122
 
127
-TextureManager& getTextureManager();
128
-
129 123
 #endif
130 124
 

+ 4
- 4
include/system/Shader.h Näytä tiedosto

@@ -52,19 +52,19 @@ class Shader {
52 52
     void loadUniform(int uni, glm::vec2 vec);
53 53
     void loadUniform(int uni, glm::vec4 vec);
54 54
     void loadUniform(int uni, glm::mat4 mat);
55
-    void loadUniform(int uni, int texture, TextureManager::TextureStorage store);
55
+    void loadUniform(int uni, int texture, TextureStorage store);
56 56
 
57 57
     static int initialize();
58 58
     static void shutdown();
59 59
 
60 60
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
61
-                       TextureManager::TextureStorage store = TextureManager::TextureStorage::SYSTEM);
61
+                       TextureStorage store = TextureStorage::SYSTEM);
62 62
 
63 63
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
64
-                       TextureManager::TextureStorage store = TextureManager::TextureStorage::GAME);
64
+                       TextureStorage store = TextureStorage::GAME);
65 65
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
66 66
                        unsigned int texture, glm::mat4 MVP,
67
-                       TextureManager::TextureStorage store = TextureManager::TextureStorage::GAME);
67
+                       TextureStorage store = TextureStorage::GAME);
68 68
 
69 69
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
70 70
                        unsigned int mode = GL_TRIANGLES);

+ 1
- 1
include/utils/pcx.h Näytä tiedosto

@@ -32,7 +32,7 @@ int pcxCheck(const char* filename);
32 32
  */
33 33
 int pcxLoad(const char* filename, unsigned char** image,
34 34
             unsigned int* width, unsigned int* height,
35
-            TextureManager::ColorMode* mode, unsigned int* bpp);
35
+            ColorMode* mode, unsigned int* bpp);
36 36
 
37 37
 #endif
38 38
 

+ 1
- 1
src/Game.cpp Näytä tiedosto

@@ -77,7 +77,7 @@ void Game::destroy() {
77 77
     Camera::reset();
78 78
     Render::clearRoomList();
79 79
     SoundManager::clear();
80
-    getTextureManager().clear();
80
+    TextureManager::clear();
81 81
     getWorld().destroy();
82 82
 }
83 83
 

+ 1
- 1
src/MenuFolder.cpp Näytä tiedosto

@@ -82,7 +82,7 @@ void MenuFolder::display() {
82 82
     // Draw half-transparent overlay
83 83
     glm::vec4 color(0.0f, 0.0f, 0.0f, 0.75f);
84 84
     Render::drawTexture(0.0f, 0.0f, Window::getSize().x, Window::getSize().y,
85
-                        color, TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
85
+                        color, TEXTURE_WHITE, TextureStorage::SYSTEM);
86 86
 
87 87
     // Draw heading
88 88
     Font::drawTextCentered(0, 10, 1.2f, BLUE, Window::getSize().x, VERSION);

+ 2
- 2
src/Mesh.cpp Näytä tiedosto

@@ -58,11 +58,11 @@ void Mesh::prepare() {
58 58
 
59 59
     int vertIndex = 0;
60 60
     for (int i = 0; i < indicesBuff.size(); i++) {
61
-        unsigned int texture = getTextureManager().getTile(texturesBuff.at(i)).getTexture();
61
+        unsigned int texture = TextureManager::getTile(texturesBuff.at(i)).getTexture();
62 62
         for (int v = 0; v < ((indicesBuff.at(i) == 0) ? 4 : 3); v++) {
63 63
             ind.push_back(vert.size());
64 64
             vert.push_back(verticesBuff.at(vertIndex + v));
65
-            uvBuff.push_back(getTextureManager().getTile(texturesBuff.at(i)).getUV(v));
65
+            uvBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
66 66
             tex.push_back(texture);
67 67
         }
68 68
 

+ 2
- 2
src/Render.cpp Näytä tiedosto

@@ -53,7 +53,7 @@ void Render::display() {
53 53
     if (mode == RenderMode::LoadScreen) {
54 54
         glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f);
55 55
         drawTexture(0.0f, 0.0f, Window::getSize().x, Window::getSize().y,
56
-                    color, TEXTURE_SPLASH, TextureManager::TextureStorage::SYSTEM);
56
+                    color, TEXTURE_SPLASH, TextureStorage::SYSTEM);
57 57
         return;
58 58
     }
59 59
 
@@ -165,7 +165,7 @@ void Render::screenShot(const char* filenameBase) {
165 165
 }
166 166
 
167 167
 void Render::drawTexture(float x, float y, float w, float h, glm::vec4 color,
168
-                         unsigned int texture, TextureManager::TextureStorage s) {
168
+                         unsigned int texture, TextureStorage s) {
169 169
     std::vector<glm::vec2> vertices;
170 170
     std::vector<glm::vec2> uvs;
171 171
 

+ 2
- 2
src/RoomMesh.cpp Näytä tiedosto

@@ -38,11 +38,11 @@ void RoomMesh::prepare() {
38 38
 
39 39
     int vertIndex = 0;
40 40
     for (int i = 0; i < indicesBuff.size(); i++) {
41
-        unsigned int texture = getTextureManager().getTile(texturesBuff.at(i)).getTexture();
41
+        unsigned int texture = TextureManager::getTile(texturesBuff.at(i)).getTexture();
42 42
         for (int v = 0; v < ((indicesBuff.at(i) == 0) ? 4 : 3); v++) {
43 43
             ind.push_back(vert.size());
44 44
             vert.push_back(verticesBuff.at(vertIndex + v));
45
-            uvBuff.push_back(getTextureManager().getTile(texturesBuff.at(i)).getUV(v));
45
+            uvBuff.push_back(TextureManager::getTile(texturesBuff.at(i)).getUV(v));
46 46
             tex.push_back(texture);
47 47
         }
48 48
 

+ 119
- 111
src/TextureManager.cpp Näytä tiedosto

@@ -23,117 +23,13 @@
23 23
 #include "utils/strings.h"
24 24
 #include "TextureManager.h"
25 25
 
26
-glm::vec2 TextureTile::getUV(unsigned int i) {
27
-    glm::vec2 uv(vertices.at(i).xPixel,
28
-                 vertices.at(i).yPixel);
29
-
30
-    /*! \fixme
31
-     * This is my somewhat hacky approach to fixing
32
-     * the bad texture-bleeding problems everywhere.
33
-     * That's better, but makes the seams between
34
-     * each sector much more visible!
35
-     */
36
-
37
-    if (vertices.at(i).xCoordinate == 1) {
38
-        uv.x += 0.375f;
39
-    }
40
-
41
-    if (vertices.at(i).yCoordinate == 1) {
42
-        uv.y += 0.375f;
43
-    }
44
-
45
-    return uv / 256.0f;
46
-}
47
-
48
-// ----------------------------------------------------------------------------
49
-
50
-TextureManager::~TextureManager() {
51
-    while (mTextureIdsSystem.size() > 0) {
52
-        unsigned int id = mTextureIdsSystem.at(mTextureIdsSystem.size() - 1);
53
-        glDeleteTextures(1, &id);
54
-        mTextureIdsSystem.pop_back();
55
-    }
56
-
57
-    clear();
58
-}
59
-
60
-void TextureManager::clear() {
61
-    while (mTextureIdsGame.size() > 0) {
62
-        unsigned int id = mTextureIdsGame.at(mTextureIdsGame.size() - 1);
63
-        glDeleteTextures(1, &id);
64
-        mTextureIdsGame.pop_back();
65
-    }
66
-
67
-    while (!tiles.empty()) {
68
-        delete tiles.at(tiles.size() - 1);
69
-        tiles.pop_back();
70
-    }
71
-
72
-    animations.clear();
73
-
74
-    gameUnits.clear();
75
-    systemUnits.clear();
76
-    nextFreeTextureUnit = 0;
77
-}
78
-
79
-void TextureManager::addTile(TextureTile* t) {
80
-    tiles.push_back(t);
81
-}
82
-
83
-int TextureManager::numTiles() {
84
-    return tiles.size();
85
-}
86
-
87
-TextureTile& TextureManager::getTile(int index) {
88
-    assert(index >= 0);
89
-    assert(index < tiles.size());
90
-    return *tiles.at(index);
91
-}
92
-
93
-void TextureManager::addAnimatedTile(int index, int tile) {
94
-    while (index >= animations.size())
95
-        animations.push_back(std::vector<int>());
96
-
97
-    animations.at(index).push_back(tile);
98
-}
99
-
100
-int TextureManager::numAnimatedTiles() {
101
-    return animations.size();
102
-}
103
-
104
-int TextureManager::getFirstTileAnimation(int index) {
105
-    assert(index < animations.size());
106
-    assert(animations.at(index).size() > 0);
107
-    return animations.at(index).at(0);
108
-}
109
-
110
-int TextureManager::getNextTileAnimation(int tile) {
111
-    for (int a = 0; a < animations.size(); a++) {
112
-        for (int i = 0; i < animations.at(a).size(); i++) {
113
-            if (animations.at(a).at(i) == tile) {
114
-                if (i < (animations.at(a).size() - 1))
115
-                    return animations.at(a).at(i + 1);
116
-                else
117
-                    return animations.at(a).at(0);
118
-            }
119
-        }
120
-    }
121
-    return -1;
122
-}
123
-
124
-std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
125
-    if (s == TextureStorage::GAME)
126
-        return mTextureIdsGame;
127
-    else
128
-        return mTextureIdsSystem;
129
-}
130
-
131
-std::vector<int>& TextureManager::getUnits(TextureStorage s) {
132
-    if (s == TextureStorage::GAME)
133
-        return gameUnits;
134
-    else
135
-        return systemUnits;
136
-}
26
+std::vector<unsigned int> TextureManager::mTextureIdsGame;
27
+std::vector<unsigned int> TextureManager::mTextureIdsSystem;
28
+std::vector<TextureTile*> TextureManager::tiles;
29
+std::vector<std::vector<int>> TextureManager::animations;
30
+std::vector<int> TextureManager::gameUnits;
31
+std::vector<int> TextureManager::systemUnits;
32
+unsigned int TextureManager::nextFreeTextureUnit = 0;
137 33
 
138 34
 int TextureManager::initialize() {
139 35
     assert(mTextureIdsGame.size() == 0);
@@ -176,6 +72,35 @@ int TextureManager::initializeSplash() {
176 72
     return 0;
177 73
 }
178 74
 
75
+void TextureManager::shutdown() {
76
+    while (mTextureIdsSystem.size() > 0) {
77
+        unsigned int id = mTextureIdsSystem.at(mTextureIdsSystem.size() - 1);
78
+        glDeleteTextures(1, &id);
79
+        mTextureIdsSystem.pop_back();
80
+    }
81
+
82
+    clear();
83
+}
84
+
85
+void TextureManager::clear() {
86
+    while (mTextureIdsGame.size() > 0) {
87
+        unsigned int id = mTextureIdsGame.at(mTextureIdsGame.size() - 1);
88
+        glDeleteTextures(1, &id);
89
+        mTextureIdsGame.pop_back();
90
+    }
91
+
92
+    while (!tiles.empty()) {
93
+        delete tiles.at(tiles.size() - 1);
94
+        tiles.pop_back();
95
+    }
96
+
97
+    animations.clear();
98
+
99
+    gameUnits.clear();
100
+    systemUnits.clear();
101
+    nextFreeTextureUnit = 0;
102
+}
103
+
179 104
 int TextureManager::loadBufferSlot(unsigned char* image,
180 105
                                    unsigned int width, unsigned int height,
181 106
                                    ColorMode mode, unsigned int bpp,
@@ -272,6 +197,51 @@ int TextureManager::bindTexture(unsigned int n, TextureStorage s) {
272 197
     }
273 198
 }
274 199
 
200
+void TextureManager::addTile(TextureTile* t) {
201
+    tiles.push_back(t);
202
+}
203
+
204
+int TextureManager::numTiles() {
205
+    return tiles.size();
206
+}
207
+
208
+TextureTile& TextureManager::getTile(int index) {
209
+    assert(index >= 0);
210
+    assert(index < tiles.size());
211
+    return *tiles.at(index);
212
+}
213
+
214
+void TextureManager::addAnimatedTile(int index, int tile) {
215
+    while (index >= animations.size())
216
+        animations.push_back(std::vector<int>());
217
+
218
+    animations.at(index).push_back(tile);
219
+}
220
+
221
+int TextureManager::numAnimatedTiles() {
222
+    return animations.size();
223
+}
224
+
225
+int TextureManager::getFirstTileAnimation(int index) {
226
+    assert(index < animations.size());
227
+    assert(animations.at(index).size() > 0);
228
+    return animations.at(index).at(0);
229
+}
230
+
231
+int TextureManager::getNextTileAnimation(int tile) {
232
+    for (int a = 0; a < animations.size(); a++) {
233
+        for (int i = 0; i < animations.at(a).size(); i++) {
234
+            if (animations.at(a).at(i) == tile) {
235
+                if (i < (animations.at(a).size() - 1))
236
+                    return animations.at(a).at(i + 1);
237
+                else
238
+                    return animations.at(a).at(0);
239
+            }
240
+        }
241
+    }
242
+    return -1;
243
+}
244
+
275 245
 int TextureManager::loadImage(std::string filename, TextureStorage s, int slot) {
276 246
     if (stringEndsWith(filename, ".pcx")) {
277 247
         return loadPCX(filename, s, slot);
@@ -321,3 +291,41 @@ int TextureManager::loadPCX(std::string filename, TextureStorage s, int slot) {
321 291
     return -4;
322 292
 }
323 293
 
294
+std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
295
+    if (s == TextureStorage::GAME)
296
+        return mTextureIdsGame;
297
+    else
298
+        return mTextureIdsSystem;
299
+}
300
+
301
+std::vector<int>& TextureManager::getUnits(TextureStorage s) {
302
+    if (s == TextureStorage::GAME)
303
+        return gameUnits;
304
+    else
305
+        return systemUnits;
306
+}
307
+
308
+// ----------------------------------------------------------------------------
309
+
310
+glm::vec2 TextureTile::getUV(unsigned int i) {
311
+    glm::vec2 uv(vertices.at(i).xPixel,
312
+                 vertices.at(i).yPixel);
313
+
314
+    /*! \fixme
315
+     * This is my somewhat hacky approach to fixing
316
+     * the bad texture-bleeding problems everywhere.
317
+     * That's better, but makes the seams between
318
+     * each sector much more visible!
319
+     */
320
+
321
+    if (vertices.at(i).xCoordinate == 1) {
322
+        uv.x += 0.375f;
323
+    }
324
+
325
+    if (vertices.at(i).yCoordinate == 1) {
326
+        uv.y += 0.375f;
327
+    }
328
+
329
+    return uv / 256.0f;
330
+}
331
+

+ 27
- 31
src/UI.cpp Näytä tiedosto

@@ -92,9 +92,9 @@ int UI::initialize() {
92 92
     void* tex_data = stbi_load_from_memory((const unsigned char*)png_data,
93 93
                                            (int)png_size, &tex_x, &tex_y, &tex_comp, 0);
94 94
 
95
-    fontTex = getTextureManager().loadBufferSlot((unsigned char*)tex_data,
96
-              tex_x, tex_y, TextureManager::ColorMode::RGBA, 32,
97
-              TextureManager::TextureStorage::SYSTEM, -1, false);
95
+    fontTex = TextureManager::loadBufferSlot((unsigned char*)tex_data,
96
+                                             tex_x, tex_y, ColorMode::RGBA, 32,
97
+                                             TextureStorage::SYSTEM, -1, false);
98 98
 
99 99
     stbi_image_free(tex_data);
100 100
 
@@ -219,15 +219,13 @@ void UI::display() {
219 219
             static bool game = getGame().isLoaded();
220 220
             static int index = 0;
221 221
             ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
222
-            ImGui::SliderInt("##texslide", &index, 0, getTextureManager().numTextures(
223
-                                 game ? TextureManager::TextureStorage::GAME
224
-                                 : TextureManager::TextureStorage::SYSTEM) - 1);
222
+            ImGui::SliderInt("##texslide", &index, 0, TextureManager::.numTextures(
223
+                                 game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1);
225 224
             ImGui::PopItemWidth();
226 225
             ImGui::SameLine();
227 226
             if (ImGui::Button("+##texplus", ImVec2(0, 0), true)) {
228
-                if (index < (getTextureManager().numTextures(
229
-                                 game ? TextureManager::TextureStorage::GAME
230
-                                 : TextureManager::TextureStorage::SYSTEM) - 1))
227
+                if (index < (TextureManager::numTextures(
228
+                                 game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1))
231 229
                     index++;
232 230
                 else
233 231
                     index = 0;
@@ -237,12 +235,11 @@ void UI::display() {
237 235
                 if (index > 0)
238 236
                     index--;
239 237
                 else
240
-                    index = getTextureManager().numTextures(
241
-                                game ? TextureManager::TextureStorage::GAME
242
-                                : TextureManager::TextureStorage::SYSTEM) - 1;
238
+                    index = TextureManager::numTextures(
239
+                                game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1;
243 240
             }
244 241
             ImGui::SameLine();
245
-            if ((getTextureManager().numTextures() > 0)) {
242
+            if ((TextureManager::numTextures() > 0)) {
246 243
                 ImGui::Checkbox("Game##texgame", &game);
247 244
             } else {
248 245
                 game = false;
@@ -261,8 +258,7 @@ void UI::display() {
261 258
             }
262 259
             if (visibleTex) {
263 260
                 getRender().debugDisplayTexture(index,
264
-                                                game ? TextureManager::TextureStorage::GAME
265
-                                                : TextureManager::TextureStorage::SYSTEM,
261
+                                                game ? TextureStorage::GAME : TextureStorage::SYSTEM,
266 262
                                                 ImGui::GetWindowPos().x - ImGui::GetWindowWidth(),
267 263
                                                 ImGui::GetWindowPos().y,
268 264
                                                 ImGui::GetWindowWidth(), ImGui::GetWindowWidth());
@@ -270,14 +266,14 @@ void UI::display() {
270 266
         }
271 267
 
272 268
         if (ImGui::CollapsingHeader("Textile Viewer")) {
273
-            if (getTextureManager().numTiles() > 0) {
269
+            if (TextureManager::numTiles() > 0) {
274 270
                 static int index = 0;
275 271
                 ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
276
-                ImGui::SliderInt("##tileslide", &index, 0, getTextureManager().numTiles() - 1);
272
+                ImGui::SliderInt("##tileslide", &index, 0, TextureManager::numTiles() - 1);
277 273
                 ImGui::PopItemWidth();
278 274
                 ImGui::SameLine();
279 275
                 if (ImGui::Button("+##tileplus", ImVec2(0, 0), true)) {
280
-                    if (index < (getTextureManager().numTiles() - 1))
276
+                    if (index < (TextureManager::numTiles() - 1))
281 277
                         index++;
282 278
                     else
283 279
                         index = 0;
@@ -287,7 +283,7 @@ void UI::display() {
287 283
                     if (index > 0)
288 284
                         index--;
289 285
                     else
290
-                        index = getTextureManager().numTiles() - 1;
286
+                        index = TextureManager::numTiles() - 1;
291 287
                 }
292 288
                 ImGui::SameLine();
293 289
                 if (ImGui::Button("Show##tileshow")) {
@@ -301,8 +297,8 @@ void UI::display() {
301 297
                     getRender().debugDisplayTextile();
302 298
                     visibleTile = false;
303 299
                 }
304
-                if (visibleTile && (index < getTextureManager().numTiles())) {
305
-                    ImGui::Text(getTextureManager().getTile(index).isTriangle() ? "Triangle" : "Rectangle");
300
+                if (visibleTile && (index < TextureManager::numTiles())) {
301
+                    ImGui::Text(TextureManager::.getTile(index).isTriangle() ? "Triangle" : "Rectangle");
306 302
                 }
307 303
                 if (visibleTile) {
308 304
                     getRender().debugDisplayTextile(index,
@@ -316,29 +312,29 @@ void UI::display() {
316 312
         }
317 313
 
318 314
         if (ImGui::CollapsingHeader("Animated Textile Viewer")) {
319
-            if (getTextureManager().numAnimatedTiles() > 0) {
315
+            if (TextureManager::.numAnimatedTiles() > 0) {
320 316
                 static int index = 0;
321
-                static int tile = getTextureManager().getFirstTileAnimation(index);
317
+                static int tile = TextureManager::.getFirstTileAnimation(index);
322 318
                 ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
323
-                if (ImGui::SliderInt("##animslide", &index, 0, getTextureManager().numAnimatedTiles() - 1)) {
324
-                    tile = getTextureManager().getFirstTileAnimation(index);
319
+                if (ImGui::SliderInt("##animslide", &index, 0, TextureManager::.numAnimatedTiles() - 1)) {
320
+                    tile = TextureManager::.getFirstTileAnimation(index);
325 321
                 }
326 322
                 ImGui::PopItemWidth();
327 323
                 ImGui::SameLine();
328 324
                 if (ImGui::Button("+##animplus", ImVec2(0, 0), true)) {
329
-                    if (index < (getTextureManager().numAnimatedTiles() - 1))
325
+                    if (index < (TextureManager::.numAnimatedTiles() - 1))
330 326
                         index++;
331 327
                     else
332 328
                         index = 0;
333
-                    tile = getTextureManager().getFirstTileAnimation(index);
329
+                    tile = TextureManager::.getFirstTileAnimation(index);
334 330
                 }
335 331
                 ImGui::SameLine();
336 332
                 if (ImGui::Button("-##animminus", ImVec2(0, 0), true)) {
337 333
                     if (index > 0)
338 334
                         index--;
339 335
                     else
340
-                        index = getTextureManager().numAnimatedTiles() - 1;
341
-                    tile = getTextureManager().getFirstTileAnimation(index);
336
+                        index = TextureManager::.numAnimatedTiles() - 1;
337
+                    tile = TextureManager::.getFirstTileAnimation(index);
342 338
                 }
343 339
                 ImGui::SameLine();
344 340
                 if (ImGui::Button("Show##animshow")) {
@@ -362,7 +358,7 @@ void UI::display() {
362 358
                                                         ImGui::GetWindowPos().y,
363 359
                                                         (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
364 360
                         fr = RunTime::getFPS() / 2;
365
-                        tile = getTextureManager().getNextTileAnimation(tile);
361
+                        tile = TextureManager::.getNextTileAnimation(tile);
366 362
                     }
367 363
                     ImGui::Text("Current Tile: %d", tile);
368 364
                 }
@@ -537,7 +533,7 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
537 533
 
538 534
     imguiShader.use();
539 535
     imguiShader.loadUniform(0, Window::getSize());
540
-    imguiShader.loadUniform(1, fontTex, TextureManager::TextureStorage::SYSTEM);
536
+    imguiShader.loadUniform(1, fontTex, TextureStorage::SYSTEM);
541 537
     vert.bindBuffer(0, 2);
542 538
     uv.bindBuffer(1, 2);
543 539
     col.bindBuffer(2, 4);

+ 5
- 5
src/loader/LoaderTR2.cpp Näytä tiedosto

@@ -88,9 +88,9 @@ void LoaderTR2::loadPaletteTextiles() {
88 88
 
89 89
         // Convert 16bit textile to 32bit textile
90 90
         unsigned char* img = argb16to32(&arr[0], 256, 256);
91
-        int r = getTextureManager().loadBufferSlot(img, 256, 256,
92
-                TextureManager::ColorMode::ARGB, 32,
93
-                TextureManager::TextureStorage::GAME, i);
91
+        int r = TextureManager::loadBufferSlot(img, 256, 256,
92
+                                               ColorMode::ARGB, 32,
93
+                                               TextureStorage::GAME, i);
94 94
         assert(r >= 0); //! \fixme properly handle error when texture could not be loaded!
95 95
         delete [] img;
96 96
     }
@@ -134,7 +134,7 @@ void LoaderTR2::loadTextures() {
134 134
             t->add(TextureTileVertex(xCoordinate, xPixel, yCoordinate, yPixel));
135 135
         }
136 136
 
137
-        getTextureManager().addTile(t);
137
+        TextureManager::addTile(t);
138 138
     }
139 139
 
140 140
     if (numObjectTextures > 0)
@@ -161,7 +161,7 @@ void LoaderTR2::loadAnimatedTextures() {
161 161
         }
162 162
 
163 163
         for (int i = 0; i < count; i++) {
164
-            getTextureManager().addAnimatedTile(a, animatedTextures.at(pos + i + 1));
164
+            TextureManager::addAnimatedTile(a, animatedTextures.at(pos + i + 1));
165 165
         }
166 166
 
167 167
         pos += count + 1;

+ 2
- 8
src/main.cpp Näytä tiedosto

@@ -31,7 +31,6 @@ static std::string configFileToUse;
31 31
 static std::shared_ptr<Game> gGame;
32 32
 static std::shared_ptr<Log> gLog;
33 33
 static std::shared_ptr<MenuFolder> gMenu;
34
-static std::shared_ptr<TextureManager> gTextureManager;
35 34
 static std::shared_ptr<World> gWorld;
36 35
 
37 36
 Game& getGame() {
@@ -46,10 +45,6 @@ Menu& getMenu() {
46 45
     return *gMenu;
47 46
 }
48 47
 
49
-TextureManager& getTextureManager() {
50
-    return *gTextureManager;
51
-}
52
-
53 48
 World& getWorld() {
54 49
     return *gWorld;
55 50
 }
@@ -70,7 +65,6 @@ int main(int argc, char* argv[]) {
70 65
     gGame.reset(new Game());
71 66
     gLog.reset(new Log());
72 67
     gMenu.reset(new MenuFolder());
73
-    gTextureManager.reset(new TextureManager());
74 68
     gWorld.reset(new World());
75 69
 
76 70
     Command::fillCommandList();
@@ -91,7 +85,7 @@ int main(int argc, char* argv[]) {
91 85
     }
92 86
 
93 87
     // Initialize Texture Manager
94
-    error = getTextureManager().initialize();
88
+    error = TextureManager::initialize();
95 89
     if (error != 0) {
96 90
         std::cout << "Could not initialize TextureManager (" << error << ")!" << std::endl;
97 91
         return -3;
@@ -111,7 +105,7 @@ int main(int argc, char* argv[]) {
111 105
         Command::executeFile(configFileToUse);
112 106
     }
113 107
 
114
-    error = getTextureManager().initializeSplash();
108
+    error = TextureManager::initializeSplash();
115 109
     if (error != 0) {
116 110
         std::cout << "Coult not load Splash Texture (" << error << ")!" << std::endl;
117 111
         return -4;

+ 21
- 20
src/system/FontSDL.cpp Näytä tiedosto

@@ -37,8 +37,9 @@ int FontSDL::initialize(std::string font) {
37 37
         }
38 38
 
39 39
         // Reserve slot
40
-        mFontTexture = getTextureManager().loadBufferSlot(nullptr, 256, 256,
41
-                       TextureManager::ColorMode::RGBA, 32, TextureManager::TextureStorage::SYSTEM);
40
+        mFontTexture = TextureManager::loadBufferSlot(nullptr, 256, 256,
41
+                                                      ColorMode::RGBA, 32,
42
+                                                      TextureStorage::SYSTEM);
42 43
 
43 44
         mFontInit = true;
44 45
     }
@@ -88,25 +89,25 @@ void FontSDL::drawText(unsigned int x, unsigned int y, float scale,
88 89
     int w = (int)((float)surface->w * scale);
89 90
     int h = (int)((float)surface->h * scale);
90 91
 
91
-    TextureManager::ColorMode textureFormat;
92
+    ColorMode textureFormat;
92 93
     unsigned int bpp = 0;
93 94
     if (surface->format->BytesPerPixel == 4) {
94 95
         if (surface->format->Rmask == 0x000000FF)
95
-            textureFormat = TextureManager::ColorMode::RGBA;
96
+            textureFormat = ColorMode::RGBA;
96 97
         else
97
-            textureFormat = TextureManager::ColorMode::BGRA;
98
+            textureFormat = ColorMode::BGRA;
98 99
         bpp = 32;
99 100
     } else {
100 101
         if (surface->format->Rmask == 0x000000FF)
101
-            textureFormat = TextureManager::ColorMode::RGB;
102
+            textureFormat = ColorMode::RGB;
102 103
         else
103
-            textureFormat = TextureManager::ColorMode::BGR;
104
+            textureFormat = ColorMode::BGR;
104 105
         bpp = 24;
105 106
     }
106 107
 
107
-    getTextureManager().loadBufferSlot(static_cast<unsigned char*>(surface->pixels),
108
-                                       surface->w, surface->h, textureFormat, bpp,
109
-                                       TextureManager::TextureStorage::SYSTEM, mFontTexture);
108
+    TextureManager::loadBufferSlot(static_cast<unsigned char*>(surface->pixels),
109
+                                   surface->w, surface->h, textureFormat, bpp,
110
+                                   TextureStorage::SYSTEM, mFontTexture);
110 111
     SDL_FreeSurface(surface);
111 112
 
112 113
     std::vector<glm::vec2> vertices;
@@ -131,7 +132,7 @@ void FontSDL::drawText(unsigned int x, unsigned int y, float scale,
131 132
     vertexBuffer.bufferData(vertices);
132 133
     uvBuffer.bufferData(uvs);
133 134
     Shader::drawGL(vertexBuffer, uvBuffer, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f),
134
-                   mFontTexture, TextureManager::TextureStorage::SYSTEM);
135
+                   mFontTexture, TextureStorage::SYSTEM);
135 136
 }
136 137
 
137 138
 unsigned int FontSDL::heightText(float scale, unsigned int maxWidth, std::string s) {
@@ -173,25 +174,25 @@ void FontSDL::drawTextWrapped(unsigned int x, unsigned int y, float scale,
173 174
     int w = (int)((float)surface->w * scale);
174 175
     int h = (int)((float)surface->h * scale);
175 176
 
176
-    TextureManager::ColorMode textureFormat;
177
+    ColorMode textureFormat;
177 178
     unsigned int bpp = 0;
178 179
     if (surface->format->BytesPerPixel == 4) {
179 180
         if (surface->format->Rmask == 0x000000FF)
180
-            textureFormat = TextureManager::ColorMode::RGBA;
181
+            textureFormat = ColorMode::RGBA;
181 182
         else
182
-            textureFormat = TextureManager::ColorMode::BGRA;
183
+            textureFormat = ColorMode::BGRA;
183 184
         bpp = 32;
184 185
     } else {
185 186
         if (surface->format->Rmask == 0x000000FF)
186
-            textureFormat = TextureManager::ColorMode::RGB;
187
+            textureFormat = ColorMode::RGB;
187 188
         else
188
-            textureFormat = TextureManager::ColorMode::BGR;
189
+            textureFormat = ColorMode::BGR;
189 190
         bpp = 24;
190 191
     }
191 192
 
192
-    getTextureManager().loadBufferSlot(static_cast<unsigned char*>(surface->pixels),
193
-                                       surface->w, surface->h, textureFormat, bpp,
194
-                                       TextureManager::TextureStorage::SYSTEM, mFontTexture);
193
+    TextureManager::loadBufferSlot(static_cast<unsigned char*>(surface->pixels),
194
+                                   surface->w, surface->h, textureFormat, bpp,
195
+                                   TextureStorage::SYSTEM, mFontTexture);
195 196
     SDL_FreeSurface(surface);
196 197
 
197 198
     std::vector<glm::vec2> vertices;
@@ -216,6 +217,6 @@ void FontSDL::drawTextWrapped(unsigned int x, unsigned int y, float scale,
216 217
     vertexBuffer.bufferData(vertices);
217 218
     uvBuffer.bufferData(uvs);
218 219
     Shader::drawGL(vertexBuffer, uvBuffer, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f),
219
-                   mFontTexture, TextureManager::TextureStorage::SYSTEM);
220
+                   mFontTexture, TextureStorage::SYSTEM);
220 221
 }
221 222
 

+ 3
- 2
src/system/FontTRLE.cpp Näytä tiedosto

@@ -48,8 +48,9 @@ int FontTRLE::initialize(std::string font) {
48 48
         pixels[i] = pixels[i + 1] = pixels[i + 2] = (unsigned char)y;
49 49
     }
50 50
 
51
-    mFontTexture = getTextureManager().loadBufferSlot(pixels, 256, 256,
52
-                   TextureManager::ColorMode::BGRA, 32, TextureManager::TextureStorage::SYSTEM);
51
+    mFontTexture = TextureManager::loadBufferSlot(pixels, 256, 256,
52
+                                                  ColorMode::BGRA, 32,
53
+                                                  TextureStorage::SYSTEM);
53 54
     delete [] pixels;
54 55
 
55 56
     // Try to load .lps file or use default glyph positions

+ 5
- 6
src/system/Shader.cpp Näytä tiedosto

@@ -7,7 +7,6 @@
7 7
 
8 8
 #include "global.h"
9 9
 #include "Log.h"
10
-#include "TextureManager.h"
11 10
 #include "system/Window.h"
12 11
 #include "system/Shader.h"
13 12
 
@@ -88,8 +87,8 @@ void Shader::loadUniform(int uni, glm::mat4 mat) {
88 87
     glUniformMatrix4fv(getUniform(uni), 1, GL_FALSE, &mat[0][0]);
89 88
 }
90 89
 
91
-void Shader::loadUniform(int uni, int texture, TextureManager::TextureStorage store) {
92
-    glUniform1i(getUniform(uni), getTextureManager().bindTexture(texture, store));
90
+void Shader::loadUniform(int uni, int texture, TextureStorage store) {
91
+    glUniform1i(getUniform(uni), TextureManager::bindTexture(texture, store));
93 92
 }
94 93
 
95 94
 void Shader::use() {
@@ -231,7 +230,7 @@ void Shader::shutdown() {
231 230
 }
232 231
 
233 232
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
234
-                    unsigned int texture, TextureManager::TextureStorage store) {
233
+                    unsigned int texture, TextureStorage store) {
235 234
     assert(vertices.getSize() == uvs.getSize());
236 235
     assert((vertices.getSize() % 3) == 0);
237 236
 
@@ -251,7 +250,7 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
251 250
 }
252 251
 
253 252
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture,
254
-                    glm::mat4 MVP, TextureManager::TextureStorage store) {
253
+                    glm::mat4 MVP, TextureStorage store) {
255 254
     assert(vertices.getSize() == uvs.getSize());
256 255
     assert((vertices.getSize() % 3) == 0);
257 256
 
@@ -266,7 +265,7 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int text
266 265
 }
267 266
 
268 267
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, ShaderBuffer& indices,
269
-                    unsigned int texture, glm::mat4 MVP, TextureManager::TextureStorage store) {
268
+                    unsigned int texture, glm::mat4 MVP, TextureStorage store) {
270 269
     assert(vertices.getSize() == uvs.getSize());
271 270
     assert((indices.getSize() % 3) == 0);
272 271
 

+ 2
- 2
src/utils/pcx.cpp Näytä tiedosto

@@ -67,7 +67,7 @@ int pcxCheck(const char* filename) {
67 67
 
68 68
 int pcxLoad(const char* filename, unsigned char** image,
69 69
             unsigned int* width, unsigned int* height,
70
-            TextureManager::ColorMode* mode, unsigned int* bpp) {
70
+            ColorMode* mode, unsigned int* bpp) {
71 71
     assert(filename != nullptr);
72 72
     assert(filename[0] != '\0');
73 73
     assert(image != nullptr);
@@ -242,7 +242,7 @@ int pcxLoad(const char* filename, unsigned char** image,
242 242
         }
243 243
     }
244 244
 
245
-    *mode = TextureManager::ColorMode::RGBA;
245
+    *mode = ColorMode::RGBA;
246 246
     *bpp = 32;
247 247
 
248 248
     delete [] buffer;

Loading…
Peruuta
Tallenna