Browse Source

TextureManager now has independent storages

Thomas Buck 9 years ago
parent
commit
60c217d16a
13 changed files with 118 additions and 380 deletions
  1. 3
    0
      ChangeLog.md
  2. 0
    6
      include/Game.h
  3. 20
    52
      include/TextureManager.h
  4. 2
    57
      include/TombRaider.h
  5. 5
    20
      src/Game.cpp
  6. 15
    14
      src/Mesh.cpp
  7. 1
    7
      src/Render.cpp
  8. 2
    16
      src/Room.cpp
  9. 3
    4
      src/Sprite.cpp
  10. 9
    13
      src/StaticMesh.cpp
  11. 46
    90
      src/TextureManager.cpp
  12. 10
    99
      src/TombRaider.cpp
  13. 2
    2
      src/UI.cpp

+ 3
- 0
ChangeLog.md View File

@@ -2,6 +2,9 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20141122 ]
6
+    * TextureManager now knows the difference between level and system textures.
7
+
5 8
     [ 20141116 ]
6 9
     * Fixed background color of wireframe mode
7 10
 

+ 0
- 6
include/Game.h View File

@@ -32,9 +32,6 @@ class Game {
32 32
     void handleAction(ActionEvents action, bool isFinished);
33 33
     void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
34 34
 
35
-    unsigned int getTextureStart();
36
-    unsigned int getTextureOffset();
37
-
38 35
     Entity& getLara();
39 36
 
40 37
   private:
@@ -52,9 +49,6 @@ class Game {
52 49
 
53 50
     TombRaider mTombRaider;
54 51
 
55
-    unsigned int mTextureStart;
56
-    unsigned int mTextureOffset;
57
-
58 52
     long mLara;
59 53
 };
60 54
 

+ 20
- 52
include/TextureManager.h View File

@@ -11,59 +11,31 @@
11 11
 
12 12
 #include <vector>
13 13
 
14
+// These are loaded into TextureStorage::SYSTEM by initialize()!
15
+#define TEXTURE_WHITE 0
16
+#define TEXTURE_SPLASH 1
17
+
14 18
 /*!
15 19
  * \brief Texture registry
16 20
  */
17 21
 class TextureManager {
18 22
   public:
19 23
 
20
-    enum TextureFlag {
21
-        fUseMultiTexture = (1 << 0),
24
+    enum class TextureStorage {
25
+        GAME,
26
+        SYSTEM
22 27
     };
23 28
 
24
-    /*!
25
-    * \brief Constructs an object of Texture
26
-    */
27
-    TextureManager();
28
-
29
-    /*!
30
-     * \brief Deconstructs an object of Texture
31
-     */
32 29
     ~TextureManager();
33 30
 
34
-    /*!
35
-     * \brief Resets all texture data
36
-     */
37
-    void reset();
38
-
39 31
     int initialize();
40 32
 
41 33
     /*!
42
-     * \brief Get number of textures in use
43
-     * \returns used texture count, or -1 on error (uninitialized)
44
-     */
45
-    int getTextureCount();
46
-
47
-    /*!
48
-     * \brief Sets up multitexture rendering with passed ids
49
-     * \param texture0 first texture for multitexture
50
-     * \param texture1 second texture for multitexture
51
-     */
52
-    void bindMultiTexture(int texture0, int texture1);
53
-
54
-    /*!
55 34
      * \brief Binds the texture for use in GL
56 35
      * \param n valid texture index
36
+     * \param s Which TextureStorage should be accessed
57 37
      */
58
-    void bindTextureId(unsigned int n);
59
-
60
-    /*!
61
-     * \brief Clears an option flag
62
-     * \param flag flag to clear
63
-     */
64
-    void clearFlag(TextureFlag flag);
65
-
66
-    void disableMultiTexture();
38
+    void bindTextureId(unsigned int n, TextureStorage s = TextureStorage::GAME);
67 39
 
68 40
     /*!
69 41
      * \brief Loads Buffer as texture
@@ -72,6 +44,7 @@ class TextureManager {
72 44
      * \param height height of image
73 45
      * \param mode mode of image
74 46
      * \param bpp bits per pixel of image
47
+     * \param s Which TextureStorage should be accessed
75 48
      * \param slot slot (ID) of image
76 49
      * \param filter if the texture should be mipmap filtered
77 50
      * \returns texture ID or < 0 on error
@@ -79,25 +52,20 @@ class TextureManager {
79 52
     int loadBufferSlot(unsigned char* image,
80 53
                        unsigned int width, unsigned int height,
81 54
                        ColorMode mode, unsigned int bpp,
82
-                       unsigned int slot, bool filter = true);
55
+                       TextureStorage s = TextureStorage::GAME,
56
+                       int slot = -1, bool filter = true);
83 57
 
84
-    int loadImage(const char* filename);
85
-
86
-    /*!
87
-     * \brief Sets an option flag
88
-     * \param flag flag to set
89
-     */
90
-    void setFlag(TextureFlag flag);
91
-
92
-    void useMultiTexture(float aU, float aV, float bU, float bV);
58
+    int loadImage(const char* filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
93 59
 
94 60
   private:
95
-    int loadTGA(const char* filename);
96
-    int loadPCX(const char* filename);
97
-    int loadPNG(const char* filename);
61
+    std::vector<unsigned int>& getIds(TextureStorage s);
62
+
63
+    int loadTGA(const char* filename, TextureStorage s, int slot);
64
+    int loadPCX(const char* filename, TextureStorage s, int slot);
65
+    int loadPNG(const char* filename, TextureStorage s, int slot);
98 66
 
99
-    std::vector<unsigned int> mTextureIds;
100
-    unsigned int mFlags;
67
+    std::vector<unsigned int> mTextureIdsGame;
68
+    std::vector<unsigned int> mTextureIdsSystem;
101 69
 };
102 70
 
103 71
 TextureManager& getTextureManager();

+ 2
- 57
include/TombRaider.h View File

@@ -52,8 +52,6 @@ class TombRaider {
52 52
 
53 53
     int NumStaticMeshes();
54 54
 
55
-    int NumSprites();
56
-
57 55
     int NumSpriteSequences();
58 56
 
59 57
     int NumItems();
@@ -66,14 +64,6 @@ class TombRaider {
66 64
 
67 65
     tr2_item_t* Item();
68 66
 
69
-    tr2_object_texture_t* ObjectTextures();
70
-
71
-    /*!
72
-     * \brief Get number of boxes
73
-     * \returns number of boxes
74
-     */
75
-    unsigned int getNumBoxes();
76
-
77 67
     tr2_box_t* Box();
78 68
 
79 69
     tr2_mesh_t* Mesh();
@@ -100,13 +90,6 @@ class TombRaider {
100 90
     tr2_sprite_sequence_t* SpriteSequence();
101 91
 
102 92
     /*!
103
-     * \brief Makes a 32bit RGBA image from a stexture/bmap
104
-     * \param texture valid index into tex_special list
105
-     * \returns 32bit RGBA image or NULL on error
106
-     */
107
-    unsigned char* SpecialTexTile(int texture);
108
-
109
-    /*!
110 93
      * \brief Get copies of texture and it's bumpmap
111 94
      * \param texture valid textile index
112 95
      * \param image will be set to texture if found, or NULL
@@ -114,20 +97,12 @@ class TombRaider {
114 97
      */
115 98
     void Texture(int texture, unsigned char** image, unsigned char** bumpmap);
116 99
 
117
-    unsigned int* Palette16();
118
-
119
-    unsigned char* Palette8();
100
+    //unsigned int* Palette16();
101
+    //unsigned char* Palette8();
120 102
 
121 103
     tr2_room_t* Room();
122 104
 
123 105
     /*!
124
-     * \brief Check if a file is a TombRaider pak
125
-     * \param filename file to check
126
-     * \returns 0 if it is a TombRaider pak
127
-     */
128
-    static int checkMime(const char* filename);
129
-
130
-    /*!
131 106
      * \brief Loads TombRaider 1-5 pak into memory
132 107
      * and does some processing.
133 108
      * \param filename points to valid TombRaider pak
@@ -137,14 +112,6 @@ class TombRaider {
137 112
     int Load(const char* filename);
138 113
 
139 114
     /*!
140
-     * \brief Makes a clamped 0.0 to 1.0 texel from coord pair
141
-     * \param texel texel value, is modified, divided by 255.0 and returned
142
-     * \param offset if offset is negative, texel is decreased by one, else increased
143
-     * \returns modified texel divided by 255.0
144
-     */
145
-    float adjustTexel(unsigned char texel, char offset);
146
-
147
-    /*!
148 115
      * \brief Compute rotation angles from moveable animation data
149 116
      * \param frame moveable animation data
150 117
      * \param frame_offset moveable animation data
@@ -166,12 +133,6 @@ class TombRaider {
166 133
      */
167 134
     void computeUV(tr2_object_texture_vert_t* st, float* u, float* v);
168 135
 
169
-    /*!
170
-     * \brief Get number of bump maps in loaded pak
171
-     * \returns number of bump maps
172
-     */
173
-    int getBumpMapCount();
174
-
175 136
     void getColor(int index, float color[4]);
176 137
 
177 138
     tr2_version_type getEngine();
@@ -550,8 +511,6 @@ class TombRaider {
550 511
      */
551 512
     int getSkyModelId();
552 513
 
553
-    void getSprites();
554
-
555 514
     /*!
556 515
      * \brief Get a copy of a sound sample and its byte size
557 516
      * \param index sound sample index
@@ -590,20 +549,6 @@ class TombRaider {
590 549
 
591 550
     void reset();
592 551
 
593
-    void setDebug(bool toggle);
594
-
595
-    /*!
596
-     * \brief Sets lighting factor for each vertex color per room in TR3 paks
597
-     * \param f new lighting factor
598
-     */
599
-    void setRoomVertexLightingFactor(float f);
600
-
601
-    /*!
602
-     * \brief Set scaling for sprite texel alignment, etc.
603
-     * \param f new scaling factor
604
-     */
605
-    void setTexelScalingFactor(float f);
606
-
607 552
   private:
608 553
 
609 554
     void extractMeshes(unsigned char* mesh_data,

+ 5
- 20
src/Game.cpp View File

@@ -31,27 +31,15 @@ std::map<int, int> gMapTex2Bump;
31 31
 Game::Game() {
32 32
     mLoaded = false;
33 33
     mLara = -1;
34
-    mTextureStart = 0;
35
-    mTextureOffset = 0;
36 34
 }
37 35
 
38 36
 Game::~Game() {
39 37
 }
40 38
 
41
-unsigned int Game::getTextureStart() {
42
-    return mTextureStart;
43
-}
44
-
45
-unsigned int Game::getTextureOffset() {
46
-    return mTextureOffset;
47
-}
48
-
49 39
 int Game::initialize() {
50 40
     // Enable Renderer
51 41
     getRender().setMode(Render::modeLoadScreen);
52 42
 
53
-    mTextureStart = getTextureManager().getTextureCount();
54
-
55 43
     return 0;
56 44
 }
57 45
 
@@ -270,20 +258,19 @@ void Game::processTextures() {
270 258
 
271 259
         // Overwrite any previous level textures on load
272 260
         getTextureManager().loadBufferSlot(image, 256, 256,
273
-                                           RGBA, 32, (mTextureStart - 1) + i);
261
+                                           RGBA, 32, TextureManager::TextureStorage::GAME, i);
274 262
 
275 263
 #ifdef MULTITEXTURE
276
-        gMapTex2Bump[(mTextureStart - 1) + i] = -1;
264
+        gMapTex2Bump[i] = -1;
277 265
 #endif
278 266
 
279 267
         if (bumpmap) {
280 268
 #ifdef MULTITEXTURE
281
-            gMapTex2Bump[(mTextureStart - 1) + i] = (mTextureStart - 1) + i +
282
-                                                    mTombRaider.NumTextures();
269
+            gMapTex2Bump[i] = i + mTombRaider.NumTextures();
283 270
 #endif
284 271
             getTextureManager().loadBufferSlot(bumpmap, 256, 256,
285
-                                               RGBA, 32,
286
-                                               (mTextureStart - 1) + i + mTombRaider.NumTextures());
272
+                                               RGBA, 32, TextureManager::TextureStorage::GAME,
273
+                                               i + mTombRaider.NumTextures());
287 274
         }
288 275
 
289 276
         if (image)
@@ -293,8 +280,6 @@ void Game::processTextures() {
293 280
             delete [] bumpmap;
294 281
     }
295 282
 
296
-    mTextureOffset = (mTextureStart - 1) + mTombRaider.NumTextures();
297
-
298 283
     getLog() << "Found " << mTombRaider.NumTextures() << " textures." << Log::endl;
299 284
 }
300 285
 

+ 15
- 14
src/Mesh.cpp View File

@@ -8,6 +8,7 @@
8 8
 #include <stdlib.h>
9 9
 
10 10
 #include "global.h"
11
+#include "TextureManager.h"
11 12
 #include "Mesh.h"
12 13
 
13 14
 
@@ -122,16 +123,16 @@ void Mesh::drawAlpha() {
122 123
         switch (mMode) {
123 124
             case MeshModeWireframe:
124 125
                 glColor3f(0.0, 0.0, 1.0);
125
-                glBindTexture(GL_TEXTURE_2D, 0);
126
+                getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
126 127
                 break;
127 128
             case MeshModeSolid:
128 129
                 // Bind WHITE texture for solid colors
129
-                glBindTexture(GL_TEXTURE_2D, 0);
130
+                getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
130 131
                 break;
131 132
             case MeshModeTexture:
132 133
             case MeshModeMultiTexture:
133 134
                 // Bind texture id for textures
134
-                glBindTexture(GL_TEXTURE_2D, mQuads[i].texture + 1);
135
+                getTextureManager().bindTextureId(mQuads[i].texture);
135 136
                 break;
136 137
         }
137 138
 
@@ -155,16 +156,16 @@ void Mesh::drawAlpha() {
155 156
         switch (mMode) {
156 157
             case MeshModeWireframe:
157 158
                 glColor3f(0.0, 1.0, 0.0);
158
-                glBindTexture(GL_TEXTURE_2D, 0);
159
+                getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
159 160
                 break;
160 161
             case MeshModeSolid:
161 162
                 // Bind WHITE texture for solid colors
162
-                glBindTexture(GL_TEXTURE_2D, 0);
163
+                getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
163 164
                 break;
164 165
             case MeshModeTexture:
165 166
             case MeshModeMultiTexture:
166 167
                 // Bind texture id for textures
167
-                glBindTexture(GL_TEXTURE_2D, mTris[i].texture + 1);
168
+                getTextureManager().bindTextureId(mTris[i].texture);
168 169
                 break;
169 170
         }
170 171
 
@@ -231,17 +232,17 @@ void Mesh::drawSolid() {
231 232
                 break;
232 233
             case MeshModeWireframe:
233 234
                 // Bind WHITE texture for solid colors
234
-                glBindTexture(GL_TEXTURE_2D, 0);
235
+                getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
235 236
                 break;
236 237
 #ifdef MULTITEXTURE
237 238
             case MeshModeMultiTexture:
238 239
                 glActiveTextureARB(GL_TEXTURE0_ARB);
239 240
                 glEnable(GL_TEXTURE_2D);
240
-                glBindTexture(GL_TEXTURE_2D, mQuads[i].texture + 1);
241
+                getTextureManager().bindTextureId(mQuads[i].texture);
241 242
 
242 243
                 glActiveTextureARB(GL_TEXTURE1_ARB);
243 244
                 glEnable(GL_TEXTURE_2D);
244
-                glBindTexture(GL_TEXTURE_2D, mQuads[i].bumpmap + 1);
245
+                getTextureManager().bindTextureId(mQuads[i].bumpmap);
245 246
                 break;
246 247
 #else
247 248
             case MeshModeMultiTexture:
@@ -249,7 +250,7 @@ void Mesh::drawSolid() {
249 250
             case MeshModeTexture:
250 251
                 // Bind texture id for textures
251 252
                 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
252
-                glBindTexture(GL_TEXTURE_2D, mQuads[i].texture + 1);
253
+                getTextureManager().bindTextureId(mQuads[i].texture);
253 254
                 break;
254 255
         }
255 256
 
@@ -286,17 +287,17 @@ void Mesh::drawSolid() {
286 287
                 break;
287 288
             case MeshModeWireframe:
288 289
                 // Bind WHITE texture for solid colors
289
-                glBindTexture(GL_TEXTURE_2D, 0);
290
+                getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
290 291
                 break;
291 292
 #ifdef MULTITEXTURE
292 293
             case MeshModeMultiTexture:
293 294
                 glActiveTextureARB(GL_TEXTURE0_ARB);
294 295
                 glEnable(GL_TEXTURE_2D);
295
-                glBindTexture(GL_TEXTURE_2D, mTris[i].texture + 1);
296
+                getTextureManager().bindTextureId(mTris[i].texture);
296 297
 
297 298
                 glActiveTextureARB(GL_TEXTURE1_ARB);
298 299
                 glEnable(GL_TEXTURE_2D);
299
-                glBindTexture(GL_TEXTURE_2D, mTris[i].bumpmap + 1);
300
+                getTextureManager().bindTextureId(mTris[i].bumpmap);
300 301
                 break;
301 302
 #else
302 303
             case MeshModeMultiTexture:
@@ -304,7 +305,7 @@ void Mesh::drawSolid() {
304 305
             case MeshModeTexture:
305 306
                 // Bind texture id for textures
306 307
                 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
307
-                glBindTexture(GL_TEXTURE_2D, mTris[i].texture + 1);
308
+                getTextureManager().bindTextureId(mTris[i].texture);
308 309
                 break;
309 310
         }
310 311
 

+ 1
- 7
src/Render.cpp View File

@@ -339,9 +339,6 @@ void Render::drawLoadScreen() {
339 339
     float x = 0.0f, y = 0.0f, z = 0.0f;
340 340
     float w = getWindow().getWidth(), h = getWindow().getHeight();
341 341
 
342
-    if (getTextureManager().getTextureCount() <= 0)
343
-        return;
344
-
345 342
     // Mongoose 2002.01.01, Rendered while game is loading...
346 343
     //! \fixme seperate logo/particle coor later
347 344
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -356,10 +353,7 @@ void Render::drawLoadScreen() {
356 353
     glTranslatef(0.0f, 0.0f, -2000.0f);
357 354
     glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
358 355
 
359
-    if (getTextureManager().getTextureCount() < 2)
360
-        getTextureManager().bindTextureId(0); //! \fixme store texture id somewhere
361
-    else
362
-        getTextureManager().bindTextureId(1);
356
+    getTextureManager().bindTextureId(TEXTURE_SPLASH, TextureManager::TextureStorage::SYSTEM);
363 357
 
364 358
     glBegin(GL_TRIANGLE_STRIP);
365 359
     glTexCoord2f(1.0, 1.0);

+ 2
- 16
src/Room.cpp View File

@@ -104,9 +104,7 @@ Room::Room(TombRaider& tr, unsigned int index) {
104 104
     mesh.bufferNormalArray(normalCount, normalArray);
105 105
     mesh.bufferColorArray(vertexCount, colorArray);
106 106
 
107
-    tr.getRoomTriangles(index, getGame().getTextureStart(),
108
-                        &triCount, &indices, &texCoords, &textures,
109
-                        &fflags);
107
+    tr.getRoomTriangles(index, 0, &triCount, &indices, &texCoords, &textures, &fflags);
110 108
 
111 109
     mesh.bufferTriangles(triCount, indices, texCoords, textures, fflags);
112 110
 #else
@@ -161,8 +159,6 @@ Room::Room(TombRaider& tr, unsigned int index) {
161 159
         tr.getRoomTriangle(index, t,
162 160
                            indices, texCoords, &texture, &flags);
163 161
 
164
-        texture += getGame().getTextureStart();
165
-
166 162
         if (texture > (int)TextureLimit) {
167 163
             getLog() << "Handling bad room[" << index << "].tris["
168 164
                      << t << "].texture = " << texture << Log::endl;
@@ -189,8 +185,6 @@ Room::Room(TombRaider& tr, unsigned int index) {
189 185
         tr.getRoomRectangle(index, r,
190 186
                             indices, texCoords, &texture, &flags);
191 187
 
192
-        texture += getGame().getTextureStart();
193
-
194 188
         if (texture > (int)TextureLimit) {
195 189
             getLog() << "Handling bad room[" << index << "].quad["
196 190
                      << r << "].texture = " << texture << Log::endl;
@@ -302,10 +296,6 @@ Room::Room(TombRaider& tr, unsigned int index) {
302 296
         tr.getRoomTriangle(index, t,
303 297
                            indices, texCoords, &texture, &flags);
304 298
 
305
-        // Adjust texture id using getGame().getTextureStart() to map into
306
-        // correct textures
307
-        texture += getGame().getTextureStart();
308
-
309 299
         unsigned int j = tris_mesh_map[texture] - 1;
310 300
 
311 301
         // Setup per vertex
@@ -352,10 +342,6 @@ Room::Room(TombRaider& tr, unsigned int index) {
352 342
         tr.getRoomRectangle(index, r,
353 343
                             indices, texCoords, &texture, &flags);
354 344
 
355
-        // Adjust texture id using getGame().getTextureStart() to map into
356
-        // correct textures
357
-        texture += getGame().getTextureStart();
358
-
359 345
         if (texture > (int)TextureLimit) {
360 346
             texture = TextureLimit - 1;
361 347
         }
@@ -424,7 +410,7 @@ void Room::display(bool alpha) {
424 410
     glPushMatrix();
425 411
     //LightingSetup();
426 412
 
427
-    getTextureManager().bindTextureId(0); // \fixme WHITE texture
413
+    getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
428 414
 
429 415
     if ((!alpha) && getRender().getMode() == Render::modeWireframe) {
430 416
         glLineWidth(2.0);

+ 3
- 4
src/Sprite.cpp View File

@@ -9,6 +9,7 @@
9 9
 #include "Camera.h"
10 10
 #include "Game.h"
11 11
 #include "Render.h"
12
+#include "TextureManager.h"
12 13
 #include "Sprite.h"
13 14
 
14 15
 SpriteSequence::SpriteSequence(TombRaider& tr, unsigned int item, unsigned int sequence) {
@@ -79,7 +80,7 @@ Sprite::Sprite(TombRaider& tr, unsigned int item, unsigned int sequence, unsigne
79 80
     texel[0][0] = (float)(x) / texelScale;
80 81
     texel[0][1] = (float)(y + height) / texelScale;
81 82
 
82
-    texture = sprite->tile + getGame().getTextureStart();
83
+    texture = sprite->tile;
83 84
     radius = width2 / 2.0f;
84 85
 }
85 86
 
@@ -90,8 +91,6 @@ Sprite::Sprite(TombRaider& tr, unsigned int room, unsigned int index) {
90 91
     tr.getRoomSprite(room, index,
91 92
                      10.0f, &texture, pos, spriteVertices, spriteTexCoords);
92 93
 
93
-    texture += getGame().getTextureStart(); // OpenRaider preloads some textures
94
-
95 94
     for (unsigned int j = 0; j < 12; j++)
96 95
         vertex[j / 3][j % 3] = spriteVertices[j];
97 96
 
@@ -140,7 +139,7 @@ void Sprite::display() {
140 139
             glColor3ubv(WHITE);
141 140
             break;
142 141
         default:
143
-            glBindTexture(GL_TEXTURE_2D, texture + 1);
142
+            getTextureManager().bindTextureId(texture);
144 143
 
145 144
             glBegin(GL_TRIANGLE_STRIP);
146 145
             glTexCoord2fv(texel[0]);

+ 9
- 13
src/StaticMesh.cpp View File

@@ -31,8 +31,7 @@ void TexturedTriangle::display(float* vertices, float* colors, float* normals) {
31 31
 
32 32
     if ((getRender().getMode() != Render::modeWireframe)
33 33
         && (getRender().getMode() != Render::modeSolid)) {
34
-        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
35
-        glBindTexture(GL_TEXTURE_2D, texture + 1);
34
+        getTextureManager().bindTextureId(texture);
36 35
     }
37 36
 
38 37
     glBegin(GL_TRIANGLES);
@@ -116,8 +115,7 @@ int setupTextureColor(float* colorf) {
116 115
         texture = gColorTextureHACK.at(colorI);
117 116
     } catch (...) {
118 117
         unsigned char* image = generateColorTexture(color, 32, 32, 32);
119
-        texture = getTextureManager().loadBufferSlot(image, 32, 32,
120
-                  RGBA, 32, getTextureManager().getTextureCount());
118
+        texture = getTextureManager().loadBufferSlot(image, 32, 32, RGBA, 32);
121 119
         delete [] image;
122 120
     }
123 121
 
@@ -157,7 +155,7 @@ StaticMesh::StaticMesh(TombRaider& tr, unsigned int index) {
157 155
                                    vertexIndices, st,
158 156
                                    &texture, &transparency);
159 157
         triangles.push_back(
160
-            new TexturedTriangle(vertexIndices, st, texture + getGame().getTextureStart(), transparency));
158
+            new TexturedTriangle(vertexIndices, st, texture, transparency));
161 159
     }
162 160
 
163 161
     // Coloured Triangles
@@ -180,7 +178,7 @@ StaticMesh::StaticMesh(TombRaider& tr, unsigned int index) {
180 178
         transparency = 0;
181 179
 
182 180
         triangles.push_back(
183
-            new TexturedTriangle(vertexIndices, st, texture + getGame().getTextureStart(), transparency));
181
+            new TexturedTriangle(vertexIndices, st, texture, transparency));
184 182
     }
185 183
 
186 184
     // Textured Rectangles
@@ -190,10 +188,9 @@ StaticMesh::StaticMesh(TombRaider& tr, unsigned int index) {
190 188
                                     vertexIndices, st,
191 189
                                     &texture, &transparency);
192 190
         triangles.push_back(
193
-            new TexturedTriangle(vertexIndices, st, texture + getGame().getTextureStart(), transparency));
191
+            new TexturedTriangle(vertexIndices, st, texture, transparency));
194 192
         triangles.push_back(
195
-            new TexturedTriangle(vertexIndices + 3, st + 6, texture + getGame().getTextureStart(),
196
-                                 transparency));
193
+            new TexturedTriangle(vertexIndices + 3, st + 6, texture, transparency));
197 194
     }
198 195
 
199 196
     // Coloured Rectangles
@@ -217,9 +214,9 @@ StaticMesh::StaticMesh(TombRaider& tr, unsigned int index) {
217 214
         transparency = 0;
218 215
 
219 216
         triangles.push_back(
220
-            new TexturedTriangle(vertexIndices, st, texture + getGame().getTextureStart(), transparency));
217
+            new TexturedTriangle(vertexIndices, st, texture, transparency));
221 218
         triangles.push_back(
222
-            new TexturedTriangle(vertexIndices + 3, st, texture + getGame().getTextureStart(), transparency));
219
+            new TexturedTriangle(vertexIndices + 3, st, texture, transparency));
223 220
     }
224 221
 }
225 222
 
@@ -246,8 +243,7 @@ void StaticMesh::display() {
246 243
         if (getRender().getMode() == Render::modeWireframe)
247 244
             glColor3ubv(WHITE);
248 245
 
249
-        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
250
-        glBindTexture(GL_TEXTURE_2D, 1);  // White texture for colors
246
+        getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
251 247
 
252 248
         for (unsigned int i = 0; i < triangles.size(); i++)
253 249
             triangles.at(i)->display(vertices, colors, normals);

+ 46
- 90
src/TextureManager.cpp View File

@@ -24,94 +24,51 @@
24 24
 #include "utils/png.h"
25 25
 #endif
26 26
 
27
-TextureManager::TextureManager() {
28
-    mFlags = 0;
27
+std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
28
+    if (s == TextureStorage::GAME)
29
+        return mTextureIdsGame;
30
+    else
31
+        return mTextureIdsSystem;
29 32
 }
30 33
 
31 34
 TextureManager::~TextureManager() {
32
-    reset();
33
-}
35
+    while (mTextureIdsSystem.size() > 0) {
36
+        unsigned int id = mTextureIdsSystem.at(mTextureIdsSystem.size() - 1);
37
+        glDeleteTextures(1, &id);
38
+        mTextureIdsSystem.pop_back();
39
+    }
34 40
 
35
-void TextureManager::reset() {
36
-    while (mTextureIds.size() > 0) {
37
-        unsigned int id = mTextureIds.at(mTextureIds.size() - 1);
41
+    while (mTextureIdsGame.size() > 0) {
42
+        unsigned int id = mTextureIdsGame.at(mTextureIdsGame.size() - 1);
38 43
         glDeleteTextures(1, &id);
39
-        mTextureIds.pop_back();
44
+        mTextureIdsGame.pop_back();
40 45
     }
41 46
 }
42 47
 
43 48
 int TextureManager::initialize() {
44 49
     unsigned char* image = generateColorTexture(WHITE, 32, 32, 32);
45
-    loadBufferSlot(image, 32, 32, RGBA, 32, mTextureIds.size());
50
+    int res = loadBufferSlot(image, 32, 32, RGBA, 32, TextureStorage::SYSTEM, TEXTURE_WHITE);
46 51
     delete [] image;
47
-
48
-    //! \fixme Temporary
49
-    std::string filename(getRunTime().getPakDir());
50
-    filename += "/tr2/TITLE.PCX";
51
-    if (loadPCX(filename.c_str()) < 0) {
52
-        //! \fixme Error Checking. Return negative error code, check in calling place too
53
-        filename = getRunTime().getDataDir();
54
-        filename += "/splash.tga";
55
-        loadTGA(filename.c_str());
52
+    if (res < 0) {
53
+        return -1;
56 54
     }
57 55
 
58
-    return (mTextureIds.size() == 0) ? -1 : 0;
59
-}
60
-
61
-void TextureManager::setFlag(TextureFlag flag) {
62
-    mFlags |= flag;
63
-}
64
-
65
-void TextureManager::clearFlag(TextureFlag flag) {
66
-    mFlags &= ~flag;
67
-}
68
-
69
-int TextureManager::getTextureCount() {
70
-    return mTextureIds.size();
71
-}
72
-
73
-void TextureManager::disableMultiTexture() {
74
-    mFlags &= ~fUseMultiTexture;
75
-
76
-#ifdef MULTITEXTURE
77
-    glDisable(GL_TEXTURE_2D);
78
-    glActiveTextureARB(GL_TEXTURE0_ARB);
79
-#endif
80
-}
81
-
82
-void TextureManager::useMultiTexture(float aU, float aV, float bU, float bV) {
83
-    if (!(mFlags & fUseMultiTexture))
84
-        return;
85
-
86
-#ifdef MULTITEXTURE
87
-    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, aU, aV);
88
-    glMultiTexCoord2fARB(GL_TEXTURE1_ARB, bU, bV);
89
-#endif
90
-}
91
-
92
-void TextureManager::bindMultiTexture(int texture0, int texture1) {
93
-    assert(texture0 >= 0);
94
-    assert(texture1 >= 0);
95
-    assert((unsigned int)texture0 < mTextureIds.size());
96
-    assert((unsigned int)texture1 < mTextureIds.size());
97
-
98
-    mFlags |= fUseMultiTexture;
99
-
100
-#ifdef MULTITEXTURE
101
-    glActiveTextureARB(GL_TEXTURE0_ARB);
102
-    glEnable(GL_TEXTURE_2D);
103
-    glBindTexture(GL_TEXTURE_2D, mTextureIds.at(texture0));
56
+    //! \fixme Temporary?
57
+    std::string filename = getRunTime().getPakDir() + "/tr2/TITLE.PCX";
58
+    if (loadPCX(filename.c_str(), TextureStorage::SYSTEM, TEXTURE_SPLASH) < 0) {
59
+        filename = getRunTime().getDataDir() + "/splash.tga";
60
+        if (loadTGA(filename.c_str(), TextureStorage::SYSTEM, TEXTURE_SPLASH) < 0) {
61
+            return -2;
62
+        }
63
+    }
104 64
 
105
-    glActiveTextureARB(GL_TEXTURE1_ARB);
106
-    glEnable(GL_TEXTURE_2D);
107
-    glBindTexture(GL_TEXTURE_2D, mTextureIds.at(texture1));
108
-#endif
65
+    return 0;
109 66
 }
110 67
 
111 68
 int TextureManager::loadBufferSlot(unsigned char* image,
112 69
                                    unsigned int width, unsigned int height,
113 70
                                    ColorMode mode, unsigned int bpp,
114
-                                   unsigned int slot, bool filter) {
71
+                                   TextureStorage s, int slot, bool filter) {
115 72
     assert(image != NULL);
116 73
     assert(width > 0);
117 74
     assert(height > 0);
@@ -120,10 +77,13 @@ int TextureManager::loadBufferSlot(unsigned char* image,
120 77
            || (mode == RGBA) || (mode ==  BGRA));
121 78
     assert((bpp == 8) || (bpp == 24) || (bpp == 32));
122 79
 
123
-    while (mTextureIds.size() <= slot) {
80
+    if (slot == -1)
81
+        slot = getIds(s).size();
82
+
83
+    while (getIds(s).size() <= slot) {
124 84
         unsigned int id;
125 85
         glGenTextures(1, &id);
126
-        mTextureIds.push_back(id);
86
+        getIds(s).push_back(id);
127 87
     }
128 88
 
129 89
     unsigned int glcMode;
@@ -159,10 +119,8 @@ int TextureManager::loadBufferSlot(unsigned char* image,
159 119
     glColor3ubv(WHITE);
160 120
     glEnable(GL_DEPTH_TEST);
161 121
     glShadeModel(GL_SMOOTH);
162
-
163 122
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
164
-
165
-    glBindTexture(GL_TEXTURE_2D, mTextureIds.at(slot));
123
+    glBindTexture(GL_TEXTURE_2D, getIds(s).at(slot));
166 124
 
167 125
     if (filter) {
168 126
         glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
@@ -177,27 +135,25 @@ int TextureManager::loadBufferSlot(unsigned char* image,
177 135
 
178 136
     glTexImage2D(GL_TEXTURE_2D, 0, bpp / 8, width, height, 0, glcMode, GL_UNSIGNED_BYTE, image);
179 137
 
180
-    //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
181
-
182 138
     return slot;
183 139
 }
184 140
 
185
-void TextureManager::bindTextureId(unsigned int n) {
186
-    assert(n < mTextureIds.size());
141
+void TextureManager::bindTextureId(unsigned int n, TextureStorage s) {
142
+    assert(n < getIds(s).size());
187 143
 
188 144
     glEnable(GL_TEXTURE_2D);
189
-    //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
145
+    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
190 146
 
191
-    glBindTexture(GL_TEXTURE_2D, mTextureIds.at(n));
147
+    glBindTexture(GL_TEXTURE_2D, getIds(s).at(n));
192 148
 }
193 149
 
194
-int TextureManager::loadImage(const char* filename) {
150
+int TextureManager::loadImage(const char* filename, TextureStorage s, int slot) {
195 151
     if (stringEndsWith(filename, ".pcx") || stringEndsWith(filename, ".PCX")) {
196
-        return loadPCX(filename);
152
+        return loadPCX(filename, s, slot);
197 153
     } else if (stringEndsWith(filename, ".png") || stringEndsWith(filename, ".PNG")) {
198
-        return loadPNG(filename);
154
+        return loadPNG(filename, s, slot);
199 155
     } else if (stringEndsWith(filename, ".tga") || stringEndsWith(filename, ".TGA")) {
200
-        return loadTGA(filename);
156
+        return loadTGA(filename, s, slot);
201 157
     } else {
202 158
         getLog() << "No known image file type? (" << filename << ")" << Log::endl;
203 159
     }
@@ -205,7 +161,7 @@ int TextureManager::loadImage(const char* filename) {
205 161
     return -1;
206 162
 }
207 163
 
208
-int TextureManager::loadPCX(const char* filename) {
164
+int TextureManager::loadPCX(const char* filename, TextureStorage s, int slot) {
209 165
     assert(filename != NULL);
210 166
     assert(filename[0] != '\0');
211 167
 
@@ -221,14 +177,14 @@ int TextureManager::loadPCX(const char* filename) {
221 177
             delete [] image;
222 178
             image = image2;
223 179
         }
224
-        id = loadBufferSlot(image, w, h, c, bpp, mTextureIds.size());
180
+        id = loadBufferSlot(image, w, h, c, bpp, s, slot);
225 181
         delete [] image;
226 182
     }
227 183
 
228 184
     return id;
229 185
 }
230 186
 
231
-int TextureManager::loadPNG(const char* filename) {
187
+int TextureManager::loadPNG(const char* filename, TextureStorage s, int slot) {
232 188
 #ifdef USING_PNG
233 189
     assert(filename != NULL);
234 190
     assert(filename[0] != '\0');
@@ -249,7 +205,7 @@ int TextureManager::loadPNG(const char* filename) {
249 205
             delete [] image;
250 206
             image = image2;
251 207
         }
252
-        id = loadBufferSlot(image, w, h, c, bpp, mTextureIds.size());
208
+        id = loadBufferSlot(image, w, h, c, bpp, s, slot);
253 209
         delete [] image;
254 210
     }
255 211
 
@@ -260,7 +216,7 @@ int TextureManager::loadPNG(const char* filename) {
260 216
 #endif
261 217
 }
262 218
 
263
-int TextureManager::loadTGA(const char* filename) {
219
+int TextureManager::loadTGA(const char* filename, TextureStorage s, int slot) {
264 220
     assert(filename != NULL);
265 221
     assert(filename[0] != '\0');
266 222
 
@@ -281,7 +237,7 @@ int TextureManager::loadTGA(const char* filename) {
281 237
             id = loadBufferSlot(image, w, h,
282 238
                                 (type == 2) ? RGBA : RGB,
283 239
                                 (type == 2) ? 32 : 24,
284
-                                mTextureIds.size());
240
+                                s, slot);
285 241
             delete [] image;
286 242
         }
287 243
     }

+ 10
- 99
src/TombRaider.cpp View File

@@ -113,11 +113,11 @@ int TombRaider::NumStaticMeshes() {
113 113
     return _num_static_meshes;
114 114
 }
115 115
 
116
-
116
+/*
117 117
 int TombRaider::NumSprites() {
118 118
     return _num_sprite_textures;
119 119
 }
120
-
120
+*/
121 121
 
122 122
 int TombRaider::NumSpriteSequences() {
123 123
     return _num_sprite_sequences;
@@ -144,16 +144,15 @@ tr2_item_t* TombRaider::Item() {
144 144
     return _items;
145 145
 }
146 146
 
147
-
147
+/*
148 148
 tr2_object_texture_t* TombRaider::ObjectTextures() {
149 149
     return _object_textures;
150 150
 }
151 151
 
152
-
153 152
 unsigned int TombRaider::getNumBoxes() {
154 153
     return _num_boxes;
155 154
 }
156
-
155
+*/
157 156
 
158 157
 tr2_box_t* TombRaider::Box() {
159 158
     return _boxes;
@@ -251,21 +250,11 @@ unsigned short* TombRaider::Frame() {
251 250
 
252 251
 
253 252
 tr2_moveable_t* TombRaider::Moveable() {
254
-    /*
255
-       if (n > 0 || n > (int)_num_moveables)
256
-       return NULL;
257
-       */
258
-
259 253
     return _moveables;
260 254
 }
261 255
 
262 256
 
263 257
 tr2_meshtree_t* TombRaider::MeshTree() {
264
-    /*
265
-       if (n > 0 || n > (int)_num_mesh_trees)
266
-       return NULL;
267
-       */
268
-
269 258
     return _mesh_trees;
270 259
 }
271 260
 
@@ -279,26 +268,6 @@ tr2_sprite_sequence_t* TombRaider::SpriteSequence() {
279 268
     return _sprite_sequences;
280 269
 }
281 270
 
282
-unsigned char* TombRaider::SpecialTexTile(int texture) {
283
-    unsigned char* image;
284
-    unsigned char* ptr;
285
-
286
-
287
-    image = NULL;
288
-
289
-    if (texture >= 0 && texture < NumSpecialTextures()) {
290
-        // Get base and offset into 32bit special textures/bump maps
291
-        ptr = _tex_special;
292
-        ptr += 256 * 256 * 4 * texture;
293
-
294
-        // Clone it as a single 256x256 @ 32bpp image
295
-        image = new unsigned char[256 * 256 * 4];
296
-        memcpy(image, ptr, 256 * 256 * 4);
297
-    }
298
-
299
-    return image;
300
-}
301
-
302 271
 
303 272
 int TombRaider::NumSpecialTextures() {
304 273
     return _num_tex_special;
@@ -319,57 +288,12 @@ void TombRaider::Texture(int texture, unsigned char** image,
319 288
 }
320 289
 
321 290
 
322
-unsigned int* TombRaider::Palette16() {
323
-    return _palette16;
324
-}
325
-
326
-
327
-unsigned char* TombRaider::Palette8() {
328
-    return (unsigned char*)_palette8;
329
-}
330
-
331
-
332
-int TombRaider::checkMime(const char* filename) {
333
-    FILE* f;
334
-    unsigned int version;
335
-
336
-    if (!filename || !filename[0]) {
337
-        print("checkFile", "Given filename was empty string or NULL");
338
-        return -1;
339
-    }
340
-
341
-    f = fopen(filename, "rb");
342
-
343
-    if (!f) {
344
-        perror(filename);
345
-        return -1;
346
-    }
347
-
348
-    //! \fixme Endianess
349
-    fread(&version, sizeof(version), 1, f);
350
-    fclose(f);
351
-
352
-    switch (version) {
353
-        case 0x00000020:
354
-        case 0x0000002d:
355
-        case 0xff080038:
356
-        case 0xff180038:
357
-        case 0xfffffff0: // bogus
358
-        case 0x00345254: // "TR4\0"
359
-            return 0;
360
-        default:
361
-            return 1;
362
-    }
363
-}
364
-
365
-
366 291
 int TombRaider::Load(const char* filename) {
367 292
     FILE* f;
368 293
     int i, j, l;
369 294
     unsigned int num_mesh_data_words, num_mesh_pointers, data_size, data_offset;
370 295
     unsigned int* mesh_pointer_list;
371 296
     unsigned char* raw_mesh_data;
372
-    bool tr5;
373 297
     long debugf;
374 298
 
375 299
 
@@ -386,8 +310,6 @@ int TombRaider::Load(const char* filename) {
386 310
 
387 311
     printDebug("Load", "mPakVersion = %u", mPakVersion);
388 312
 
389
-    tr5 = false;
390
-
391 313
     switch (mPakVersion) {
392 314
         case 0x00000020:
393 315
             mEngineVersion = TR_VERSION_1;
@@ -1744,15 +1666,6 @@ int TombRaider::Load(const char* filename) {
1744 1666
 // Public Accessors
1745 1667
 ////////////////////////////////////////////////////////////
1746 1668
 
1747
-float TombRaider::adjustTexel(unsigned char texel, char offset) {
1748
-    if (offset >= 0)
1749
-        texel++;
1750
-    else
1751
-        texel--;
1752
-
1753
-    return ((float)texel / 255.0f);
1754
-}
1755
-
1756 1669
 
1757 1670
 void TombRaider::computeRotationAngles(unsigned short** frame,
1758 1671
                                        unsigned int* frame_offset,
@@ -1847,11 +1760,11 @@ void TombRaider::computeUV(tr2_object_texture_vert_t* st, float* u, float* v) {
1847 1760
     *v = (float)y / 255.0f;
1848 1761
 }
1849 1762
 
1850
-
1763
+/*
1851 1764
 int TombRaider::getBumpMapCount() {
1852 1765
     return _num_bump_map_textures / 2;
1853 1766
 }
1854
-
1767
+*/
1855 1768
 
1856 1769
 void TombRaider::getColor(int index, float color[4]) {
1857 1770
     switch (getEngine()) {
@@ -3480,9 +3393,8 @@ int TombRaider::getSkyModelId() {
3480 3393
     return skyMesh;
3481 3394
 }
3482 3395
 
3483
-
3396
+#if 0
3484 3397
 void TombRaider::getSprites() {
3485
-#ifdef FIXME
3486 3398
     int i, j, k, l, x, y, s_index, width, height;
3487 3399
     float scale, width2, height2;
3488 3400
     tr2_sprite_texture_t* sprite;
@@ -3577,9 +3489,8 @@ void TombRaider::getSprites() {
3577 3489
     }
3578 3490
 
3579 3491
     printf("\n");
3580
-#endif
3581 3492
 }
3582
-
3493
+#endif
3583 3494
 
3584 3495
 void TombRaider::getSoundSample(unsigned int index,
3585 3496
                                 unsigned int* bytes, unsigned char** data) {
@@ -3986,12 +3897,11 @@ void TombRaider::reset() {
3986 3897
     _num_overlaps = 0;
3987 3898
 }
3988 3899
 
3989
-
3900
+/*
3990 3901
 void TombRaider::setDebug(bool toggle) {
3991 3902
     mDebug = toggle;
3992 3903
 }
3993 3904
 
3994
-
3995 3905
 void TombRaider::setRoomVertexLightingFactor(float f) {
3996 3906
     mRoomVertexLightingFactor = f;
3997 3907
 }
@@ -3999,6 +3909,7 @@ void TombRaider::setRoomVertexLightingFactor(float f) {
3999 3909
 void TombRaider::setTexelScalingFactor(float f) {
4000 3910
     mTexelScale = f;
4001 3911
 }
3912
+*/
4002 3913
 
4003 3914
 ////////////////////////////////////////////////////////////
4004 3915
 // Private Accessors

+ 2
- 2
src/UI.cpp View File

@@ -75,7 +75,7 @@ int UI::initialize() {
75 75
 
76 76
     //! \fixme TODO use proper texture slot
77 77
     fontTex = getTextureManager().loadBufferSlot((unsigned char*)tex_data,
78
-              tex_x, tex_y, RGBA, 32, 0, false);
78
+              tex_x, tex_y, RGBA, 32, TextureManager::TextureStorage::SYSTEM, -1, false);
79 79
 
80 80
     stbi_image_free(tex_data);
81 81
 
@@ -282,7 +282,7 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
282 282
     glEnableClientState(GL_COLOR_ARRAY);
283 283
 
284 284
     // Setup texture
285
-    getTextureManager().bindTextureId(fontTex);
285
+    getTextureManager().bindTextureId(fontTex, TextureManager::TextureStorage::SYSTEM);
286 286
 
287 287
     // Render command lists
288 288
     for (int n = 0; n < cmd_lists_count; n++) {

Loading…
Cancel
Save