]> icculus.org git repositories - divverent/darkplaces.git/blob - model_brush.h
optimizing R_DrawSurfaces and WorldNode functions
[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         // surface number, to avoid having to do a divide to find the number of a surface from it's address
158         int number;
159         // should be drawn if visframe == r_framecount (set by WorldNode functions)
160         //int visframe;
161         // should be drawn if onscreen and not a backface (used for setting visframe)
162         //int pvsframe;
163         // chain of surfaces marked visible by pvs
164         //struct msurface_s *pvschain;
165
166         // the node plane this is on, backwards if SURF_PLANEBACK flag set
167         mplane_t *plane;
168         // SURF_ flags
169         int flags;
170         // rendering chain
171         struct msurface_s *texturechain;
172
173         // look up in model->surfedges[], negative numbers are backwards edges
174         int firstedge;
175         int numedges;
176
177         short texturemins[2];
178         short extents[2];
179
180         mtexinfo_t *texinfo;
181         texture_t *currenttexture; // updated (animated) during early surface processing each frame
182
183         // index into d_lightstylevalue array, 255 means not used (black)
184         qbyte styles[MAXLIGHTMAPS];
185         // RGB lighting data [numstyles][height][width][3]
186         qbyte *samples;
187         // stain to apply on lightmap (soot/dirt/blood/whatever)
188         qbyte *stainsamples;
189
190         // these fields are generated during model loading
191         // the lightmap texture fragment to use on the surface
192         rtexture_t *lightmaptexture;
193         // the stride when building lightmaps to comply with fragment update
194         int lightmaptexturestride;
195         // mesh for rendering
196         surfmesh_t *mesh;
197
198         // these are just 3D points defining the outline of the polygon,
199         // no texcoord info (that can be generated from these)
200         int poly_numverts;
201         float *poly_verts;
202         // bounding box for onscreen checks, and center for sorting
203         vec3_t poly_mins, poly_maxs, poly_center;
204
205         // these are regenerated every frame
206         // lighting info
207         int dlightframe;
208         int dlightbits[8];
209         // avoid redundent addition of dlights
210         int lightframe;
211         // only render each surface once
212         //int worldnodeframe;
213
214         // these cause lightmap updates if regenerated
215         // values currently used in lightmap
216         unsigned short cached_light[MAXLIGHTMAPS];
217         // if lightmap was lit by dynamic lights, force update on next frame
218         short cached_dlight;
219         // to cause lightmap to be rerendered when v_overbrightbits changes
220         short cached_lightscalebit;
221         // rerender lightmaps when r_ambient changes
222         float cached_ambient;
223 }
224 msurface_t;
225
226 typedef struct mnode_s
227 {
228 // common with leaf
229         // always 0 in nodes
230         int contents;
231
232         struct mnode_s *parent;
233         struct mportal_s *portals;
234
235         // for bounding box culling
236         vec3_t mins;
237         vec3_t maxs;
238
239 // node specific
240         mplane_t *plane;
241         struct mnode_s *children[2];
242
243         unsigned short firstsurface;
244         unsigned short numsurfaces;
245 }
246 mnode_t;
247
248 typedef struct mleaf_s
249 {
250 // common with node
251         // always negative in leafs
252         int contents;
253
254         struct mnode_s *parent;
255         struct mportal_s *portals;
256
257         // for bounding box culling
258         vec3_t mins;
259         vec3_t maxs;
260
261 // leaf specific
262         // potentially visible if current (r_pvsframecount)
263         int pvsframe;
264         // used by certain worldnode variants to avoid processing the same leaf twice in a frame
265         int worldnodeframe;
266         // used by polygon-through-portals visibility checker
267         int portalmarkid;
268
269         qbyte *compressed_vis;
270
271         int *firstmarksurface;
272         int nummarksurfaces;
273         qbyte ambient_sound_level[NUM_AMBIENTS];
274 }
275 mleaf_t;
276
277 typedef struct
278 {
279         dclipnode_t *clipnodes;
280         mplane_t *planes;
281         int firstclipnode;
282         int lastclipnode;
283         vec3_t clip_mins;
284         vec3_t clip_maxs;
285         vec3_t clip_size;
286 }
287 hull_t;
288
289 typedef struct mportal_s
290 {
291         struct mportal_s *next; // the next portal on this leaf
292         mleaf_t *here; // the leaf this portal is on
293         mleaf_t *past; // the leaf through this portal (infront)
294         mvertex_t *points;
295         int numpoints;
296         mplane_t plane;
297         int visframe; // is this portal visible this frame?
298 }
299 mportal_t;
300
301 typedef struct mlight_s
302 {
303         // location of light
304         vec3_t origin;
305         // distance attenuation scale (smaller is a larger light)
306         float falloff;
307         // color and brightness combined
308         vec3_t light;
309         // brightness bias, used for limiting radius without a hard edge
310         float subtract;
311         // spotlight direction
312         vec3_t spotdir;
313         // cosine of spotlight cone angle (or 0 if not a spotlight)
314         float spotcone;
315         // distance bias (larger value is softer and darker)
316         float distbias;
317         // light style controlling this light
318         int style;
319         // used only for loading calculations, number of leafs this shines on
320         //int numleafs;
321 }
322 mlight_t;
323
324 extern rtexture_t *r_notexture;
325 extern texture_t r_notexture_mip;
326
327 struct model_s;
328 void Mod_LoadBrushModel (struct model_s *mod, void *buffer);
329 void Mod_BrushInit(void);
330
331 void Mod_FindNonSolidLocation(vec3_t pos, struct model_s *mod);
332 mleaf_t *Mod_PointInLeaf (const float *p, struct model_s *model);
333 int Mod_PointContents (const float *p, struct model_s *model);
334 qbyte *Mod_LeafPVS (mleaf_t *leaf, struct model_s *model);
335
336 #endif
337