gl_model.h (5317B)
1 /* 2 Copyright (C) 1997-2001 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 21 /* 22 23 d*_t structures are on-disk representations 24 m*_t structures are in-memory 25 26 */ 27 28 /* 29 ============================================================================== 30 31 BRUSH MODELS 32 33 ============================================================================== 34 */ 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 46 typedef struct 47 { 48 vec3_t mins, maxs; 49 vec3_t origin; // for sounds or lights 50 float radius; 51 int headnode; 52 int visleafs; // not including the solid leaf 0 53 int firstface, numfaces; 54 } mmodel_t; 55 56 57 #define SIDE_FRONT 0 58 #define SIDE_BACK 1 59 #define SIDE_ON 2 60 61 62 #define SURF_PLANEBACK 2 63 #define SURF_DRAWSKY 4 64 #define SURF_DRAWTURB 0x10 65 #define SURF_DRAWBACKGROUND 0x40 66 #define SURF_UNDERWATER 0x80 67 68 // !!! if this is changed, it must be changed in asm_draw.h too !!! 69 typedef struct 70 { 71 unsigned short v[2]; 72 unsigned int cachededgeoffset; 73 } medge_t; 74 75 typedef struct mtexinfo_s 76 { 77 float vecs[2][4]; 78 int flags; 79 int numframes; 80 struct mtexinfo_s *next; // animation chain 81 image_t *image; 82 } mtexinfo_t; 83 84 #define VERTEXSIZE 7 85 86 typedef struct glpoly_s 87 { 88 struct glpoly_s *next; 89 struct glpoly_s *chain; 90 int numverts; 91 int flags; // for SURF_UNDERWATER (not needed anymore?) 92 float verts[4][VERTEXSIZE]; // variable sized (xyz s1t1 s2t2) 93 } glpoly_t; 94 95 typedef struct msurface_s 96 { 97 int visframe; // should be drawn when node is crossed 98 99 cplane_t *plane; 100 int flags; 101 102 int firstedge; // look up in model->surfedges[], negative numbers 103 int numedges; // are backwards edges 104 105 short texturemins[2]; 106 short extents[2]; 107 108 int light_s, light_t; // gl lightmap coordinates 109 int dlight_s, dlight_t; // gl lightmap coordinates for dynamic lightmaps 110 111 glpoly_t *polys; // multiple if warped 112 struct msurface_s *texturechain; 113 struct msurface_s *lightmapchain; 114 115 mtexinfo_t *texinfo; 116 117 // lighting info 118 int dlightframe; 119 int dlightbits; 120 121 int lightmaptexturenum; 122 byte styles[MAXLIGHTMAPS]; 123 float cached_light[MAXLIGHTMAPS]; // values currently used in lightmap 124 byte *samples; // [numstyles*surfsize] 125 } msurface_t; 126 127 typedef struct mnode_s 128 { 129 // common with leaf 130 int contents; // -1, to differentiate from leafs 131 int visframe; // node needs to be traversed if current 132 133 float minmaxs[6]; // for bounding box culling 134 135 struct mnode_s *parent; 136 137 // node specific 138 cplane_t *plane; 139 struct mnode_s *children[2]; 140 141 unsigned short firstsurface; 142 unsigned short numsurfaces; 143 } mnode_t; 144 145 146 147 typedef struct mleaf_s 148 { 149 // common with node 150 int contents; // wil be a negative contents number 151 int visframe; // node needs to be traversed if current 152 153 float minmaxs[6]; // for bounding box culling 154 155 struct mnode_s *parent; 156 157 // leaf specific 158 int cluster; 159 int area; 160 161 msurface_t **firstmarksurface; 162 int nummarksurfaces; 163 } mleaf_t; 164 165 166 //=================================================================== 167 168 // 169 // Whole model 170 // 171 172 typedef enum {mod_bad, mod_brush, mod_sprite, mod_alias } modtype_t; 173 174 typedef struct model_s 175 { 176 char name[MAX_QPATH]; 177 178 int registration_sequence; 179 180 modtype_t type; 181 int numframes; 182 183 int flags; 184 185 // 186 // volume occupied by the model graphics 187 // 188 vec3_t mins, maxs; 189 float radius; 190 191 // 192 // solid volume for clipping 193 // 194 qboolean clipbox; 195 vec3_t clipmins, clipmaxs; 196 197 // 198 // brush model 199 // 200 int firstmodelsurface, nummodelsurfaces; 201 int lightmap; // only for submodels 202 203 int numsubmodels; 204 mmodel_t *submodels; 205 206 int numplanes; 207 cplane_t *planes; 208 209 int numleafs; // number of visible leafs, not counting 0 210 mleaf_t *leafs; 211 212 int numvertexes; 213 mvertex_t *vertexes; 214 215 int numedges; 216 medge_t *edges; 217 218 int numnodes; 219 int firstnode; 220 mnode_t *nodes; 221 222 int numtexinfo; 223 mtexinfo_t *texinfo; 224 225 int numsurfaces; 226 msurface_t *surfaces; 227 228 int numsurfedges; 229 int *surfedges; 230 231 int nummarksurfaces; 232 msurface_t **marksurfaces; 233 234 dvis_t *vis; 235 236 byte *lightdata; 237 238 // for alias models and skins 239 image_t *skins[MAX_MD2SKINS]; 240 241 int extradatasize; 242 void *extradata; 243 } model_t; 244 245 //============================================================================ 246 247 void Mod_Init (void); 248 void Mod_ClearAll (void); 249 model_t *Mod_ForName (char *name, qboolean crash); 250 mleaf_t *Mod_PointInLeaf (float *p, model_t *model); 251 byte *Mod_ClusterPVS (int cluster, model_t *model); 252 253 void Mod_Modellist_f (void); 254 255 void *Hunk_Begin (int maxsize); 256 void *Hunk_Alloc (int size); 257 int Hunk_End (void); 258 void Hunk_Free (void *base); 259 260 void Mod_FreeAll (void); 261 void Mod_Free (model_t *mod);