]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - model_brush.h
fixed typo
[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 /*
25 ==============================================================================
26
27 BRUSH MODELS
28
29 ==============================================================================
30 */
31
32
33 //
34 // in memory representation
35 //
36 typedef struct
37 {
38         vec3_t position;
39 }
40 mvertex_t;
41
42 #define SIDE_FRONT 0
43 #define SIDE_BACK 1
44 #define SIDE_ON 2
45
46
47 // plane_t structure
48 typedef struct mplane_s
49 {
50         vec3_t normal;
51         float dist;
52         // for texture axis selection and fast side tests
53         int type;
54         // LordHavoc: faster than id's signbits system
55         int (*BoxOnPlaneSideFunc) (vec3_t emins, vec3_t emaxs, struct mplane_s *p);
56 }
57 mplane_t;
58
59 typedef struct texture_s
60 {
61         // name
62         char name[16];
63         // size
64         unsigned int width, height;
65         // SURF_ flags
66         unsigned int flags;
67
68         // base texture without fullbrights, never NULL
69         rtexture_t *texture;
70         // fullbrights texture, NULL if no fullbrights used
71         rtexture_t *glowtexture;
72         // alpha texture (used for fogging), NULL if opaque
73         rtexture_t *fogtexture;
74         // detail texture (usually not used if transparent)
75         rtexture_t *detailtexture;
76
77         // total frames in sequence and alternate sequence
78         int anim_total[2];
79         // direct pointers to each of the frames in the sequences
80         // (indexed as [alternate][frame])
81         struct texture_s *anim_frames[2][10];
82         // set if animated or there is an alternate frame set
83         // (this is an optimization in the renderer)
84         int animated;
85 }
86 texture_t;
87
88
89 #define SURF_PLANEBACK 2
90 #define SURF_DRAWSKY 4
91 #define SURF_DRAWTURB 0x10
92 #define SURF_LIGHTMAP 0x20
93 #define SURF_DRAWNOALPHA 0x100
94 #define SURF_DRAWFULLBRIGHT 0x200
95 #define SURF_LIGHTBOTHSIDES 0x400
96 #define SURF_CLIPSOLID 0x800 // this polygon can obscure other polygons
97
98 typedef struct
99 {
100         unsigned short v[2];
101 }
102 medge_t;
103
104 typedef struct
105 {
106         float vecs[2][4];
107         texture_t *texture;
108         int flags;
109 }
110 mtexinfo_t;
111
112 // LordHavoc: replaces glpoly, triangle mesh
113 typedef struct surfmesh_s
114 {
115         // can be multiple meshs per surface
116         struct surfmesh_s *chain;
117         int numverts;
118         int numtriangles;
119         float *verts;
120         int *lightmapoffsets;
121         float *st;
122         float *uv;
123         float *ab;
124         int *index;
125 }
126 surfmesh_t;
127
128 typedef struct msurface_s
129 {
130         // should be drawn if visframe == r_framecount (set by WorldNode functions)
131         int visframe;
132         // should be drawn if onscreen and not a backface (used for setting visframe)
133         int pvsframe;
134         // chain of surfaces marked visible by pvs
135         struct msurface_s *pvschain;
136
137         // the node plane this is on, backwards if SURF_PLANEBACK flag set
138         mplane_t *plane;
139         // SURF_ flags
140         int flags;
141         struct Cshader_s *shader;
142         struct msurface_s *chain; // shader rendering chain
143
144         // look up in model->surfedges[], negative numbers are backwards edges
145         int firstedge;
146         int numedges;
147
148         short texturemins[2];
149         short extents[2];
150
151         mtexinfo_t *texinfo;
152         texture_t *currenttexture; // updated (animated) during early surface processing each frame
153
154         // index into d_lightstylevalue array, 255 means not used (black)
155         qbyte styles[MAXLIGHTMAPS];
156         // RGB lighting data [numstyles][height][width][3]
157         qbyte *samples;
158         // stain to apply on lightmap (soot/dirt/blood/whatever)
159         qbyte *stainsamples;
160
161         // these fields are generated during model loading
162         // the lightmap texture fragment to use on the surface
163         rtexture_t *lightmaptexture;
164         // the stride when building lightmaps to comply with fragment update
165         int lightmaptexturestride;
166         // mesh for rendering
167         surfmesh_t *mesh;
168
169         // these are just 3D points defining the outline of the polygon,
170         // no texcoord info (that can be generated from these)
171         int poly_numverts;
172         float *poly_verts;
173         // bounding box for onscreen checks, and center for sorting
174         vec3_t poly_mins, poly_maxs, poly_center;
175
176         // these are regenerated every frame
177         // lighting info
178         int dlightframe;
179         int dlightbits[8];
180         // avoid redundent addition of dlights
181         int lightframe;
182         // only render each surface once
183         int worldnodeframe;
184
185         // these cause lightmap updates if regenerated
186         // values currently used in lightmap
187         unsigned short cached_light[MAXLIGHTMAPS];
188         // if lightmap was lit by dynamic lights, force update on next frame
189         short cached_dlight;
190         // to cause lightmap to be rerendered when v_overbrightbits changes
191         short cached_lightscalebit;
192         // rerender lightmaps when r_ambient changes
193         float cached_ambient;
194 }
195 msurface_t;
196
197 #define SHADERSTAGE_SKY 0
198 #define SHADERSTAGE_NORMAL 1
199 #define SHADERSTAGE_COUNT 2
200
201 struct entity_render_s;
202 // change this stuff when real shaders are added
203 typedef struct Cshader_s
204 {
205         void (*shaderfunc[SHADERSTAGE_COUNT])(const struct entity_render_s *ent, const msurface_t *firstsurf);
206         // list of surfaces using this shader (used during surface rendering)
207         msurface_t *chain;
208 }
209 Cshader_t;
210
211 extern Cshader_t Cshader_wall_vertex;
212 extern Cshader_t Cshader_wall_lightmap;
213 extern Cshader_t Cshader_wall_fullbright;
214 extern Cshader_t Cshader_water;
215 extern Cshader_t Cshader_sky;
216
217 typedef struct mnode_s
218 {
219 // common with leaf
220         // always 0 in nodes
221         int contents;
222
223         struct mnode_s *parent;
224         struct mportal_s *portals;
225
226         // for bounding box culling
227         vec3_t mins;
228         vec3_t maxs;
229
230 // node specific
231         mplane_t *plane;
232         struct mnode_s *children[2];
233
234         unsigned short firstsurface;
235         unsigned short numsurfaces;
236 }
237 mnode_t;
238
239 typedef struct mleaf_s
240 {
241 // common with node
242         // always negative in leafs
243         int contents;
244
245         struct mnode_s *parent;
246         struct mportal_s *portals;
247
248         // for bounding box culling
249         vec3_t mins;
250         vec3_t maxs;
251
252 // leaf specific
253         // potentially visible if current (r_pvsframecount)
254         int pvsframe;
255         // used by certain worldnode variants to avoid processing the same leaf twice in a frame
256         int worldnodeframe;
257         // used by polygon-through-portals visibility checker
258         int portalmarkid;
259
260         qbyte *compressed_vis;
261
262         msurface_t **firstmarksurface;
263         int nummarksurfaces;
264         qbyte ambient_sound_level[NUM_AMBIENTS];
265 }
266 mleaf_t;
267
268 typedef struct
269 {
270         dclipnode_t *clipnodes;
271         mplane_t *planes;
272         int firstclipnode;
273         int lastclipnode;
274         vec3_t clip_mins;
275         vec3_t clip_maxs;
276         vec3_t clip_size;
277 }
278 hull_t;
279
280 typedef struct mportal_s
281 {
282         struct mportal_s *next; // the next portal on this leaf
283         mleaf_t *here; // the leaf this portal is on
284         mleaf_t *past; // the leaf through this portal (infront)
285         mvertex_t *points;
286         int numpoints;
287         mplane_t plane;
288         int visframe; // is this portal visible this frame?
289 }
290 mportal_t;
291
292 typedef struct mlight_s
293 {
294         // location of light
295         vec3_t origin;
296         // distance attenuation scale (smaller is a larger light)
297         float falloff;
298         // color and brightness combined
299         vec3_t light;
300         // brightness bias, used for limiting radius without a hard edge
301         float subtract;
302         // spotlight direction
303         vec3_t spotdir;
304         // cosine of spotlight cone angle (or 0 if not a spotlight)
305         float spotcone;
306         // distance bias (larger value is softer and darker)
307         float distbias;
308         // light style controlling this light
309         int style;
310         // used only for loading calculations, number of leafs this shines on
311         //int numleafs;
312 }
313 mlight_t;
314
315 extern rtexture_t *r_notexture;
316 extern texture_t r_notexture_mip;
317
318 struct model_s;
319 void Mod_LoadBrushModel (struct model_s *mod, void *buffer);
320 void Mod_BrushInit(void);
321
322 void Mod_FindNonSolidLocation(vec3_t pos, struct model_s *mod);
323 mleaf_t *Mod_PointInLeaf (const float *p, struct model_s *model);
324 int Mod_PointContents (const float *p, struct model_s *model);
325 qbyte *Mod_LeafPVS (mleaf_t *leaf, struct model_s *model);
326
327 #endif
328