]> icculus.org git repositories - divverent/darkplaces.git/blob - render.h
b7e8f853e4d8c38f51c1563b87486a7cb4c411bd
[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 #include "svbsp.h"
25
26 // 1.0f / N table
27 extern float ixtable[4096];
28
29 // fog stuff
30 extern void FOG_clear(void);
31
32 // sky stuff
33 extern cvar_t r_sky;
34 extern cvar_t r_skyscroll1;
35 extern cvar_t r_skyscroll2;
36 extern int skyrenderlater, skyrendermasked;
37 extern int R_SetSkyBox(const char *sky);
38 extern void R_SkyStartFrame(void);
39 extern void R_Sky(void);
40 extern void R_ResetSkyBox(void);
41
42 // SHOWLMP stuff (Nehahra)
43 extern void SHOWLMP_decodehide(void);
44 extern void SHOWLMP_decodeshow(void);
45 extern void SHOWLMP_drawall(void);
46
47 // render profiling stuff
48 extern int r_timereport_active;
49
50 // lighting stuff
51 extern cvar_t r_ambient;
52 extern cvar_t gl_flashblend;
53
54 // vis stuff
55 extern cvar_t r_novis;
56
57 extern cvar_t r_lerpsprites;
58 extern cvar_t r_lerpmodels;
59 extern cvar_t r_lerplightstyles;
60 extern cvar_t r_waterscroll;
61
62 extern cvar_t developer_texturelogging;
63
64 // shadow volume bsp struct with automatically growing nodes buffer
65 extern svbsp_t r_svbsp;
66
67 typedef struct rmesh_s
68 {
69         // vertices of this mesh
70         int maxvertices;
71         int numvertices;
72         float *vertex3f;
73         float *svector3f;
74         float *tvector3f;
75         float *normal3f;
76         float *texcoord2f;
77         float *texcoordlightmap2f;
78         float *color4f;
79         // triangles of this mesh
80         int maxtriangles;
81         int numtriangles;
82         int *element3i;
83         int *neighbor3i;
84         // snapping epsilon
85         float epsilon2;
86 }
87 rmesh_t;
88
89 // useful functions for rendering
90 void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b);
91 void R_FillColors(float *out, int verts, float r, float g, float b, float a);
92 int R_Mesh_AddVertex3f(rmesh_t *mesh, const float *v);
93 void R_Mesh_AddPolygon3f(rmesh_t *mesh, int numvertices, float *vertex3f);
94 void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *planes);
95
96 #define TOP_RANGE               16                      // soldier uniform colors
97 #define BOTTOM_RANGE    96
98
99 //=============================================================================
100
101 extern cvar_t r_nearclip;
102
103 // forces all rendering to draw triangle outlines
104 extern cvar_t r_showtris;
105 extern cvar_t r_shownormals;
106 extern cvar_t r_showlighting;
107 extern cvar_t r_showshadowvolumes;
108 extern cvar_t r_showcollisionbrushes;
109 extern cvar_t r_showcollisionbrushes_polygonfactor;
110 extern cvar_t r_showcollisionbrushes_polygonoffset;
111 extern cvar_t r_showdisabledepthtest;
112
113 //
114 // view origin
115 //
116 extern cvar_t r_drawentities;
117 extern cvar_t r_drawviewmodel;
118 extern cvar_t r_speeds;
119 extern cvar_t r_fullbright;
120 extern cvar_t r_wateralpha;
121 extern cvar_t r_dynamic;
122
123 void R_Init(void);
124 void R_UpdateVariables(void); // must call after setting up most of r_refdef, but before calling R_RenderView
125 void R_RenderView(void); // must set r_refdef and call R_UpdateVariables first
126
127 typedef enum r_refdef_scene_type_s {
128         RST_CLIENT,
129         RST_MENU,
130         RST_COUNT
131 } r_refdef_scene_type_t;
132
133 void R_SelectScene( r_refdef_scene_type_t scenetype );
134 r_refdef_scene_t * R_GetScenePointer( r_refdef_scene_type_t scenetype );
135
136 void R_SkinFrame_PrepareForPurge(void);
137 void R_SkinFrame_MarkUsed(skinframe_t *skinframe);
138 void R_SkinFrame_Purge(void);
139 // set last to NULL to start from the beginning
140 skinframe_t *R_SkinFrame_FindNextByName( skinframe_t *last, const char *name );
141 skinframe_t *R_SkinFrame_Find(const char *name, int textureflags, int comparewidth, int compareheight, int comparecrc, qboolean add);
142 skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qboolean complain);
143 skinframe_t *R_SkinFrame_LoadInternalBGRA(const char *name, int textureflags, const unsigned char *skindata, int width, int height);
144 skinframe_t *R_SkinFrame_LoadInternalQuake(const char *name, int textureflags, int loadpantsandshirt, int loadglowtexture, const unsigned char *skindata, int width, int height);
145 skinframe_t *R_SkinFrame_LoadInternal8bit(const char *name, int textureflags, const unsigned char *skindata, int width, int height, const unsigned int *palette, const unsigned int *alphapalette);
146 skinframe_t *R_SkinFrame_LoadMissing(void);
147
148 rtexture_t *R_GetCubemap(const char *basename);
149
150 void R_View_WorldVisibility(qboolean forcenovis);
151 void R_DrawDecals(void);
152 void R_DrawParticles(void);
153 void R_DrawExplosions(void);
154
155 #define gl_solid_format 3
156 #define gl_alpha_format 4
157
158 int R_CullBox(const vec3_t mins, const vec3_t maxs);
159 int R_CullBoxCustomPlanes(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes);
160
161 #include "r_modules.h"
162
163 #include "meshqueue.h"
164
165 extern qboolean r_framedata_failed;
166 void R_FrameData_Reset(void);
167 void R_FrameData_NewFrame(void);
168 void *R_FrameData_Alloc(size_t size);
169 void *R_FrameData_Store(size_t size, void *data);
170
171 void R_AnimCache_Free(void);
172 void R_AnimCache_ClearCache(void);
173 qboolean R_AnimCache_GetEntity(entity_render_t *ent, qboolean wantnormals, qboolean wanttangents);
174 void R_AnimCache_CacheVisibleEntities(void);
175
176 #include "r_lerpanim.h"
177
178 extern cvar_t r_render;
179 extern cvar_t r_renderview;
180 extern cvar_t r_waterwarp;
181
182 extern cvar_t r_textureunits;
183
184 extern cvar_t r_glsl_offsetmapping;
185 extern cvar_t r_glsl_offsetmapping_reliefmapping;
186 extern cvar_t r_glsl_offsetmapping_scale;
187 extern cvar_t r_glsl_deluxemapping;
188
189 extern cvar_t gl_polyblend;
190 extern cvar_t gl_dither;
191
192 extern cvar_t cl_deathfade;
193
194 extern cvar_t r_smoothnormals_areaweighting;
195
196 extern cvar_t r_test;
197
198 #include "gl_backend.h"
199
200 extern rtexture_t *r_texture_blanknormalmap;
201 extern rtexture_t *r_texture_white;
202 extern rtexture_t *r_texture_grey128;
203 extern rtexture_t *r_texture_black;
204 extern rtexture_t *r_texture_notexture;
205 extern rtexture_t *r_texture_whitecube;
206 extern rtexture_t *r_texture_normalizationcube;
207 extern rtexture_t *r_texture_fogattenuation;
208 //extern rtexture_t *r_texture_fogintensity;
209
210 extern unsigned int r_queries[MAX_OCCLUSION_QUERIES];
211 extern unsigned int r_numqueries;
212 extern unsigned int r_maxqueries;
213
214 void R_TimeReport(char *name);
215
216 // r_stain
217 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);
218
219 void R_CalcBeam_Vertex3f(float *vert, const vec3_t org1, const vec3_t org2, float width);
220 void R_CalcSprite_Vertex3f(float *vertex3f, const vec3_t origin, const vec3_t left, const vec3_t up, float scalex1, float scalex2, float scaley1, float scaley2);
221
222 extern mempool_t *r_main_mempool;
223
224 typedef struct rsurfacestate_s
225 {
226         // processing buffers
227         int array_size;
228         float *array_modelvertex3f;
229         float *array_modelsvector3f;
230         float *array_modeltvector3f;
231         float *array_modelnormal3f;
232         float *array_deformedvertex3f;
233         float *array_deformedsvector3f;
234         float *array_deformedtvector3f;
235         float *array_deformednormal3f;
236         float *array_generatedtexcoordtexture2f;
237         float *array_color4f;
238         float *array_texcoord3f;
239
240         // current model array pointers
241         // these may point to processing buffers if model is animated,
242         // otherwise they point to static data.
243         // these are not directly used for rendering, they are just another level
244         // of processing
245         //
246         // these either point at array_model* buffers (if the model is animated)
247         // or the model->surfmesh.data_* buffers (if the model is not animated)
248         //
249         // these are only set when an entity render begins, they do not change on
250         // a per surface basis.
251         //
252         // this indicates the model* arrays are pointed at array_model* buffers
253         // (in other words, the model has been animated in software)
254         qboolean generatedvertex;
255         const float *modelvertex3f;
256         int modelvertex3f_bufferobject;
257         size_t modelvertex3f_bufferoffset;
258         const float *modelsvector3f;
259         int modelsvector3f_bufferobject;
260         size_t modelsvector3f_bufferoffset;
261         const float *modeltvector3f;
262         int modeltvector3f_bufferobject;
263         size_t modeltvector3f_bufferoffset;
264         const float *modelnormal3f;
265         int modelnormal3f_bufferobject;
266         size_t modelnormal3f_bufferoffset;
267         const float *modellightmapcolor4f;
268         int modellightmapcolor4f_bufferobject;
269         size_t modellightmapcolor4f_bufferoffset;
270         const float *modeltexcoordtexture2f;
271         int modeltexcoordtexture2f_bufferobject;
272         size_t modeltexcoordtexture2f_bufferoffset;
273         const float *modeltexcoordlightmap2f;
274         int modeltexcoordlightmap2f_bufferobject;
275         size_t modeltexcoordlightmap2f_bufferoffset;
276         const int *modelelement3i;
277         const unsigned short *modelelement3s;
278         int modelelement3i_bufferobject;
279         int modelelement3s_bufferobject;
280         const int *modellightmapoffsets;
281         int modelnum_vertices;
282         int modelnum_triangles;
283         const msurface_t *modelsurfaces;
284         // current rendering array pointers
285         // these may point to any of several different buffers depending on how
286         // much processing was needed to prepare this model for rendering
287         // these usually equal the model* pointers, they only differ if
288         // deformvertexes is used in a q3 shader, and consequently these can
289         // change on a per-surface basis (according to rsurface.texture)
290         //
291         // the exception is the color array which is often generated based on
292         // colormod, alpha fading, and fogging, it may also come from q3bsp vertex
293         // lighting of certain surfaces
294         const float *vertex3f;
295         int vertex3f_bufferobject;
296         size_t vertex3f_bufferoffset;
297         const float *svector3f;
298         int svector3f_bufferobject;
299         size_t svector3f_bufferoffset;
300         const float *tvector3f;
301         int tvector3f_bufferobject;
302         size_t tvector3f_bufferoffset;
303         const float *normal3f;
304         int normal3f_bufferobject;
305         size_t normal3f_bufferoffset;
306         const float *lightmapcolor4f;
307         int lightmapcolor4f_bufferobject;
308         size_t lightmapcolor4f_bufferoffset;
309         const float *texcoordtexture2f;
310         int texcoordtexture2f_bufferobject;
311         size_t texcoordtexture2f_bufferoffset;
312         const float *texcoordlightmap2f;
313         int texcoordlightmap2f_bufferobject;
314         size_t texcoordlightmap2f_bufferoffset;
315         // some important fields from the entity
316         int ent_skinnum;
317         int ent_qwskin;
318         int ent_flags;
319         float ent_shadertime;
320         int ent_alttextures; // used by q1bsp animated textures (pressed buttons)
321         // transform matrices to render this entity and effects on this entity
322         matrix4x4_t matrix;
323         matrix4x4_t inversematrix;
324         // scale factors for transforming lengths into/out of entity space
325         float matrixscale;
326         float inversematrixscale;
327         // animation blending state from entity
328         frameblend_t frameblend[MAX_FRAMEBLENDS];
329         skeleton_t *skeleton;
330         // directional model shading state from entity
331         vec3_t modellight_ambient;
332         vec3_t modellight_diffuse;
333         vec3_t modellight_lightdir;
334         // colormapping state from entity (these are black if colormapping is off)
335         vec3_t colormap_pantscolor;
336         vec3_t colormap_shirtcolor;
337         // special coloring of ambient/diffuse textures (gloss not affected)
338         // colormod[3] is the alpha of the entity
339         float colormod[4];
340         // special coloring of glow textures
341         float glowmod[3];
342         // view location in model space
343         vec3_t localvieworigin;
344         // polygon offset data for submodels
345         float basepolygonfactor;
346         float basepolygonoffset;
347         // current texture in batching code
348         texture_t *texture;
349         // whether lightmapping is active on this batch
350         // (otherwise vertex colored)
351         qboolean uselightmaptexture;
352         // fog plane in model space for direct application to vertices
353         float fograngerecip;
354         float fogmasktabledistmultiplier;
355         float fogplane[4];
356         float fogheightfade;
357         float fogplaneviewdist;
358
359         // rtlight rendering
360         // light currently being rendered
361         const rtlight_t *rtlight;
362
363         // this is the location of the light in entity space
364         vec3_t entitylightorigin;
365         // this transforms entity coordinates to light filter cubemap coordinates
366         // (also often used for other purposes)
367         matrix4x4_t entitytolight;
368         // based on entitytolight this transforms -1 to +1 to 0 to 1 for purposes
369         // of attenuation texturing in full 3D (Z result often ignored)
370         matrix4x4_t entitytoattenuationxyz;
371         // this transforms only the Z to S, and T is always 0.5
372         matrix4x4_t entitytoattenuationz;
373
374         // pointer to an entity_render_t used only by R_GetCurrentTexture and
375         // RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity as a unique id within
376         // each frame (see r_frame also)
377         entity_render_t *entity;
378 }
379 rsurfacestate_t;
380
381 extern rsurfacestate_t rsurface;
382
383 void RSurf_ActiveWorldEntity(void);
384 void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, qboolean wanttangents, qboolean prepass);
385 void RSurf_ActiveCustomEntity(const matrix4x4_t *matrix, const matrix4x4_t *inversematrix, int entflags, double shadertime, float r, float g, float b, float a, int numvertices, const float *vertex3f, const float *texcoord2f, const float *normal3f, const float *svector3f, const float *tvector3f, const float *color4f, int numtriangles, const int *element3i, const unsigned short *element3s, qboolean wantnormals, qboolean wanttangents);
386 void RSurf_SetupDepthAndCulling(void);
387
388 void R_Mesh_ResizeArrays(int newvertices);
389
390 texture_t *R_GetCurrentTexture(texture_t *t);
391 void R_DrawWorldSurfaces(qboolean skysurfaces, qboolean writedepth, qboolean depthonly, qboolean debug, qboolean prepass);
392 void R_DrawModelSurfaces(entity_render_t *ent, qboolean skysurfaces, qboolean writedepth, qboolean depthonly, qboolean debug, qboolean prepass);
393 void R_AddWaterPlanes(entity_render_t *ent);
394 void R_DrawCustomSurface(skinframe_t *skinframe, const matrix4x4_t *texmatrix, int materialflags, int firstvertex, int numvertices, int firsttriangle, int numtriangles, qboolean writedepth, qboolean prepass);
395 void R_DrawCustomSurface_Texture(texture_t *texture, const matrix4x4_t *texmatrix, int materialflags, int firstvertex, int numvertices, int firsttriangle, int numtriangles, qboolean writedepth, qboolean prepass);
396
397 void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generatetangents, int texturenumsurfaces, const msurface_t **texturesurfacelist);
398 void RSurf_DrawBatch_Simple(int texturenumsurfaces, const msurface_t **texturesurfacelist);
399
400 void R_DecalSystem_SplatEntities(const vec3_t org, const vec3_t normal, float r, float g, float b, float a, float s1, float t1, float s2, float t2, float size);
401
402 typedef enum rsurfacepass_e
403 {
404         RSURFPASS_BASE,
405         RSURFPASS_BACKGROUND,
406         RSURFPASS_RTLIGHT,
407         RSURFPASS_DEFERREDGEOMETRY,
408 }
409 rsurfacepass_t;
410
411 typedef enum gl20_texunit_e
412 {
413         // postprocess shaders, and generic shaders:
414         GL20TU_FIRST = 0,
415         GL20TU_SECOND = 1,
416         GL20TU_GAMMARAMPS = 2,
417         // standard material properties
418         GL20TU_NORMAL = 0,
419         GL20TU_COLOR = 1,
420         GL20TU_GLOSS = 2,
421         GL20TU_GLOW = 3,
422         // material properties for a second material
423         GL20TU_SECONDARY_NORMAL = 4,
424         GL20TU_SECONDARY_COLOR = 5,
425         GL20TU_SECONDARY_GLOSS = 6,
426         GL20TU_SECONDARY_GLOW = 7,
427         // material properties for a colormapped material
428         // conflicts with secondary material
429         GL20TU_PANTS = 4,
430         GL20TU_SHIRT = 5,
431         // fog fade in the distance
432         GL20TU_FOGMASK = 8,
433         // compiled ambient lightmap and deluxemap
434         GL20TU_LIGHTMAP = 9,
435         GL20TU_DELUXEMAP = 10,
436         // refraction, used by water shaders
437         GL20TU_REFRACTION = 3,
438         // reflection, used by water shaders, also with normal material rendering
439         // conflicts with secondary material
440         GL20TU_REFLECTION = 7,
441         // rtlight attenuation (distance fade) and cubemap filter (projection texturing)
442         // conflicts with lightmap/deluxemap
443         GL20TU_ATTENUATION = 9,
444         GL20TU_CUBE = 10,
445         GL20TU_SHADOWMAPRECT = 11,
446         GL20TU_SHADOWMAPCUBE = 11,
447         GL20TU_SHADOWMAP2D = 11,
448         GL20TU_CUBEPROJECTION = 12,
449         // rtlight prepass data (screenspace depth and normalmap)
450         GL20TU_SCREENDEPTH = 13,
451         GL20TU_SCREENNORMALMAP = 14,
452         // lightmap prepass data (screenspace diffuse and specular from lights)
453         GL20TU_SCREENDIFFUSE = 11,
454         GL20TU_SCREENSPECULAR = 12,
455         // fake reflections
456         GL20TU_REFLECTMASK = 14,
457         GL20TU_REFLECTCUBE = 15
458 }
459 gl20_texunit;
460
461 void R_SetupShader_Generic(rtexture_t *first, rtexture_t *second, int texturemode, int rgbscale);
462 void R_SetupShader_DepthOrShadow(void);
463 void R_SetupShader_ShowDepth(void);
464 void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, float ambientscale, float diffusescale, float specularscale, rsurfacepass_t rsurfacepass);
465 void R_SetupShader_DeferredLight(const rtlight_t *rtlight);
466
467 typedef struct r_waterstate_waterplane_s
468 {
469         rtexture_t *texture_refraction;
470         rtexture_t *texture_reflection;
471         mplane_t plane;
472         int materialflags; // combined flags of all water surfaces on this plane
473         unsigned char pvsbits[(MAX_MAP_LEAFS+7)>>3]; // FIXME: buffer overflow on huge maps
474         qboolean pvsvalid;
475 }
476 r_waterstate_waterplane_t;
477
478 typedef struct r_waterstate_s
479 {
480         qboolean enabled;
481
482         qboolean renderingscene; // true while rendering a refraction or reflection texture, disables water surfaces
483
484         int waterwidth, waterheight;
485         int texturewidth, textureheight;
486
487         int maxwaterplanes; // same as MAX_WATERPLANES
488         int numwaterplanes;
489         r_waterstate_waterplane_t waterplanes[MAX_WATERPLANES];
490
491         float screenscale[2];
492         float screencenter[2];
493 }
494 r_waterstate_t;
495
496 extern r_waterstate_t r_waterstate;
497
498 #endif
499