Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Render.h 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 OpenRaider Renderer class
  21. */
  22. class Render {
  23. public:
  24. typedef enum {
  25. modeDisabled,
  26. modeLoadScreen,
  27. modeVertexLight,
  28. modeSolid,
  29. modeWireframe,
  30. modeTexture
  31. } RenderMode;
  32. typedef enum {
  33. fPortals = (1 << 0),
  34. fRoomAlpha = (1 << 1),
  35. fViewModel = (1 << 2),
  36. fSprites = (1 << 3),
  37. fRoomModels = (1 << 4),
  38. fEntityModels = (1 << 5),
  39. fFog = (1 << 6),
  40. fUsePortals = (1 << 7),
  41. fGL_Lights = (1 << 8),
  42. fOneRoom = (1 << 9),
  43. fRenderPonytail = (1 << 10),
  44. // fMultiTexture = (1 << 11), //! \todo Whats up with Multitexture stuff? Where is it needed?
  45. fUpdateRoomListPerFrame = (1 << 12),
  46. fAnimateAllModels = (1 << 13),
  47. fAllRooms = (1 << 14)
  48. } RenderFlags;
  49. typedef enum {
  50. roomMesh,
  51. skeletalMesh
  52. } RenderMeshType;
  53. /*!
  54. * \brief Constructs an object of Render
  55. */
  56. Render();
  57. /*!
  58. * \brief Deconstructs an object of Render
  59. */
  60. ~Render();
  61. /*!
  62. * \brief Makes a screenshot, writes to disk
  63. * \param filenameBase basename of file to be written
  64. */
  65. void screenShot(char *filenameBase);
  66. /*!
  67. * \brief Gets current rendering mode
  68. * \returns current RenderMode
  69. * \fixme Don't return enum as int?!
  70. */
  71. int getMode();
  72. /*!
  73. * \brief Loads textures in a certain id slot
  74. * \param image Image to load
  75. * \param width width of image
  76. * \param height height of image
  77. * \param id id for texture
  78. * \sa Texture::loadBufferSlot()
  79. */
  80. void loadTexture(unsigned char *image,
  81. unsigned int width, unsigned int height,
  82. unsigned int id);
  83. /*!
  84. * \brief Sets up textures for OpenRaider
  85. * \param textureDir Is valid and exists with textures
  86. * \returns number of loaded textures
  87. */
  88. int initTextures(char *textureDir);
  89. /*!
  90. * Removes current world/entity/etc geometry
  91. */
  92. void ClearWorld();
  93. /*!
  94. * \brief Clears bitflags, changes state of renderer in some way
  95. * \param flags RenderFlags to clear (ORed)
  96. * \fixme use enum not integer as parameter?!
  97. */
  98. void clearFlags(unsigned int flags);
  99. /*!
  100. * \brief Sets bitflags, changes state of renderer in some way
  101. * \param flags RenderFlags to set (ORed)
  102. * \fixme use enum not integer as parameter?!
  103. */
  104. void setFlags(unsigned int flags);
  105. void setMode(int n);
  106. /*!
  107. * \brief Renders a single game frame
  108. */
  109. void display();
  110. void setSkyMesh(int index, bool rot);
  111. void ViewModel(entity_t *ent, int index);
  112. void addSkeletalModel(SkeletalModel *mdl);
  113. unsigned int getFlags();
  114. /*!
  115. * \brief Check if a bounding box is in the View Volume
  116. * \param bboxMin Start coordinates of a valid bounding box
  117. * \param bboxMax End coordinates of a valid bounding box
  118. * \returns true if bounding box is visible
  119. */
  120. bool isVisible(float bboxMin[3], float bboxMax[3]);
  121. /*!
  122. * \brief Check if a point is in the View Volume
  123. * \param x X coordinate
  124. * \param y Y coordinate
  125. * \param z Z coordinate
  126. * \returns true if point is visible
  127. */
  128. bool isVisible(float x, float y, float z);
  129. /*!
  130. * \brief Check if a sphere is in the View Volume
  131. * \param x X coordinate of center of sphere
  132. * \param y Y coordinate of center of sphere
  133. * \param z Z coordinate of center of sphere
  134. * \param radius radius of sphere
  135. * \returns true if sphere is visible
  136. */
  137. bool isVisible(float x, float y, float z, float radius);
  138. //! \fixme should be private
  139. ViewVolume mViewVolume; //!< View Volume for frustum culling
  140. std::vector<SkeletalModel *> mModels;
  141. private:
  142. void drawLoadScreen();
  143. /*!
  144. * \brief Build a visible room list starting at index
  145. * \param index valid room index where to start the list
  146. */
  147. void newRoomRenderList(int index);
  148. /*!
  149. * \brief Build a visible room list starting from room and
  150. * only considers its linked rooms and their linked rooms.
  151. * \param room First room in list
  152. */
  153. void buildRoomRenderList(Room *room);
  154. /*!
  155. * \brief Renders visible world object.
  156. *
  157. * Texture must be initialized.
  158. */
  159. void drawObjects();
  160. /*!
  161. * \brief Renders Sky domes/boxes/etc by scaling factor.
  162. *
  163. * Texture must be initialized.
  164. * \param scale correct scale for map size
  165. */
  166. void drawSkyMesh(float scale);
  167. /*!
  168. * \brief Renders a skeletal model.
  169. *
  170. * Texture must be initialized!
  171. * \param model model to render
  172. */
  173. void drawModel(SkeletalModel *model);
  174. /*!
  175. * Renders a room in 2 seperate passes to handle alpha.
  176. *
  177. * Currently doesnt sort alpha but looks pretty good.
  178. * Texture must be initialized.
  179. * Draw all rooms with alpha false, then again with alpha true.
  180. * \param rRoom room to render
  181. * \param draw_alpha once false, once true
  182. */
  183. void drawRoom(Room *rRoom, bool draw_alpha);
  184. /*!
  185. * \brief Renders static room model.
  186. *
  187. * Texture must be initialized.
  188. * \param mesh Static model to render
  189. */
  190. void drawRoomModel(StaticModel &mesh);
  191. /*!
  192. * \brief Renders a mesh.
  193. *
  194. * Texture must be initialized.
  195. * \param r_mesh Mesh to render.
  196. * \param type Must be object containing mesh
  197. */
  198. void drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type);
  199. /*!
  200. * \brief Renders a sprite.
  201. *
  202. * Texture must be initialized.
  203. * \param sprite sprite to render
  204. */
  205. void drawSprite(Sprite &sprite);
  206. /*!
  207. * \brief Updates View Volume. Call once per render frame.
  208. */
  209. void updateViewVolume();
  210. //! \fixme Let them eat cake...? O.o
  211. void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
  212. Texture mTexture; //!< Texture subsystem
  213. std::vector<Room *> mRoomRenderList;
  214. unsigned int mFlags; //!< Rendering flags
  215. unsigned int mMode; //!< Rendering mode
  216. int mLock;
  217. int mSkyMesh; //!< Skymesh model id
  218. bool mSkyMeshRotation; //!< Should Skymesh be rotated?
  219. };
  220. #endif