]> git.xonotic.org Git - xonotic/darkplaces.git/blob - model_brush.h
Merge MR 'Set groundentity when sv_gameplayfix_downtracesupportsongroundflag detects...
[xonotic/darkplaces.git] / model_brush.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_BRUSH_H
22 #define MODEL_BRUSH_H
23
24 #include "qtypes.h"
25 #include "qdefs.h"
26 #include "bspfile.h"
27
28 /*
29 ==============================================================================
30
31 BRUSH MODELS
32
33 ==============================================================================
34 */
35
36
37
38 //
39 // in memory representation
40 //
41 typedef struct mvertex_s
42 {
43         vec3_t position;
44 }
45 mvertex_t;
46
47 #define SIDE_FRONT 0
48 #define SIDE_BACK 1
49 #define SIDE_ON 2
50
51
52 // plane_t structure
53 typedef struct mplane_s
54 {
55         union
56         {
57                 struct
58                 {
59                         vec3_t normal;
60                         vec_t dist;
61                 };
62                 vec4_t normal_and_dist;
63         };
64         // for texture axis selection and fast side tests
65         int type; // set by PlaneClassify()
66         int signbits; // set by PlaneClassify()
67 }
68 mplane_t;
69
70 #define SHADERSTAGE_SKY 0
71 #define SHADERSTAGE_NORMAL 1
72 #define SHADERSTAGE_COUNT 2
73
74 //#define SURF_PLANEBACK 2
75
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
118 // render reflection
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)
142
143 typedef struct medge_s
144 {
145         unsigned int v[2];
146 }
147 medge_t;
148
149 struct entity_render_s;
150 struct texture_s;
151 struct msurface_s;
152
153 typedef struct mnode_s
154 {
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
160         vec3_t mins;
161         vec3_t maxs;
162         // supercontents from all brushes inside this node or leaf
163         int combinedsupercontents;
164
165         // this part unique to node
166         struct mnode_s *children[2];
167
168         // q1bsp specific
169         unsigned int firstsurface;
170         unsigned int numsurfaces;
171 }
172 mnode_t;
173
174 typedef struct mleaf_s
175 {
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
181         vec3_t mins;
182         vec3_t maxs;
183         // supercontents from all brushes inside this node or leaf
184         int combinedsupercontents;
185
186         // this part unique to leaf
187         // common
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
191         int numleafsurfaces;
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
198 }
199 mleaf_t;
200
201 typedef struct mclipnode_s
202 {
203         int                     planenum;
204         int                     children[2];    // negative numbers are contents
205 } mclipnode_t;
206
207 typedef struct hull_s
208 {
209         mclipnode_t *clipnodes;
210         mplane_t *planes;
211         int firstclipnode;
212         int lastclipnode;
213         vec3_t clip_mins;
214         vec3_t clip_maxs;
215         vec3_t clip_size;
216 }
217 hull_t;
218
219 typedef struct mportal_s
220 {
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)
224         int numpoints;
225         mvertex_t *points;
226         vec3_t mins, maxs; // culling
227         mplane_t plane;
228         double tracetime; // refreshed to realtime by traceline tests
229 }
230 mportal_t;
231
232 typedef struct svbspmesh_s
233 {
234         struct svbspmesh_s *next;
235         int numverts, maxverts;
236         int numtriangles, maxtriangles;
237         float *verts;
238         int *elements;
239 }
240 svbspmesh_t;
241
242 typedef struct model_brush_lightstyleinfo_s
243 {
244         int style;
245         int value;
246         int numsurfaces;
247         int *surfacelist;
248 }
249 model_brush_lightstyleinfo_t;
250
251 typedef struct model_brush_s
252 {
253         // true if this model is a HalfLife .bsp file
254         qbool ishlbsp;
255         // true if this model is a BSP2rmqe .bsp file (expanded 32bit bsp format for rmqe)
256         qbool isbsp2rmqe;
257         // true if this model is a BSP2 .bsp file (expanded 32bit bsp format for DarkPlaces, others?)
258         qbool isbsp2;
259         // true if this model is a Quake2 .bsp file (IBSP38)
260         qbool isq2bsp;
261         // true if this model is a Quake3 .bsp file (IBSP46)
262         qbool isq3bsp;
263         // true if this model is a Quake1/Quake2 .bsp file where skymasking capability exists
264         qbool skymasking;
265         // string of entity definitions (.map format)
266         char *entities;
267
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)
271         int submodel;
272
273         // number of submodels in this map (just used by server to know how many
274         // submodels to load)
275         int numsubmodels;
276         // pointers to each of the submodels
277         struct model_s **submodels;
278
279         int num_planes;
280         mplane_t *data_planes;
281
282         int num_nodes;
283         mnode_t *data_nodes;
284
285         // visible leafs, not counting 0 (solid)
286         int num_visleafs;
287         // number of actual leafs (including 0 which is solid)
288         int num_leafs;
289         mleaf_t *data_leafs;
290
291         int num_leafbrushes;
292         int *data_leafbrushes;
293
294         int num_leafsurfaces;
295         int *data_leafsurfaces;
296
297         int num_portals;
298         mportal_t *data_portals;
299
300         int num_portalpoints;
301         mvertex_t *data_portalpoints;
302
303         int num_brushes;
304         struct q3mbrush_s *data_brushes;
305
306         int num_brushsides;
307         struct q3mbrushside_s *data_brushsides;
308
309         // pvs
310         int num_pvsclusters;
311         int num_pvsclusterbytes;
312         unsigned char *data_pvsclusters;
313         // example
314         //pvschain = model->brush.data_pvsclusters + mycluster * model->brush.num_pvsclusterbytes;
315         //if (pvschain[thatcluster >> 3] & (1 << (thatcluster & 7)))
316
317         // collision geometry for q3 curves
318         int num_collisionvertices;
319         int num_collisiontriangles;
320         float *data_collisionvertex3f;
321         int *data_collisionelement3i;
322
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;
325
326         // a mesh containing all SUPERCONTENTS_SOLID surfaces for this model or submodel, for physics engines to use
327         struct shadowmesh_s *collisionmesh;
328
329         // common functions
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);
346
347         char skybox[MAX_QPATH];
348
349         struct skinframe_s *solidskyskinframe;
350         struct skinframe_s *alphaskyskinframe;
351
352         qbool supportwateralpha;
353
354         // QuakeWorld
355         int qw_md4sum;
356         int qw_md4sum2;
357 }
358 model_brush_t;
359
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)
364
365 #endif