]> icculus.org git repositories - divverent/darkplaces.git/blob - model_brush.h
detail texturing added (although with just one generated texture applied to everything)
[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 typedef struct surfvertex_s
112 {
113         // position
114         float v[3];
115         // offset into lightmap (used by vertex lighting)
116         int lightmapoffset;
117         // texture coordinates
118         float st[2];
119         // lightmap coordinates
120         float uv[2];
121         // detail texture coordinates
122         float ab[2];
123 }
124 surfvertex_t;
125
126 // LordHavoc: replaces glpoly, triangle mesh
127 typedef struct surfmesh_s
128 {
129         // can be multiple meshs per surface
130         struct surfmesh_s *chain;
131         int numverts;
132         int numtriangles;
133         surfvertex_t *vertex;
134         int *index;
135 }
136 surfmesh_t;
137
138 typedef struct msurface_s
139 {
140         // should be drawn if visframe == r_framecount (set by WorldNode functions)
141         int                     visframe;
142
143         // the node plane this is on, backwards if SURF_PLANEBACK flag set
144         mplane_t        *plane;
145         // SURF_ flags
146         int                     flags;
147         struct Cshader_s        *shader;
148         struct msurface_s       *chain; // shader rendering chain
149
150         // look up in model->surfedges[], negative numbers are backwards edges
151         int                     firstedge;
152         int                     numedges;
153
154         short           texturemins[2];
155         short           extents[2];
156
157         mtexinfo_t      *texinfo;
158         texture_t       *currenttexture; // updated (animated) during early surface processing each frame
159
160         // index into d_lightstylevalue array, 255 means not used (black)
161         qbyte           styles[MAXLIGHTMAPS];
162         // RGB lighting data [numstyles][height][width][3]
163         qbyte           *samples;
164         // stain to apply on lightmap (soot/dirt/blood/whatever)
165         qbyte           *stainsamples;
166
167         // these fields are generated during model loading
168         // the lightmap texture fragment to use on the surface
169         rtexture_t *lightmaptexture;
170         // the stride when building lightmaps to comply with fragment update
171         int                     lightmaptexturestride;
172         // mesh for rendering
173         surfmesh_t      *mesh;
174
175         // these are just 3D points defining the outline of the polygon,
176         // no texcoord info (that can be generated from these)
177         int                     poly_numverts;
178         float           *poly_verts;
179
180         // these are regenerated every frame
181         // lighting info
182         int                     dlightframe;
183         int                     dlightbits[8];
184         // avoid redundent addition of dlights
185         int                     lightframe;
186         // only render each surface once
187         int                     worldnodeframe;
188         // marked when surface is prepared for the frame
189         int                     insertframe;
190
191         // these cause lightmap updates if regenerated
192         // values currently used in lightmap
193         unsigned short cached_light[MAXLIGHTMAPS];
194         // if lightmap was lit by dynamic lights, force update on next frame
195         short           cached_dlight;
196         // to cause lightmap to be rerendered when v_overbrightbits changes
197         short           cached_lightscalebit;
198         // rerender lightmaps when r_ambient changes
199         float           cached_ambient;
200 }
201 msurface_t;
202
203 #define SHADERSTAGE_SKY 0
204 #define SHADERSTAGE_NORMAL 1
205 #define SHADERSTAGE_COUNT 2
206
207 // change this stuff when real shaders are added
208 typedef struct Cshader_s
209 {
210         void (*shaderfunc[SHADERSTAGE_COUNT])(msurface_t *firstsurf);
211         // list of surfaces using this shader (used during surface rendering)
212         msurface_t *chain;
213 }
214 Cshader_t;
215
216 extern Cshader_t Cshader_wall_vertex;
217 extern Cshader_t Cshader_wall_lightmap;
218 extern Cshader_t Cshader_wall_fullbright;
219 extern Cshader_t Cshader_water;
220 extern Cshader_t Cshader_sky;
221
222 // warning: if this is changed, references must be updated in cpu_* assembly files
223 typedef struct mnode_s
224 {
225 // common with leaf
226         int                                     contents;               // 0, to differentiate from leafs
227
228         struct mnode_s          *parent;
229         struct mportal_s        *portals;
230
231         // for bounding box culling
232         vec3_t                          mins;
233         vec3_t                          maxs;
234
235 // node specific
236         mplane_t                        *plane;
237         struct mnode_s          *children[2];
238
239         unsigned short          firstsurface;
240         unsigned short          numsurfaces;
241 }
242 mnode_t;
243
244 typedef struct mleaf_s
245 {
246 // common with node
247         int                                     contents;               // will be a negative contents number
248
249         struct mnode_s          *parent;
250         struct mportal_s        *portals;
251
252         // for bounding box culling
253         vec3_t                          mins;
254         vec3_t                          maxs;
255
256 // leaf specific
257         int                                     visframe;               // visible if current (r_framecount)
258         int                                     worldnodeframe; // used by certain worldnode variants to avoid processing the same leaf twice in a frame
259         int                                     portalmarkid;   // used by polygon-through-portals visibility checker
260
261         // LordHavoc: leaf based dynamic lighting
262         int                                     dlightbits[8];
263         int                                     dlightframe;
264
265         qbyte                           *compressed_vis;
266
267         msurface_t                      **firstmarksurface;
268         int                                     nummarksurfaces;
269         qbyte                           ambient_sound_level[NUM_AMBIENTS];
270 }
271 mleaf_t;
272
273 typedef struct
274 {
275         dclipnode_t     *clipnodes;
276         mplane_t        *planes;
277         int                     firstclipnode;
278         int                     lastclipnode;
279         vec3_t          clip_mins;
280         vec3_t          clip_maxs;
281         vec3_t          clip_size;
282 }
283 hull_t;
284
285 typedef struct mportal_s
286 {
287         struct mportal_s *next; // the next portal on this leaf
288         mleaf_t *here; // the leaf this portal is on
289         mleaf_t *past; // the leaf through this portal (infront)
290         mvertex_t *points;
291         int numpoints;
292         mplane_t plane;
293         int visframe; // is this portal visible this frame?
294 }
295 mportal_t;
296
297 typedef struct mlight_s
298 {
299         vec3_t origin;
300         float falloff;
301         vec3_t light;
302         float subtract;
303         vec3_t spotdir;
304         float spotcone; // cosine of spotlight cone angle (or 0 if not a spotlight)
305         float distbias;
306         int style;
307         int numleafs; // used only for loading calculations, number of leafs this shines on
308 }
309 mlight_t;
310
311 extern rtexture_t *r_notexture;
312 extern texture_t r_notexture_mip;
313
314 struct model_s;
315 void Mod_LoadBrushModel (struct model_s *mod, void *buffer);
316 void Mod_BrushInit(void);
317 void Mod_FindNonSolidLocation(vec3_t pos, struct model_s *mod);
318
319 #endif
320