Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Render.h 9.4KB

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