gl_model.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. Copyright (C) 1997-2001 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. /*
  16. d*_t structures are on-disk representations
  17. m*_t structures are in-memory
  18. */
  19. /*
  20. ==============================================================================
  21. BRUSH MODELS
  22. ==============================================================================
  23. */
  24. //
  25. // in memory representation
  26. //
  27. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  28. typedef struct
  29. {
  30. vec3_t position;
  31. } mvertex_t;
  32. typedef struct
  33. {
  34. vec3_t mins, maxs;
  35. vec3_t origin; // for sounds or lights
  36. float radius;
  37. int headnode;
  38. int visleafs; // not including the solid leaf 0
  39. int firstface, numfaces;
  40. } mmodel_t;
  41. #define SIDE_FRONT 0
  42. #define SIDE_BACK 1
  43. #define SIDE_ON 2
  44. #define SURF_PLANEBACK 2
  45. #define SURF_DRAWSKY 4
  46. #define SURF_DRAWTURB 0x10
  47. #define SURF_DRAWBACKGROUND 0x40
  48. #define SURF_UNDERWATER 0x80
  49. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  50. typedef struct
  51. {
  52. unsigned short v[2];
  53. unsigned int cachededgeoffset;
  54. } medge_t;
  55. typedef struct mtexinfo_s
  56. {
  57. float vecs[2][4];
  58. int flags;
  59. int numframes;
  60. struct mtexinfo_s *next; // animation chain
  61. image_t *image;
  62. } mtexinfo_t;
  63. #define VERTEXSIZE 7
  64. typedef struct glpoly_s
  65. {
  66. struct glpoly_s *next;
  67. struct glpoly_s *chain;
  68. int numverts;
  69. int flags; // for SURF_UNDERWATER (not needed anymore?)
  70. float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2)
  71. } glpoly_t;
  72. typedef struct msurface_s
  73. {
  74. int visframe; // should be drawn when node is crossed
  75. cplane_t *plane;
  76. int flags;
  77. int firstedge; // look up in model->surfedges[], negative numbers
  78. int numedges; // are backwards edges
  79. short texturemins[2];
  80. short extents[2];
  81. int light_s, light_t; // gl lightmap coordinates
  82. int dlight_s, dlight_t; // gl lightmap coordinates for dynamic lightmaps
  83. glpoly_t *polys; // multiple if warped
  84. struct msurface_s *texturechain;
  85. struct msurface_s *lightmapchain;
  86. mtexinfo_t *texinfo;
  87. // lighting info
  88. int dlightframe;
  89. int dlightbits;
  90. int lightmaptexturenum;
  91. byte styles[MAXLIGHTMAPS];
  92. float cached_light[MAXLIGHTMAPS]; // values currently used in lightmap
  93. byte *samples; // [numstyles*surfsize]
  94. } msurface_t;
  95. typedef struct mnode_s
  96. {
  97. // common with leaf
  98. int contents; // -1, to differentiate from leafs
  99. int visframe; // node needs to be traversed if current
  100. float minmaxs[6]; // for bounding box culling
  101. struct mnode_s *parent;
  102. // node specific
  103. cplane_t *plane;
  104. struct mnode_s *children[2];
  105. unsigned short firstsurface;
  106. unsigned short numsurfaces;
  107. } mnode_t;
  108. typedef struct mleaf_s
  109. {
  110. // common with node
  111. int contents; // wil be a negative contents number
  112. int visframe; // node needs to be traversed if current
  113. float minmaxs[6]; // for bounding box culling
  114. struct mnode_s *parent;
  115. // leaf specific
  116. int cluster;
  117. int area;
  118. msurface_t **firstmarksurface;
  119. int nummarksurfaces;
  120. } mleaf_t;
  121. //===================================================================
  122. //
  123. // Whole model
  124. //
  125. typedef enum {mod_bad, mod_brush, mod_sprite, mod_alias } modtype_t;
  126. typedef struct model_s
  127. {
  128. char name[MAX_QPATH];
  129. int registration_sequence;
  130. modtype_t type;
  131. int numframes;
  132. int flags;
  133. //
  134. // volume occupied by the model graphics
  135. //
  136. vec3_t mins, maxs;
  137. float radius;
  138. //
  139. // solid volume for clipping
  140. //
  141. qboolean clipbox;
  142. vec3_t clipmins, clipmaxs;
  143. //
  144. // brush model
  145. //
  146. int firstmodelsurface, nummodelsurfaces;
  147. int lightmap; // only for submodels
  148. int numsubmodels;
  149. mmodel_t *submodels;
  150. int numplanes;
  151. cplane_t *planes;
  152. int numleafs; // number of visible leafs, not counting 0
  153. mleaf_t *leafs;
  154. int numvertexes;
  155. mvertex_t *vertexes;
  156. int numedges;
  157. medge_t *edges;
  158. int numnodes;
  159. int firstnode;
  160. mnode_t *nodes;
  161. int numtexinfo;
  162. mtexinfo_t *texinfo;
  163. int numsurfaces;
  164. msurface_t *surfaces;
  165. int numsurfedges;
  166. int *surfedges;
  167. int nummarksurfaces;
  168. msurface_t **marksurfaces;
  169. dvis_t *vis;
  170. byte *lightdata;
  171. // for alias models and skins
  172. image_t *skins[MAX_MD2SKINS];
  173. int extradatasize;
  174. void *extradata;
  175. } model_t;
  176. //============================================================================
  177. void Mod_Init (void);
  178. void Mod_ClearAll (void);
  179. model_t *Mod_ForName (char *name, qboolean crash);
  180. mleaf_t *Mod_PointInLeaf (float *p, model_t *model);
  181. byte *Mod_ClusterPVS (int cluster, model_t *model);
  182. void Mod_Modellist_f (void);
  183. void *Hunk_Begin (int maxsize);
  184. void *Hunk_Alloc (int size);
  185. int Hunk_End (void);
  186. void Hunk_Free (void *base);
  187. void Mod_FreeAll (void);
  188. void Mod_Free (model_t *mod);