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

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