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