]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - model_shared.h
ae1bb4f99354422b6ec4ba5804de08a4f145b6e9
[xonotic/darkplaces.git] / model_shared.h
1 /*
2 Copyright (C) 1996-1997 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 #ifndef MODEL_SHARED_H
22 #define MODEL_SHARED_H
23
24 typedef enum {ST_SYNC=0, ST_RAND } synctype_t;
25
26 /*
27
28 d*_t structures are on-disk representations
29 m*_t structures are in-memory
30
31 */
32
33 typedef enum {mod_invalid, mod_brushq1, mod_sprite, mod_alias, mod_brushq2, mod_brushq3} modtype_t;
34
35 typedef struct animscene_s
36 {
37         char name[32]; // for viewthing support
38         int firstframe;
39         int framecount;
40         int loop; // true or false
41         float framerate;
42 }
43 animscene_t;
44
45 typedef struct skinframe_s
46 {
47         rtexture_t *stain; // inverse modulate with background (used for decals and such)
48         rtexture_t *merged; // original texture without glow
49         rtexture_t *base; // original texture without pants/shirt/glow
50         rtexture_t *pants; // pants only (in greyscale)
51         rtexture_t *shirt; // shirt only (in greyscale)
52         rtexture_t *nmap; // normalmap (bumpmap for dot3)
53         rtexture_t *gloss; // glossmap (for dot3)
54         rtexture_t *detail; // detail texture (silly bumps for non-dot3)
55         rtexture_t *glow; // glow only (fullbrights)
56         rtexture_t *fog; // alpha of the base texture (if not opaque)
57 }
58 skinframe_t;
59
60 #define MAX_SKINS 256
61
62 typedef struct overridetagname_s
63 {
64         char name[MAX_QPATH];
65 }
66 overridetagname_t;
67
68 // a replacement set of tag names, per skin
69 typedef struct overridetagnameset_s
70 {
71         int num_overridetagnames;
72         overridetagname_t *data_overridetagnames;
73 }
74 overridetagnameset_t;
75
76 // LordHavoc: replaces glpoly, triangle mesh
77 typedef struct surfmesh_s
78 {
79         int num_vertices; // number of vertices in the mesh
80         int num_triangles; // number of triangles in the mesh
81         float *data_vertex3f; // float[verts*3] vertex locations
82         float *data_svector3f; // float[verts*3] direction of 'S' (right) texture axis for each vertex
83         float *data_tvector3f; // float[verts*3] direction of 'T' (down) texture axis for each vertex
84         float *data_normal3f; // float[verts*3] direction of 'R' (out) texture axis for each vertex
85         int *data_lightmapoffsets; // index into surface's lightmap samples for vertex lighting
86         float *data_texcoordtexture2f; // float[verts*2] texcoords for surface texture
87         float *data_texcoordlightmap2f; // float[verts*2] texcoords for lightmap texture
88         float *data_texcoorddetail2f; // float[verts*2] texcoords for detail texture
89         float *data_lightmapcolor4f;
90         int *data_element3i; // int[tris*3] triangles of the mesh, 3 indices into vertex arrays for each
91         int *data_neighbor3i; // int[tris*3] neighboring triangle on each edge (-1 if none)
92
93         int num_collisionvertices;
94         int num_collisiontriangles;
95         float *data_collisionvertex3f;
96         int *data_collisionelement3i;
97 }
98 surfmesh_t;
99
100 #define SHADOWMESHVERTEXHASH 1024
101 typedef struct shadowmeshvertexhash_s
102 {
103         struct shadowmeshvertexhash_s *next;
104 }
105 shadowmeshvertexhash_t;
106
107 typedef struct shadowmesh_s
108 {
109         // next mesh in chain
110         struct shadowmesh_s *next;
111         // used for light mesh (NULL on shadow mesh)
112         rtexture_t *map_diffuse;
113         rtexture_t *map_specular;
114         rtexture_t *map_normal;
115         // buffer sizes
116         int numverts, maxverts;
117         int numtriangles, maxtriangles;
118         // used always
119         float *vertex3f;
120         // used for light mesh (NULL on shadow mesh)
121         float *svector3f;
122         float *tvector3f;
123         float *normal3f;
124         float *texcoord2f;
125         // used always
126         int *element3i;
127         // used for shadow mesh (NULL on light mesh)
128         int *neighbor3i;
129         // these are NULL after Mod_ShadowMesh_Finish is performed, only used
130         // while building meshes
131         shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries;
132 }
133 shadowmesh_t;
134
135
136 #include "matrixlib.h"
137
138 #include "model_brush.h"
139 #include "model_sprite.h"
140 #include "model_alias.h"
141
142 typedef struct model_alias_s
143 {
144         // mdl/md2/md3/zym model formats are treated the same after loading
145
146         // the shader meshes comprising this model
147         int                             aliasnum_meshes;
148         aliasmesh_t             *aliasdata_meshes;
149
150         // for md3 models
151         int                             aliasnum_tags;
152         int                             aliasnum_tagframes;
153         aliastag_t              *aliasdata_tags;
154
155         // for skeletal models
156         int                             aliasnum_bones;
157         aliasbone_t             *aliasdata_bones;
158         int                             aliasnum_poses;
159         float                   *aliasdata_poses;
160 }
161 model_alias_t;
162
163 typedef struct model_sprite_s
164 {
165         int                             sprnum_type;
166         mspriteframe_t  *sprdata_frames;
167 }
168 model_sprite_t;
169
170 struct trace_s;
171
172 typedef struct model_brush_s
173 {
174         // true if this model is a HalfLife .bsp file
175         qboolean ishlbsp;
176         // string of entity definitions (.map format)
177         char *entities;
178         // number of submodels in this map (just used by server to know how many
179         // submodels to load)
180         int numsubmodels;
181         // pointers to each of the submodels if .isworldmodel is true
182         struct model_s **submodels;
183
184         // pvs
185         int num_pvsclusters;
186         int num_pvsclusterbytes;
187         unsigned char *data_pvsclusters;
188         // example
189         //pvschain = model->brush.data_pvsclusters + mycluster * model->brush.num_pvsclusterbytes;
190         //if (pvschain[thatcluster >> 3] & (1 << (thatcluster & 7)))
191
192         // a mesh containing all shadow casting geometry for the whole model (including submodels), portions of this are referenced by each surface's num_firstshadowmeshtriangle
193         shadowmesh_t *shadowmesh;
194
195         // common functions
196         int (*SuperContentsFromNativeContents)(struct model_s *model, int nativecontents);
197         int (*NativeContentsFromSuperContents)(struct model_s *model, int supercontents);
198         qbyte *(*GetPVS)(struct model_s *model, const vec3_t p);
199         int (*FatPVS)(struct model_s *model, const vec3_t org, vec_t radius, qbyte *pvsbuffer, int pvsbufferlength);
200         int (*BoxTouchingPVS)(struct model_s *model, const qbyte *pvs, const vec3_t mins, const vec3_t maxs);
201         void (*LightPoint)(struct model_s *model, const vec3_t p, vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal);
202         void (*FindNonSolidLocation)(struct model_s *model, const vec3_t in, vec3_t out, vec_t radius);
203         // these are actually only found on brushq1, but NULL is handled gracefully
204         void (*AmbientSoundLevelsForPoint)(struct model_s *model, const vec3_t p, qbyte *out, int outsize);
205         void (*RoundUpToHullSize)(struct model_s *cmodel, const vec3_t inmins, const vec3_t inmaxs, vec3_t outmins, vec3_t outmaxs);
206
207         char skybox[64];
208
209         rtexture_t *solidskytexture;
210         rtexture_t *alphaskytexture;
211 }
212 model_brush_t;
213
214 typedef struct model_brushq1_s
215 {
216         // lightmap format, set to r_lightmaprgba when model is loaded
217         int                             lightmaprgba;
218
219         dmodel_t                *submodels;
220
221         int                             numplanes;
222         mplane_t                *planes;
223
224         // number of actual leafs (including 0 which is solid)
225         int                             num_leafs;
226         // visible leafs, not counting 0 (solid)
227         int                             num_visleafs;
228         mleaf_t                 *data_leafs;
229
230         int                             numvertexes;
231         mvertex_t               *vertexes;
232
233         int                             numedges;
234         medge_t                 *edges;
235
236         int                             numnodes;
237         mnode_t                 *nodes;
238
239         int                             numtexinfo;
240         mtexinfo_t              *texinfo;
241
242         int                             numsurfaces;
243         msurface_t              *surfaces;
244         int                             *surfacevisframes;
245         int                             *surfacepvsframes;
246         msurface_t              *surfacepvsnext;
247
248         int                             numsurfedges;
249         int                             *surfedges;
250
251         int                             numclipnodes;
252         dclipnode_t             *clipnodes;
253
254         int                             nummarksurfaces;
255         int                             *marksurfaces;
256
257         hull_t                  hulls[MAX_MAP_HULLS];
258
259         int                             numtextures;
260         texture_t               *textures;
261
262         int                             num_compressedpvs;
263         qbyte                   *data_compressedpvs;
264
265         int                             num_lightdata;
266         qbyte                   *lightdata;
267
268         int                             numportals;
269         mportal_t               *portals;
270
271         int                             numportalpoints;
272         mvertex_t               *portalpoints;
273
274         int                             numlights;
275         mlight_t                *lights;
276
277         // pvs visibility marking
278         mleaf_t                 *pvsviewleaf;
279         int                             pvsviewleafnovis;
280         int                             pvsframecount;
281         mleaf_t                 *pvsleafchain;
282         int                             *pvssurflist;
283         int                             pvssurflistlength;
284         // these get rebuilt as the player moves around if this is the world,
285         // otherwise they are left alone (no pvs for bmodels)
286         msurface_t              ***pvstexturechains;
287         msurface_t              **pvstexturechainsbuffer;
288         int                             *pvstexturechainslength;
289
290         // lightmap update chains for light styles
291         int                             light_styles;
292         qbyte                   *light_style;
293         int                             *light_stylevalue;
294         msurface_t              ***light_styleupdatechains;
295         msurface_t              **light_styleupdatechainsbuffer;
296
297         mleaf_t *(*PointInLeaf)(struct model_s *model, const float *p);
298         void (*BuildPVSTextureChains)(struct model_s *model);
299 }
300 model_brushq1_t;
301
302 /* MSVC can't compile empty structs, so this is commented out for now
303 typedef struct model_brushq2_s
304 {
305 }
306 model_brushq2_t;
307 */
308
309 // surfaceflags from bsp
310 #define Q3SURFACEFLAG_NODAMAGE 1
311 #define Q3SURFACEFLAG_SLICK 2
312 #define Q3SURFACEFLAG_SKY 4
313 #define Q3SURFACEFLAG_LADDER 8
314 #define Q3SURFACEFLAG_NOIMPACT 16
315 #define Q3SURFACEFLAG_NOMARKS 32
316 #define Q3SURFACEFLAG_FLESH 64
317 #define Q3SURFACEFLAG_NODRAW 128
318 #define Q3SURFACEFLAG_HINT 256
319 #define Q3SURFACEFLAG_SKIP 512
320 #define Q3SURFACEFLAG_NOLIGHTMAP 1024
321 #define Q3SURFACEFLAG_POINTLIGHT 2048
322 #define Q3SURFACEFLAG_METALSTEPS 4096
323 #define Q3SURFACEFLAG_NOSTEPS 8192
324 #define Q3SURFACEFLAG_NONSOLID 16384
325 #define Q3SURFACEFLAG_LIGHTFILTER 32768
326 #define Q3SURFACEFLAG_ALPHASHADOW 65536
327 #define Q3SURFACEFLAG_NODLIGHT 131072
328 #define Q3SURFACEFLAG_DUST 262144
329
330 // surfaceparms from shaders
331 #define Q3SURFACEPARM_ALPHASHADOW 1
332 #define Q3SURFACEPARM_AREAPORTAL 2
333 #define Q3SURFACEPARM_CLUSTERPORTAL 4
334 #define Q3SURFACEPARM_DETAIL 8
335 #define Q3SURFACEPARM_DONOTENTER 16
336 #define Q3SURFACEPARM_FOG 32
337 #define Q3SURFACEPARM_LAVA 64
338 #define Q3SURFACEPARM_LIGHTFILTER 128
339 #define Q3SURFACEPARM_METALSTEPS 256
340 #define Q3SURFACEPARM_NODAMAGE 512
341 #define Q3SURFACEPARM_NODLIGHT 1024
342 #define Q3SURFACEPARM_NODRAW 2048
343 #define Q3SURFACEPARM_NODROP 4096
344 #define Q3SURFACEPARM_NOIMPACT 8192
345 #define Q3SURFACEPARM_NOLIGHTMAP 16384
346 #define Q3SURFACEPARM_NOMARKS 32768
347 #define Q3SURFACEPARM_NOMIPMAPS 65536
348 #define Q3SURFACEPARM_NONSOLID 131072
349 #define Q3SURFACEPARM_ORIGIN 262144
350 #define Q3SURFACEPARM_PLAYERCLIP 524288
351 #define Q3SURFACEPARM_SKY 1048576
352 #define Q3SURFACEPARM_SLICK 2197152
353 #define Q3SURFACEPARM_SLIME 4194304
354 #define Q3SURFACEPARM_STRUCTURAL 8388608
355 #define Q3SURFACEPARM_TRANS 16777216
356 #define Q3SURFACEPARM_WATER 33554432
357 #define Q3SURFACEPARM_POINTLIGHT 67108864
358
359 // various flags from shaders
360 #define Q3TEXTUREFLAG_TWOSIDED 1
361 #define Q3TEXTUREFLAG_ADDITIVE 2
362 #define Q3TEXTUREFLAG_NOMIPMAPS 4
363 #define Q3TEXTUREFLAG_NOPICMIP 8
364 #define Q3TEXTUREFLAG_AUTOSPRITE 16
365 #define Q3TEXTUREFLAG_AUTOSPRITE2 32
366 #define Q3TEXTUREFLAG_ALPHATEST 64
367
368 struct q3msurface_s;
369 typedef struct q3mtexture_s
370 {
371         char name[Q3PATHLENGTH];
372         char firstpasstexturename[Q3PATHLENGTH];
373         int surfaceflags;
374         int nativecontents;
375         int supercontents;
376         int surfaceparms;
377         int textureflags;
378
379         int number;
380         skinframe_t skin;
381
382         int numfaces;
383         struct q3msurface_s **facelist;
384         int *facenumlist;
385 }
386 q3mtexture_t;
387
388 typedef struct q3mnode_s
389 {
390         //this part shared between node and leaf
391         struct mplane_s *plane; // != NULL
392         struct q3mnode_s *parent;
393         vec3_t mins;
394         vec3_t maxs;
395         // this part unique to nodes
396         struct q3mnode_s *children[2];
397 }
398 q3mnode_t;
399
400 typedef struct q3mleaf_s
401 {
402         //this part shared between node and leaf
403         struct mplane_s *plane; // == NULL
404         struct q3mnode_s *parent;
405         vec3_t mins;
406         vec3_t maxs;
407         // this part unique to leafs
408         int clusterindex;
409         int areaindex;
410         int numleaffaces;
411         struct q3msurface_s **firstleafface;
412         int *firstleaffacenum;
413         int numleafbrushes;
414         struct q3mbrush_s **firstleafbrush;
415 }
416 q3mleaf_t;
417
418 typedef struct q3mmodel_s
419 {
420         vec3_t mins;
421         vec3_t maxs;
422         int numfaces;
423         struct q3msurface_s *firstface;
424         int numbrushes;
425         struct q3mbrush_s *firstbrush;
426 }
427 q3mmodel_t;
428
429 typedef struct q3mbrush_s
430 {
431         struct colbrushf_s *colbrushf;
432         int numbrushsides;
433         struct q3mbrushside_s *firstbrushside;
434         struct q3mtexture_s *texture;
435 }
436 q3mbrush_t;
437
438 typedef struct q3mbrushside_s
439 {
440         struct mplane_s *plane;
441         struct q3mtexture_s *texture;
442 }
443 q3mbrushside_t;
444
445 typedef struct q3meffect_s
446 {
447         char shadername[Q3PATHLENGTH];
448         struct q3mbrush_s *brush;
449         int unknown; // 5 or -1
450 }
451 q3meffect_t;
452
453 typedef struct q3msurface_s
454 {
455         // FIXME: collisionmarkframe should be kept in a separate array
456         // FIXME: visframe should be kept in a separate array
457         // FIXME: shadowmark should be kept in a separate array
458
459         struct q3mtexture_s *texture;
460         struct q3meffect_s *effect;
461         rtexture_t *lightmaptexture;
462         int collisionmarkframe; // don't collide twice in one trace
463         int visframe; // visframe == r_framecount means it is visible this frame
464         // bounding box for culling
465         float mins[3];
466         float maxs[3];
467
468         int num_vertices;
469         int num_triangles;
470         float *data_vertex3f;
471         float *data_svector3f;
472         float *data_tvector3f;
473         float *data_normal3f;
474         float *data_texcoordtexture2f;
475         float *data_texcoordlightmap2f;
476         float *data_color4f;
477         int *data_element3i;
478         int *data_neighbor3i;
479
480         int num_collisionvertices;
481         int num_collisiontriangles;
482         float *data_collisionvertex3f;
483         int *data_collisionelement3i;
484
485         // index into model->brush.shadowmesh
486         int num_firstshadowmeshtriangle;
487
488         // used for shadow volume generation
489         int shadowmark;
490 }
491 q3msurface_t;
492
493 typedef struct model_brushq3_s
494 {
495         // if non-zero this is a submodel
496         // (this is the number of the submodel, an index into data_models)
497         int submodel;
498
499         int num_textures;
500         q3mtexture_t *data_textures;
501         q3msurface_t **data_texturefaces;
502         int *data_texturefacenums;
503
504         int num_planes;
505         mplane_t *data_planes;
506
507         int num_nodes;
508         q3mnode_t *data_nodes;
509
510         int num_leafs;
511         q3mleaf_t *data_leafs;
512
513         int num_leafbrushes;
514         q3mbrush_t **data_leafbrushes;
515
516         int num_leaffaces;
517         q3msurface_t **data_leaffaces;
518         int *data_leaffacenums;
519
520         int num_models;
521         q3mmodel_t *data_models;
522         // each submodel gets its own model struct so this is different for each.
523         q3mmodel_t *data_thismodel;
524
525         int num_brushes;
526         q3mbrush_t *data_brushes;
527
528         int num_brushsides;
529         q3mbrushside_t *data_brushsides;
530
531         int num_vertices;
532         float *data_vertex3f;
533         float *data_texcoordtexture2f;
534         float *data_texcoordlightmap2f;
535         float *data_svector3f;
536         float *data_tvector3f;
537         float *data_normal3f;
538         float *data_color4f;
539
540         int num_triangles;
541         int *data_element3i;
542         int *data_neighbor3i;
543
544         int num_effects;
545         q3meffect_t *data_effects;
546
547         int num_faces;
548         q3msurface_t *data_faces;
549
550         // lightmap textures
551         int num_lightmaps;
552         rtexture_t **data_lightmaps;
553
554         // voxel light data with directional shading
555         int num_lightgrid;
556         q3dlightgrid_t *data_lightgrid;
557         // size of each cell (may vary by map, typically 64 64 128)
558         float num_lightgrid_cellsize[3];
559         // 1.0 / num_lightgrid_cellsize
560         float num_lightgrid_scale[3];
561         // dimensions of the world model in lightgrid cells
562         int num_lightgrid_imins[3];
563         int num_lightgrid_imaxs[3];
564         int num_lightgrid_isize[3];
565         // indexing/clamping
566         int num_lightgrid_dimensions[3];
567         // transform modelspace coordinates to lightgrid index
568         matrix4x4_t num_lightgrid_indexfromworld;
569 }
570 model_brushq3_t;
571
572 typedef struct model_s
573 {
574         // name and path of model, for example "progs/player.mdl"
575         char                    name[MAX_QPATH];
576         // model needs to be loaded if this is false
577         qboolean                loaded;
578         // set if the model is used in current map, models which are not, are purged
579         qboolean                used;
580         // true if this is the world model (I.E. defines what sky to use, and may contain submodels)
581         qboolean                isworldmodel;
582         // CRC of the file this model was loaded from, to reload if changed
583         unsigned int    crc;
584         // mod_brush, mod_alias, mod_sprite
585         modtype_t               type;
586         // memory pool for allocations
587         mempool_t               *mempool;
588         // all models use textures...
589         rtexturepool_t  *texturepool;
590         // flags from the model file
591         int                             flags;
592         // engine calculated flags, ones that can not be set in the file
593         int                             flags2;
594         // number of QC accessible frame(group)s in the model
595         int                             numframes;
596         // number of QC accessible skin(group)s in the model
597         int                             numskins;
598         // whether to randomize animated framegroups
599         synctype_t              synctype;
600         // bounding box at angles '0 0 0'
601         vec3_t                  normalmins, normalmaxs;
602         // bounding box if yaw angle is not 0, but pitch and roll are
603         vec3_t                  yawmins, yawmaxs;
604         // bounding box if pitch or roll are used
605         vec3_t                  rotatedmins, rotatedmaxs;
606         // sphere radius, usable at any angles
607         float                   radius;
608         // squared sphere radius for easier comparisons
609         float                   radius2;
610         // skin animation info
611         animscene_t             *skinscenes; // [numskins]
612         // skin animation info
613         animscene_t             *animscenes; // [numframes]
614         // range of surface numbers in this (sub)model
615         int                             firstmodelsurface;
616         int                             nummodelsurfaces;
617         // list of surface numbers in this (sub)model
618         int                             *surfacelist;
619         // entire static model in one set of arrays
620         // (portions referenced by each surface)
621         surfmesh_t              *entiremesh;
622         // draw the model's sky polygons (only used by brush models)
623         void(*DrawSky)(struct entity_render_s *ent);
624         // draw the model using lightmap/dlight shading
625         void(*Draw)(struct entity_render_s *ent);
626         // gathers info on which clusters and surfaces are lit by light, as well as calculating a bounding box
627         void(*GetLightInfo)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outclusterlist, qbyte *outclusterpvs, int *outnumclusterspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer);
628         // draw a shadow volume for the model based on light source
629         void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist);
630         // draw the lighting on a model (through stencil)
631         void(*DrawLight)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist);
632         // trace a box against this model
633         void (*TraceBox)(struct model_s *model, int frame, struct trace_s *trace, const vec3_t boxstartmins, const vec3_t boxstartmaxs, const vec3_t boxendmins, const vec3_t boxendmaxs, int hitsupercontentsmask);
634         // fields belonging to each type of model
635         model_alias_t   alias;
636         model_sprite_t  sprite;
637         model_brush_t   brush;
638         model_brushq1_t brushq1;
639         /* MSVC can't handle an empty struct, so this is commented out for now
640         model_brushq2_t brushq2;
641         */
642         model_brushq3_t brushq3;
643         // skin files can have different tags for each skin
644         overridetagnameset_t    *data_overridetagnamesforskin;
645         // flags this model for offseting sounds to the model center (used by brush models)
646         int soundfromcenter;
647 }
648 model_t;
649
650 //============================================================================
651
652 // this can be used for anything without a valid texture
653 extern rtexture_t *r_notexture;
654 #define NUM_DETAILTEXTURES 1
655 extern rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
656 // every texture must be in a pool...
657 extern rtexturepool_t *mod_shared_texturepool;
658
659 extern rtexture_t *mod_shared_distorttexture[64];
660
661 // model loading
662 extern model_t *loadmodel;
663 extern qbyte *mod_base;
664 // sky/water subdivision
665 //extern cvar_t gl_subdivide_size;
666 // texture fullbrights
667 extern cvar_t r_fullbrights;
668
669 void Mod_Init (void);
670 void Mod_CheckLoaded (model_t *mod);
671 void Mod_ClearAll (void);
672 model_t *Mod_FindName (const char *name);
673 model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel);
674 void Mod_UnloadModel (model_t *mod);
675
676 void Mod_ClearUsed(void);
677 void Mod_PurgeUnused(void);
678 void Mod_LoadModels(void);
679
680 extern model_t *loadmodel;
681 extern char loadname[32];       // for hunk tags
682
683 int Mod_BuildVertexRemapTableFromElements(int numelements, const int *elements, int numvertices, int *remapvertices);
684 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
685 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
686 void Mod_BuildNormals(int numverts, int numtriangles, const float *vertex3f, const int *elements, float *normal3f);
687 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
688
689 surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, int numcollisionvertices, int numcollisiontriangles, qboolean detailtexcoords, qboolean lightmapoffsets, qboolean vertexcolors);
690
691 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts, int maxtriangles, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, int light, int neighbors, int expandable);
692 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh, int light, int neighbors);
693 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, float *vertex14f);
694 void Mod_ShadowMesh_AddTriangle(mempool_t *mempool, shadowmesh_t *mesh, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, float *vertex14f);
695 void Mod_ShadowMesh_AddMesh(mempool_t *mempool, shadowmesh_t *mesh, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, const float *vertex3f, const float *svector3f, const float *tvector3f, const float *normal3f, const float *texcoord2f, int numtris, const int *element3i);
696 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int maxverts, int maxtriangles, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, int light, int neighbors, int expandable);
697 shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh, int light, int neighbors);
698 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
699 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
700
701 int Mod_LoadSkinFrame(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture);
702 int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, char *basename, int textureflags, int loadpantsandshirt, int usedetailtexture, int loadglowtexture, qbyte *skindata, int width, int height);
703
704 // used for talking to the QuakeC mainly
705 int Mod_Q1BSP_NativeContentsFromSuperContents(struct model_s *model, int supercontents);
706 int Mod_Q1BSP_SuperContentsFromNativeContents(struct model_s *model, int nativecontents);
707
708 extern cvar_t r_mipskins;
709
710 typedef struct skinfileitem_s
711 {
712         struct skinfileitem_s *next;
713         char name[MAX_QPATH];
714         char replacement[MAX_QPATH];
715 }
716 skinfileitem_t;
717
718 typedef struct skinfile_s
719 {
720         struct skinfile_s *next;
721         skinfileitem_t *items;
722 }
723 skinfile_t;
724
725 skinfile_t *Mod_LoadSkinFiles(void);
726 void Mod_FreeSkinFiles(skinfile_t *skinfile);
727 int Mod_CountSkinFiles(skinfile_t *skinfile);
728
729 void Mod_SnapVertices(int numcomponents, int numvertices, float *vertices, float snap);
730 int Mod_RemoveDegenerateTriangles(int numtriangles, const int *inelement3i, int *outelement3i, const float *vertex3f);
731
732 #endif  // MODEL_SHARED_H
733