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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*!
  2. * \file include/Render.h
  3. * \brief OpenRaider Renderer class
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #ifndef _RENDER_H_
  9. #define _RENDER_H_
  10. #include <vector>
  11. #include "config.h"
  12. #include "math/Matrix.h"
  13. #include "ViewVolume.h"
  14. #include "World.h"
  15. #include "SkeletalModel.h"
  16. #include "Mesh.h"
  17. #include "Texture.h"
  18. #include "Camera.h"
  19. #include "RoomData.h"
  20. /*!
  21. * \brief OpenRaider Renderer class
  22. */
  23. class Render {
  24. public:
  25. typedef enum {
  26. modeDisabled,
  27. modeLoadScreen,
  28. modeVertexLight,
  29. modeSolid,
  30. modeWireframe,
  31. modeTexture
  32. } RenderMode;
  33. typedef enum {
  34. fRoomAlpha = (1 << 0),
  35. fViewModel = (1 << 1),
  36. fEntityModels = (1 << 2),
  37. fFog = (1 << 3),
  38. fUsePortals = (1 << 4),
  39. fGL_Lights = (1 << 5),
  40. fOneRoom = (1 << 6),
  41. fRenderPonytail = (1 << 7),
  42. // fMultiTexture = (1 << 8), //! \todo Whats up with Multitexture stuff? Where is it needed?
  43. fUpdateRoomListPerFrame = (1 << 9),
  44. fAnimateAllModels = (1 << 10),
  45. fAllRooms = (1 << 11)
  46. } RenderFlags;
  47. /*!
  48. * \brief Constructs an object of Render
  49. */
  50. Render();
  51. /*!
  52. * \brief Deconstructs an object of Render
  53. */
  54. ~Render();
  55. /*!
  56. * \brief Makes a screenshot, writes to disk
  57. * \param filenameBase basename of file to be written
  58. */
  59. void screenShot(char *filenameBase);
  60. /*!
  61. * \brief Gets current rendering mode
  62. * \returns current RenderMode
  63. * \fixme Don't return enum as int?!
  64. */
  65. int getMode();
  66. /*!
  67. * \brief Loads textures in a certain id slot
  68. * \param image Image to load
  69. * \param width width of image
  70. * \param height height of image
  71. * \param id id for texture
  72. * \sa Texture::loadBufferSlot()
  73. */
  74. void loadTexture(unsigned char *image,
  75. unsigned int width, unsigned int height,
  76. unsigned int id);
  77. /*!
  78. * \brief Sets up textures for OpenRaider
  79. * \param textureDir Is valid and exists with textures
  80. * \returns number of loaded textures
  81. */
  82. int initTextures(char *textureDir);
  83. /*!
  84. * Removes current world/entity/etc geometry
  85. */
  86. void ClearWorld();
  87. /*!
  88. * \brief Clears bitflags, changes state of renderer in some way
  89. * \param flags RenderFlags to clear (ORed)
  90. * \fixme use enum not integer as parameter?!
  91. */
  92. void clearFlags(unsigned int flags);
  93. /*!
  94. * \brief Sets bitflags, changes state of renderer in some way
  95. * \param flags RenderFlags to set (ORed)
  96. * \fixme use enum not integer as parameter?!
  97. */
  98. void setFlags(unsigned int flags);
  99. void setMode(int n);
  100. /*!
  101. * \brief Renders a single game frame
  102. */
  103. void display();
  104. void setSkyMesh(int index, bool rot);
  105. void addSkeletalModel(SkeletalModel *mdl);
  106. unsigned int getFlags();
  107. /*!
  108. * \brief Check if a point is in the View Volume
  109. * \param x X coordinate
  110. * \param y Y coordinate
  111. * \param z Z coordinate
  112. * \returns true if point is visible
  113. */
  114. bool isVisible(float x, float y, float z);
  115. /*!
  116. * \brief Check if a sphere is in the View Volume
  117. * \param x X coordinate of center of sphere
  118. * \param y Y coordinate of center of sphere
  119. * \param z Z coordinate of center of sphere
  120. * \param radius radius of sphere
  121. * \returns true if sphere is visible
  122. */
  123. bool isVisible(float x, float y, float z, float radius);
  124. bool isVisible(BoundingBox &box);
  125. /*!
  126. * \brief Renders a mesh.
  127. *
  128. * Texture must be initialized.
  129. * \param r_mesh Mesh to render.
  130. */
  131. void drawModelMesh(model_mesh_t *r_mesh);
  132. //! \fixme should be private
  133. ViewVolume mViewVolume; //!< View Volume for frustum culling
  134. std::vector<SkeletalModel *> mModels;
  135. Texture mTexture; //!< Texture subsystem
  136. private:
  137. void drawLoadScreen();
  138. /*!
  139. * \brief Build a visible room list starting at index
  140. * \param index valid room index where to start the list
  141. */
  142. void newRoomRenderList(int index);
  143. /*!
  144. * \brief Build a visible room list starting from room and
  145. * only considers its linked rooms and their linked rooms.
  146. * \param room First room in list
  147. */
  148. void buildRoomRenderList(Room &room);
  149. /*!
  150. * \brief Renders visible world object.
  151. *
  152. * Texture must be initialized.
  153. */
  154. void drawObjects();
  155. /*!
  156. * \brief Renders Sky domes/boxes/etc by scaling factor.
  157. *
  158. * Texture must be initialized.
  159. * \param scale correct scale for map size
  160. */
  161. void drawSkyMesh(float scale);
  162. /*!
  163. * \brief Renders a skeletal model.
  164. *
  165. * Texture must be initialized!
  166. * \param model model to render
  167. */
  168. void drawModel(SkeletalModel *model);
  169. /*!
  170. * \brief Updates View Volume. Call once per render frame.
  171. */
  172. void updateViewVolume();
  173. //! \fixme Let them eat cake...? O.o
  174. void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
  175. std::vector<Room *> mRoomRenderList;
  176. unsigned int mFlags; //!< Rendering flags
  177. unsigned int mMode; //!< Rendering mode
  178. int mLock;
  179. int mSkyMesh; //!< Skymesh model id
  180. bool mSkyMeshRotation; //!< Should Skymesh be rotated?
  181. };
  182. #endif