]> icculus.org git repositories - divverent/darkplaces.git/blob - render.h
remove the -f makefile.bsd
[divverent/darkplaces.git] / render.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 RENDER_H
22 #define RENDER_H
23
24 // flag arrays used for visibility checking on world model
25 // (all other entities have no per-surface/per-leaf visibility checks)
26 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_clusters
27 extern unsigned char r_pvsbits[(32768+7)>>3];
28 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_leafs
29 extern unsigned char r_worldleafvisible[32768];
30 // TODO: dynamic resize according to r_refdef.worldmodel->num_surfaces
31 extern unsigned char r_worldsurfacevisible[262144];
32
33 // 1.0f / N table
34 extern float ixtable[4096];
35
36 // far clip distance for scene
37 extern float r_farclip;
38
39 // fog stuff
40 extern void FOG_clear(void);
41 extern float fog_density, fog_red, fog_green, fog_blue;
42
43 // sky stuff
44 extern cvar_t r_sky;
45 extern cvar_t r_skyscroll1;
46 extern cvar_t r_skyscroll2;
47 extern int skyrendernow, skyrendermasked;
48 extern int R_SetSkyBox(const char *sky);
49 extern void R_SkyStartFrame(void);
50 extern void R_Sky(void);
51 extern void R_ResetSkyBox(void);
52
53 // SHOWLMP stuff (Nehahra)
54 extern void SHOWLMP_decodehide(void);
55 extern void SHOWLMP_decodeshow(void);
56 extern void SHOWLMP_drawall(void);
57 extern void SHOWLMP_clear(void);
58
59 // render profiling stuff
60 extern char r_speeds_string[1024];
61 extern int r_timereport_active;
62
63 // lighting stuff
64 extern cvar_t r_ambient;
65 extern cvar_t gl_flashblend;
66
67 // vis stuff
68 extern cvar_t r_novis;
69
70 extern cvar_t r_lerpsprites;
71 extern cvar_t r_lerpmodels;
72 extern cvar_t r_waterscroll;
73
74 extern cvar_t developer_texturelogging;
75
76 typedef struct rmesh_s
77 {
78         // vertices of this mesh
79         int maxvertices;
80         int numvertices;
81         float *vertex3f;
82         float *svector3f;
83         float *tvector3f;
84         float *normal3f;
85         float *texcoord2f;
86         float *texcoordlightmap2f;
87         float *color4f;
88         // triangles of this mesh
89         int maxtriangles;
90         int numtriangles;
91         int *element3i;
92         int *neighbor3i;
93         // snapping epsilon
94         float epsilon2;
95 }
96 rmesh_t;
97
98 // useful functions for rendering
99 void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b);
100 void R_FillColors(float *out, int verts, float r, float g, float b, float a);
101 int R_Mesh_AddVertex3f(rmesh_t *mesh, const float *v);
102 void R_Mesh_AddPolygon3f(rmesh_t *mesh, int numvertices, float *vertex3f);
103 void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *planes);
104
105 #define TOP_RANGE               16                      // soldier uniform colors
106 #define BOTTOM_RANGE    96
107
108 //=============================================================================
109
110 extern int r_framecount;
111 extern mplane_t frustum[5];
112
113 typedef struct renderstats_s
114 {
115         int entities;
116         int entities_surfaces;
117         int entities_triangles;
118         int world_leafs;
119         int world_portals;
120         int particles;
121         int meshes;
122         int meshes_elements;
123         int lights;
124         int lights_clears;
125         int lights_scissored;
126         int lights_lighttriangles;
127         int lights_shadowtriangles;
128         int lights_dynamicshadowtriangles;
129         int bloom;
130         int bloom_copypixels;
131         int bloom_drawpixels;
132 }
133 renderstats_t;
134
135 extern renderstats_t renderstats;
136
137 // brightness of world lightmaps and related lighting
138 // (often reduced when world rtlights are enabled)
139 extern float r_lightmapintensity;
140 // whether to draw world lights realtime, dlights realtime, and their shadows
141 extern qboolean r_rtworld;
142 extern qboolean r_rtworldshadows;
143 extern qboolean r_rtdlight;
144 extern qboolean r_rtdlightshadows;
145
146 extern cvar_t r_nearclip;
147
148 // forces all rendering to draw triangle outlines
149 extern cvar_t r_showtris;
150 extern cvar_t r_shownormals;
151 extern cvar_t r_showlighting;
152 extern cvar_t r_showshadowvolumes;
153 extern cvar_t r_showcollisionbrushes;
154 extern cvar_t r_showcollisionbrushes_polygonfactor;
155 extern cvar_t r_showcollisionbrushes_polygonoffset;
156 extern cvar_t r_showdisabledepthtest;
157
158 //
159 // view origin
160 //
161 extern vec3_t r_vieworigin;
162 extern vec3_t r_viewforward;
163 extern vec3_t r_viewleft;
164 extern vec3_t r_viewright;
165 extern vec3_t r_viewup;
166 extern int r_view_x;
167 extern int r_view_y;
168 extern int r_view_z;
169 extern int r_view_width;
170 extern int r_view_height;
171 extern int r_view_depth;
172 extern matrix4x4_t r_view_matrix;
173 extern float r_polygonfactor;
174 extern float r_polygonoffset;
175 extern float r_shadowpolygonfactor;
176 extern float r_shadowpolygonoffset;
177
178 extern  mleaf_t         *r_viewleaf, *r_oldviewleaf;
179
180 extern  qboolean        envmap;
181
182 extern cvar_t r_drawentities;
183 extern cvar_t r_drawviewmodel;
184 extern cvar_t r_speeds;
185 extern cvar_t r_fullbright;
186 extern cvar_t r_wateralpha;
187 extern cvar_t r_dynamic;
188
189 void R_Init(void);
190 void R_UpdateWorld(void); // needs no r_refdef
191 void R_RenderView(void); // must call R_UpdateWorld and set r_refdef first
192
193
194 void R_InitSky (unsigned char *src, int bytesperpixel); // called at level load
195
196 void R_WorldVisibility();
197 void R_DrawParticles(void);
198 void R_DrawExplosions(void);
199
200 #define gl_solid_format 3
201 #define gl_alpha_format 4
202
203 int R_CullBox(const vec3_t mins, const vec3_t maxs);
204
205 #define FOGTABLEWIDTH 1024
206 extern vec3_t fogcolor;
207 extern vec_t fogdensity;
208 extern vec_t fogrange;
209 extern vec_t fograngerecip;
210 extern int fogtableindex;
211 extern vec_t fogtabledistmultiplier;
212 extern float fogtable[FOGTABLEWIDTH];
213 extern qboolean fogenabled;
214 #define VERTEXFOGTABLE(dist) (fogtableindex = (int)((dist) * fogtabledistmultiplier), fogtable[bound(0, fogtableindex, FOGTABLEWIDTH - 1)])
215
216 #include "r_modules.h"
217
218 #include "meshqueue.h"
219
220 #include "r_lerpanim.h"
221
222 extern cvar_t r_render;
223 extern cvar_t r_waterwarp;
224
225 extern cvar_t r_textureunits;
226 extern cvar_t r_glsl;
227 extern cvar_t r_glsl_offsetmapping;
228 extern cvar_t r_glsl_offsetmapping_reliefmapping;
229 extern cvar_t r_glsl_offsetmapping_scale;
230 extern cvar_t r_glsl_usehalffloat;
231 extern cvar_t r_glsl_surfacenormalize;
232 extern cvar_t r_glsl_deluxemapping;
233
234 extern cvar_t gl_polyblend;
235 extern cvar_t gl_dither;
236
237 extern cvar_t r_smoothnormals_areaweighting;
238
239 #include "gl_backend.h"
240
241 #include "r_light.h"
242
243 extern rtexture_t *r_texture_blanknormalmap;
244 extern rtexture_t *r_texture_white;
245 extern rtexture_t *r_texture_black;
246 extern rtexture_t *r_texture_notexture;
247 extern rtexture_t *r_texture_whitecube;
248 extern rtexture_t *r_texture_normalizationcube;
249 extern rtexture_t *r_texture_fogattenuation;
250 extern rtexture_t *r_texture_fogintensity;
251
252 void R_TimeReport(char *name);
253
254 // r_stain
255 void R_Stain(const vec3_t origin, float radius, int cr1, int cg1, int cb1, int ca1, int cr2, int cg2, int cb2, int ca2);
256
257 void R_DrawWorldCrosshair(void);
258 void R_Draw2DCrosshair(void);
259
260 void R_CalcBeam_Vertex3f(float *vert, const vec3_t org1, const vec3_t org2, float width);
261 void R_DrawSprite(int blendfunc1, int blendfunc2, rtexture_t *texture, rtexture_t *fogtexture, int depthdisable, const vec3_t origin, const vec3_t left, const vec3_t up, float scalex1, float scalex2, float scaley1, float scaley2, float cr, float cg, float cb, float ca);
262
263 extern mempool_t *r_main_mempool;
264
265 extern int rsurface_array_size;
266 extern float *rsurface_array_vertex3f;
267 extern float *rsurface_array_svector3f;
268 extern float *rsurface_array_tvector3f;
269 extern float *rsurface_array_normal3f;
270 extern float *rsurface_array_color4f;
271 extern float *rsurface_array_texcoord3f;
272
273 void R_Mesh_ResizeArrays(int newvertices);
274
275 struct entity_render_s;
276 struct texture_s;
277 struct msurface_s;
278 void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t);
279 void R_UpdateAllTextureInfo(entity_render_t *ent);
280 void R_QueueTextureSurfaceList(entity_render_t *ent, struct texture_s *texture, int texturenumsurfaces, const struct msurface_s **texturesurfacelist, const vec3_t modelorg);
281 void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces);
282
283 #define SHADERPERMUTATION_MODE_LIGHTSOURCE (1<<0) // (lightsource) use directional pixel shading from light source (rtlight)
284 #define SHADERPERMUTATION_MODE_LIGHTDIRECTIONMAP_MODELSPACE (1<<1) // (lightmap) use directional pixel shading from texture containing modelspace light directions (deluxemap)
285 #define SHADERPERMUTATION_MODE_LIGHTDIRECTIONMAP_TANGENTSPACE (1<<2) // (lightmap) use directional pixel shading from texture containing tangentspace light directions (deluxemap)
286 #define SHADERPERMUTATION_MODE_LIGHTDIRECTION (1<<3) // (lightmap) use directional pixel shading from fixed light direction (q3bsp)
287 #define SHADERPERMUTATION_GLOW (1<<4) // (lightmap) blend in an additive glow texture
288 #define SHADERPERMUTATION_FOG (1<<5) // tint the color by fog color or black if using additive blend mode
289 #define SHADERPERMUTATION_COLORMAPPING (1<<6) // indicates this is a colormapped skin
290 #define SHADERPERMUTATION_SPECULAR (1<<7) // (lightsource or deluxemapping) render specular effects
291 #define SHADERPERMUTATION_CUBEFILTER (1<<8) // (lightsource) use cubemap light filter
292 #define SHADERPERMUTATION_OFFSETMAPPING (1<<9) // adjust texcoords to roughly simulate a displacement mapped surface
293 #define SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING (1<<10) // adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
294 #define SHADERPERMUTATION_SURFACENORMALIZE (1<<11) // (lightsource or deluxemapping) improved bumpmapping
295 #define SHADERPERMUTATION_GEFORCEFX (1<<12) // use half vector types if available (NVIDIA specific)
296 #define SHADERPERMUTATION_COUNT (1<<13) // how many permutations are possible
297
298 typedef struct r_glsl_permutation_s
299 {
300         // indicates if we have tried compiling this permutation already
301         qboolean compiled;
302         // 0 if compilation failed
303         int program;
304         int loc_Texture_Normal;
305         int loc_Texture_Color;
306         int loc_Texture_Gloss;
307         int loc_Texture_Cube;
308         int loc_Texture_FogMask;
309         int loc_Texture_Pants;
310         int loc_Texture_Shirt;
311         int loc_Texture_Lightmap;
312         int loc_Texture_Deluxemap;
313         int loc_Texture_Glow;
314         int loc_FogColor;
315         int loc_LightPosition;
316         int loc_EyePosition;
317         int loc_LightColor;
318         int loc_Color_Pants;
319         int loc_Color_Shirt;
320         int loc_FogRangeRecip;
321         int loc_AmbientScale;
322         int loc_DiffuseScale;
323         int loc_SpecularScale;
324         int loc_SpecularPower;
325         int loc_OffsetMapping_Scale;
326         int loc_AmbientColor;
327         int loc_DiffuseColor;
328         int loc_SpecularColor;
329         int loc_LightDir;
330 }
331 r_glsl_permutation_t;
332
333 // information about each possible shader permutation
334 extern r_glsl_permutation_t r_glsl_permutations[SHADERPERMUTATION_COUNT];
335 // currently selected permutation
336 r_glsl_permutation_t *r_glsl_permutation;
337
338 void R_GLSL_CompilePermutation(int permutation);
339 void R_SetupSurfaceShader(const entity_render_t *ent, const texture_t *texture, const vec3_t modelorg, const vec3_t lightcolorbase, qboolean modellighting);
340
341 #endif
342