gl_model.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __MODEL__
  16. #define __MODEL__
  17. #include "modelgen.h"
  18. #include "spritegn.h"
  19. /*
  20. d*_t structures are on-disk representations
  21. m*_t structures are in-memory
  22. */
  23. // entity effects
  24. #define EF_BRIGHTFIELD 1
  25. #define EF_MUZZLEFLASH 2
  26. #define EF_BRIGHTLIGHT 4
  27. #define EF_DIMLIGHT 8
  28. #define EF_FLAG1 16
  29. #define EF_FLAG2 32
  30. #define EF_BLUE 64
  31. #define EF_RED 128
  32. /*
  33. ==============================================================================
  34. BRUSH MODELS
  35. ==============================================================================
  36. */
  37. //
  38. // in memory representation
  39. //
  40. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  41. typedef struct
  42. {
  43. vec3_t position;
  44. } mvertex_t;
  45. #define SIDE_FRONT 0
  46. #define SIDE_BACK 1
  47. #define SIDE_ON 2
  48. // plane_t structure
  49. // !!! if this is changed, it must be changed in asm_i386.h too !!!
  50. typedef struct mplane_s
  51. {
  52. vec3_t normal;
  53. float dist;
  54. byte type; // for texture axis selection and fast side tests
  55. byte signbits; // signx + signy<<1 + signz<<1
  56. byte pad[2];
  57. } mplane_t;
  58. typedef struct texture_s
  59. {
  60. char name[16];
  61. unsigned width, height;
  62. int gl_texturenum;
  63. struct msurface_s *texturechain; // for gl_texsort drawing
  64. int anim_total; // total tenths in sequence ( 0 = no)
  65. int anim_min, anim_max; // time for this frame min <=time< max
  66. struct texture_s *anim_next; // in the animation sequence
  67. struct texture_s *alternate_anims; // bmodels in frmae 1 use these
  68. unsigned offsets[MIPLEVELS]; // four mip maps stored
  69. } texture_t;
  70. #define SURF_PLANEBACK 2
  71. #define SURF_DRAWSKY 4
  72. #define SURF_DRAWSPRITE 8
  73. #define SURF_DRAWTURB 0x10
  74. #define SURF_DRAWTILED 0x20
  75. #define SURF_DRAWBACKGROUND 0x40
  76. #define SURF_UNDERWATER 0x80
  77. #define SURF_DONTWARP 0x100
  78. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  79. typedef struct
  80. {
  81. unsigned short v[2];
  82. unsigned int cachededgeoffset;
  83. } medge_t;
  84. typedef struct
  85. {
  86. float vecs[2][4];
  87. float mipadjust;
  88. texture_t *texture;
  89. int flags;
  90. } mtexinfo_t;
  91. #define VERTEXSIZE 7
  92. typedef struct glpoly_s
  93. {
  94. struct glpoly_s *next;
  95. struct glpoly_s *chain;
  96. int numverts;
  97. int flags; // for SURF_UNDERWATER
  98. float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
  99. } glpoly_t;
  100. typedef struct msurface_s
  101. {
  102. int visframe; // should be drawn when node is crossed
  103. mplane_t *plane;
  104. int flags;
  105. int firstedge; // look up in model->surfedges[], negative numbers
  106. int numedges; // are backwards edges
  107. short texturemins[2];
  108. short extents[2];
  109. int light_s, light_t; // gl lightmap coordinates
  110. glpoly_t *polys; // multiple if warped
  111. struct msurface_s *texturechain;
  112. mtexinfo_t *texinfo;
  113. // lighting info
  114. int dlightframe;
  115. int dlightbits;
  116. int lightmaptexturenum;
  117. byte styles[MAXLIGHTMAPS];
  118. int cached_light[MAXLIGHTMAPS]; // values currently used in lightmap
  119. qboolean cached_dlight; // true if dynamic light in cache
  120. byte *samples; // [numstyles*surfsize]
  121. } msurface_t;
  122. typedef struct mnode_s
  123. {
  124. // common with leaf
  125. int contents; // 0, to differentiate from leafs
  126. int visframe; // node needs to be traversed if current
  127. float minmaxs[6]; // for bounding box culling
  128. struct mnode_s *parent;
  129. // node specific
  130. mplane_t *plane;
  131. struct mnode_s *children[2];
  132. unsigned short firstsurface;
  133. unsigned short numsurfaces;
  134. } mnode_t;
  135. typedef struct mleaf_s
  136. {
  137. // common with node
  138. int contents; // wil be a negative contents number
  139. int visframe; // node needs to be traversed if current
  140. float minmaxs[6]; // for bounding box culling
  141. struct mnode_s *parent;
  142. // leaf specific
  143. byte *compressed_vis;
  144. efrag_t *efrags;
  145. msurface_t **firstmarksurface;
  146. int nummarksurfaces;
  147. int key; // BSP sequence number for leaf's contents
  148. byte ambient_sound_level[NUM_AMBIENTS];
  149. } mleaf_t;
  150. // !!! if this is changed, it must be changed in asm_i386.h too !!!
  151. typedef struct
  152. {
  153. dclipnode_t *clipnodes;
  154. mplane_t *planes;
  155. int firstclipnode;
  156. int lastclipnode;
  157. vec3_t clip_mins;
  158. vec3_t clip_maxs;
  159. } hull_t;
  160. /*
  161. ==============================================================================
  162. SPRITE MODELS
  163. ==============================================================================
  164. */
  165. // FIXME: shorten these?
  166. typedef struct mspriteframe_s
  167. {
  168. int width;
  169. int height;
  170. float up, down, left, right;
  171. int gl_texturenum;
  172. } mspriteframe_t;
  173. typedef struct
  174. {
  175. int numframes;
  176. float *intervals;
  177. mspriteframe_t *frames[1];
  178. } mspritegroup_t;
  179. typedef struct
  180. {
  181. spriteframetype_t type;
  182. mspriteframe_t *frameptr;
  183. } mspriteframedesc_t;
  184. typedef struct
  185. {
  186. int type;
  187. int maxwidth;
  188. int maxheight;
  189. int numframes;
  190. float beamlength; // remove?
  191. void *cachespot; // remove?
  192. mspriteframedesc_t frames[1];
  193. } msprite_t;
  194. /*
  195. ==============================================================================
  196. ALIAS MODELS
  197. Alias models are position independent, so the cache manager can move them.
  198. ==============================================================================
  199. */
  200. typedef struct
  201. {
  202. int firstpose;
  203. int numposes;
  204. float interval;
  205. trivertx_t bboxmin;
  206. trivertx_t bboxmax;
  207. int frame;
  208. char name[16];
  209. } maliasframedesc_t;
  210. typedef struct
  211. {
  212. trivertx_t bboxmin;
  213. trivertx_t bboxmax;
  214. int frame;
  215. } maliasgroupframedesc_t;
  216. typedef struct
  217. {
  218. int numframes;
  219. int intervals;
  220. maliasgroupframedesc_t frames[1];
  221. } maliasgroup_t;
  222. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  223. typedef struct mtriangle_s {
  224. int facesfront;
  225. int vertindex[3];
  226. } mtriangle_t;
  227. #define MAX_SKINS 32
  228. typedef struct {
  229. int ident;
  230. int version;
  231. vec3_t scale;
  232. vec3_t scale_origin;
  233. float boundingradius;
  234. vec3_t eyeposition;
  235. int numskins;
  236. int skinwidth;
  237. int skinheight;
  238. int numverts;
  239. int numtris;
  240. int numframes;
  241. synctype_t synctype;
  242. int flags;
  243. float size;
  244. int numposes;
  245. int poseverts;
  246. int posedata; // numposes*poseverts trivert_t
  247. int commands; // gl command list with embedded s/t
  248. int gl_texturenum[MAX_SKINS][4];
  249. maliasframedesc_t frames[1]; // variable sized
  250. } aliashdr_t;
  251. #define MAXALIASVERTS 1024
  252. #define MAXALIASFRAMES 256
  253. #define MAXALIASTRIS 2048
  254. extern aliashdr_t *pheader;
  255. extern stvert_t stverts[MAXALIASVERTS];
  256. extern mtriangle_t triangles[MAXALIASTRIS];
  257. extern trivertx_t *poseverts[MAXALIASFRAMES];
  258. //===================================================================
  259. //
  260. // Whole model
  261. //
  262. typedef enum {mod_brush, mod_sprite, mod_alias} modtype_t;
  263. #define EF_ROCKET 1 // leave a trail
  264. #define EF_GRENADE 2 // leave a trail
  265. #define EF_GIB 4 // leave a trail
  266. #define EF_ROTATE 8 // rotate (bonus items)
  267. #define EF_TRACER 16 // green split trail
  268. #define EF_ZOMGIB 32 // small blood trail
  269. #define EF_TRACER2 64 // orange split trail + rotate
  270. #define EF_TRACER3 128 // purple trail
  271. typedef struct model_s
  272. {
  273. char name[MAX_QPATH];
  274. qboolean needload; // bmodels and sprites don't cache normally
  275. modtype_t type;
  276. int numframes;
  277. synctype_t synctype;
  278. int flags;
  279. //
  280. // volume occupied by the model graphics
  281. //
  282. vec3_t mins, maxs;
  283. float radius;
  284. //
  285. // solid volume for clipping
  286. //
  287. qboolean clipbox;
  288. vec3_t clipmins, clipmaxs;
  289. //
  290. // brush model
  291. //
  292. int firstmodelsurface, nummodelsurfaces;
  293. int numsubmodels;
  294. dmodel_t *submodels;
  295. int numplanes;
  296. mplane_t *planes;
  297. int numleafs; // number of visible leafs, not counting 0
  298. mleaf_t *leafs;
  299. int numvertexes;
  300. mvertex_t *vertexes;
  301. int numedges;
  302. medge_t *edges;
  303. int numnodes;
  304. mnode_t *nodes;
  305. int numtexinfo;
  306. mtexinfo_t *texinfo;
  307. int numsurfaces;
  308. msurface_t *surfaces;
  309. int numsurfedges;
  310. int *surfedges;
  311. int numclipnodes;
  312. dclipnode_t *clipnodes;
  313. int nummarksurfaces;
  314. msurface_t **marksurfaces;
  315. hull_t hulls[MAX_MAP_HULLS];
  316. int numtextures;
  317. texture_t **textures;
  318. byte *visdata;
  319. byte *lightdata;
  320. char *entities;
  321. unsigned checksum;
  322. unsigned checksum2;
  323. //
  324. // additional model data
  325. //
  326. cache_user_t cache; // only access through Mod_Extradata
  327. } model_t;
  328. //============================================================================
  329. void Mod_Init (void);
  330. void Mod_ClearAll (void);
  331. model_t *Mod_ForName (char *name, qboolean crash);
  332. void *Mod_Extradata (model_t *mod); // handles caching
  333. void Mod_TouchModel (char *name);
  334. mleaf_t *Mod_PointInLeaf (float *p, model_t *model);
  335. byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model);
  336. #endif // __MODEL__