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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. * \returns number of loaded textures
  137. */
  138. int initTextures(char *textureDir);
  139. /*!
  140. * Removes current world/entity/etc geometry
  141. */
  142. void ClearWorld();
  143. /*!
  144. * \brief Clears bitflags, changes state of renderer in some way
  145. * \param flags RenderFlags to clear (ORed)
  146. * \fixme use enum not integer as parameter?!
  147. */
  148. void clearFlags(unsigned int flags);
  149. /*!
  150. * \brief Sets bitflags, changes state of renderer in some way
  151. * \param flags RenderFlags to set (ORed)
  152. * \fixme use enum not integer as parameter?!
  153. */
  154. void setFlags(unsigned int flags);
  155. void setMode(int n);
  156. /*!
  157. * \brief Renders a single game frame
  158. */
  159. void display();
  160. void setSkyMesh(int index, bool rot);
  161. void ViewModel(entity_t *ent, int index);
  162. void addSkeletalModel(SkeletalModel *mdl);
  163. unsigned int getFlags();
  164. //! \fixme should be private
  165. ViewVolume mViewVolume; //!< View Volume for frustum culling
  166. std::vector<SkeletalModel *> mModels;
  167. private:
  168. void drawLoadScreen();
  169. /*!
  170. * \brief Check if a bounding box is in the View Volume
  171. * \param bboxMin Start coordinates of a valid bounding box
  172. * \param bboxMax End coordinates of a valid bounding box
  173. * \returns true if bounding box is visible
  174. */
  175. bool isVisible(float bboxMin[3], float bboxMax[3]);
  176. /*!
  177. * \brief Check if a point is in the View Volume
  178. * \param x X coordinate
  179. * \param y Y coordinate
  180. * \param z Z coordinate
  181. * \returns true if point is visible
  182. */
  183. bool isVisible(float x, float y, float z);
  184. /*!
  185. * \brief Check if a sphere is in the View Volume
  186. * \param x X coordinate of center of sphere
  187. * \param y Y coordinate of center of sphere
  188. * \param z Z coordinate of center of sphere
  189. * \param radius radius of sphere
  190. * \returns true if sphere is visible
  191. */
  192. bool isVisible(float x, float y, float z, float radius);
  193. /*!
  194. * \brief Build a visible room list starting at index
  195. * \param index valid room index where to start the list
  196. */
  197. void newRoomRenderList(int index);
  198. /*!
  199. * \brief Build a visible room list starting from room and
  200. * only considers its linked rooms and their linked rooms.
  201. * \param room First room in list
  202. */
  203. void buildRoomRenderList(RenderRoom *room);
  204. /*!
  205. * \brief Renders visible world object.
  206. *
  207. * Texture must be initialized.
  208. */
  209. void drawObjects();
  210. /*!
  211. * \brief Renders Sky domes/boxes/etc by scaling factor.
  212. *
  213. * Texture must be initialized.
  214. * \param scale correct scale for map size
  215. */
  216. void drawSkyMesh(float scale);
  217. /*!
  218. * \brief Renders a skeletal model.
  219. *
  220. * Texture must be initialized!
  221. * \param model model to render
  222. */
  223. void drawModel(SkeletalModel *model);
  224. /*!
  225. * Renders a room in 2 seperate passes to handle alpha.
  226. *
  227. * Currently doesnt sort alpha but looks pretty good.
  228. * Texture must be initialized.
  229. * Draw all rooms with alpha false, then again with alpha true.
  230. * \param rRoom room to render
  231. * \param draw_alpha once false, once true
  232. */
  233. void drawRoom(RenderRoom *rRoom, bool draw_alpha);
  234. /*!
  235. * \brief Renders static room model.
  236. *
  237. * Texture must be initialized.
  238. * \param mesh Static model to render
  239. */
  240. void drawRoomModel(static_model_t *mesh);
  241. /*!
  242. * \brief Renders a mesh.
  243. *
  244. * Texture must be initialized.
  245. * \param r_mesh Mesh to render.
  246. * \param type Must be object containing mesh
  247. */
  248. void drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type);
  249. /*!
  250. * \brief Renders a sprite.
  251. *
  252. * Texture must be initialized.
  253. * \param sprite sprite to render
  254. */
  255. void drawSprite(sprite_t *sprite);
  256. /*!
  257. * \brief Updates View Volume. Call once per render frame.
  258. */
  259. void updateViewVolume();
  260. //! \fixme Let them eat cake...? O.o
  261. void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
  262. Texture mTexture; //!< Texture subsystem
  263. std::vector<RenderRoom *> mRoomRenderList;
  264. std::vector<RenderRoom *> mRooms;
  265. unsigned int mFlags; //!< Rendering flags
  266. unsigned int mMode; //!< Rendering mode
  267. int mLock;
  268. int mSkyMesh; //!< Skymesh model id
  269. bool mSkyMeshRotation; //!< Should Skymesh be rotated?
  270. };
  271. #endif