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

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