2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
25 ==============================================================================
29 ==============================================================================
34 // in memory representation
48 typedef struct mplane_s
52 // for texture axis selection and fast side tests
54 // LordHavoc: faster than id's signbits system
55 int (*BoxOnPlaneSideFunc) (vec3_t emins, vec3_t emaxs, struct mplane_s *p);
59 #define SHADERSTAGE_SKY 0
60 #define SHADERSTAGE_NORMAL 1
61 #define SHADERSTAGE_COUNT 2
63 #define SHADERFLAGS_NEEDLIGHTMAP 1
65 struct entity_render_s;
67 // change this stuff when real shaders are added
68 typedef struct Cshader_s
70 void (*shaderfunc[SHADERSTAGE_COUNT])(const struct entity_render_s *ent, const struct texture_s *texture);
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;
80 typedef struct texture_s
85 unsigned int width, height;
89 // base texture without fullbrights, never NULL
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;
98 // shader to use for this texture
101 // list of surfaces to render using this texture
102 struct msurface_s *surfacechain;
104 // total frames in sequence and alternate sequence
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)
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
139 // LordHavoc: replaces glpoly, triangle mesh
140 typedef struct surfmesh_s
142 // can be multiple meshs per surface
143 struct surfmesh_s *chain;
147 int *lightmapoffsets;
155 typedef struct msurface_s
157 // should be drawn if visframe == r_framecount (set by WorldNode functions)
159 // should be drawn if onscreen and not a backface (used for setting visframe)
161 // chain of surfaces marked visible by pvs
162 struct msurface_s *pvschain;
164 // the node plane this is on, backwards if SURF_PLANEBACK flag set
169 struct msurface_s *texturechain;
171 // look up in model->surfedges[], negative numbers are backwards edges
175 short texturemins[2];
179 texture_t *currenttexture; // updated (animated) during early surface processing each frame
181 // index into d_lightstylevalue array, 255 means not used (black)
182 qbyte styles[MAXLIGHTMAPS];
183 // RGB lighting data [numstyles][height][width][3]
185 // stain to apply on lightmap (soot/dirt/blood/whatever)
188 // these fields are generated during model loading
189 // the lightmap texture fragment to use on the surface
190 rtexture_t *lightmaptexture;
191 // the stride when building lightmaps to comply with fragment update
192 int lightmaptexturestride;
193 // mesh for rendering
196 // these are just 3D points defining the outline of the polygon,
197 // no texcoord info (that can be generated from these)
200 // bounding box for onscreen checks, and center for sorting
201 vec3_t poly_mins, poly_maxs, poly_center;
203 // these are regenerated every frame
207 // avoid redundent addition of dlights
209 // only render each surface once
212 // these cause lightmap updates if regenerated
213 // values currently used in lightmap
214 unsigned short cached_light[MAXLIGHTMAPS];
215 // if lightmap was lit by dynamic lights, force update on next frame
217 // to cause lightmap to be rerendered when v_overbrightbits changes
218 short cached_lightscalebit;
219 // rerender lightmaps when r_ambient changes
220 float cached_ambient;
224 typedef struct mnode_s
230 struct mnode_s *parent;
231 struct mportal_s *portals;
233 // for bounding box culling
239 struct mnode_s *children[2];
241 unsigned short firstsurface;
242 unsigned short numsurfaces;
246 typedef struct mleaf_s
249 // always negative in leafs
252 struct mnode_s *parent;
253 struct mportal_s *portals;
255 // for bounding box culling
260 // potentially visible if current (r_pvsframecount)
262 // used by certain worldnode variants to avoid processing the same leaf twice in a frame
264 // used by polygon-through-portals visibility checker
267 qbyte *compressed_vis;
269 msurface_t **firstmarksurface;
271 qbyte ambient_sound_level[NUM_AMBIENTS];
277 dclipnode_t *clipnodes;
287 typedef struct mportal_s
289 struct mportal_s *next; // the next portal on this leaf
290 mleaf_t *here; // the leaf this portal is on
291 mleaf_t *past; // the leaf through this portal (infront)
295 int visframe; // is this portal visible this frame?
299 typedef struct mlight_s
303 // distance attenuation scale (smaller is a larger light)
305 // color and brightness combined
307 // brightness bias, used for limiting radius without a hard edge
309 // spotlight direction
311 // cosine of spotlight cone angle (or 0 if not a spotlight)
313 // distance bias (larger value is softer and darker)
315 // light style controlling this light
317 // used only for loading calculations, number of leafs this shines on
322 extern rtexture_t *r_notexture;
323 extern texture_t r_notexture_mip;
326 void Mod_LoadBrushModel (struct model_s *mod, void *buffer);
327 void Mod_BrushInit(void);
329 void Mod_FindNonSolidLocation(vec3_t pos, struct model_s *mod);
330 mleaf_t *Mod_PointInLeaf (const float *p, struct model_s *model);
331 int Mod_PointContents (const float *p, struct model_s *model);
332 qbyte *Mod_LeafPVS (mleaf_t *leaf, struct model_s *model);