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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 ViewModel(entity_t *ent, int index);
  106. void addSkeletalModel(SkeletalModel *mdl);
  107. unsigned int getFlags();
  108. /*!
  109. * \brief Check if a point is in the View Volume
  110. * \param x X coordinate
  111. * \param y Y coordinate
  112. * \param z Z coordinate
  113. * \returns true if point is visible
  114. */
  115. bool isVisible(float x, float y, float z);
  116. /*!
  117. * \brief Check if a sphere is in the View Volume
  118. * \param x X coordinate of center of sphere
  119. * \param y Y coordinate of center of sphere
  120. * \param z Z coordinate of center of sphere
  121. * \param radius radius of sphere
  122. * \returns true if sphere is visible
  123. */
  124. bool isVisible(float x, float y, float z, float radius);
  125. bool isVisible(Box &box);
  126. /*!
  127. * \brief Renders a mesh.
  128. *
  129. * Texture must be initialized.
  130. * \param r_mesh Mesh to render.
  131. */
  132. void drawModelMesh(model_mesh_t *r_mesh);
  133. //! \fixme should be private
  134. ViewVolume mViewVolume; //!< View Volume for frustum culling
  135. std::vector<SkeletalModel *> mModels;
  136. Texture mTexture; //!< Texture subsystem
  137. private:
  138. void drawLoadScreen();
  139. /*!
  140. * \brief Build a visible room list starting at index
  141. * \param index valid room index where to start the list
  142. */
  143. void newRoomRenderList(int index);
  144. /*!
  145. * \brief Build a visible room list starting from room and
  146. * only considers its linked rooms and their linked rooms.
  147. * \param room First room in list
  148. */
  149. void buildRoomRenderList(Room &room);
  150. /*!
  151. * \brief Renders visible world object.
  152. *
  153. * Texture must be initialized.
  154. */
  155. void drawObjects();
  156. /*!
  157. * \brief Renders Sky domes/boxes/etc by scaling factor.
  158. *
  159. * Texture must be initialized.
  160. * \param scale correct scale for map size
  161. */
  162. void drawSkyMesh(float scale);
  163. /*!
  164. * \brief Renders a skeletal model.
  165. *
  166. * Texture must be initialized!
  167. * \param model model to render
  168. */
  169. void drawModel(SkeletalModel *model);
  170. /*!
  171. * \brief Updates View Volume. Call once per render frame.
  172. */
  173. void updateViewVolume();
  174. //! \fixme Let them eat cake...? O.o
  175. void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
  176. std::vector<Room *> mRoomRenderList;
  177. unsigned int mFlags; //!< Rendering flags
  178. unsigned int mMode; //!< Rendering mode
  179. int mLock;
  180. int mSkyMesh; //!< Skymesh model id
  181. bool mSkyMeshRotation; //!< Should Skymesh be rotated?
  182. };
  183. #endif