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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : Render
  5. * Author : Mongoose
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : Render
  9. * License : No use w/o permission (C) 2001 Mongoose
  10. * Comments: This is the renderer class for OpenRaider
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History ------------------------------------------------
  17. *
  18. * 2001.05.21:
  19. * Mongoose - Created
  20. ================================================================*/
  21. #ifndef _RENDER_H_
  22. #define _RENDER_H_
  23. #include <List.h>
  24. #include <Vector.h>
  25. #include <Matrix.h>
  26. #include <ViewVolume.h>
  27. #include <Light.h>
  28. #include <World.h>
  29. #include <SkeletalModel.h>
  30. #include <Mesh.h>
  31. #include <Texture.h>
  32. #include <Camera.h>
  33. #include <GLString.h>
  34. #ifdef USING_EMITTER
  35. #include <Emitter.h>
  36. #endif
  37. class RenderRoom {
  38. public:
  39. RenderRoom() {
  40. room = 0x0;
  41. dist = 0.0f;
  42. center[0] = center[1] = center[2] = 0.0f;
  43. }
  44. ~RenderRoom() {
  45. //! \fixme Hangs when erasing - might be shared pointers somewhere
  46. //lights.erase();
  47. }
  48. void computeCenter() {
  49. if (room)
  50. helMidpoint3v(room->bbox_min, room->bbox_max, center);
  51. }
  52. vec_t dist; //!< Distance to near plane, move to room?
  53. vec3_t center; //!< Center of bbox, move to room?
  54. room_mesh_t *room; //!< Physical room stored in World, very dangerous as allocated and used
  55. Vector<Light *> lights; //!< List of lights in this room
  56. Mesh mesh; //!< OpenGL mesh that represents this room
  57. };
  58. class Render
  59. {
  60. public:
  61. typedef enum {
  62. modeDisabled,
  63. modeLoadScreen,
  64. modeVertexLight,
  65. modeSolid,
  66. modeWireframe,
  67. modeTexture
  68. } RenderMode;
  69. typedef enum {
  70. fParticles = (1 << 0),
  71. fPortals = (1 << 1),
  72. fRoomAlpha = (1 << 2),
  73. fViewModel = (1 << 3),
  74. fSprites = (1 << 4),
  75. fRoomModels = (1 << 5),
  76. fEntityModels = (1 << 6),
  77. fFog = (1 << 7),
  78. fUsePortals = (1 << 8),
  79. fFastCard = (1 << 9),
  80. fGL_Lights = (1 << 10),
  81. fOneRoom = (1 << 11),
  82. fRenderPonytail = (1 << 12),
  83. fMultiTexture = (1 << 13),
  84. fUpdateRoomListPerFrame = (1 << 14),
  85. fAnimateAllModels = (1 << 15),
  86. fAllRooms = (1 << 16)
  87. } RenderFlags;
  88. typedef enum {
  89. roomMesh,
  90. skeletalMesh
  91. } RenderMeshType;
  92. ////////////////////////////////////////////////////////////
  93. // Constructors
  94. ////////////////////////////////////////////////////////////
  95. Render();
  96. /*------------------------------------------------------
  97. * Pre :
  98. * Post : Constructs an object of Render
  99. *
  100. *-- History ------------------------------------------
  101. *
  102. * 2001.05.21:
  103. * Mongoose - Created
  104. ------------------------------------------------------*/
  105. ~Render();
  106. /*------------------------------------------------------
  107. * Pre : Render object is allocated
  108. * Post : Deconstructs an object of Render
  109. *
  110. *-- History ------------------------------------------
  111. *
  112. * 2001.05.21:
  113. * Mongoose - Created
  114. ------------------------------------------------------*/
  115. ////////////////////////////////////////////////////////////
  116. // Public Accessors
  117. ////////////////////////////////////////////////////////////
  118. void screenShot(char *filenameBase);
  119. /*------------------------------------------------------
  120. * Pre :
  121. * Post : Makes a screenshot, writes to disk as file
  122. *
  123. *-- History ------------------------------------------
  124. *
  125. * 2002.12.20:
  126. * Mongoose - Created, factored out of OpenRaider class
  127. ------------------------------------------------------*/
  128. int getMode();
  129. /*------------------------------------------------------
  130. * Pre :
  131. * Post : Gets current rendering mode
  132. *
  133. *-- History ------------------------------------------
  134. *
  135. * 2001.05.21:
  136. * Mongoose - Created
  137. ------------------------------------------------------*/
  138. ////////////////////////////////////////////////////////////
  139. // Public Mutators
  140. ////////////////////////////////////////////////////////////
  141. void addRoom(RenderRoom *rRoom);
  142. /*------------------------------------------------------
  143. * Pre :
  144. * Post :
  145. *
  146. *-- History ------------------------------------------
  147. *
  148. * 2002.12.21:
  149. * Mongoose - Created, factored out of World
  150. ------------------------------------------------------*/
  151. void Init(int width, int height, bool fastCard);
  152. /*------------------------------------------------------
  153. * Pre :
  154. * Post : Starts and sets up OpenGL target
  155. *
  156. *-- History ------------------------------------------
  157. *
  158. * 2001.05.21:
  159. * Mongoose - Created
  160. ------------------------------------------------------*/
  161. void loadTexture(unsigned char *image,
  162. unsigned int width, unsigned int height,
  163. unsigned int id);
  164. /*------------------------------------------------------
  165. * Pre :
  166. * Post : Loads textures in a certian id slot
  167. *
  168. *-- History ------------------------------------------
  169. *
  170. * 2002.12.20:
  171. * Mongoose - Created, factored out of OpenRaider class
  172. ------------------------------------------------------*/
  173. void initTextures(char *textureDir, unsigned int *numLoaded,
  174. unsigned int *nextId);
  175. /*------------------------------------------------------
  176. * Pre : textureDir is valid and exists with textures
  177. * Post : Sets up textures for OpenRaider
  178. * Returns number of loaded textures and
  179. *
  180. * numLoaded will update number of
  181. * external textures loaded
  182. *
  183. * nextId will update next level texture id
  184. *
  185. *-- History ------------------------------------------
  186. *
  187. * 2002.12.20:
  188. * Mongoose - Created, factored out of OpenRaider class
  189. ------------------------------------------------------*/
  190. void initEmitter(const char *name, unsigned int size,
  191. unsigned int snowTex1, unsigned int snowTex2);
  192. /*------------------------------------------------------
  193. * Pre : Textures are init and these args are valid
  194. * Post : Emitter is set up for rendering with 2 textures
  195. * in a overhead rain or snow like pattern
  196. *
  197. *-- History ------------------------------------------
  198. *
  199. * 2002.12.20:
  200. * Mongoose - Created
  201. ------------------------------------------------------*/
  202. void ClearWorld();
  203. /*------------------------------------------------------
  204. * Pre :
  205. * Post : Removes current world/entity/etc geometery
  206. *
  207. *-- History ------------------------------------------
  208. *
  209. * 2001.05.21:
  210. * Mongoose - Created
  211. ------------------------------------------------------*/
  212. void toggleFlag(unsigned int flag);
  213. void clearFlags(unsigned int flags);
  214. void setFlags(unsigned int flags);
  215. /*------------------------------------------------------
  216. * Pre : (Un)Sets bitflags for various control use
  217. * Post : Changes state of renderer in some way
  218. *
  219. *-- History ------------------------------------------
  220. *
  221. * 2002.03.21:
  222. * Mongoose - Created
  223. ------------------------------------------------------*/
  224. void setMode(int n);
  225. /*------------------------------------------------------
  226. * Pre :
  227. * Post :
  228. *
  229. *-- History ------------------------------------------
  230. *
  231. * 2001.05.21:
  232. * Mongoose - Created
  233. ------------------------------------------------------*/
  234. void Update(int width, int height);
  235. /*------------------------------------------------------
  236. * Pre :
  237. * Post :
  238. *
  239. *-- History ------------------------------------------
  240. *
  241. * 2001.05.21:
  242. * Mongoose - Created
  243. ------------------------------------------------------*/
  244. void Display();
  245. /*------------------------------------------------------
  246. * Pre :
  247. * Post : Renders a single game frame
  248. *
  249. *-- History ------------------------------------------
  250. *
  251. * 2001.05.21:
  252. * Mongoose - Created
  253. ------------------------------------------------------*/
  254. void setSkyMesh(int index, bool rot);
  255. /*------------------------------------------------------
  256. * Pre :
  257. * Post :
  258. *
  259. *-- History ------------------------------------------
  260. *
  261. * 2001.05.21:
  262. * Mongoose - Created
  263. ------------------------------------------------------*/
  264. void ViewModel(entity_t *ent, int index);
  265. /*------------------------------------------------------
  266. * Pre :
  267. * Post :
  268. *
  269. *-- History ------------------------------------------
  270. *
  271. * 2001.05.21:
  272. * Mongoose - Created
  273. ------------------------------------------------------*/
  274. void RegisterCamera(Camera *camera);
  275. /*------------------------------------------------------
  276. * Pre :
  277. * Post :
  278. *
  279. *-- History ------------------------------------------
  280. *
  281. * 2001.05.21:
  282. * Mongoose - Created
  283. ------------------------------------------------------*/
  284. GLString *GetString();
  285. /*------------------------------------------------------
  286. * Pre :
  287. * Post : Returns GL text output agent
  288. *
  289. *-- History ------------------------------------------
  290. *
  291. * 2002.01.04:
  292. * Mongoose - Created
  293. ------------------------------------------------------*/
  294. //! \fixme Should be private
  295. void drawLoadScreen();
  296. /*------------------------------------------------------
  297. * Pre : Texture is init
  298. * Post : Renders load screen
  299. *
  300. *-- History ------------------------------------------
  301. *
  302. * 2002.01.01:
  303. * Mongoose - Created
  304. ------------------------------------------------------*/
  305. void addSkeletalModel(SkeletalModel *mdl);
  306. /*------------------------------------------------------
  307. * Pre :
  308. * Post :
  309. *
  310. *-- History ------------------------------------------
  311. *
  312. * 2002.01.01:
  313. * Mongoose - Created
  314. ------------------------------------------------------*/
  315. private:
  316. ////////////////////////////////////////////////////////////
  317. // Private Accessors
  318. ////////////////////////////////////////////////////////////
  319. bool isVisible(float bboxMin[3], float bboxMax[3]);
  320. /*------------------------------------------------------
  321. * Pre : Abstract bounding box must be valid
  322. * Post : If object's bounding box is in viewing volume
  323. * return true, else false
  324. *
  325. *-- History ------------------------------------------
  326. *
  327. * 2002.12.16:
  328. * Mongoose - Moved to Render class
  329. *
  330. * 2001.06.06:
  331. * Mongoose - Created
  332. ------------------------------------------------------*/
  333. bool isVisible(float x, float y, float z);
  334. /*------------------------------------------------------
  335. * Pre :
  336. * Post : Is point in view volume?
  337. *
  338. *-- History ------------------------------------------
  339. *
  340. * 2002.12.16:
  341. * Mongoose - Created
  342. ------------------------------------------------------*/
  343. bool isVisible(float x, float y, float z, float radius);
  344. /*------------------------------------------------------
  345. * Pre :
  346. * Post : Is sphere in view volume?
  347. *
  348. *-- History ------------------------------------------
  349. *
  350. * 2002.12.16:
  351. * Mongoose - Created
  352. ------------------------------------------------------*/
  353. ////////////////////////////////////////////////////////////
  354. // Private Mutators
  355. ////////////////////////////////////////////////////////////
  356. void newRoomRenderList(int index);
  357. /*------------------------------------------------------
  358. * Pre : room index is valid
  359. * Post : Build a visible room list starting at index
  360. *
  361. *-- History ------------------------------------------
  362. *
  363. * 2002.01.01:
  364. * Mongoose - Created
  365. ------------------------------------------------------*/
  366. void buildRoomRenderList(RenderRoom *room);
  367. /*------------------------------------------------------
  368. * Pre : room is valid
  369. * Post : Build a visible room list starting from room
  370. * and only consider it's linked rooms and their
  371. * linked rooms
  372. *
  373. *-- History ------------------------------------------
  374. *
  375. * 2002.01.01:
  376. * Mongoose - Created
  377. ------------------------------------------------------*/
  378. void drawObjects();
  379. /*------------------------------------------------------
  380. * Pre : Texture is init
  381. * Post : Renders visible world objects
  382. *
  383. *-- History ------------------------------------------
  384. *
  385. * 2002.01.01:
  386. * Mongoose - Created
  387. ------------------------------------------------------*/
  388. void drawSkyMesh(float scale);
  389. /*------------------------------------------------------
  390. * Pre : Texture is init
  391. * scale is correct for map size
  392. * Post : Renders Sky domes/boxes/etc by scaling factor
  393. *
  394. *-- History ------------------------------------------
  395. *
  396. * 2002.01.01:
  397. * Mongoose - Created
  398. ------------------------------------------------------*/
  399. void drawModel(SkeletalModel *model);
  400. /*------------------------------------------------------
  401. * Pre : Texture is init
  402. * Post : Renders a skeletal model
  403. *
  404. *-- History ------------------------------------------
  405. *
  406. * 2002.01.01:
  407. * Mongoose - Created
  408. ------------------------------------------------------*/
  409. void drawRoom(RenderRoom *rRoom, bool draw_alpha);
  410. /*------------------------------------------------------
  411. * Pre : Texture is init
  412. * Draw all rooms with alpha false, then
  413. * draw with alpha true
  414. *
  415. * Post : Renders a room in 2 seperate passes to
  416. * handle alpha, currently doesn't sort alpha
  417. * but looks pretty good
  418. *
  419. *-- History ------------------------------------------
  420. *
  421. * 2002.01.01:
  422. * Mongoose - Created
  423. ------------------------------------------------------*/
  424. void drawRoomModel(static_model_t *mesh);
  425. /*------------------------------------------------------
  426. * Pre : Texture is init
  427. * Post : Renders static room model
  428. *
  429. *-- History ------------------------------------------
  430. *
  431. * 2002.01.01:
  432. * Mongoose - Created
  433. ------------------------------------------------------*/
  434. void drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type);
  435. /*------------------------------------------------------
  436. * Pre : Texture is init, type is object containing mesh
  437. * Post : Renders a mesh
  438. *
  439. *-- History ------------------------------------------
  440. *
  441. * 2002.01.01:
  442. * Mongoose - Created
  443. ------------------------------------------------------*/
  444. void drawSprite(sprite_t *sprite);
  445. /*------------------------------------------------------
  446. * Pre : Texture is init
  447. * Post : Renders a sprite
  448. *
  449. *-- History ------------------------------------------
  450. *
  451. * 2002.01.01:
  452. * Mongoose - Created
  453. ------------------------------------------------------*/
  454. void updateViewVolume();
  455. /*------------------------------------------------------
  456. * Pre : Call once per render frame
  457. * Post : Updated view volume
  458. *
  459. *-- History ------------------------------------------
  460. *
  461. * 2002.12.16:
  462. * Mongoose - Created
  463. ------------------------------------------------------*/
  464. void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
  465. /*------------------------------------------------------
  466. * Pre :
  467. * Post : Let them eat cake...
  468. *
  469. *-- History ------------------------------------------
  470. *
  471. * 2003.05.19:
  472. * Mongoose - Created
  473. ------------------------------------------------------*/
  474. #ifdef USING_EMITTER
  475. Emitter *mEmitter; /* Particle emitter test */
  476. #endif
  477. Texture mTexture; /* Texture subsystem */
  478. Camera *mCamera; /* Camera subsystem */
  479. GLString mString; /* GL Text subsystem */
  480. Vector<RenderRoom *> mRoomRenderList;
  481. Vector<RenderRoom *> mRooms;
  482. Vector<SkeletalModel *> mModels;
  483. unsigned int mFlags; /* Rendering flags */
  484. unsigned int mWidth; /* Viewport width */
  485. unsigned int mHeight; /* Viewport height */
  486. unsigned int mMode; /* Rendering mode */
  487. unsigned int *mNumTexturesLoaded;
  488. unsigned int *mNextTextureId;
  489. // float mSplash;
  490. int mLock;
  491. int mSkyMesh; /* Skymesh model id */
  492. bool mSkyMeshRotation; /* Should Skymesh be rotated? */
  493. };
  494. #endif