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