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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. private:
  200. /*!
  201. * \brief Check if a bounding box is in the View Volume
  202. * \param bboxMin Start coordinates of a valid bounding box
  203. * \param bboxMax End coordinates of a valid bounding box
  204. * \returns true if bounding box is visible
  205. */
  206. bool isVisible(float bboxMin[3], float bboxMax[3]);
  207. /*!
  208. * \brief Check if a point is in the View Volume
  209. * \param x X coordinate
  210. * \param y Y coordinate
  211. * \param z Z coordinate
  212. * \returns true if point is visible
  213. */
  214. bool isVisible(float x, float y, float z);
  215. /*!
  216. * \brief Check if a sphere is in the View Volume
  217. * \param x X coordinate of center of sphere
  218. * \param y Y coordinate of center of sphere
  219. * \param z Z coordinate of center of sphere
  220. * \param radius radius of sphere
  221. * \returns true if sphere is visible
  222. */
  223. bool isVisible(float x, float y, float z, float radius);
  224. /*!
  225. * \brief Build a visible room list starting at index
  226. * \param index valid room index where to start the list
  227. */
  228. void newRoomRenderList(int index);
  229. /*!
  230. * \brief Build a visible room list starting from room and
  231. * only considers its linked rooms and their linked rooms.
  232. * \param room First room in list
  233. */
  234. void buildRoomRenderList(RenderRoom *room);
  235. /*!
  236. * \brief Renders visible world object.
  237. *
  238. * Texture must be initialized.
  239. */
  240. void drawObjects();
  241. /*!
  242. * \brief Renders Sky domes/boxes/etc by scaling factor.
  243. *
  244. * Texture must be initialized.
  245. * \param scale correct scale for map size
  246. */
  247. void drawSkyMesh(float scale);
  248. /*!
  249. * \brief Renders a skeletal model.
  250. *
  251. * Texture must be initialized!
  252. * \param model model to render
  253. */
  254. void drawModel(SkeletalModel *model);
  255. /*!
  256. * Renders a room in 2 seperate passes to handle alpha.
  257. *
  258. * Currently doesnt sort alpha but looks pretty good.
  259. * Texture must be initialized.
  260. * Draw all rooms with alpha false, then again with alpha true.
  261. * \param rRoom room to render
  262. * \param draw_alpha once false, once true
  263. */
  264. void drawRoom(RenderRoom *rRoom, bool draw_alpha);
  265. /*!
  266. * \brief Renders static room model.
  267. *
  268. * Texture must be initialized.
  269. * \param mesh Static model to render
  270. */
  271. void drawRoomModel(static_model_t *mesh);
  272. /*!
  273. * \brief Renders a mesh.
  274. *
  275. * Texture must be initialized.
  276. * \param r_mesh Mesh to render.
  277. * \param type Must be object containing mesh
  278. */
  279. void drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type);
  280. /*!
  281. * \brief Renders a sprite.
  282. *
  283. * Texture must be initialized.
  284. * \param sprite sprite to render
  285. */
  286. void drawSprite(sprite_t *sprite);
  287. /*!
  288. * \brief Updates View Volume. Call once per render frame.
  289. */
  290. void updateViewVolume();
  291. //! \fixme Let them eat cake...? O.o
  292. void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
  293. Texture mTexture; //!< Texture subsystem
  294. Camera *mCamera; //!< Camera subsystem
  295. GLString mString; //!< GL Text subsystem
  296. Vector<RenderRoom *> mRoomRenderList;
  297. Vector<RenderRoom *> mRooms;
  298. Vector<SkeletalModel *> mModels;
  299. unsigned int mFlags; //!< Rendering flags
  300. unsigned int mWidth; //!< Viewport width
  301. unsigned int mHeight; //!< Viewport height
  302. unsigned int mMode; //!< Rendering mode
  303. unsigned int *mNumTexturesLoaded;
  304. unsigned int *mNextTextureId;
  305. int mLock;
  306. int mSkyMesh; //!< Skymesh model id
  307. bool mSkyMeshRotation; //!< Should Skymesh be rotated?
  308. #ifdef USING_EMITTER
  309. Emitter *mEmitter; //!< Particle emitter test
  310. #endif
  311. };
  312. #endif