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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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 <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 initEmitter(const char *name, unsigned int size,
  199. unsigned int snowTex1, unsigned int snowTex2);
  200. /*------------------------------------------------------
  201. * Pre : Textures are init and these args are valid
  202. * Post : Emitter is set up for rendering with 2 textures
  203. * in a overhead rain or snow like pattern
  204. *
  205. *-- History ------------------------------------------
  206. *
  207. * 2002.12.20:
  208. * Mongoose - Created
  209. ------------------------------------------------------*/
  210. void ClearWorld();
  211. /*------------------------------------------------------
  212. * Pre :
  213. * Post : Removes current world/entity/etc geometery
  214. *
  215. *-- History ------------------------------------------
  216. *
  217. * 2001.05.21:
  218. * Mongoose - Created
  219. ------------------------------------------------------*/
  220. void toggleFlag(unsigned int flag);
  221. void clearFlags(unsigned int flags);
  222. void setFlags(unsigned int flags);
  223. /*------------------------------------------------------
  224. * Pre : (Un)Sets bitflags for various control use
  225. * Post : Changes state of renderer in some way
  226. *
  227. *-- History ------------------------------------------
  228. *
  229. * 2002.03.21:
  230. * Mongoose - Created
  231. ------------------------------------------------------*/
  232. void setMode(int n);
  233. /*------------------------------------------------------
  234. * Pre :
  235. * Post :
  236. *
  237. *-- History ------------------------------------------
  238. *
  239. * 2001.05.21:
  240. * Mongoose - Created
  241. ------------------------------------------------------*/
  242. void Update(int width, int height);
  243. /*------------------------------------------------------
  244. * Pre :
  245. * Post :
  246. *
  247. *-- History ------------------------------------------
  248. *
  249. * 2001.05.21:
  250. * Mongoose - Created
  251. ------------------------------------------------------*/
  252. void Display();
  253. /*------------------------------------------------------
  254. * Pre :
  255. * Post : Renders a single game frame
  256. *
  257. *-- History ------------------------------------------
  258. *
  259. * 2001.05.21:
  260. * Mongoose - Created
  261. ------------------------------------------------------*/
  262. void setSkyMesh(int index, bool rot);
  263. /*------------------------------------------------------
  264. * Pre :
  265. * Post :
  266. *
  267. *-- History ------------------------------------------
  268. *
  269. * 2001.05.21:
  270. * Mongoose - Created
  271. ------------------------------------------------------*/
  272. void ViewModel(entity_t *ent, int index);
  273. /*------------------------------------------------------
  274. * Pre :
  275. * Post :
  276. *
  277. *-- History ------------------------------------------
  278. *
  279. * 2001.05.21:
  280. * Mongoose - Created
  281. ------------------------------------------------------*/
  282. void RegisterCamera(Camera *camera);
  283. /*------------------------------------------------------
  284. * Pre :
  285. * Post :
  286. *
  287. *-- History ------------------------------------------
  288. *
  289. * 2001.05.21:
  290. * Mongoose - Created
  291. ------------------------------------------------------*/
  292. GLString *GetString();
  293. /*------------------------------------------------------
  294. * Pre :
  295. * Post : Returns GL text output agent
  296. *
  297. *-- History ------------------------------------------
  298. *
  299. * 2002.01.04:
  300. * Mongoose - Created
  301. ------------------------------------------------------*/
  302. //! \fixme Should be private
  303. void drawLoadScreen();
  304. /*------------------------------------------------------
  305. * Pre : Texture is init
  306. * Post : Renders load screen
  307. *
  308. *-- History ------------------------------------------
  309. *
  310. * 2002.01.01:
  311. * Mongoose - Created
  312. ------------------------------------------------------*/
  313. void addSkeletalModel(SkeletalModel *mdl);
  314. /*------------------------------------------------------
  315. * Pre :
  316. * Post :
  317. *
  318. *-- History ------------------------------------------
  319. *
  320. * 2002.01.01:
  321. * Mongoose - Created
  322. ------------------------------------------------------*/
  323. private:
  324. ////////////////////////////////////////////////////////////
  325. // Private Accessors
  326. ////////////////////////////////////////////////////////////
  327. bool isVisible(float bboxMin[3], float bboxMax[3]);
  328. /*------------------------------------------------------
  329. * Pre : Abstract bounding box must be valid
  330. * Post : If object's bounding box is in viewing volume
  331. * return true, else false
  332. *
  333. *-- History ------------------------------------------
  334. *
  335. * 2002.12.16:
  336. * Mongoose - Moved to Render class
  337. *
  338. * 2001.06.06:
  339. * Mongoose - Created
  340. ------------------------------------------------------*/
  341. bool isVisible(float x, float y, float z);
  342. /*------------------------------------------------------
  343. * Pre :
  344. * Post : Is point in view volume?
  345. *
  346. *-- History ------------------------------------------
  347. *
  348. * 2002.12.16:
  349. * Mongoose - Created
  350. ------------------------------------------------------*/
  351. bool isVisible(float x, float y, float z, float radius);
  352. /*------------------------------------------------------
  353. * Pre :
  354. * Post : Is sphere in view volume?
  355. *
  356. *-- History ------------------------------------------
  357. *
  358. * 2002.12.16:
  359. * Mongoose - Created
  360. ------------------------------------------------------*/
  361. ////////////////////////////////////////////////////////////
  362. // Private Mutators
  363. ////////////////////////////////////////////////////////////
  364. void newRoomRenderList(int index);
  365. /*------------------------------------------------------
  366. * Pre : room index is valid
  367. * Post : Build a visible room list starting at index
  368. *
  369. *-- History ------------------------------------------
  370. *
  371. * 2002.01.01:
  372. * Mongoose - Created
  373. ------------------------------------------------------*/
  374. void buildRoomRenderList(RenderRoom *room);
  375. /*------------------------------------------------------
  376. * Pre : room is valid
  377. * Post : Build a visible room list starting from room
  378. * and only consider it's linked rooms and their
  379. * linked rooms
  380. *
  381. *-- History ------------------------------------------
  382. *
  383. * 2002.01.01:
  384. * Mongoose - Created
  385. ------------------------------------------------------*/
  386. void drawObjects();
  387. /*------------------------------------------------------
  388. * Pre : Texture is init
  389. * Post : Renders visible world objects
  390. *
  391. *-- History ------------------------------------------
  392. *
  393. * 2002.01.01:
  394. * Mongoose - Created
  395. ------------------------------------------------------*/
  396. void drawSkyMesh(float scale);
  397. /*------------------------------------------------------
  398. * Pre : Texture is init
  399. * scale is correct for map size
  400. * Post : Renders Sky domes/boxes/etc by scaling factor
  401. *
  402. *-- History ------------------------------------------
  403. *
  404. * 2002.01.01:
  405. * Mongoose - Created
  406. ------------------------------------------------------*/
  407. void drawModel(SkeletalModel *model);
  408. /*------------------------------------------------------
  409. * Pre : Texture is init
  410. * Post : Renders a skeletal model
  411. *
  412. *-- History ------------------------------------------
  413. *
  414. * 2002.01.01:
  415. * Mongoose - Created
  416. ------------------------------------------------------*/
  417. void drawRoom(RenderRoom *rRoom, bool draw_alpha);
  418. /*------------------------------------------------------
  419. * Pre : Texture is init
  420. * Draw all rooms with alpha false, then
  421. * draw with alpha true
  422. *
  423. * Post : Renders a room in 2 seperate passes to
  424. * handle alpha, currently doesn't sort alpha
  425. * but looks pretty good
  426. *
  427. *-- History ------------------------------------------
  428. *
  429. * 2002.01.01:
  430. * Mongoose - Created
  431. ------------------------------------------------------*/
  432. void drawRoomModel(static_model_t *mesh);
  433. /*------------------------------------------------------
  434. * Pre : Texture is init
  435. * Post : Renders static room model
  436. *
  437. *-- History ------------------------------------------
  438. *
  439. * 2002.01.01:
  440. * Mongoose - Created
  441. ------------------------------------------------------*/
  442. void drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type);
  443. /*------------------------------------------------------
  444. * Pre : Texture is init, type is object containing mesh
  445. * Post : Renders a mesh
  446. *
  447. *-- History ------------------------------------------
  448. *
  449. * 2002.01.01:
  450. * Mongoose - Created
  451. ------------------------------------------------------*/
  452. void drawSprite(sprite_t *sprite);
  453. /*------------------------------------------------------
  454. * Pre : Texture is init
  455. * Post : Renders a sprite
  456. *
  457. *-- History ------------------------------------------
  458. *
  459. * 2002.01.01:
  460. * Mongoose - Created
  461. ------------------------------------------------------*/
  462. void updateViewVolume();
  463. /*------------------------------------------------------
  464. * Pre : Call once per render frame
  465. * Post : Updated view volume
  466. *
  467. *-- History ------------------------------------------
  468. *
  469. * 2002.12.16:
  470. * Mongoose - Created
  471. ------------------------------------------------------*/
  472. void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
  473. /*------------------------------------------------------
  474. * Pre :
  475. * Post : Let them eat cake...
  476. *
  477. *-- History ------------------------------------------
  478. *
  479. * 2003.05.19:
  480. * Mongoose - Created
  481. ------------------------------------------------------*/
  482. #ifdef USING_EMITTER
  483. Emitter *mEmitter; /* Particle emitter test */
  484. #endif
  485. Texture mTexture; /* Texture subsystem */
  486. Camera *mCamera; /* Camera subsystem */
  487. GLString mString; /* GL Text subsystem */
  488. Vector<RenderRoom *> mRoomRenderList;
  489. Vector<RenderRoom *> mRooms;
  490. Vector<SkeletalModel *> mModels;
  491. unsigned int mFlags; /* Rendering flags */
  492. unsigned int mWidth; /* Viewport width */
  493. unsigned int mHeight; /* Viewport height */
  494. unsigned int mMode; /* Rendering mode */
  495. unsigned int *mNumTexturesLoaded;
  496. unsigned int *mNextTextureId;
  497. // float mSplash;
  498. int mLock;
  499. int mSkyMesh; /* Skymesh model id */
  500. bool mSkyMeshRotation; /* Should Skymesh be rotated? */
  501. };
  502. #endif