Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Render.h 10KB

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