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

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