Thomas Buck hace 10 años
padre
commit
b32e1ce56f
Se han modificado 3 ficheros con 2388 adiciones y 0 borrados
  1. 356
    0
      include/Render.h
  2. 1
    0
      src/CMakeLists.txt
  3. 2031
    0
      src/Render.cpp

+ 356
- 0
include/Render.h Ver fichero

@@ -0,0 +1,356 @@
1
+/*!
2
+ * \file include/Render.h
3
+ * \brief OpenRaider Renderer class
4
+ *
5
+ * \author Mongoose
6
+ * \author xythobuz
7
+ */
8
+
9
+#ifndef _RENDER_H_
10
+#define _RENDER_H_
11
+
12
+#include <vector>
13
+
14
+#include "Config.h"
15
+#include "math/Matrix.h"
16
+#include "ViewVolume.h"
17
+#include "World.h"
18
+#include "SkeletalModel.h"
19
+#include "Mesh.h"
20
+#include "Texture.h"
21
+#include "Camera.h"
22
+
23
+#ifdef USING_EMITTER
24
+#include "Emitter.h"
25
+#endif
26
+
27
+/*!
28
+ * \brief The GL light class
29
+ */
30
+class Light {
31
+public:
32
+    /*!
33
+     * \brief Type a light can be of
34
+     */
35
+    typedef enum {
36
+        typePoint       = 1, //!< Point light
37
+        typeSpot        = 2, //!< Spot light
38
+        typeDirectional = 3  //!< Directional light
39
+    } LightType;
40
+
41
+    vec4_t mPos; //! Light position in 3 space
42
+    vec3_t mDir; //! Light direction
43
+    float mAtt;
44
+    vec4_t mColor; //! Color of light
45
+    vec_t mCutoff; //! Fade out distance
46
+    LightType mType; //! Type of light
47
+};
48
+
49
+/*!
50
+ * \brief RenderRoom used by Renderer
51
+ */
52
+class RenderRoom {
53
+public:
54
+
55
+    /*!
56
+     * \brief Constructs an object of RenderRoom
57
+     */
58
+    RenderRoom() {
59
+        room = 0x0;
60
+        dist = 0.0f;
61
+    }
62
+
63
+    /*!
64
+     * \brief Deconstructs an object of RenderRoom
65
+     */
66
+    ~RenderRoom() {
67
+        // \fixme Hangs when erasing - might be shared pointers somewhere
68
+        for (std::vector<Light *>::size_type i = 0; i != lights.size(); i++) {
69
+            if (lights[i])
70
+                delete lights[i];
71
+        }
72
+        lights.clear();
73
+    }
74
+
75
+    vec_t dist;             //!< Distance to near plane, move to room?
76
+    std::vector<Light *> lights; //!< List of lights in this room
77
+    Mesh mesh;              //!< OpenGL mesh that represents this room
78
+
79
+    //! \fixme very dangerous as allocated and used
80
+    room_mesh_t *room;      //!< Physical room stored in World
81
+};
82
+
83
+/*!
84
+ * \brief OpenRaider Renderer class
85
+ */
86
+class Render {
87
+public:
88
+
89
+    typedef enum {
90
+        modeDisabled,
91
+        modeVertexLight,
92
+        modeSolid,
93
+        modeWireframe,
94
+        modeTexture
95
+    } RenderMode;
96
+
97
+    typedef enum {
98
+        fParticles              = (1 << 0),
99
+        fPortals                = (1 << 1),
100
+        fRoomAlpha              = (1 << 2),
101
+        fViewModel              = (1 << 3),
102
+        fSprites                = (1 << 4),
103
+        fRoomModels             = (1 << 5),
104
+        fEntityModels           = (1 << 6),
105
+        fFog                    = (1 << 7),
106
+        fUsePortals             = (1 << 8),
107
+        fGL_Lights              = (1 << 9),
108
+        fOneRoom                = (1 << 10),
109
+        fRenderPonytail         = (1 << 11),
110
+        fMultiTexture           = (1 << 12),
111
+        fUpdateRoomListPerFrame = (1 << 13),
112
+        fAnimateAllModels       = (1 << 14),
113
+        fAllRooms               = (1 << 15)
114
+    } RenderFlags;
115
+
116
+    typedef enum {
117
+        roomMesh,
118
+        skeletalMesh
119
+    } RenderMeshType;
120
+
121
+    /*!
122
+     * \brief Constructs an object of Render
123
+     */
124
+    Render();
125
+
126
+    /*!
127
+     * \brief Deconstructs an object of Render
128
+     */
129
+    ~Render();
130
+
131
+    /*!
132
+     * \brief Makes a screenshot, writes to disk
133
+     * \param filenameBase basename of file to be written
134
+     */
135
+    void screenShot(char *filenameBase);
136
+
137
+    /*!
138
+     * \brief Gets current rendering mode
139
+     * \returns current RenderMode
140
+     * \fixme Don't return enum as int?!
141
+     */
142
+    int getMode();
143
+
144
+    void addRoom(RenderRoom *rRoom);
145
+
146
+    /*!
147
+     * \brief Starts and sets up OpenGL target
148
+     * \param width width of window
149
+     * \param height height of window
150
+     */
151
+    void Init(int width, int height);
152
+
153
+    /*!
154
+     * \brief Loads textures in a certain id slot
155
+     * \param image Image to load
156
+     * \param width width of image
157
+     * \param height height of image
158
+     * \param id id for texture
159
+     * \sa Texture::loadBufferSlot()
160
+     */
161
+    void loadTexture(unsigned char *image,
162
+                          unsigned int width, unsigned int height,
163
+                          unsigned int id);
164
+
165
+    /*!
166
+     * \brief Sets up textures for OpenRaider.
167
+     * \param textureDir Is valid and exists with textures
168
+     * \param numLoaded returns number of loaded textures and will update
169
+     * number of external textures loaded
170
+     * \param nextId will update next level texture id
171
+     */
172
+    void initTextures(char *textureDir, unsigned int *numLoaded,
173
+                            unsigned int *nextId);
174
+
175
+    /*!
176
+     * \brief Initializes Emitter.
177
+     *
178
+     * Emitter is set up for rendering with 2 textures in
179
+     * a overhead rain or snow like pattern.
180
+     * Textures have to be initialized!
181
+     * \param name valid C-String name
182
+     * \param size valid size
183
+     * \param snowTex1 valid first texture
184
+     * \param snowTex2 valid second texture
185
+     */
186
+    void initEmitter(const char *name, unsigned int size,
187
+                          unsigned int snowTex1, unsigned int snowTex2);
188
+
189
+    /*!
190
+     * Removes current world/entity/etc geometry
191
+     */
192
+    void ClearWorld();
193
+
194
+    /*!
195
+     * \brief Clears bitflags, changes state of renderer in some way
196
+     * \param flags RenderFlags to clear (ORed)
197
+     * \fixme use enum not integer as parameter?!
198
+     */
199
+    void clearFlags(unsigned int flags);
200
+
201
+    /*!
202
+     * \brief Sets bitflags, changes state of renderer in some way
203
+     * \param flags RenderFlags to set (ORed)
204
+     * \fixme use enum not integer as parameter?!
205
+     */
206
+    void setFlags(unsigned int flags);
207
+
208
+    void setMode(int n);
209
+
210
+    void Update(int width, int height);
211
+
212
+    /*!
213
+     * \brief Renders a single game frame
214
+     */
215
+    void Display();
216
+
217
+    void setSkyMesh(int index, bool rot);
218
+
219
+    void ViewModel(entity_t *ent, int index);
220
+
221
+    void RegisterCamera(Camera *camera);
222
+
223
+    void addSkeletalModel(SkeletalModel *mdl);
224
+
225
+private:
226
+
227
+    /*!
228
+     * \brief Check if a bounding box is in the View Volume
229
+     * \param bboxMin Start coordinates of a valid bounding box
230
+     * \param bboxMax End coordinates of a valid bounding box
231
+     * \returns true if bounding box is visible
232
+     */
233
+    bool isVisible(float bboxMin[3], float bboxMax[3]);
234
+
235
+    /*!
236
+     * \brief Check if a point is in the View Volume
237
+     * \param x X coordinate
238
+     * \param y Y coordinate
239
+     * \param z Z coordinate
240
+     * \returns true if point is visible
241
+     */
242
+    bool isVisible(float x, float y, float z);
243
+
244
+    /*!
245
+     * \brief Check if a sphere is in the View Volume
246
+     * \param x X coordinate of center of sphere
247
+     * \param y Y coordinate of center of sphere
248
+     * \param z Z coordinate of center of sphere
249
+     * \param radius radius of sphere
250
+     * \returns true if sphere is visible
251
+     */
252
+    bool isVisible(float x, float y, float z, float radius);
253
+
254
+    /*!
255
+     * \brief Build a visible room list starting at index
256
+     * \param index valid room index where to start the list
257
+     */
258
+    void newRoomRenderList(int index);
259
+
260
+    /*!
261
+     * \brief Build a visible room list starting from room and
262
+     * only considers its linked rooms and their linked rooms.
263
+     * \param room First room in list
264
+     */
265
+    void buildRoomRenderList(RenderRoom *room);
266
+
267
+    /*!
268
+     * \brief Renders visible world object.
269
+     *
270
+     * Texture must be initialized.
271
+     */
272
+    void drawObjects();
273
+
274
+    /*!
275
+     * \brief Renders Sky domes/boxes/etc by scaling factor.
276
+     *
277
+     * Texture must be initialized.
278
+     * \param scale correct scale for map size
279
+     */
280
+    void drawSkyMesh(float scale);
281
+
282
+    /*!
283
+     * \brief Renders a skeletal model.
284
+     *
285
+     * Texture must be initialized!
286
+     * \param model model to render
287
+     */
288
+    void drawModel(SkeletalModel *model);
289
+
290
+    /*!
291
+     * Renders a room in 2 seperate passes to handle alpha.
292
+     *
293
+     * Currently doesnt sort alpha but looks pretty good.
294
+     * Texture must be initialized.
295
+     * Draw all rooms with alpha false, then again with alpha true.
296
+     * \param rRoom room to render
297
+     * \param draw_alpha once false, once true
298
+     */
299
+    void drawRoom(RenderRoom *rRoom, bool draw_alpha);
300
+
301
+    /*!
302
+     * \brief Renders static room model.
303
+     *
304
+     * Texture must be initialized.
305
+     * \param mesh Static model to render
306
+     */
307
+    void drawRoomModel(static_model_t *mesh);
308
+
309
+    /*!
310
+     * \brief Renders a mesh.
311
+     *
312
+     * Texture must be initialized.
313
+     * \param r_mesh Mesh to render.
314
+     * \param type Must be object containing mesh
315
+     */
316
+    void drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type);
317
+
318
+    /*!
319
+     * \brief Renders a sprite.
320
+     *
321
+     * Texture must be initialized.
322
+     * \param sprite sprite to render
323
+     */
324
+    void drawSprite(sprite_t *sprite);
325
+
326
+    /*!
327
+     * \brief Updates View Volume. Call once per render frame.
328
+     */
329
+    void updateViewVolume();
330
+
331
+    //! \fixme Let them eat cake...? O.o
332
+    void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
333
+
334
+    Texture mTexture;                     //!< Texture subsystem
335
+    Camera *mCamera;                      //!< Camera subsystem
336
+
337
+    std::vector<RenderRoom *> mRoomRenderList;
338
+    std::vector<RenderRoom *> mRooms;
339
+    std::vector<SkeletalModel *> mModels;
340
+
341
+    unsigned int mFlags;                  //!< Rendering flags
342
+    unsigned int mWidth;                  //!< Viewport width
343
+    unsigned int mHeight;                 //!< Viewport height
344
+    unsigned int mMode;                   //!< Rendering mode
345
+    unsigned int *mNumTexturesLoaded;
346
+    unsigned int *mNextTextureId;
347
+    int mLock;
348
+    int mSkyMesh;                         //!< Skymesh model id
349
+    bool mSkyMeshRotation;                //!< Should Skymesh be rotated?
350
+
351
+#ifdef USING_EMITTER
352
+    Emitter *mEmitter;                    //!< Particle emitter test
353
+#endif
354
+};
355
+
356
+#endif

+ 1
- 0
src/CMakeLists.txt Ver fichero

@@ -40,6 +40,7 @@ set (SRCS ${SRCS} "Menu.cpp")
40 40
 set (SRCS ${SRCS} "Mesh.cpp")
41 41
 set (SRCS ${SRCS} "OpenRaider.cpp")
42 42
 set (SRCS ${SRCS} "Particle.cpp")
43
+set (SRCS ${SRCS} "Render.cpp")
43 44
 set (SRCS ${SRCS} "SkeletalModel.cpp")
44 45
 set (SRCS ${SRCS} "Sound.cpp")
45 46
 set (SRCS ${SRCS} "Texture.cpp")

+ 2031
- 0
src/Render.cpp
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero


Loading…
Cancelar
Guardar