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
27 #include "r_qshader.h"
28 #include "matrixlib.h"
34 typedef enum synctype_e {ST_SYNC=0, ST_RAND } synctype_t;
38 d*_t structures are on-disk representations
39 m*_t structures are in-memory
43 typedef enum modtype_e {mod_invalid, mod_brushq1, mod_sprite, mod_alias, mod_brushq2, mod_brushq3, mod_obj, mod_null} modtype_t;
45 typedef struct animscene_s
47 char name[32]; // for viewthing support
50 int loop; // true or false
57 typedef struct texvecvertex_s
64 typedef struct blendweights_s
66 unsigned char index[4];
67 unsigned char influence[4];
71 typedef struct r_meshbuffer_s
73 int bufferobject; // OpenGL
74 void *devicebuffer; // Direct3D
77 qbool isuniformbuffer;
84 // used for mesh lists in q1bsp/q3bsp map models
85 // (the surfaces reference portions of these meshes)
86 typedef struct surfmesh_s
88 // triangle data in system memory
89 int num_triangles; // number of triangles in the mesh
90 int *data_element3i; // int[tris*3] triangles of the mesh, 3 indices into vertex arrays for each
92 // vertex data in system memory
93 int num_vertices; // number of vertices in the mesh
94 float *data_vertex3f; // float[verts*3] vertex locations
95 float *data_svector3f; // float[verts*3] direction of 'S' (right) texture axis for each vertex
96 float *data_tvector3f; // float[verts*3] direction of 'T' (down) texture axis for each vertex
97 float *data_normal3f; // float[verts*3] direction of 'R' (out) texture axis for each vertex
98 float *data_texcoordtexture2f; // float[verts*2] texcoords for surface texture
99 float *data_texcoordlightmap2f; // float[verts*2] texcoords for lightmap texture
100 float *data_lightmapcolor4f;
101 unsigned char *data_skeletalindex4ub;
102 unsigned char *data_skeletalweight4ub;
103 int *data_lightmapoffsets; // index into surface's lightmap samples for vertex lighting
104 // index buffer - only one of these will be non-NULL
105 r_meshbuffer_t *data_element3i_indexbuffer;
106 int data_element3i_bufferoffset;
107 unsigned short *data_element3s; // unsigned short[tris*3] triangles of the mesh in unsigned short format (NULL if num_vertices > 65536)
108 r_meshbuffer_t *data_element3s_indexbuffer;
109 int data_element3s_bufferoffset;
111 r_meshbuffer_t *data_vertex3f_vertexbuffer;
112 int data_vertex3f_bufferoffset;
113 r_meshbuffer_t *data_svector3f_vertexbuffer;
114 int data_svector3f_bufferoffset;
115 r_meshbuffer_t *data_tvector3f_vertexbuffer;
116 int data_tvector3f_bufferoffset;
117 r_meshbuffer_t *data_normal3f_vertexbuffer;
118 int data_normal3f_bufferoffset;
119 r_meshbuffer_t *data_texcoordtexture2f_vertexbuffer;
120 int data_texcoordtexture2f_bufferoffset;
121 r_meshbuffer_t *data_texcoordlightmap2f_vertexbuffer;
122 int data_texcoordlightmap2f_bufferoffset;
123 r_meshbuffer_t *data_lightmapcolor4f_vertexbuffer;
124 int data_lightmapcolor4f_bufferoffset;
125 r_meshbuffer_t *data_skeletalindex4ub_vertexbuffer;
126 int data_skeletalindex4ub_bufferoffset;
127 r_meshbuffer_t *data_skeletalweight4ub_vertexbuffer;
128 int data_skeletalweight4ub_bufferoffset;
129 // morph blending, these are zero if model is skeletal or static
131 struct md3vertex_s *data_morphmd3vertex;
132 struct trivertx_s *data_morphmdlvertex;
133 struct texvecvertex_s *data_morphtexvecvertex;
134 float *data_morphmd2framesize6f;
135 float num_morphmdlframescale[3];
136 float num_morphmdlframetranslate[3];
137 // skeletal blending, these are NULL if model is morph or static
138 struct blendweights_s *data_blendweights;
140 unsigned short *blends;
141 // set if there is some kind of animation on this model
144 // dynamic mesh building support (Mod_Mesh_*)
145 int num_vertexhashsize; // always pow2 for simple masking
146 int *data_vertexhash; // hash table - wrapping buffer for storing index of similar vertex with -1 as terminator
147 int max_vertices; // preallocated size of data_vertex3f and friends (always >= num_vertices)
148 int max_triangles; // preallocated size of data_element3i
152 #define SHADOWMESHVERTEXHASH 1024
153 typedef struct shadowmeshvertexhash_s
155 struct shadowmeshvertexhash_s *next;
157 shadowmeshvertexhash_t;
159 typedef struct shadowmesh_s
161 struct mempool_s *mempool;
166 r_meshbuffer_t *vbo_vertexbuffer;
167 int vbooffset_vertex3f;
172 r_meshbuffer_t *element3i_indexbuffer;
173 int element3i_bufferoffset;
174 unsigned short *element3s;
175 r_meshbuffer_t *element3s_indexbuffer;
176 int element3s_bufferoffset;
178 // used for shadow mapping cubemap side partitioning
179 int sideoffsets[6], sidetotals[6];
181 // these are NULL after Mod_ShadowMesh_Finish is performed, only used
182 // while building meshes
183 shadowmeshvertexhash_t **vertexhashtable, *vertexhashentries;
187 typedef struct texture_s
194 unsigned int width, height;
196 //unsigned int flags;
198 // base material flags
199 int basematerialflags;
200 // current material flags (updated each bmodel render)
201 int currentmaterialflags;
202 // base material alpha (used for Q2 materials)
205 // PolygonOffset values for rendering this material
206 // (these are added to the r_refdef values and submodel values)
207 float biaspolygonfactor;
208 float biaspolygonoffset;
210 // textures to use when rendering this material (derived from materialshaderpass)
211 struct skinframe_s *currentskinframe;
212 // textures to use for terrain texture blending (derived from backgroundshaderpass)
213 struct skinframe_s *backgroundcurrentskinframe;
215 // total frames in sequence and alternate sequence
217 // direct pointers to each of the frames in the sequences
218 // (indexed as [alternate][frame])
219 struct texture_s *anim_frames[2][10];
220 // 1 = q1bsp animation with anim_total[0] >= 2 (animated) or anim_total[1] >= 1 (alternate frame set)
221 // 2 = q2bsp animation with anim_total[0] >= 2 (uses self.frame)
224 // renderer checks if this texture needs updating...
225 int update_lastrenderframe;
226 void *update_lastrenderentity;
227 // the current alpha of this texture (may be affected by r_wateralpha, also basealpha, and ent->alpha)
229 // current value of blendfunc - one of:
230 // {GL_SRC_ALPHA, GL_ONE}
231 // {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}
232 // {customblendfunc[0], customblendfunc[1]}
234 int currentblendfunc[2];
235 // the current texture frame in animation
236 struct texture_s *currentframe;
237 // current texture transform matrix (used for water scrolling)
238 matrix4x4_t currenttexmatrix;
239 matrix4x4_t currentbackgroundtexmatrix;
241 // various q3 shader features
242 q3shaderinfo_deform_t deforms[Q3MAXDEFORMS];
243 texture_shaderpass_t *shaderpasses[Q3SHADER_MAXLAYERS]; // all shader passes in one array
244 texture_shaderpass_t *materialshaderpass; // equal to one of shaderpasses[] or NULL
245 texture_shaderpass_t *backgroundshaderpass; // equal to one of shaderpasses[] or NULL
246 unsigned char startpreshaderpass; // range within shaderpasses[]
247 unsigned char endpreshaderpass; // number of preshaderpasses
248 unsigned char startpostshaderpass; // range within shaderpasses[]
249 unsigned char endpostshaderpass; // number of postshaderpasses
252 struct rtexture_s *basetexture; // original texture without pants/shirt/glow
253 struct rtexture_s *pantstexture; // pants only (in greyscale)
254 struct rtexture_s *shirttexture; // shirt only (in greyscale)
255 struct rtexture_s *nmaptexture; // normalmap (bumpmap for dot3)
256 struct rtexture_s *glosstexture; // glossmap (for dot3)
257 struct rtexture_s *glowtexture; // glow only (fullbrights)
258 struct rtexture_s *fogtexture; // alpha of the base texture (if not opaque)
259 struct rtexture_s *reflectmasktexture; // mask for fake reflections
260 struct rtexture_s *reflectcubetexture; // fake reflections cubemap
261 struct rtexture_s *backgroundbasetexture; // original texture without pants/shirt/glow
262 struct rtexture_s *backgroundnmaptexture; // normalmap (bumpmap for dot3)
263 struct rtexture_s *backgroundglosstexture; // glossmap (for dot3)
264 struct rtexture_s *backgroundglowtexture; // glow only (fullbrights)
267 // rendering parameters - updated by R_GetCurrentTexture using rsurface.render_* fields
268 // (almost) all map textures are lightmap (no MATERIALFLAG_MODELLIGHT set),
269 // (almost) all model textures are MATERIALFLAG_MODELLIGHT,
270 // MATERIALFLAG_FULLBRIGHT is rendered as a forced MATERIALFLAG_MODELLIGHT with rtlights disabled
271 float render_glowmod[3];
272 // MATERIALFLAG_MODELLIGHT uses these parameters
273 float render_modellight_ambient[3];
274 float render_modellight_diffuse[3];
275 float render_modellight_lightdir_world[3];
276 float render_modellight_lightdir_local[3];
277 float render_modellight_specular[3];
278 // lightmap rendering (not MATERIALFLAG_MODELLIGHT)
279 float render_lightmap_ambient[3];
280 float render_lightmap_diffuse[3];
281 float render_lightmap_specular[3];
282 // rtlights use these colors for the materials on this entity
283 float render_rtlight_diffuse[3];
284 float render_rtlight_specular[3];
285 // tint applied on top of render_*_diffuse for pants layer
286 float render_colormap_pants[3];
287 // tint applied on top of render_*_diffuse for shirt layer
288 float render_colormap_shirt[3];
291 int customblendfunc[2];
298 // we have to load the texture multiple times when Q2SURF_ flags differ,
299 // though it still shares the skinframe
305 /// this points to a variant of the sky texture that has MATERIALFLAG_NOSHADOW, for the e1m5 logo shadow trick.
306 struct texture_s *skynoshadowtexture;
309 float reflectmin; // when refraction is used, minimum amount of reflection (when looking straight down)
310 float reflectmax; // when refraction is used, maximum amount of reflection (when looking parallel to water)
311 float refractfactor; // amount of refraction distort (1.0 = like the cvar specifies)
312 vec4_t refractcolor4f; // color tint of refraction (including alpha factor)
313 float reflectfactor; // amount of reflection distort (1.0 = like the cvar specifies)
314 vec4_t reflectcolor4f; // color tint of reflection (including alpha factor)
315 float r_water_wateralpha; // additional wateralpha to apply when r_water is active
316 float r_water_waterscroll[2]; // scale and speed
317 float refractive_index; // used by r_shadow_bouncegrid for bending photons for refracted light
318 int camera_entity; // entity number for use by cameras
321 dpoffsetmapping_technique_t offsetmapping;
325 // transparent sort category
326 dptransparentsortcategory_t transparentsort;
329 float specularscalemod;
330 float specularpowermod;
332 // diffuse and ambient
333 float rtlightambient;
335 // used by Mod_Mesh_GetTexture for drawflag and materialflag overrides, to disambiguate the same texture with different hints
337 int mesh_defaulttexflags;
338 int mesh_defaultmaterialflags;
342 typedef struct mtexinfo_s
344 float vecs[2][4]; // [s/t][xyz offset]
347 int q2flags; // miptex flags + overrides
348 int q2value; // light emission, etc
349 char q2texture[32]; // texture name (textures/*.wal)
350 int q2nexttexinfo; // for animations, -1 = end of chain
354 typedef struct msurface_lightmapinfo_s
356 // texture mapping properties used by this surface
357 mtexinfo_t *texinfo; // q1bsp
358 // index into r_refdef.scene.lightstylevalue array, 255 means not used (black)
359 unsigned char styles[MAXLIGHTMAPS]; // q1bsp
360 // RGB lighting data [numstyles][height][width][3]
361 unsigned char *samples; // q1bsp
362 // RGB normalmap data [numstyles][height][width][3]
363 unsigned char *nmapsamples; // q1bsp
364 // stain to apply on lightmap (soot/dirt/blood/whatever)
365 unsigned char *stainsamples; // q1bsp
366 int texturemins[2]; // q1bsp
367 int extents[2]; // q1bsp
368 int lightmaporigin[2]; // q1bsp
370 msurface_lightmapinfo_t;
373 typedef struct msurface_s
375 // bounding box for onscreen checks
378 // the texture to use on the surface
380 // the lightmap texture fragment to use on the rendering mesh
381 struct rtexture_s *lightmaptexture;
382 // the lighting direction texture fragment to use on the rendering mesh
383 struct rtexture_s *deluxemaptexture;
384 // lightmaptexture rebuild information not used in q3bsp
385 msurface_lightmapinfo_t *lightmapinfo; // q1bsp
386 // fog volume info in q3bsp
387 struct q3deffect_s *effect; // q3bsp
388 // mesh information for collisions (only used by q3bsp curves)
389 int num_firstcollisiontriangle;
391 // surfaces own ranges of vertices and triangles in the model->surfmesh
392 int num_triangles; // number of triangles
393 int num_firsttriangle; // first triangle
394 int num_vertices; // number of vertices
395 int num_firstvertex; // first vertex
397 // mesh information for collisions (only used by q3bsp curves)
398 int num_collisiontriangles; // q3bsp
399 int num_collisionvertices; // q3bsp
401 // used by Mod_Mesh_Finalize when building sortedmodelsurfaces
408 #include "model_brush.h"
409 #include "model_q1bsp.h"
410 #include "model_q2bsp.h"
411 #include "model_q3bsp.h"
412 #include "model_sprite.h"
413 #include "model_alias.h"
420 typedef struct model_s
422 // name and path of model, for example "progs/player.mdl"
423 char name[MAX_QPATH];
424 // model needs to be loaded if this is false
426 // set if the model is used in current map, models which are not, are purged
428 // CRC of the file this model was loaded from, to reload if changed
430 // mod_brush, mod_alias, mod_sprite
432 // memory pool for allocations
433 struct mempool_s *mempool;
434 // all models use textures...
435 rtexturepool_t *texturepool;
436 // EF_* flags (translated from the model file's different flags layout)
438 // number of QC accessible frame(group)s in the model
440 // number of QC accessible skin(group)s in the model
442 // whether to randomize animated framegroups
444 // bounding box at angles '0 0 0'
445 vec3_t normalmins, normalmaxs;
446 // bounding box if yaw angle is not 0, but pitch and roll are
447 vec3_t yawmins, yawmaxs;
448 // bounding box if pitch or roll are used
449 vec3_t rotatedmins, rotatedmaxs;
450 // sphere radius, usable at any angles
452 // squared sphere radius for easier comparisons
454 // skin animation info
455 animscene_t *skinscenes; // [numskins]
456 // skin animation info
457 animscene_t *animscenes; // [numframes]
458 // range of surface numbers in this (sub)model
459 int firstmodelsurface;
460 int nummodelsurfaces;
461 int *sortedmodelsurfaces;
462 // range of collision brush numbers in this (sub)model
465 // BIH (Bounding Interval Hierarchy) for this (sub)model
467 bih_t render_bih; // if not set, use collision_bih instead for rendering purposes too
471 aliastag_t *data_tags;
472 // for skeletal models
474 aliasbone_t *data_bones;
475 float num_posescale; // scaling factor from origin in poses7s format (includes divide by 32767)
476 float num_poseinvscale; // scaling factor to origin in poses7s format (includes multiply by 32767)
478 short *data_poses7s; // origin xyz, quat xyzw, unit length, values normalized to +/-32767 range
479 float *data_baseboneposeinverse;
480 // textures of this model
482 int max_textures; // preallocated for expansion (Mod_Mesh_*)
483 int num_texturesperskin;
484 texture_t *data_textures;
487 // surfaces of this model
489 int max_surfaces; // preallocated for expansion (Mod_Mesh_*)
490 msurface_t *data_surfaces;
491 // optional lightmapinfo data for surface lightmap updates
492 msurface_lightmapinfo_t *data_surfaces_lightmapinfo;
493 // all surfaces belong to this mesh
495 // data type of model
496 const char *modeldatatypestring;
497 // generates vertex data for a given frameblend
498 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);
499 // draw the model's sky polygons (only used by brush models)
500 void(*DrawSky)(struct entity_render_s *ent);
501 // draw refraction/reflection textures for the model's water polygons (only used by brush models)
502 void(*DrawAddWaterPlanes)(struct entity_render_s *ent);
503 // draw the model using lightmap/dlight shading
504 void(*Draw)(struct entity_render_s *ent);
505 // draw the model to the depth buffer (no color rendering at all)
506 void(*DrawDepth)(struct entity_render_s *ent);
507 // draw any enabled debugging effects on this model (such as showing triangles, normals, collision brushes...)
508 void(*DrawDebug)(struct entity_render_s *ent);
509 // draw geometry textures for deferred rendering
510 void(*DrawPrepass)(struct entity_render_s *ent);
511 // compile an optimized shadowmap mesh for the model based on light source
512 void(*CompileShadowMap)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativelightdirection, float lightradius, int numsurfaces, const int *surfacelist);
513 // draw depth into a shadowmap
514 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);
515 // gathers info on which clusters and surfaces are lit by light, as well as calculating a bounding box
516 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);
517 // draw the lighting on a model (through stencil)
518 void(*DrawLight)(struct entity_render_s *ent, int numsurfaces, const int *surfacelist, const unsigned char *trispvs);
519 // trace a box against this model
520 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);
521 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);
522 // trace a box against this model
523 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);
524 // trace a point against this model (like PointSuperContents)
525 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);
526 // find the supercontents value at a point in this model
527 int (*PointSuperContents)(struct model_s *model, int frame, const vec3_t point);
528 // trace a line against geometry in this model and report correct texture (used by r_shadow_bouncegrid)
529 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);
530 // fields belonging to some types of model
531 model_sprite_t sprite;
533 model_brushq1_t brushq1;
534 model_brushq3_t brushq3;
535 // flags this model for offseting sounds to the model center (used by brush models)
538 // if set, the model contains light information (lightmap, or vertexlight)
546 //============================================================================
549 extern model_t *loadmodel;
550 extern unsigned char *mod_base;
552 typedef struct modloader_s
554 const char *extension;
556 size_t headersize; // The header might not be NULL terminated
557 void (*Load)(model_t *, void *, void *);
560 // sky/water subdivision
561 //extern struct cvar_s gl_subdivide_size;
562 // texture fullbrights
563 extern struct cvar_s r_fullbrights;
565 extern struct cvar_s mod_noshader_default_offsetmapping;
566 extern struct cvar_s mod_q3shader_default_offsetmapping;
567 extern struct cvar_s mod_q3shader_default_offsetmapping_scale;
568 extern struct cvar_s mod_q3shader_default_offsetmapping_bias;
569 extern struct cvar_s mod_q3shader_default_polygonoffset;
570 extern struct cvar_s mod_q3shader_default_polygonfactor;
571 extern struct cvar_s mod_q3shader_default_refractive_index;
572 extern struct cvar_s mod_q3shader_force_addalpha;
573 extern struct cvar_s mod_q3shader_force_terrain_alphaflag;
574 extern struct cvar_s mod_q3bsp_lightgrid_texture;
575 extern struct cvar_s mod_q3bsp_lightgrid_world_surfaces;
576 extern struct cvar_s mod_q3bsp_lightgrid_bsp_surfaces;
578 void Mod_Init (void);
579 void Mod_Reload (void);
580 model_t *Mod_LoadModel(model_t *mod, qbool crash, qbool checkdisk);
581 model_t *Mod_FindName (const char *name, const char *parentname);
582 model_t *Mod_ForName (const char *name, qbool crash, qbool checkdisk, const char *parentname);
583 void Mod_UnloadModel (model_t *mod);
585 void Mod_ClearUsed(void);
586 void Mod_PurgeUnused(void);
587 void Mod_RemoveStaleWorldModels(model_t *skip); // only used during loading!
589 extern model_t *loadmodel;
590 extern char loadname[32]; // for hunk tags
592 int Mod_BuildVertexRemapTableFromElements(int numelements, const int *elements, int numvertices, int *remapvertices);
593 void Mod_BuildNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const int *elements, float *normal3f, qbool areaweighting);
594 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);
596 qbool Mod_ValidateElements(int *element3i, unsigned short *element3s, int numtriangles, int firstvertex, int numvertices, const char *filename, int fileline);
597 void Mod_AllocSurfMesh(struct mempool_s *mempool, int numvertices, int numtriangles, qbool lightmapoffsets, qbool vertexcolors);
598 void Mod_MakeSortedSurfaces(model_t *mod);
600 // called specially by brush model loaders before generating submodels
601 // automatically called after model loader returns
602 void Mod_BuildVBOs(void);
604 shadowmesh_t *Mod_ShadowMesh_Alloc(struct mempool_s *mempool, int maxverts, int maxtriangles);
605 int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, const float *vertex3f);
606 void Mod_ShadowMesh_AddMesh(shadowmesh_t *mesh, const float *vertex3f, int numtris, const int *element3i);
607 shadowmesh_t *Mod_ShadowMesh_Begin(struct mempool_s *mempool, int maxverts, int maxtriangles);
608 shadowmesh_t *Mod_ShadowMesh_Finish(shadowmesh_t *firstmesh, qbool createvbo);
609 void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius);
610 void Mod_ShadowMesh_Free(shadowmesh_t *mesh);
612 void Mod_CreateCollisionMesh(model_t *mod);
614 void Mod_FreeQ3Shaders(void);
615 void Mod_LoadQ3Shaders(void);
616 shader_t *Mod_LookupQ3Shader(const char *name);
617 qbool Mod_LoadTextureFromQ3Shader(struct mempool_s *mempool, const char *modelname, texture_t *texture, const char *name, qbool warnmissing, qbool fallback, int defaulttexflags, int defaultmaterialflags);
618 texture_shaderpass_t *Mod_CreateShaderPass(struct mempool_s *mempool, struct skinframe_s *skinframe);
619 texture_shaderpass_t *Mod_CreateShaderPassFromQ3ShaderLayer(struct mempool_s *mempool, const char *modelname, q3shaderinfo_layer_t *layer, int layerindex, int texflags, const char *texturename);
620 /// Sets up a material to render the provided skinframe. See also R_SkinFrame_LoadInternalBGRA.
621 void Mod_LoadCustomMaterial(struct mempool_s *mempool, texture_t *texture, const char *name, int supercontents, int materialflags, struct skinframe_s *skinframe);
622 /// Removes all shaderpasses from material, and optionally deletes the textures in the skinframes.
623 void Mod_UnloadCustomMaterial(texture_t *texture, qbool purgeskins);
625 extern struct cvar_s r_mipskins;
626 extern struct cvar_s r_mipnormalmaps;
628 typedef struct skinfileitem_s
630 struct skinfileitem_s *next;
631 char name[MAX_QPATH];
632 char replacement[MAX_QPATH];
636 typedef struct skinfile_s
638 struct skinfile_s *next;
639 skinfileitem_t *items;
643 skinfile_t *Mod_LoadSkinFiles(void);
644 void Mod_FreeSkinFiles(skinfile_t *skinfile);
645 int Mod_CountSkinFiles(skinfile_t *skinfile);
646 void Mod_BuildAliasSkinsFromSkinFiles(texture_t *skin, skinfile_t *skinfile, const char *meshname, const char *shadername);
648 void Mod_SnapVertices(int numcomponents, int numvertices, float *vertices, float snap);
649 int Mod_RemoveDegenerateTriangles(int numtriangles, const int *inelement3i, int *outelement3i, const float *vertex3f);
650 void Mod_VertexRangeFromElements(int numelements, const int *elements, int *firstvertexpointer, int *lastvertexpointer);
652 typedef struct mod_alloclightmap_row_s
657 mod_alloclightmap_row_t;
659 typedef struct mod_alloclightmap_state_s
664 mod_alloclightmap_row_t *rows;
666 mod_alloclightmap_state_t;
668 void Mod_AllocLightmap_Init(mod_alloclightmap_state_t *state, struct mempool_s *mempool, int width, int height);
669 void Mod_AllocLightmap_Free(mod_alloclightmap_state_t *state);
670 void Mod_AllocLightmap_Reset(mod_alloclightmap_state_t *state);
671 qbool Mod_AllocLightmap_Block(mod_alloclightmap_state_t *state, int blockwidth, int blockheight, int *outx, int *outy);
674 void Mod_BrushInit(void);
675 // used for talking to the QuakeC mainly
676 int Mod_Q1BSP_NativeContentsFromSuperContents(int supercontents);
677 int Mod_Q1BSP_SuperContentsFromNativeContents(int nativecontents);
678 // used for loading wal files in Mod_LoadTextureFromQ3Shader
679 int Mod_Q2BSP_SuperContentsFromNativeContents(int nativecontents);
680 int Mod_Q2BSP_NativeContentsFromSuperContents(int supercontents);
682 // a lot of model formats use the Q1BSP code, so here are the prototypes...
683 struct entity_render_s;
684 void R_Mod_DrawAddWaterPlanes(struct entity_render_s *ent);
685 void R_Mod_DrawSky(struct entity_render_s *ent);
686 void R_Mod_Draw(struct entity_render_s *ent);
687 void R_Mod_DrawDepth(struct entity_render_s *ent);
688 void R_Mod_DrawDebug(struct entity_render_s *ent);
689 void R_Mod_DrawPrepass(struct entity_render_s *ent);
690 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);
691 void R_Mod_CompileShadowMap(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativelightdirection, float lightradius, int numsurfaces, const int *surfacelist);
692 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);
693 void R_Mod_DrawLight(struct entity_render_s *ent, int numsurfaces, const int *surfacelist, const unsigned char *trispvs);
695 // dynamic mesh building (every frame) for debugging and other uses
696 void Mod_Mesh_Create(model_t *mod, const char *name);
697 void Mod_Mesh_Destroy(model_t *mod);
698 void Mod_Mesh_Reset(model_t *mod);
699 texture_t *Mod_Mesh_GetTexture(model_t *mod, const char *name, int defaultdrawflags, int defaulttexflags, int defaultmaterialflags);
700 msurface_t *Mod_Mesh_AddSurface(model_t *mod, texture_t *tex, qbool batchwithprevioussurface);
701 void Mod_Mesh_CheckResize_Vertex(model_t *mod, msurface_t *surf);
702 int Mod_Mesh_AddVertex(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);
703 int Mod_Mesh_IndexForVertex(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);
704 void Mod_Mesh_AddTriangle(model_t *mod, msurface_t *surf, int e0, int e1, int e2);
705 void Mod_Mesh_Validate(model_t *mod);
706 void Mod_Mesh_Finalize(model_t *mod);
708 // Collision optimization using Bounding Interval Hierarchy
709 void Mod_CollisionBIH_TracePoint(model_t *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);
710 void Mod_CollisionBIH_TraceLine(model_t *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);
711 void Mod_CollisionBIH_TraceBox(model_t *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);
712 void Mod_CollisionBIH_TraceBrush(model_t *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);
713 void Mod_CollisionBIH_TracePoint_Mesh(model_t *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);
714 qbool Mod_CollisionBIH_TraceLineOfSight(struct model_s *model, const vec3_t start, const vec3_t end, const vec3_t acceptmins, const vec3_t acceptmaxs);
715 int Mod_CollisionBIH_PointSuperContents(struct model_s *model, int frame, const vec3_t point);
716 int Mod_CollisionBIH_PointSuperContents_Mesh(struct model_s *model, int frame, const vec3_t point);
717 bih_t *Mod_MakeCollisionBIH(model_t *model, qbool userendersurfaces, bih_t *out);
722 void Mod_AliasInit(void);
723 int Mod_Alias_GetTagMatrix(const model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, int tagindex, matrix4x4_t *outmatrix);
724 int Mod_Alias_GetTagIndexForName(const model_t *model, unsigned int skin, const char *tagname);
725 int Mod_Alias_GetExtendedTagInfoForIndex(const 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);
727 void Mod_Skeletal_FreeBuffers(void);
730 void Mod_SpriteInit(void);
733 void Mod_2PSB_Load(model_t *mod, void *buffer, void *bufferend);
734 void Mod_BSP2_Load(model_t *mod, void *buffer, void *bufferend);
735 void Mod_HLBSP_Load(model_t *mod, void *buffer, void *bufferend);
736 void Mod_Q1BSP_Load(model_t *mod, void *buffer, void *bufferend);
737 void Mod_IBSP_Load(model_t *mod, void *buffer, void *bufferend);
738 void Mod_MAP_Load(model_t *mod, void *buffer, void *bufferend);
739 void Mod_OBJ_Load(model_t *mod, void *buffer, void *bufferend);
740 void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend);
741 void Mod_IDP2_Load(model_t *mod, void *buffer, void *bufferend);
742 void Mod_IDP3_Load(model_t *mod, void *buffer, void *bufferend);
743 void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer, void *bufferend);
744 void Mod_DARKPLACESMODEL_Load(model_t *mod, void *buffer, void *bufferend);
745 void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend);
746 void Mod_IDSP_Load(model_t *mod, void *buffer, void *bufferend);
747 void Mod_IDS2_Load(model_t *mod, void *buffer, void *bufferend);
748 void Mod_INTERQUAKEMODEL_Load(model_t *mod, void *buffer, void *bufferend);
750 #endif // MODEL_SHARED_H