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.
29 ==============================================================================
33 ==============================================================================
39 // in memory representation
41 typedef struct mvertex_s
53 typedef struct mplane_s
62 vec4_t normal_and_dist;
64 // for texture axis selection and fast side tests
65 int type; // set by PlaneClassify()
66 int signbits; // set by PlaneClassify()
70 #define SHADERSTAGE_SKY 0
71 #define SHADERSTAGE_NORMAL 1
72 #define SHADERSTAGE_COUNT 2
74 //#define SURF_PLANEBACK 2
76 // indicates that all triangles of the surface should be added to the BIH collision system
77 #define MATERIALFLAG_MESHCOLLISIONS 0x00000001
78 // use alpha blend on this material
79 #define MATERIALFLAG_ALPHA 0x00000002
80 // use additive blend on this material
81 #define MATERIALFLAG_ADD 0x00000004
82 // turn off depth test on this material
83 #define MATERIALFLAG_NODEPTHTEST 0x00000008
84 // multiply alpha by r_wateralpha cvar
85 #define MATERIALFLAG_WATERALPHA 0x00000010
86 // draw with no lighting
87 #define MATERIALFLAG_FULLBRIGHT 0x00000020
88 // drawn as a normal surface (alternative to SKY)
89 #define MATERIALFLAG_WALL 0x00000040
90 // this surface shows the sky in its place, alternative to WALL
91 // skipped if transparent
92 #define MATERIALFLAG_SKY 0x00000080
93 // swirling water effect (used with MATERIALFLAG_WALL)
94 #define MATERIALFLAG_WATERSCROLL 0x00000100
95 // skips drawing the surface
96 #define MATERIALFLAG_NODRAW 0x00000200
97 // probably used only on q1bsp water
98 #define MATERIALFLAG_LIGHTBOTHSIDES 0x00000400
99 // use alpha test on this material
100 #define MATERIALFLAG_ALPHATEST 0x00000800
101 // treat this material as a blended transparency (as opposed to an alpha test
102 // transparency), this causes special fog behavior, and disables glDepthMask
103 #define MATERIALFLAG_BLENDED 0x00001000
104 // render using a custom blendfunc
105 #define MATERIALFLAG_CUSTOMBLEND 0x00002000
106 // do not cast shadows from this material
107 #define MATERIALFLAG_NOSHADOW 0x00004000
108 // render using vertex alpha (q3bsp) as texture blend parameter between foreground (normal) skinframe and background skinframe
109 #define MATERIALFLAG_VERTEXTEXTUREBLEND 0x00008000
110 // disables GL_CULL_FACE on this texture (making it double sided)
111 #define MATERIALFLAG_NOCULLFACE 0x00010000
112 // render with a very short depth range (like 10% of normal), this causes entities to appear infront of most of the scene
113 #define MATERIALFLAG_SHORTDEPTHRANGE 0x00020000
114 // render water, comprising refraction and reflection (note: this is always opaque, the shader does the alpha effect)
115 #define MATERIALFLAG_WATERSHADER 0x00040000
116 // render refraction (note: this is just a way to distort the background, otherwise useless)
117 #define MATERIALFLAG_REFRACTION 0x00080000
119 #define MATERIALFLAG_REFLECTION 0x00100000
120 // use model lighting on this material (q1bsp lightmap sampling or q3bsp lightgrid, implies FULLBRIGHT is false)
121 #define MATERIALFLAG_MODELLIGHT 0x00200000
122 // causes RSurf_GetCurrentTexture to leave alone certain fields
123 #define MATERIALFLAG_CUSTOMSURFACE 0x00800000
124 // causes MATERIALFLAG_BLENDED to render a depth pass before rendering, hiding backfaces and other hidden geometry
125 #define MATERIALFLAG_TRANSDEPTH 0x01000000
126 // like refraction, but doesn't distort etc.
127 #define MATERIALFLAG_CAMERA 0x02000000
128 // disable rtlight on surface - does not disable other types of lighting (LIGHTMAP, MODELLIGHT)
129 #define MATERIALFLAG_NORTLIGHT 0x04000000
130 // alphagen vertex - should always be used with MATERIALFLAG_ALPHA | MATERIALFLAG_BLENDED | MATERIALFLAG_NOSHADOW (or MATERIALFLAG_ADD instead of MATERIALFLAG_ALPHA)
131 #define MATERIALFLAG_ALPHAGEN_VERTEX 0x08000000
132 // use occlusion buffer for corona
133 #define MATERIALFLAG_OCCLUDE 0x10000000
134 // use vertex color instead of lighting (e.g. particles and other glowy stuff), use with MATERIALFLAG_FULLBRIGHT
135 #define MATERIALFLAG_VERTEXCOLOR 0x20000000
136 // sample the q3bsp lightgrid in the shader rather than relying on MATERIALFLAG_MODELLIGHT
137 #define MATERIALFLAG_LIGHTGRID 0x40000000
138 // combined mask of all attributes that require depth sorted rendering
139 #define MATERIALFLAGMASK_DEPTHSORTED (MATERIALFLAG_BLENDED | MATERIALFLAG_NODEPTHTEST)
140 // combined mask of all attributes that cause some sort of transparency
141 #define MATERIALFLAGMASK_TRANSLUCENT (MATERIALFLAG_WATERALPHA | MATERIALFLAG_SKY | MATERIALFLAG_NODRAW | MATERIALFLAG_ALPHATEST | MATERIALFLAG_BLENDED | MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION)
143 typedef struct medge_s
149 struct entity_render_s;
153 typedef struct mnode_s
155 //this part shared between node and leaf
156 mplane_t *plane; // != NULL
157 struct mnode_s *parent;
158 struct mportal_s *portals;
159 // for bounding box culling
162 // supercontents from all brushes inside this node or leaf
163 int combinedsupercontents;
165 // this part unique to node
166 struct mnode_s *children[2];
169 unsigned int firstsurface;
170 unsigned int numsurfaces;
174 typedef struct mleaf_s
176 //this part shared between node and leaf
177 mplane_t *plane; // == NULL
178 struct mnode_s *parent;
179 struct mportal_s *portals;
180 // for bounding box culling
183 // supercontents from all brushes inside this node or leaf
184 int combinedsupercontents;
186 // this part unique to leaf
188 int clusterindex; // -1 is not in pvs, >= 0 is pvs bit number
189 int areaindex; // q3bsp
190 int containscollisionsurfaces; // indicates whether the leafsurfaces contains q3 patches
192 int *firstleafsurface;
193 int numleafbrushes; // q3bsp
194 int *firstleafbrush; // q3bsp
195 unsigned char ambient_sound_level[NUM_AMBIENTS]; // q1bsp
196 int contents; // q1bsp: // TODO: remove (only used temporarily during loading when making collision hull 0)
197 int portalmarkid; // q1bsp // used by see-polygon-through-portals visibility checker
201 typedef struct mclipnode_s
204 int children[2]; // negative numbers are contents
207 typedef struct hull_s
209 mclipnode_t *clipnodes;
219 typedef struct mportal_s
221 struct mportal_s *next; // the next portal on this leaf
222 mleaf_t *here; // the leaf this portal is on
223 mleaf_t *past; // the leaf through this portal (infront)
226 vec3_t mins, maxs; // culling
228 double tracetime; // refreshed to realtime by traceline tests
232 typedef struct svbspmesh_s
234 struct svbspmesh_s *next;
235 int numverts, maxverts;
236 int numtriangles, maxtriangles;
242 typedef struct model_brush_lightstyleinfo_s
249 model_brush_lightstyleinfo_t;
251 typedef struct model_brush_s
253 // true if this model is a HalfLife .bsp file
255 // true if this model is a BSP2rmqe .bsp file (expanded 32bit bsp format for rmqe)
257 // true if this model is a BSP2 .bsp file (expanded 32bit bsp format for DarkPlaces, others?)
259 // true if this model is a Quake2 .bsp file (IBSP38)
261 // true if this model is a Quake3 .bsp file (IBSP46)
263 // true if this model is a Quake1/Quake2 .bsp file where skymasking capability exists
265 // string of entity definitions (.map format)
268 // if not NULL this is a submodel
269 struct model_s *parentmodel;
270 // (this is the number of the submodel, an index into submodels)
273 // number of submodels in this map (just used by server to know how many
274 // submodels to load)
276 // pointers to each of the submodels
277 struct model_s **submodels;
280 mplane_t *data_planes;
285 // visible leafs, not counting 0 (solid)
287 // number of actual leafs (including 0 which is solid)
292 int *data_leafbrushes;
294 int num_leafsurfaces;
295 int *data_leafsurfaces;
298 mportal_t *data_portals;
300 int num_portalpoints;
301 mvertex_t *data_portalpoints;
304 struct q3mbrush_s *data_brushes;
307 struct q3mbrushside_s *data_brushsides;
311 int num_pvsclusterbytes;
312 unsigned char *data_pvsclusters;
314 //pvschain = model->brush.data_pvsclusters + mycluster * model->brush.num_pvsclusterbytes;
315 //if (pvschain[thatcluster >> 3] & (1 << (thatcluster & 7)))
317 // collision geometry for q3 curves
318 int num_collisionvertices;
319 int num_collisiontriangles;
320 float *data_collisionvertex3f;
321 int *data_collisionelement3i;
323 // a mesh containing all shadow casting geometry for the whole model (including submodels), portions of this are referenced by each surface's num_firstshadowmeshtriangle
324 struct shadowmesh_s *shadowmesh;
326 // a mesh containing all SUPERCONTENTS_SOLID surfaces for this model or submodel, for physics engines to use
327 struct shadowmesh_s *collisionmesh;
330 int (*SuperContentsFromNativeContents)(int nativecontents);
331 int (*NativeContentsFromSuperContents)(int supercontents);
332 unsigned char *(*GetPVS)(struct model_s *model, const vec3_t p);
333 int (*FatPVS)(struct model_s *model, const vec3_t org, vec_t radius, unsigned char *pvsbuffer, int pvsbufferlength, qbool merge);
334 int (*BoxTouchingPVS)(struct model_s *model, const unsigned char *pvs, const vec3_t mins, const vec3_t maxs);
335 int (*BoxTouchingLeafPVS)(struct model_s *model, const unsigned char *pvs, const vec3_t mins, const vec3_t maxs);
336 int (*BoxTouchingVisibleLeafs)(struct model_s *model, const unsigned char *visibleleafs, const vec3_t mins, const vec3_t maxs);
337 int (*FindBoxClusters)(struct model_s *model, const vec3_t mins, const vec3_t maxs, int maxclusters, int *clusterlist);
338 void (*LightPoint)(struct model_s *model, const vec3_t p, vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal);
339 void (*FindNonSolidLocation)(struct model_s *model, const vec3_t in, vec3_t out, vec_t radius);
340 mleaf_t *(*PointInLeaf)(struct model_s *model, const vec3_t p);
341 // these are actually only found on brushq1, but NULL is handled gracefully
342 void (*AmbientSoundLevelsForPoint)(struct model_s *model, const vec3_t p, unsigned char *out, int outsize);
343 void (*RoundUpToHullSize)(struct model_s *cmodel, const vec3_t inmins, const vec3_t inmaxs, vec3_t outmins, vec3_t outmaxs);
344 // trace a line of sight through this model (returns false if the line if sight is definitely blocked)
345 qbool (*TraceLineOfSight)(struct model_s *model, const vec3_t start, const vec3_t end, const vec3_t acceptmins, const vec3_t acceptmaxs);
347 char skybox[MAX_QPATH];
349 struct skinframe_s *solidskyskinframe;
350 struct skinframe_s *alphaskyskinframe;
352 qbool supportwateralpha;
360 // the first cast is to shut up a stupid warning by clang, the second cast is to make both sides have the same type
361 #define CHECKPVSBIT(pvs,b) ((b) >= 0 ? (unsigned char) ((pvs)[(b) >> 3] & (1 << ((b) & 7))) : (unsigned char) false)
362 #define SETPVSBIT(pvs,b) (void) ((b) >= 0 ? (unsigned char) ((pvs)[(b) >> 3] |= (1 << ((b) & 7))) : (unsigned char) false)
363 #define CLEARPVSBIT(pvs,b) (void) ((b) >= 0 ? (unsigned char) ((pvs)[(b) >> 3] &= ~(1 << ((b) & 7))) : (unsigned char) false)