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

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