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