浏览代码

Simplified Render Texture loading

Thomas Buck 11 年前
父节点
当前提交
6eba26fb03
共有 4 个文件被更改,包括 13 次插入36 次删除
  1. 0
    1
      include/Game.h
  2. 3
    8
      include/Render.h
  3. 6
    7
      src/Game.cpp
  4. 4
    20
      src/Render.cpp

+ 0
- 1
include/Game.h 查看文件

60
     TombRaider mTombRaider;
60
     TombRaider mTombRaider;
61
 
61
 
62
     unsigned int mTextureStart;
62
     unsigned int mTextureStart;
63
-    unsigned int mTextureLevelOffset;
64
     unsigned int mTextureOffset;
63
     unsigned int mTextureOffset;
65
 };
64
 };
66
 
65
 

+ 3
- 8
include/Render.h 查看文件

152
                           unsigned int id);
152
                           unsigned int id);
153
 
153
 
154
     /*!
154
     /*!
155
-     * \brief Sets up textures for OpenRaider.
155
+     * \brief Sets up textures for OpenRaider
156
      * \param textureDir Is valid and exists with textures
156
      * \param textureDir Is valid and exists with textures
157
-     * \param numLoaded returns number of loaded textures and will update
158
-     * number of external textures loaded
159
-     * \param nextId will update next level texture id
157
+     * \returns number of loaded textures
160
      */
158
      */
161
-    void initTextures(char *textureDir, unsigned int *numLoaded,
162
-                            unsigned int *nextId);
159
+    int initTextures(char *textureDir);
163
 
160
 
164
     /*!
161
     /*!
165
      * Removes current world/entity/etc geometry
162
      * Removes current world/entity/etc geometry
318
 
315
 
319
     unsigned int mFlags;                  //!< Rendering flags
316
     unsigned int mFlags;                  //!< Rendering flags
320
     unsigned int mMode;                   //!< Rendering mode
317
     unsigned int mMode;                   //!< Rendering mode
321
-    unsigned int *mNumTexturesLoaded;
322
-    unsigned int *mNextTextureId;
323
     int mLock;
318
     int mLock;
324
     int mSkyMesh;                         //!< Skymesh model id
319
     int mSkyMesh;                         //!< Skymesh model id
325
     bool mSkyMeshRotation;                //!< Should Skymesh be rotated?
320
     bool mSkyMeshRotation;                //!< Should Skymesh be rotated?

+ 6
- 7
src/Game.cpp 查看文件

43
     mLara = NULL;
43
     mLara = NULL;
44
 
44
 
45
     mTextureStart = 0;
45
     mTextureStart = 0;
46
-    mTextureLevelOffset = 0;
47
     mTextureOffset = 0;
46
     mTextureOffset = 0;
48
 }
47
 }
49
 
48
 
53
 
52
 
54
 int Game::initialize() {
53
 int Game::initialize() {
55
     // Enable Renderer
54
     // Enable Renderer
56
-    getRender().initTextures(getOpenRaider().mDataDir, &mTextureStart, &mTextureLevelOffset);
55
+    mTextureStart = getRender().initTextures(getOpenRaider().mDataDir);
57
     getRender().setMode(Render::modeLoadScreen);
56
     getRender().setMode(Render::modeLoadScreen);
58
 
57
 
59
     // Enable World Hopping
58
     // Enable World Hopping
235
         mTombRaider.Texture(i, &image, &bumpmap);
234
         mTombRaider.Texture(i, &image, &bumpmap);
236
 
235
 
237
         // Overwrite any previous level textures on load
236
         // Overwrite any previous level textures on load
238
-        getRender().loadTexture(image, 256, 256, mTextureLevelOffset + i);
237
+        getRender().loadTexture(image, 256, 256, (mTextureStart - 1) + i);
239
 
238
 
240
 #ifdef MULTITEXTURE
239
 #ifdef MULTITEXTURE
241
-        gMapTex2Bump[mTextureLevelOffset + i] = -1;
240
+        gMapTex2Bump[(mTextureStart - 1) + i] = -1;
242
 #endif
241
 #endif
243
 
242
 
244
         if (bumpmap)
243
         if (bumpmap)
245
         {
244
         {
246
 #ifdef MULTITEXTURE
245
 #ifdef MULTITEXTURE
247
-            gMapTex2Bump[mTextureLevelOffset + i] = mTextureLevelOffset + i +
246
+            gMapTex2Bump[(mTextureStart - 1) + i] = (mTextureStart - 1) + i +
248
                     mTombRaider.NumTextures();
247
                     mTombRaider.NumTextures();
249
 #endif
248
 #endif
250
-            getRender().loadTexture(bumpmap, 256, 256, mTextureLevelOffset + i +
249
+            getRender().loadTexture(bumpmap, 256, 256, (mTextureStart - 1) + i +
251
                     mTombRaider.NumTextures());
250
                     mTombRaider.NumTextures());
252
         }
251
         }
253
 
252
 
261
         //fflush(stdout);
260
         //fflush(stdout);
262
     }
261
     }
263
 
262
 
264
-    mTextureOffset = mTextureLevelOffset + mTombRaider.NumTextures();
263
+    mTextureOffset = (mTextureStart - 1) + mTombRaider.NumTextures();
265
 
264
 
266
     printf("Done! Found %d textures.\n", mTombRaider.NumTextures());
265
     printf("Done! Found %d textures.\n", mTombRaider.NumTextures());
267
 }
266
 }

+ 4
- 20
src/Render.cpp 查看文件

92
     mFlags = (fRoomAlpha | fViewModel | fSprites |
92
     mFlags = (fRoomAlpha | fViewModel | fSprites |
93
             fRoomModels | fEntityModels |
93
             fRoomModels | fEntityModels |
94
             fUsePortals | fUpdateRoomListPerFrame);
94
             fUsePortals | fUpdateRoomListPerFrame);
95
-
96
-    mNextTextureId = NULL;
97
-    mNumTexturesLoaded = NULL;
98
 }
95
 }
99
 
96
 
100
 
97
 
137
 }
134
 }
138
 
135
 
139
 
136
 
140
-void Render::initTextures(char *textureDir, unsigned int *numLoaded,
141
-        unsigned int *nextId)
142
-{
137
+int Render::initTextures(char *textureDir) {
143
     char filename[128];
138
     char filename[128];
144
-    int bg;
145
     unsigned int numTextures = 0;
139
     unsigned int numTextures = 0;
146
     unsigned char color[4];
140
     unsigned char color[4];
147
 
141
 
148
-    // We want to update as needed later
149
-    mNumTexturesLoaded = numLoaded;
150
-    mNextTextureId = nextId;
151
-
152
     mTexture.reset();
142
     mTexture.reset();
153
     mTexture.setMaxTextureCount(128);  /* TR never needs more than 32 iirc
143
     mTexture.setMaxTextureCount(128);  /* TR never needs more than 32 iirc
154
                                           However, color texturegen is a lot */
144
                                           However, color texturegen is a lot */
155
 
145
 
156
     mTexture.setFlag(Texture::fUseMipmaps);
146
     mTexture.setFlag(Texture::fUseMipmaps);
157
 
147
 
158
-    printf("Processing Textures:\n");
159
-
160
     color[0] = 0xff;
148
     color[0] = 0xff;
161
     color[1] = 0xff;
149
     color[1] = 0xff;
162
     color[2] = 0xff;
150
     color[2] = 0xff;
165
     if (mTexture.loadColorTexture(color, 32, 32) > -1)
153
     if (mTexture.loadColorTexture(color, 32, 32) > -1)
166
         numTextures++;
154
         numTextures++;
167
 
155
 
156
+    //! \fixme Error Checking. Return negative error code, check in calling place too
168
     snprintf(filename, 126, "%s/%s", textureDir, "splash.tga");
157
     snprintf(filename, 126, "%s/%s", textureDir, "splash.tga");
169
     filename[127] = 0;
158
     filename[127] = 0;
170
-
171
-    if ((bg = mTexture.loadTGA(filename)) > -1)
159
+    if (mTexture.loadTGA(filename) > -1)
172
         numTextures++;
160
         numTextures++;
173
 
161
 
174
-    // Weird that it isn't linear, must be some storage deal in Texture
175
-    // I forgot about Id allocation
176
-    *nextId = bg;
177
-
178
-    *numLoaded = numTextures;
162
+    return numTextures;
179
 }
163
 }
180
 
164
 
181
 
165
 

正在加载...
取消
保存