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