Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Render.h 8.5KB

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