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 9.4KB

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