2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
21 #ifndef MODEL_SHARED_H
22 #define MODEL_SHARED_H
25 #include "r_qshader.h"
27 #include "r_textures.h"
28 #include "matrixlib.h"
30 typedef enum synctype_e {ST_SYNC=0, ST_RAND } synctype_t;
34 d*_t structures are on-disk representations
35 m*_t structures are in-memory
39 typedef enum modtype_e {mod_invalid, mod_brushq1, mod_sprite, mod_alias, mod_brushq2, mod_brushq3, mod_obj, mod_null} modtype_t;
41 typedef struct animscene_s
43 char name[32]; // for viewthing support
46 int loop; // true or false
51 typedef struct skinframe_s
53 rtexture_t *stain; // inverse modulate with background (used for decals and such)
54 rtexture_t *merged; // original texture without glow
55 rtexture_t *base; // original texture without pants/shirt/glow
56 rtexture_t *pants; // pants only (in greyscale)
57 rtexture_t *shirt; // shirt only (in greyscale)
58 rtexture_t *nmap; // normalmap (bumpmap for dot3)
59 rtexture_t *gloss; // glossmap (for dot3)
60 rtexture_t *glow; // glow only (fullbrights)
61 rtexture_t *fog; // alpha of the base texture (if not opaque)
62 rtexture_t *reflect; // colored mask for cubemap reflections
63 // accounting data for hash searches:
64 // the compare variables are used to identify internal skins from certain
66 // (so that two q1bsp maps with the same texture name for different
67 // textures do not have any conflicts)
68 struct skinframe_s *next; // next on hash chain
69 char basename[MAX_QPATH]; // name of this
70 int textureflags; // texture flags to use
74 // mark and sweep garbage collection, this value is updated to a new value
75 // on each level change for the used skinframes, if some are not used they
77 unsigned int loadsequence;
78 // indicates whether this texture has transparent pixels
80 // average texture color, if applicable
82 // for mdl skins, we actually only upload on first use (many are never used, and they are almost never used in both base+pants+shirt and merged modes)
83 unsigned char *qpixels;
86 qbool qhascolormapping;
88 qbool qgeneratemerged;
96 typedef struct texvecvertex_s
103 typedef struct blendweights_s
105 unsigned char index[4];
106 unsigned char influence[4];
110 typedef struct r_meshbuffer_s
112 int bufferobject; // OpenGL
113 void *devicebuffer; // Direct3D
116 qbool isuniformbuffer;
119 char name[MAX_QPATH];
123 // used for mesh lists in q1bsp/q3bsp map models
124 // (the surfaces reference portions of these meshes)
125 typedef struct surfmesh_s
127 // triangle data in system memory
128 int num_triangles; // number of triangles in the mesh
129 int *data_element3i; // int[tris*3] triangles of the mesh, 3 indices into vertex arrays for each
131 // vertex data in system memory
132 int num_vertices; // number of vertices in the mesh
133 float *data_vertex3f; // float[verts*3] vertex locations
134 float *data_svector3f; // float[verts*3] direction of 'S' (right) texture axis for each vertex
135 float *data_tvector3f; // float[verts*3] direction of 'T' (down) texture axis for each vertex
136 float *data_normal3f; // float[verts*3] direction of 'R' (out) texture axis for each vertex
137 float *data_texcoordtexture2f; // float[verts*2] texcoords for surface texture
138 float *data_texcoordlightmap2f; // float[verts*2] texcoords for lightmap texture
139 float *data_lightmapcolor4f;
140 unsigned char *data_skeletalindex4ub;
141 unsigned char *data_skeletalweight4ub;
142 int *data_lightmapoffsets; // index into surface's lightmap samples for vertex lighting
143 // index buffer - only one of these will be non-NULL
144 r_meshbuffer_t *data_element3i_indexbuffer;
145 int data_element3i_bufferoffset;
146 unsigned short *data_element3s; // unsigned short[tris*3] triangles of the mesh in unsigned short format (NULL if num_vertices > 65536)
147 r_meshbuffer_t *data_element3s_indexbuffer;
148 int data_element3s_bufferoffset;
150 r_meshbuffer_t *data_vertex3f_vertexbuffer;
151 int data_vertex3f_bufferoffset;
152 r_meshbuffer_t *data_svector3f_vertexbuffer;
153 int data_svector3f_bufferoffset;
154 r_meshbuffer_t *data_tvector3f_vertexbuffer;
155 int data_tvector3f_bufferoffset;
156 r_meshbuffer_t *data_normal3f_vertexbuffer;
157 int data_normal3f_bufferoffset;
158 r_meshbuffer_t *data_texcoordtexture2f_vertexbuffer;
159 int data_texcoordtexture2f_bufferoffset;
160 r_meshbuffer_t *data_texcoordlightmap2f_vertexbuffer;
161 int data_texcoordlightmap2f_bufferoffset;
162 r_meshbuffer_t *data_lightmapcolor4f_vertexbuffer;
163 int data_lightmapcolor4f_bufferoffset;
164 r_meshbuffer_t *data_skeletalindex4ub_vertexbuffer;
165 int data_skeletalindex4ub_bufferoffset;
166 r_meshbuffer_t *data_skeletalweight4ub_vertexbuffer;
167 int data_skeletalweight4ub_bufferoffset;
168 // morph blending, these are zero if model is skeletal or static
170 struct md3vertex_s *data_morphmd3vertex;
171 struct trivertx_s *data_morphmdlvertex;
172 struct texvecvertex_s *data_morphtexvecvertex;
173 float *data_morphmd2framesize6f;
174 float num_morphmdlframescale[3];
175 float num_morphmdlframetranslate[3];
176 // skeletal blending, these are NULL if model is morph or static
177 struct blendweights_s *data_blendweights;
179 unsigned short *blends;
180 // set if there is some kind of animation on this model
183 // dynamic mesh building support (Mod_Mesh_*)
184 int num_vertexhashsize; // always pow2 for simple masking
185 int *data_vertexhash; // hash table - wrapping buffer for storing index of similar vertex with -1 as terminator
186 int max_vertices; // preallocated size of data_vertex3f and friends (always >= num_vertices)
187 int max_triangles; // preallocated size of data_element3i
191 #define SHADOWMESHVERTEXHASH 1024
192 typedef struct shadowmeshvertexhash_s
194 struct shadowmeshvertexhash_s *next;
196 shadowmeshvertexhash_t;
198 typedef struct shadowmesh_s
205 r_meshbuffer_t *vbo_vertexbuffer;
206 int vbooffset_vertex3f;
211 r_meshbuffer_t *element3i_indexbuffer;
212 int element3i_bufferoffset;
213 unsigned short *element3s;
214 r_meshbuffer_t *element3s_indexbuffer;
215 int element3s_bufferoffset;
217 // used for shadow mapping cubemap side partitioning
218 int sideoffsets[6], sidetotals[6];
220 // these are NULL after Mod_ShadowMesh_Finish is performed, only used
221 // while building meshes
222 shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries;
226 typedef struct texture_s
233 unsigned int width, height;
235 //unsigned int flags;
237 // base material flags
238 int basematerialflags;
239 // current material flags (updated each bmodel render)
240 int currentmaterialflags;
241 // base material alpha (used for Q2 materials)
244 // PolygonOffset values for rendering this material
245 // (these are added to the r_refdef values and submodel values)
246 float biaspolygonfactor;
247 float biaspolygonoffset;
249 // textures to use when rendering this material (derived from materialshaderpass)
250 skinframe_t *currentskinframe;
251 // textures to use for terrain texture blending (derived from backgroundshaderpass)
252 skinframe_t *backgroundcurrentskinframe;
254 // total frames in sequence and alternate sequence
256 // direct pointers to each of the frames in the sequences
257 // (indexed as [alternate][frame])
258 struct texture_s *anim_frames[2][10];
259 // 1 = q1bsp animation with anim_total[0] >= 2 (animated) or anim_total[1] >= 1 (alternate frame set)
260 // 2 = q2bsp animation with anim_total[0] >= 2 (uses self.frame)
263 // renderer checks if this texture needs updating...
264 int update_lastrenderframe;
265 void *update_lastrenderentity;
266 // the current alpha of this texture (may be affected by r_wateralpha, also basealpha, and ent->alpha)
268 // current value of blendfunc - one of:
269 // {GL_SRC_ALPHA, GL_ONE}
270 // {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}
271 // {customblendfunc[0], customblendfunc[1]}
273 int currentblendfunc[2];
274 // the current texture frame in animation
275 struct texture_s *currentframe;
276 // current texture transform matrix (used for water scrolling)
277 matrix4x4_t currenttexmatrix;
278 matrix4x4_t currentbackgroundtexmatrix;
280 // various q3 shader features
281 q3shaderinfo_deform_t deforms[Q3MAXDEFORMS];
282 texture_shaderpass_t *shaderpasses[Q3SHADER_MAXLAYERS]; // all shader passes in one array
283 texture_shaderpass_t *materialshaderpass; // equal to one of shaderpasses[] or NULL
284 texture_shaderpass_t *backgroundshaderpass; // equal to one of shaderpasses[] or NULL
285 unsigned char startpreshaderpass; // range within shaderpasses[]
286 unsigned char endpreshaderpass; // number of preshaderpasses
287 unsigned char startpostshaderpass; // range within shaderpasses[]
288 unsigned char endpostshaderpass; // number of postshaderpasses
291 rtexture_t *basetexture; // original texture without pants/shirt/glow
292 rtexture_t *pantstexture; // pants only (in greyscale)
293 rtexture_t *shirttexture; // shirt only (in greyscale)
294 rtexture_t *nmaptexture; // normalmap (bumpmap for dot3)
295 rtexture_t *glosstexture; // glossmap (for dot3)
296 rtexture_t *glowtexture; // glow only (fullbrights)
297 rtexture_t *fogtexture; // alpha of the base texture (if not opaque)
298 rtexture_t *reflectmasktexture; // mask for fake reflections
299 rtexture_t *reflectcubetexture; // fake reflections cubemap
300 rtexture_t *backgroundbasetexture; // original texture without pants/shirt/glow
301 rtexture_t *backgroundnmaptexture; // normalmap (bumpmap for dot3)
302 rtexture_t *backgroundglosstexture; // glossmap (for dot3)
303 rtexture_t *backgroundglowtexture; // glow only (fullbrights)
306 // rendering parameters - updated by R_GetCurrentTexture using rsurface.render_* fields
307 // (almost) all map textures are lightmap (no MATERIALFLAG_MODELLIGHT set),
308 // (almost) all model textures are MATERIALFLAG_MODELLIGHT,
309 // MATERIALFLAG_FULLBRIGHT is rendered as a forced MATERIALFLAG_MODELLIGHT with rtlights disabled
310 float render_glowmod[3];
311 // MATERIALFLAG_MODELLIGHT uses these parameters
312 float render_modellight_ambient[3];
313 float render_modellight_diffuse[3];
314 float render_modellight_lightdir_world[3];
315 float render_modellight_lightdir_local[3];
316 float render_modellight_specular[3];
317 // lightmap rendering (not MATERIALFLAG_MODELLIGHT)
318 float render_lightmap_ambient[3];
319 float render_lightmap_diffuse[3];
320 float render_lightmap_specular[3];
321 // rtlights use these colors for the materials on this entity
322 float render_rtlight_diffuse[3];
323 float render_rtlight_specular[3];
324 // tint applied on top of render_*_diffuse for pants layer
325 float render_colormap_pants[3];
326 // tint applied on top of render_*_diffuse for shirt layer
327 float render_colormap_shirt[3];
330 int customblendfunc[2];
337 // we have to load the texture multiple times when Q2SURF_ flags differ,
338 // though it still shares the skinframe
344 /// this points to a variant of the sky texture that has MATERIALFLAG_NOSHADOW, for the e1m5 logo shadow trick.
345 struct texture_s *skynoshadowtexture;
348 float reflectmin; // when refraction is used, minimum amount of reflection (when looking straight down)
349 float reflectmax; // when refraction is used, maximum amount of reflection (when looking parallel to water)
350 float refractfactor; // amount of refraction distort (1.0 = like the cvar specifies)
351 vec4_t refractcolor4f; // color tint of refraction (including alpha factor)
352 float reflectfactor; // amount of reflection distort (1.0 = like the cvar specifies)
353 vec4_t reflectcolor4f; // color tint of reflection (including alpha factor)
354 float r_water_wateralpha; // additional wateralpha to apply when r_water is active
355 float r_water_waterscroll[2]; // scale and speed
356 float refractive_index; // used by r_shadow_bouncegrid for bending photons for refracted light
357 int camera_entity; // entity number for use by cameras
360 dpoffsetmapping_technique_t offsetmapping;
364 // transparent sort category
365 dptransparentsortcategory_t transparentsort;
368 float specularscalemod;
369 float specularpowermod;
371 // diffuse and ambient
372 float rtlightambient;
374 // used by Mod_Mesh_GetTexture for drawflag and materialflag overrides, to disambiguate the same texture with different hints
376 int mesh_defaulttexflags;
377 int mesh_defaultmaterialflags;
381 typedef struct mtexinfo_s
383 float vecs[2][4]; // [s/t][xyz offset]
386 int q2flags; // miptex flags + overrides
387 int q2value; // light emission, etc
388 char q2texture[32]; // texture name (textures/*.wal)
389 int q2nexttexinfo; // for animations, -1 = end of chain
393 typedef struct msurface_lightmapinfo_s
395 // texture mapping properties used by this surface
396 mtexinfo_t *texinfo; // q1bsp
397 // index into r_refdef.scene.lightstylevalue array, 255 means not used (black)
398 unsigned char styles[MAXLIGHTMAPS]; // q1bsp
399 // RGB lighting data [numstyles][height][width][3]
400 unsigned char *samples; // q1bsp
401 // RGB normalmap data [numstyles][height][width][3]
402 unsigned char *nmapsamples; // q1bsp
403 // stain to apply on lightmap (soot/dirt/blood/whatever)
404 unsigned char *stainsamples; // q1bsp
405 int texturemins[2]; // q1bsp
406 int extents[2]; // q1bsp
407 int lightmaporigin[2]; // q1bsp
409 msurface_lightmapinfo_t;
412 typedef struct msurface_s
414 // bounding box for onscreen checks
417 // the texture to use on the surface
419 // the lightmap texture fragment to use on the rendering mesh
420 rtexture_t *lightmaptexture;
421 // the lighting direction texture fragment to use on the rendering mesh
422 rtexture_t *deluxemaptexture;
423 // lightmaptexture rebuild information not used in q3bsp
424 msurface_lightmapinfo_t *lightmapinfo; // q1bsp
425 // fog volume info in q3bsp
426 struct q3deffect_s *effect; // q3bsp
427 // mesh information for collisions (only used by q3bsp curves)
428 int num_firstcollisiontriangle;
430 // surfaces own ranges of vertices and triangles in the model->surfmesh
431 int num_triangles; // number of triangles
432 int num_firsttriangle; // first triangle
433 int num_vertices; // number of vertices
434 int num_firstvertex; // first vertex
436 // mesh information for collisions (only used by q3bsp curves)
437 int num_collisiontriangles; // q3bsp
438 int num_collisionvertices; // q3bsp
440 // used by Mod_Mesh_Finalize when building sortedmodelsurfaces
447 #include "model_brush.h"
448 #include "model_q1bsp.h"
449 #include "model_q2bsp.h"
450 #include "model_q3bsp.h"
451 #include "model_sprite.h"
452 #include "model_alias.h"
459 typedef struct model_s
461 // name and path of model, for example "progs/player.mdl"
462 char name[MAX_QPATH];
463 // model needs to be loaded if this is false
465 // set if the model is used in current map, models which are not, are purged
467 // CRC of the file this model was loaded from, to reload if changed
469 // mod_brush, mod_alias, mod_sprite
471 // memory pool for allocations
473 // all models use textures...
474 rtexturepool_t *texturepool;
475 // EF_* flags (translated from the model file's different flags layout)
477 // number of QC accessible frame(group)s in the model
479 // number of QC accessible skin(group)s in the model
481 // whether to randomize animated framegroups
483 // bounding box at angles '0 0 0'
484 vec3_t normalmins, normalmaxs;
485 // bounding box if yaw angle is not 0, but pitch and roll are
486 vec3_t yawmins, yawmaxs;
487 // bounding box if pitch or roll are used
488 vec3_t rotatedmins, rotatedmaxs;
489 // sphere radius, usable at any angles
491 // squared sphere radius for easier comparisons
493 // skin animation info
494 animscene_t *skinscenes; // [numskins]
495 // skin animation info
496 animscene_t *animscenes; // [numframes]
497 // range of surface numbers in this (sub)model
498 int firstmodelsurface;
499 int nummodelsurfaces;
500 int *sortedmodelsurfaces;
501 // range of collision brush numbers in this (sub)model
504 // BIH (Bounding Interval Hierarchy) for this (sub)model
506 bih_t render_bih; // if not set, use collision_bih instead for rendering purposes too
510 aliastag_t *data_tags;
511 // for skeletal models
513 aliasbone_t *data_bones;
514 float num_posescale; // scaling factor from origin in poses7s format (includes divide by 32767)
515 float num_poseinvscale; // scaling factor to origin in poses7s format (includes multiply by 32767)
517 short *data_poses7s; // origin xyz, quat xyzw, unit length, values normalized to +/-32767 range
518 float *data_baseboneposeinverse;
519 // textures of this model
521 int max_textures; // preallocated for expansion (Mod_Mesh_*)
522 int num_texturesperskin;
523 texture_t *data_textures;
526 // surfaces of this model
528 int max_surfaces; // preallocated for expansion (Mod_Mesh_*)
529 msurface_t *data_surfaces;
530 // optional lightmapinfo data for surface lightmap updates
531 msurface_lightmapinfo_t *data_surfaces_lightmapinfo;
532 // all surfaces belong to this mesh
534 // data type of model
535 const char *modeldatatypestring;
536 // generates vertex data for a given frameblend
537 void(*AnimateVertices)(const struct model_s * RESTRICT model, const struct frameblend_s * RESTRICT frameblend, const struct skeleton_s *skeleton, float * RESTRICT vertex3f, float * RESTRICT normal3f, float * RESTRICT svector3f, float * RESTRICT tvector3f);
538 // draw the model's sky polygons (only used by brush models)
539 void(*DrawSky)(struct entity_render_s *ent);
540 // draw refraction/reflection textures for the model's water polygons (only used by brush models)
541 void(*DrawAddWaterPlanes)(struct entity_render_s *ent);
542 // draw the model using lightmap/dlight shading
543 void(*Draw)(struct entity_render_s *ent);
544 // draw the model to the depth buffer (no color rendering at all)
545 void(*DrawDepth)(struct entity_render_s *ent);
546 // draw any enabled debugging effects on this model (such as showing triangles, normals, collision brushes...)
547 void(*DrawDebug)(struct entity_render_s *ent);
548 // draw geometry textures for deferred rendering
549 void(*DrawPrepass)(struct entity_render_s *ent);
550 // compile an optimized shadowmap mesh for the model based on light source
551 void(*CompileShadowMap)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativelightdirection, float lightradius, int numsurfaces, const int *surfacelist);
552 // draw depth into a shadowmap
553 void(*DrawShadowMap)(int side, struct entity_render_s *ent, const vec3_t relativelightorigin, const vec3_t relativelightdirection, float lightradius, int numsurfaces, const int *surfacelist, const unsigned char *surfacesides, const vec3_t lightmins, const vec3_t lightmaxs);
554 // gathers info on which clusters and surfaces are lit by light, as well as calculating a bounding box
555 void(*GetLightInfo)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outleaflist, unsigned char *outleafpvs, int *outnumleafspointer, int *outsurfacelist, unsigned char *outsurfacepvs, int *outnumsurfacespointer, unsigned char *outshadowtrispvs, unsigned char *outlighttrispvs, unsigned char *visitingleafpvs, int numfrustumplanes, const mplane_t *frustumplanes, qbool noocclusion);
556 // draw the lighting on a model (through stencil)
557 void(*DrawLight)(struct entity_render_s *ent, int numsurfaces, const int *surfacelist, const unsigned char *trispvs);
558 // trace a box against this model
559 void (*TraceBox)(struct model_s *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, const vec3_t boxmins, const vec3_t boxmaxs, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
560 void (*TraceBrush)(struct model_s *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, struct colbrushf_s *start, struct colbrushf_s *end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
561 // trace a box against this model
562 void (*TraceLine)(struct model_s *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
563 // trace a point against this model (like PointSuperContents)
564 void (*TracePoint)(struct model_s *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
565 // find the supercontents value at a point in this model
566 int (*PointSuperContents)(struct model_s *model, int frame, const vec3_t point);
567 // trace a line against geometry in this model and report correct texture (used by r_shadow_bouncegrid)
568 void (*TraceLineAgainstSurfaces)(struct model_s *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
569 // fields belonging to some types of model
570 model_sprite_t sprite;
572 model_brushq1_t brushq1;
573 model_brushq3_t brushq3;
574 // flags this model for offseting sounds to the model center (used by brush models)
577 // if set, the model contains light information (lightmap, or vertexlight)
585 //============================================================================
588 extern dp_model_t *loadmodel;
589 extern unsigned char *mod_base;
591 typedef struct modloader_s
593 const char *extension;
595 size_t headersize; // The header might not be NULL terminated
596 void (*Load)(dp_model_t *, void *, void *);
599 // sky/water subdivision
600 //extern cvar_t gl_subdivide_size;
601 // texture fullbrights
602 extern cvar_t r_fullbrights;
604 extern cvar_t mod_noshader_default_offsetmapping;
605 extern cvar_t mod_q3shader_default_offsetmapping;
606 extern cvar_t mod_q3shader_default_offsetmapping_scale;
607 extern cvar_t mod_q3shader_default_offsetmapping_bias;
608 extern cvar_t mod_q3shader_default_polygonoffset;
609 extern cvar_t mod_q3shader_default_polygonfactor;
610 extern cvar_t mod_q3shader_default_refractive_index;
611 extern cvar_t mod_q3shader_force_addalpha;
612 extern cvar_t mod_q3shader_force_terrain_alphaflag;
613 extern cvar_t mod_q3bsp_lightgrid_texture;
614 extern cvar_t mod_q3bsp_lightgrid_world_surfaces;
615 extern cvar_t mod_q3bsp_lightgrid_bsp_surfaces;
617 void Mod_Init (void);
618 void Mod_Reload (void);
619 dp_model_t *Mod_LoadModel(dp_model_t *mod, qbool crash, qbool checkdisk);
620 dp_model_t *Mod_FindName (const char *name, const char *parentname);
621 dp_model_t *Mod_ForName (const char *name, qbool crash, qbool checkdisk, const char *parentname);
622 void Mod_UnloadModel (dp_model_t *mod);
624 void Mod_ClearUsed(void);
625 void Mod_PurgeUnused(void);
626 void Mod_RemoveStaleWorldModels(dp_model_t *skip); // only used during loading!
628 extern dp_model_t *loadmodel;
629 extern char loadname[32]; // for hunk tags
631 int Mod_BuildVertexRemapTableFromElements(int numelements, const int *elements, int numvertices, int *remapvertices);
632 void Mod_BuildNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const int *elements, float *normal3f, qbool areaweighting);
633 void Mod_BuildTextureVectorsFromNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const float *texcoord2f, const float *normal3f, const int *elements, float *svector3f, float *tvector3f, qbool areaweighting);
635 qbool Mod_ValidateElements(int *element3i, unsigned short *element3s, int numtriangles, int firstvertex, int numvertices, const char *filename, int fileline);
636 void Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qbool lightmapoffsets, qbool vertexcolors);
637 void Mod_MakeSortedSurfaces(dp_model_t *mod);
639 // called specially by brush model loaders before generating submodels
640 // automatically called after model loader returns
641 void Mod_BuildVBOs(void);
643 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts, int maxtriangles);
644 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, const float *vertex3f);
645 void Mod_ShadowMesh_AddMesh(shadowmesh_t *mesh, const float *vertex3f, int numtris, const int *element3i);
646 shadowmesh_t *Mod_ShadowMesh_Begin(mempool_t *mempool, int maxverts, int maxtriangles);
647 shadowmesh_t *Mod_ShadowMesh_Finish(shadowmesh_t *firstmesh, qbool createvbo);
648 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
649 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
651 void Mod_CreateCollisionMesh(dp_model_t *mod);
653 void Mod_FreeQ3Shaders(void);
654 void Mod_LoadQ3Shaders(void);
655 shader_t *Mod_LookupQ3Shader(const char *name);
656 qbool Mod_LoadTextureFromQ3Shader(mempool_t *mempool, const char *modelname, texture_t *texture, const char *name, qbool warnmissing, qbool fallback, int defaulttexflags, int defaultmaterialflags);
657 texture_shaderpass_t *Mod_CreateShaderPass(mempool_t *mempool, skinframe_t *skinframe);
658 texture_shaderpass_t *Mod_CreateShaderPassFromQ3ShaderLayer(mempool_t *mempool, const char *modelname, q3shaderinfo_layer_t *layer, int layerindex, int texflags, const char *texturename);
659 /// Sets up a material to render the provided skinframe. See also R_SkinFrame_LoadInternalBGRA.
660 void Mod_LoadCustomMaterial(mempool_t *mempool, texture_t *texture, const char *name, int supercontents, int materialflags, skinframe_t *skinframe);
661 /// Removes all shaderpasses from material, and optionally deletes the textures in the skinframes.
662 void Mod_UnloadCustomMaterial(texture_t *texture, qbool purgeskins);
664 extern cvar_t r_mipskins;
665 extern cvar_t r_mipnormalmaps;
667 typedef struct skinfileitem_s
669 struct skinfileitem_s *next;
670 char name[MAX_QPATH];
671 char replacement[MAX_QPATH];
675 typedef struct skinfile_s
677 struct skinfile_s *next;
678 skinfileitem_t *items;
682 skinfile_t *Mod_LoadSkinFiles(void);
683 void Mod_FreeSkinFiles(skinfile_t *skinfile);
684 int Mod_CountSkinFiles(skinfile_t *skinfile);
685 void Mod_BuildAliasSkinsFromSkinFiles(texture_t *skin, skinfile_t *skinfile, const char *meshname, const char *shadername);
687 void Mod_SnapVertices(int numcomponents, int numvertices, float *vertices, float snap);
688 int Mod_RemoveDegenerateTriangles(int numtriangles, const int *inelement3i, int *outelement3i, const float *vertex3f);
689 void Mod_VertexRangeFromElements(int numelements, const int *elements, int *firstvertexpointer, int *lastvertexpointer);
691 typedef struct mod_alloclightmap_row_s
696 mod_alloclightmap_row_t;
698 typedef struct mod_alloclightmap_state_s
703 mod_alloclightmap_row_t *rows;
705 mod_alloclightmap_state_t;
707 void Mod_AllocLightmap_Init(mod_alloclightmap_state_t *state, mempool_t *mempool, int width, int height);
708 void Mod_AllocLightmap_Free(mod_alloclightmap_state_t *state);
709 void Mod_AllocLightmap_Reset(mod_alloclightmap_state_t *state);
710 qbool Mod_AllocLightmap_Block(mod_alloclightmap_state_t *state, int blockwidth, int blockheight, int *outx, int *outy);
713 void Mod_BrushInit(void);
714 // used for talking to the QuakeC mainly
715 int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
716 int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
717 // used for loading wal files in Mod_LoadTextureFromQ3Shader
718 int Mod_Q2BSP_SuperContentsFromNativeContents(int nativecontents);
719 int Mod_Q2BSP_NativeContentsFromSuperContents(int supercontents);
721 // a lot of model formats use the Q1BSP code, so here are the prototypes...
722 struct entity_render_s;
723 void R_Mod_DrawAddWaterPlanes(struct entity_render_s *ent);
724 void R_Mod_DrawSky(struct entity_render_s *ent);
725 void R_Mod_Draw(struct entity_render_s *ent);
726 void R_Mod_DrawDepth(struct entity_render_s *ent);
727 void R_Mod_DrawDebug(struct entity_render_s *ent);
728 void R_Mod_DrawPrepass(struct entity_render_s *ent);
729 void R_Mod_GetLightInfo(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outleaflist, unsigned char *outleafpvs, int *outnumleafspointer, int *outsurfacelist, unsigned char *outsurfacepvs, int *outnumsurfacespointer, unsigned char *outshadowtrispvs, unsigned char *outlighttrispvs, unsigned char *visitingleafpvs, int numfrustumplanes, const mplane_t *frustumplanes, qbool noocclusion);
730 void R_Mod_CompileShadowMap(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativelightdirection, float lightradius, int numsurfaces, const int *surfacelist);
731 void R_Mod_DrawShadowMap(int side, struct entity_render_s *ent, const vec3_t relativelightorigin, const vec3_t relativelightdirection, float lightradius, int modelnumsurfaces, const int *modelsurfacelist, const unsigned char *surfacesides, const vec3_t lightmins, const vec3_t lightmaxs);
732 void R_Mod_DrawLight(struct entity_render_s *ent, int numsurfaces, const int *surfacelist, const unsigned char *trispvs);
734 // dynamic mesh building (every frame) for debugging and other uses
735 void Mod_Mesh_Create(dp_model_t *mod, const char *name);
736 void Mod_Mesh_Destroy(dp_model_t *mod);
737 void Mod_Mesh_Reset(dp_model_t *mod);
738 texture_t *Mod_Mesh_GetTexture(dp_model_t *mod, const char *name, int defaultdrawflags, int defaulttexflags, int defaultmaterialflags);
739 msurface_t *Mod_Mesh_AddSurface(dp_model_t *mod, texture_t *tex, qbool batchwithprevioussurface);
740 int Mod_Mesh_IndexForVertex(dp_model_t *mod, msurface_t *surf, float x, float y, float z, float nx, float ny, float nz, float s, float t, float u, float v, float r, float g, float b, float a);
741 void Mod_Mesh_AddTriangle(dp_model_t *mod, msurface_t *surf, int e0, int e1, int e2);
742 void Mod_Mesh_Validate(dp_model_t *mod);
743 void Mod_Mesh_Finalize(dp_model_t *mod);
745 // Collision optimization using Bounding Interval Hierarchy
746 void Mod_CollisionBIH_TracePoint(dp_model_t *model, const struct frameblend_s *frameblend, const skeleton_t *skeleton, struct trace_s *trace, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
747 void Mod_CollisionBIH_TraceLine(dp_model_t *model, const struct frameblend_s *frameblend, const skeleton_t *skeleton, struct trace_s *trace, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
748 void Mod_CollisionBIH_TraceBox(dp_model_t *model, const struct frameblend_s *frameblend, const skeleton_t *skeleton, struct trace_s *trace, const vec3_t start, const vec3_t boxmins, const vec3_t boxmaxs, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
749 void Mod_CollisionBIH_TraceBrush(dp_model_t *model, const struct frameblend_s *frameblend, const skeleton_t *skeleton, struct trace_s *trace, struct colbrushf_s *start, struct colbrushf_s *end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
750 void Mod_CollisionBIH_TracePoint_Mesh(dp_model_t *model, const struct frameblend_s *frameblend, const skeleton_t *skeleton, struct trace_s *trace, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask);
751 qbool Mod_CollisionBIH_TraceLineOfSight(struct model_s *model, const vec3_t start, const vec3_t end, const vec3_t acceptmins, const vec3_t acceptmaxs);
752 int Mod_CollisionBIH_PointSuperContents(struct model_s *model, int frame, const vec3_t point);
753 int Mod_CollisionBIH_PointSuperContents_Mesh(struct model_s *model, int frame, const vec3_t point);
754 bih_t *Mod_MakeCollisionBIH(dp_model_t *model, qbool userendersurfaces, bih_t *out);
759 void Mod_AliasInit(void);
760 int Mod_Alias_GetTagMatrix(const dp_model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, int tagindex, matrix4x4_t *outmatrix);
761 int Mod_Alias_GetTagIndexForName(const dp_model_t *model, unsigned int skin, const char *tagname);
762 int Mod_Alias_GetExtendedTagInfoForIndex(const dp_model_t *model, unsigned int skin, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, int tagindex, int *parentindex, const char **tagname, matrix4x4_t *tag_localmatrix);
764 void Mod_Skeletal_FreeBuffers(void);
767 void Mod_SpriteInit(void);
770 void Mod_2PSB_Load(dp_model_t *mod, void *buffer, void *bufferend);
771 void Mod_BSP2_Load(dp_model_t *mod, void *buffer, void *bufferend);
772 void Mod_HLBSP_Load(dp_model_t *mod, void *buffer, void *bufferend);
773 void Mod_Q1BSP_Load(dp_model_t *mod, void *buffer, void *bufferend);
774 void Mod_IBSP_Load(dp_model_t *mod, void *buffer, void *bufferend);
775 void Mod_MAP_Load(dp_model_t *mod, void *buffer, void *bufferend);
776 void Mod_OBJ_Load(dp_model_t *mod, void *buffer, void *bufferend);
777 void Mod_IDP0_Load(dp_model_t *mod, void *buffer, void *bufferend);
778 void Mod_IDP2_Load(dp_model_t *mod, void *buffer, void *bufferend);
779 void Mod_IDP3_Load(dp_model_t *mod, void *buffer, void *bufferend);
780 void Mod_ZYMOTICMODEL_Load(dp_model_t *mod, void *buffer, void *bufferend);
781 void Mod_DARKPLACESMODEL_Load(dp_model_t *mod, void *buffer, void *bufferend);
782 void Mod_PSKMODEL_Load(dp_model_t *mod, void *buffer, void *bufferend);
783 void Mod_IDSP_Load(dp_model_t *mod, void *buffer, void *bufferend);
784 void Mod_IDS2_Load(dp_model_t *mod, void *buffer, void *bufferend);
785 void Mod_INTERQUAKEMODEL_Load(dp_model_t *mod, void *buffer, void *bufferend);
787 #endif // MODEL_SHARED_H