DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
model_brush.h
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, 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
31BRUSH MODELS
32
33==============================================================================
34*/
35
36
37
38//
39// in memory representation
40//
41typedef struct mvertex_s
42{
44}
46
47#define SIDE_FRONT 0
48#define SIDE_BACK 1
49#define SIDE_ON 2
50
51
52// plane_t structure
53typedef struct mplane_s
54{
55 union
56 {
57 struct
58 {
61 };
63 };
64 // for texture axis selection and fast side tests
65 int type; // set by PlaneClassify()
66 int signbits; // set by PlaneClassify()
67}
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
143typedef struct medge_s
144{
145 unsigned int v[2];
146}
147medge_t;
148
149struct entity_render_s;
150struct texture_s;
151struct msurface_s;
152
153typedef 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
162 // supercontents from all brushes inside this node or leaf
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}
172mnode_t;
173
174typedef 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
183 // supercontents from all brushes inside this node or leaf
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
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}
199mleaf_t;
200
201typedef struct mclipnode_s
202{
204 int children[2]; // negative numbers are contents
206
217hull_t;
218
219typedef 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)
226 vec3_t mins, maxs; // culling
228 double tracetime; // refreshed to realtime by traceline tests
229}
231
232typedef struct svbspmesh_s
233{
234 struct svbspmesh_s *next;
235 int numverts, maxverts;
236 int numtriangles, maxtriangles;
237 float *verts;
239}
241
242typedef struct model_brush_lightstyleinfo_s
243{
244 int style;
245 int value;
248}
250
251typedef struct model_brush_s
252{
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)
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)
272
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;
278
281
284
285 // visible leafs, not counting 0 (solid)
287 // number of actual leafs (including 0 which is solid)
290
293
296
299
302
304 struct q3mbrush_s *data_brushes;
305
307 struct q3mbrushside_s *data_brushsides;
308
309 // pvs
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
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 size_t (*FatPVS)(struct model_s *model, const vec3_t org, vec_t radius, unsigned char **pvsbuffer, mempool_t *pool, 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
353
354 // QuakeWorld
357}
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
#define NUM_AMBIENTS
Definition bspfile.h:307
vector mins
void() predraw
vector maxs
string model
static int(ZEXPORT *qz_inflate)(z_stream *strm
const GLdouble * v
Definition glquake.h:762
#define MAX_QPATH
max length of a quake game pathname
Definition qdefs.h:169
float vec_t
Definition qtypes.h:68
vec_t vec3_t[3]
Definition qtypes.h:71
bool qbool
Definition qtypes.h:9
vec_t vec4_t[4]
Definition qtypes.h:72
vec3_t clip_size
mclipnode_t * clipnodes
int firstclipnode
int lastclipnode
vec3_t clip_maxs
mplane_t * planes
vec3_t clip_mins
int numleafbrushes
int * firstleafbrush
int portalmarkid
vec3_t mins
int contents
int * firstleafsurface
mplane_t * plane
int containscollisionsurfaces
int areaindex
vec3_t maxs
int clusterindex
struct mnode_s * parent
int numleafsurfaces
struct mportal_s * portals
int combinedsupercontents
vec3_t maxs
int combinedsupercontents
struct mportal_s * portals
unsigned int numsurfaces
struct mnode_s * parent
vec3_t mins
mplane_t * plane
unsigned int firstsurface
unsigned char * data_pvsclusters
int num_collisiontriangles
struct q3mbrush_s * data_brushes
qbool supportwateralpha
struct skinframe_s * alphaskyskinframe
mportal_t * data_portals
struct model_s ** submodels
struct skinframe_s * solidskyskinframe
int * data_collisionelement3i
mvertex_t * data_portalpoints
int num_pvsclusterbytes
float * data_collisionvertex3f
int * data_leafbrushes
struct shadowmesh_s * collisionmesh
int * data_leafsurfaces
struct model_s * parentmodel
int num_collisionvertices
mplane_t * data_planes
mleaf_t * data_leafs
struct shadowmesh_s * shadowmesh
mnode_t * data_nodes
struct q3mbrushside_s * data_brushsides
vec3_t normal
Definition model_brush.h:59
vec_t dist
Definition model_brush.h:60
int signbits
Definition model_brush.h:66
vec4_t normal_and_dist
Definition model_brush.h:62
double tracetime
mleaf_t * here
mvertex_t * points
struct mportal_s * next
mleaf_t * past
mplane_t plane
vec3_t maxs
vec3_t position
Definition model_brush.h:43
float * verts
struct svbspmesh_s * next