]> git.xonotic.org Git - xonotic/darkplaces.git/blob - render.h
build: minor adjustments
[xonotic/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 typedef enum glsl_attrib_e
27 {
28         GLSLATTRIB_POSITION = 0,
29         GLSLATTRIB_COLOR = 1,
30         GLSLATTRIB_TEXCOORD0 = 2,
31         GLSLATTRIB_TEXCOORD1 = 3,
32         GLSLATTRIB_TEXCOORD2 = 4,
33         GLSLATTRIB_TEXCOORD3 = 5,
34         GLSLATTRIB_TEXCOORD4 = 6,
35         GLSLATTRIB_TEXCOORD5 = 7,
36         GLSLATTRIB_TEXCOORD6 = 8,
37         GLSLATTRIB_TEXCOORD7 = 9,
38 }
39 glsl_attrib;
40
41 typedef enum shaderlanguage_e
42 {
43         SHADERLANGUAGE_GLSL,
44         SHADERLANGUAGE_COUNT
45 }
46 shaderlanguage_t;
47
48 // this enum selects which of the glslshadermodeinfo entries should be used
49 typedef enum shadermode_e
50 {
51         SHADERMODE_GENERIC, ///< (particles/HUD/etc) vertex color, optionally multiplied by one texture
52         SHADERMODE_POSTPROCESS, ///< postprocessing shader (r_glsl_postprocess)
53         SHADERMODE_DEPTH_OR_SHADOW, ///< (depthfirst/shadows) vertex shader only
54         SHADERMODE_FLATCOLOR, ///< (lightmap) modulate texture by uniform color (q1bsp, q3bsp)
55         SHADERMODE_VERTEXCOLOR, ///< (lightmap) modulate texture by vertex colors (q3bsp)
56         SHADERMODE_LIGHTMAP, ///< (lightmap) modulate texture by lightmap texture (q1bsp, q3bsp)
57         SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE, ///< (lightmap) use directional pixel shading from texture containing modelspace light directions (q3bsp deluxemap)
58         SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE, ///< (lightmap) use directional pixel shading from texture containing tangentspace light directions (q1bsp deluxemap)
59         SHADERMODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP, // forced deluxemapping for lightmapped surfaces
60         SHADERMODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR, // forced deluxemapping for vertexlit surfaces
61         SHADERMODE_LIGHTDIRECTION, ///< (lightmap) use directional pixel shading from fixed light direction (q3bsp)
62         SHADERMODE_LIGHTSOURCE, ///< (lightsource) use directional pixel shading from light source (rtlight)
63         SHADERMODE_REFRACTION, ///< refract background (the material is rendered normally after this pass)
64         SHADERMODE_WATER, ///< refract background and reflection (the material is rendered normally after this pass)
65         SHADERMODE_DEFERREDGEOMETRY, ///< (deferred) render material properties to screenspace geometry buffers
66         SHADERMODE_DEFERREDLIGHTSOURCE, ///< (deferred) use directional pixel shading from light source (rtlight) on screenspace geometry buffers
67         SHADERMODE_COUNT
68 }
69 shadermode_t;
70
71 typedef enum shaderpermutation_e
72 {
73         SHADERPERMUTATION_DIFFUSE = 1<<0, ///< (lightsource) whether to use directional shading
74         SHADERPERMUTATION_VERTEXTEXTUREBLEND = 1<<1, ///< indicates this is a two-layer material blend based on vertex alpha (q3bsp)
75         SHADERPERMUTATION_VIEWTINT = 1<<2, ///< view tint (postprocessing only), use vertex colors (generic only)
76         SHADERPERMUTATION_COLORMAPPING = 1<<3, ///< indicates this is a colormapped skin
77         SHADERPERMUTATION_SATURATION = 1<<4, ///< saturation (postprocessing only)
78         SHADERPERMUTATION_FOGINSIDE = 1<<5, ///< tint the color by fog color or black if using additive blend mode
79         SHADERPERMUTATION_FOGOUTSIDE = 1<<6, ///< tint the color by fog color or black if using additive blend mode
80         SHADERPERMUTATION_FOGHEIGHTTEXTURE = 1<<7, ///< fog color and density determined by texture mapped on vertical axis
81         SHADERPERMUTATION_FOGALPHAHACK = 1<<8, ///< fog color and density determined by texture mapped on vertical axis
82         SHADERPERMUTATION_GAMMARAMPS = 1<<9, ///< gamma (postprocessing only)
83         SHADERPERMUTATION_CUBEFILTER = 1<<10, ///< (lightsource) use cubemap light filter
84         SHADERPERMUTATION_GLOW = 1<<11, ///< (lightmap) blend in an additive glow texture
85         SHADERPERMUTATION_BLOOM = 1<<12, ///< bloom (postprocessing only)
86         SHADERPERMUTATION_SPECULAR = 1<<13, ///< (lightsource or deluxemapping) render specular effects
87         SHADERPERMUTATION_POSTPROCESSING = 1<<14, ///< user defined postprocessing (postprocessing only)
88         SHADERPERMUTATION_REFLECTION = 1<<15, ///< normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the surface
89         SHADERPERMUTATION_OFFSETMAPPING = 1<<16, ///< adjust texcoords to roughly simulate a displacement mapped surface
90         SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING = 1<<17, ///< adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
91         SHADERPERMUTATION_SHADOWMAP2D = 1<<18, ///< (lightsource) use shadowmap texture as light filter
92         SHADERPERMUTATION_SHADOWMAPVSDCT = 1<<19, ///< (lightsource) use virtual shadow depth cube texture for shadowmap indexing
93         SHADERPERMUTATION_SHADOWMAPORTHO = 1<<20, ///< (lightsource) use orthographic shadowmap projection
94         SHADERPERMUTATION_DEFERREDLIGHTMAP = 1<<21, ///< (lightmap) read Texture_ScreenDiffuse/Specular textures and add them on top of lightmapping
95         SHADERPERMUTATION_ALPHAKILL = 1<<22, ///< (deferredgeometry) discard pixel if diffuse texture alpha below 0.5, (generic) apply global alpha
96         SHADERPERMUTATION_REFLECTCUBE = 1<<23, ///< fake reflections using global cubemap (not HDRI light probe)
97         SHADERPERMUTATION_NORMALMAPSCROLLBLEND = 1<<24, ///< (water) counter-direction normalmaps scrolling
98         SHADERPERMUTATION_BOUNCEGRID = 1<<25, ///< (lightmap) use Texture_BounceGrid as an additional source of ambient light
99         SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL = 1<<26, ///< (lightmap) use 16-component pixels in bouncegrid texture for directional lighting rather than standard 4-component
100         SHADERPERMUTATION_TRIPPY = 1<<27, ///< use trippy vertex shader effect
101         SHADERPERMUTATION_DEPTHRGB = 1<<28, ///< read/write depth values in RGB color coded format for older hardware without depth samplers
102         SHADERPERMUTATION_ALPHAGEN_VERTEX = 1<<29, ///< alphaGen vertex
103         SHADERPERMUTATION_SKELETAL = 1<<30, ///< (skeletal models) use skeletal matrices to deform vertices (gpu-skinning)
104         SHADERPERMUTATION_OCCLUDE = 1<<31, ///< use occlusion buffer for corona
105         SHADERPERMUTATION_COUNT = 32 ///< size of shaderpermutationinfo array
106 }
107 shaderpermutation_t;
108
109 // 1.0f / N table
110 extern float ixtable[4096];
111
112 // fog stuff
113 void FOG_clear(void);
114
115 // sky stuff
116 extern cvar_t r_sky;
117 extern cvar_t r_skyscroll1;
118 extern cvar_t r_skyscroll2;
119 extern cvar_t r_sky_scissor;
120 extern cvar_t r_q3bsp_renderskydepth;
121 extern int skyrenderlater, skyrendermasked;
122 extern int skyscissor[4];
123 int R_SetSkyBox(const char *sky);
124 void R_SkyStartFrame(void);
125 void R_Sky(void);
126 void R_ResetSkyBox(void);
127
128 // SHOWLMP stuff (Nehahra)
129 void SHOWLMP_decodehide(void);
130 void SHOWLMP_decodeshow(void);
131 void SHOWLMP_drawall(void);
132
133 // render profiling stuff
134 extern int r_timereport_active;
135
136 // lighting stuff
137 extern cvar_t r_ambient;
138 extern cvar_t gl_flashblend;
139
140 // vis stuff
141 extern cvar_t r_novis;
142
143 extern cvar_t r_trippy;
144 extern cvar_t r_fxaa;
145
146 extern cvar_t r_lerpsprites;
147 extern cvar_t r_lerpmodels;
148 extern cvar_t r_lerplightstyles;
149 extern cvar_t r_waterscroll;
150
151 extern cvar_t developer_texturelogging;
152
153 // shadow volume bsp struct with automatically growing nodes buffer
154 extern svbsp_t r_svbsp;
155
156 typedef struct rmesh_s
157 {
158         // vertices of this mesh
159         int maxvertices;
160         int numvertices;
161         float *vertex3f;
162         float *svector3f;
163         float *tvector3f;
164         float *normal3f;
165         float *texcoord2f;
166         float *texcoordlightmap2f;
167         float *color4f;
168         // triangles of this mesh
169         int maxtriangles;
170         int numtriangles;
171         int *element3i;
172         // snapping epsilon
173         float epsilon2;
174 }
175 rmesh_t;
176
177 // useful functions for rendering
178 void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b);
179 void R_FillColors(float *out, int verts, float r, float g, float b, float a);
180 void R_Mesh_AddPolygon3f(rmesh_t *mesh, int numvertices, float *vertex3f);
181 void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *planes);
182
183 #define TOP_RANGE               16                      // soldier uniform colors
184 #define BOTTOM_RANGE    96
185
186 //=============================================================================
187
188 extern cvar_t r_nearclip;
189
190 // forces all rendering to draw triangle outlines
191 extern cvar_t r_showoverdraw;
192 extern cvar_t r_showtris;
193 extern cvar_t r_shownormals;
194 extern cvar_t r_showlighting;
195 extern cvar_t r_showcollisionbrushes;
196 extern cvar_t r_showcollisionbrushes_polygonfactor;
197 extern cvar_t r_showcollisionbrushes_polygonoffset;
198 extern cvar_t r_showdisabledepthtest;
199
200 extern cvar_t r_drawentities;
201 extern cvar_t r_draw2d;
202 extern qboolean r_draw2d_force;
203 extern cvar_t r_drawviewmodel;
204 extern cvar_t r_drawworld;
205 extern cvar_t r_speeds;
206 extern cvar_t r_fullbright;
207 extern cvar_t r_wateralpha;
208 extern cvar_t r_dynamic;
209
210 void R_UpdateVariables(void); // must call after setting up most of r_refdef, but before calling R_RenderView
211 void R_RenderView(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, int x, int y, int width, int height); // must set r_refdef and call R_UpdateVariables and CL_UpdateEntityShading first
212 void R_RenderView_UpdateViewVectors(void); // just updates r_refdef.view.{forward,left,up,origin,right,inverse_matrix}
213
214 typedef enum r_refdef_scene_type_s {
215         RST_CLIENT,
216         RST_MENU,
217         RST_COUNT
218 } r_refdef_scene_type_t;
219
220 void R_SelectScene( r_refdef_scene_type_t scenetype );
221 r_refdef_scene_t * R_GetScenePointer( r_refdef_scene_type_t scenetype );
222
223 void R_SkinFrame_PrepareForPurge(void);
224 void R_SkinFrame_MarkUsed(skinframe_t *skinframe);
225 void R_SkinFrame_PurgeSkinFrame(skinframe_t *skinframe);
226 void R_SkinFrame_Purge(void);
227 // set last to NULL to start from the beginning
228 skinframe_t *R_SkinFrame_FindNextByName( skinframe_t *last, const char *name );
229 skinframe_t *R_SkinFrame_Find(const char *name, int textureflags, int comparewidth, int compareheight, int comparecrc, qboolean add);
230 skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qboolean complain, qboolean fallbacknotexture);
231 skinframe_t *R_SkinFrame_LoadExternal_SkinFrame(skinframe_t *skinframe, const char *name, int textureflags, qboolean complain, qboolean fallbacknotexture);
232 skinframe_t *R_SkinFrame_LoadInternalBGRA(const char *name, int textureflags, const unsigned char *skindata, int width, int height, int comparewidth, int compareheight, int comparecrc, qboolean sRGB);
233 skinframe_t *R_SkinFrame_LoadInternalQuake(const char *name, int textureflags, int loadpantsandshirt, int loadglowtexture, const unsigned char *skindata, int width, int height);
234 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);
235 skinframe_t *R_SkinFrame_LoadMissing(void);
236 skinframe_t *R_SkinFrame_LoadNoTexture(void);
237 skinframe_t *R_SkinFrame_LoadInternalUsingTexture(const char *name, int textureflags, rtexture_t *tex, int width, int height, qboolean sRGB);
238
239 rtexture_t *R_GetCubemap(const char *basename);
240
241 void R_View_WorldVisibility(qboolean forcenovis);
242 void R_DrawDecals(void);
243 void R_DrawParticles(void);
244 void R_DrawExplosions(void);
245
246 #define gl_solid_format 3
247 #define gl_alpha_format 4
248
249 int R_CullBox(const vec3_t mins, const vec3_t maxs);
250 int R_CullBoxCustomPlanes(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes);
251 qboolean R_CanSeeBox(int numsamples, vec_t eyejitter, vec_t entboxenlarge, vec_t entboxexpand, vec_t pad, vec3_t eye, vec3_t entboxmins, vec3_t entboxmaxs);
252
253 #include "r_modules.h"
254
255 #include "meshqueue.h"
256
257 /// free all R_FrameData memory
258 void R_FrameData_Reset(void);
259 /// prepare for a new frame, recycles old buffers if a resize occurred previously
260 void R_FrameData_NewFrame(void);
261 /// allocate some temporary memory for your purposes
262 void *R_FrameData_Alloc(size_t size);
263 /// allocate some temporary memory and copy this data into it
264 void *R_FrameData_Store(size_t size, void *data);
265 /// set a marker that allows you to discard the following temporary memory allocations
266 void R_FrameData_SetMark(void);
267 /// discard recent memory allocations (rewind to marker)
268 void R_FrameData_ReturnToMark(void);
269
270 /// enum of the various types of hardware buffer object used in rendering
271 /// note that the r_buffermegs[] array must be maintained to match this
272 typedef enum r_bufferdata_type_e
273 {
274         R_BUFFERDATA_VERTEX, /// vertex buffer
275         R_BUFFERDATA_INDEX16, /// index buffer - 16bit (because D3D cares)
276         R_BUFFERDATA_INDEX32, /// index buffer - 32bit (because D3D cares)
277         R_BUFFERDATA_UNIFORM, /// uniform buffer
278         R_BUFFERDATA_COUNT /// how many kinds of buffer we have
279 }
280 r_bufferdata_type_t;
281
282 /// free all dynamic vertex/index/uniform buffers
283 void R_BufferData_Reset(void);
284 /// begin a new frame (recycle old buffers)
285 void R_BufferData_NewFrame(void);
286 /// request space in a vertex/index/uniform buffer for the chosen data, returns the buffer pointer and offset, always successful
287 r_meshbuffer_t *R_BufferData_Store(size_t size, const void *data, r_bufferdata_type_t type, int *returnbufferoffset);
288
289 /// free all R_AnimCache memory
290 void R_AnimCache_Free(void);
291 /// clear the animcache pointers on all known render entities
292 void R_AnimCache_ClearCache(void);
293 /// get the skeletal data or cached animated mesh data for an entity (optionally with normals and tangents)
294 qboolean R_AnimCache_GetEntity(entity_render_t *ent, qboolean wantnormals, qboolean wanttangents);
295 /// generate animcache data for all entities marked visible
296 void R_AnimCache_CacheVisibleEntities(void);
297
298 #include "r_lerpanim.h"
299
300 extern cvar_t r_render;
301 extern cvar_t r_renderview;
302 extern cvar_t r_waterwarp;
303
304 extern cvar_t r_textureunits;
305
306 extern cvar_t r_glsl_offsetmapping;
307 extern cvar_t r_glsl_offsetmapping_reliefmapping;
308 extern cvar_t r_glsl_offsetmapping_scale;
309 extern cvar_t r_glsl_offsetmapping_lod;
310 extern cvar_t r_glsl_offsetmapping_lod_distance;
311 extern cvar_t r_glsl_deluxemapping;
312
313 extern cvar_t gl_polyblend;
314
315 extern cvar_t cl_deathfade;
316
317 extern cvar_t r_smoothnormals_areaweighting;
318
319 extern cvar_t r_test;
320
321 #include "gl_backend.h"
322
323 extern rtexture_t *r_texture_blanknormalmap;
324 extern rtexture_t *r_texture_white;
325 extern rtexture_t *r_texture_grey128;
326 extern rtexture_t *r_texture_black;
327 extern rtexture_t *r_texture_notexture;
328 extern rtexture_t *r_texture_whitecube;
329 extern rtexture_t *r_texture_normalizationcube;
330 extern rtexture_t *r_texture_fogattenuation;
331 extern rtexture_t *r_texture_fogheighttexture;
332
333 extern unsigned int r_queries[MAX_OCCLUSION_QUERIES];
334 extern unsigned int r_numqueries;
335 extern unsigned int r_maxqueries;
336
337 void R_TimeReport(const char *name);
338
339 // r_stain
340 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);
341
342 void R_CalcBeam_Vertex3f(float *vert, const float *org1, const float *org2, float width);
343 void R_CalcSprite_Vertex3f(float *vertex3f, const float *origin, const float *left, const float *up, float scalex1, float scalex2, float scaley1, float scaley2);
344
345 extern mempool_t *r_main_mempool;
346
347 typedef struct rsurfacestate_s
348 {
349         // current model array pointers
350         // these may point to processing buffers if model is animated,
351         // otherwise they point to static data.
352         // these are not directly used for rendering, they are just another level
353         // of processing
354         //
355         // these either point at array_model* buffers (if the model is animated)
356         // or the model->surfmesh.data_* buffers (if the model is not animated)
357         //
358         // these are only set when an entity render begins, they do not change on
359         // a per surface basis.
360         //
361         // this indicates the model* arrays are pointed at array_model* buffers
362         // (in other words, the model has been animated in software)
363         qboolean                    forcecurrenttextureupdate; // set for RSurf_ActiveCustomEntity to force R_GetCurrentTexture to recalculate the texture parameters (such as entity alpha)
364         qboolean                    modelgeneratedvertex;
365         // skeletal animation can be done by entity (animcache) or per batch,
366         // batch may be non-skeletal even if entity is skeletal, indicating that
367         // the dynamicvertex code path had to apply skeletal manually for a case
368         // where gpu-skinning is not possible, for this reason batch has its own
369         // variables
370         int                         entityskeletalnumtransforms; // how many transforms are used for this mesh
371         float                      *entityskeletaltransform3x4; // use gpu-skinning shader on this mesh
372         const r_meshbuffer_t       *entityskeletaltransform3x4buffer; // uniform buffer
373         int                         entityskeletaltransform3x4offset;
374         int                         entityskeletaltransform3x4size;
375         float                      *modelvertex3f;
376         const r_meshbuffer_t       *modelvertex3f_vertexbuffer;
377         int                         modelvertex3f_bufferoffset;
378         float                      *modelsvector3f;
379         const r_meshbuffer_t       *modelsvector3f_vertexbuffer;
380         int                         modelsvector3f_bufferoffset;
381         float                      *modeltvector3f;
382         const r_meshbuffer_t       *modeltvector3f_vertexbuffer;
383         int                         modeltvector3f_bufferoffset;
384         float                      *modelnormal3f;
385         const r_meshbuffer_t       *modelnormal3f_vertexbuffer;
386         int                         modelnormal3f_bufferoffset;
387         float                      *modellightmapcolor4f;
388         const r_meshbuffer_t       *modellightmapcolor4f_vertexbuffer;
389         int                         modellightmapcolor4f_bufferoffset;
390         float                      *modeltexcoordtexture2f;
391         const r_meshbuffer_t       *modeltexcoordtexture2f_vertexbuffer;
392         int                         modeltexcoordtexture2f_bufferoffset;
393         float                      *modeltexcoordlightmap2f;
394         const r_meshbuffer_t       *modeltexcoordlightmap2f_vertexbuffer;
395         int                         modeltexcoordlightmap2f_bufferoffset;
396         unsigned char              *modelskeletalindex4ub;
397         const r_meshbuffer_t       *modelskeletalindex4ub_vertexbuffer;
398         int                         modelskeletalindex4ub_bufferoffset;
399         unsigned char              *modelskeletalweight4ub;
400         const r_meshbuffer_t       *modelskeletalweight4ub_vertexbuffer;
401         int                         modelskeletalweight4ub_bufferoffset;
402         int                        *modelelement3i;
403         const r_meshbuffer_t       *modelelement3i_indexbuffer;
404         int                         modelelement3i_bufferoffset;
405         unsigned short             *modelelement3s;
406         const r_meshbuffer_t       *modelelement3s_indexbuffer;
407         int                         modelelement3s_bufferoffset;
408         int                        *modellightmapoffsets;
409         int                         modelnumvertices;
410         int                         modelnumtriangles;
411         const msurface_t           *modelsurfaces;
412         // current rendering array pointers
413         // these may point to any of several different buffers depending on how
414         // much processing was needed to prepare this model for rendering
415         // these usually equal the model* pointers, they only differ if
416         // deformvertexes is used in a q3 shader, and consequently these can
417         // change on a per-surface basis (according to rsurface.texture)
418         qboolean                    batchgeneratedvertex;
419         qboolean                    batchmultidraw;
420         int                         batchmultidrawnumsurfaces;
421         const msurface_t          **batchmultidrawsurfacelist;
422         int                         batchfirstvertex;
423         int                         batchnumvertices;
424         int                         batchfirsttriangle;
425         int                         batchnumtriangles;
426         float                      *batchvertex3f;
427         const r_meshbuffer_t       *batchvertex3f_vertexbuffer;
428         int                         batchvertex3f_bufferoffset;
429         float                      *batchsvector3f;
430         const r_meshbuffer_t       *batchsvector3f_vertexbuffer;
431         int                         batchsvector3f_bufferoffset;
432         float                      *batchtvector3f;
433         const r_meshbuffer_t       *batchtvector3f_vertexbuffer;
434         int                         batchtvector3f_bufferoffset;
435         float                      *batchnormal3f;
436         const r_meshbuffer_t       *batchnormal3f_vertexbuffer;
437         int                         batchnormal3f_bufferoffset;
438         float                      *batchlightmapcolor4f;
439         const r_meshbuffer_t       *batchlightmapcolor4f_vertexbuffer;
440         int                         batchlightmapcolor4f_bufferoffset;
441         float                      *batchtexcoordtexture2f;
442         const r_meshbuffer_t       *batchtexcoordtexture2f_vertexbuffer;
443         int                         batchtexcoordtexture2f_bufferoffset;
444         float                      *batchtexcoordlightmap2f;
445         const r_meshbuffer_t       *batchtexcoordlightmap2f_vertexbuffer;
446         int                         batchtexcoordlightmap2f_bufferoffset;
447         unsigned char              *batchskeletalindex4ub;
448         const r_meshbuffer_t       *batchskeletalindex4ub_vertexbuffer;
449         int                         batchskeletalindex4ub_bufferoffset;
450         unsigned char              *batchskeletalweight4ub;
451         const r_meshbuffer_t       *batchskeletalweight4ub_vertexbuffer;
452         int                         batchskeletalweight4ub_bufferoffset;
453         int                        *batchelement3i;
454         const r_meshbuffer_t       *batchelement3i_indexbuffer;
455         int                         batchelement3i_bufferoffset;
456         unsigned short             *batchelement3s;
457         const r_meshbuffer_t       *batchelement3s_indexbuffer;
458         int                         batchelement3s_bufferoffset;
459         int                         batchskeletalnumtransforms;
460         float                      *batchskeletaltransform3x4;
461         const r_meshbuffer_t       *batchskeletaltransform3x4buffer; // uniform buffer
462         int                         batchskeletaltransform3x4offset;
463         int                         batchskeletaltransform3x4size;
464
465         // some important fields from the entity
466         int ent_skinnum;
467         int ent_qwskin;
468         int ent_flags;
469         int ent_alttextures; // used by q1bsp animated textures (pressed buttons)
470         double shadertime; // r_refdef.scene.time - ent->shadertime
471         // transform matrices to render this entity and effects on this entity
472         matrix4x4_t matrix;
473         matrix4x4_t inversematrix;
474         // scale factors for transforming lengths into/out of entity space
475         float matrixscale;
476         float inversematrixscale;
477         // animation blending state from entity
478         frameblend_t frameblend[MAX_FRAMEBLENDS];
479         skeleton_t *skeleton;
480         // view location in model space
481         vec3_t localvieworigin;
482         // polygon offset data for submodels
483         float basepolygonfactor;
484         float basepolygonoffset;
485         // current textures in batching code
486         texture_t *texture;
487         rtexture_t *lightmaptexture;
488         rtexture_t *deluxemaptexture;
489         // whether lightmapping is active on this batch
490         // (otherwise vertex colored)
491         qboolean uselightmaptexture;
492         // fog plane in model space for direct application to vertices
493         float fograngerecip;
494         float fogmasktabledistmultiplier;
495         float fogplane[4];
496         float fogheightfade;
497         float fogplaneviewdist;
498
499         // rtlight rendering
500         // light currently being rendered
501         const rtlight_t *rtlight;
502
503         // this is the location of the light in entity space
504         vec3_t entitylightorigin;
505         // this transforms entity coordinates to light filter cubemap coordinates
506         // (also often used for other purposes)
507         matrix4x4_t entitytolight;
508         // based on entitytolight this transforms -1 to +1 to 0 to 1 for purposes
509         // of attenuation texturing in full 3D (Z result often ignored)
510         matrix4x4_t entitytoattenuationxyz;
511         // this transforms only the Z to S, and T is always 0.5
512         matrix4x4_t entitytoattenuationz;
513
514         // user wavefunc parameters (from csqc)
515         float userwavefunc_param[Q3WAVEFUNC_USER_COUNT];
516
517         // pointer to an entity_render_t used only by R_GetCurrentTexture and
518         // RSurf_ActiveModelEntity as a unique id within each frame (see r_frame
519         // also)
520         entity_render_t *entity;
521 }
522 rsurfacestate_t;
523
524 extern rsurfacestate_t rsurface;
525
526 void R_HDR_UpdateIrisAdaptation(const vec3_t point);
527
528 void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, qboolean wanttangents, qboolean prepass);
529 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);
530 void RSurf_SetupDepthAndCulling(void);
531
532 extern int r_textureframe; ///< used only by R_GetCurrentTexture, incremented per view and per UI render
533 texture_t *R_GetCurrentTexture(texture_t *t);
534 void R_DrawModelSurfaces(entity_render_t *ent, qboolean skysurfaces, qboolean writedepth, qboolean depthonly, qboolean debug, qboolean prepass, qboolean ui);
535 void R_DrawCustomSurface(skinframe_t *skinframe, const matrix4x4_t *texmatrix, int materialflags, int firstvertex, int numvertices, int firsttriangle, int numtriangles, qboolean writedepth, qboolean prepass);
536 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);
537
538 #define BATCHNEED_ARRAY_VERTEX                (1<< 0) // set up rsurface.batchvertex3f
539 #define BATCHNEED_ARRAY_NORMAL                (1<< 1) // set up rsurface.batchnormal3f
540 #define BATCHNEED_ARRAY_VECTOR                (1<< 2) // set up rsurface.batchsvector3f and rsurface.batchtvector3f
541 #define BATCHNEED_ARRAY_VERTEXTINTCOLOR       (1<< 3) // set up rsurface.batchvertexcolor4f
542 #define BATCHNEED_ARRAY_VERTEXCOLOR           (1<< 4) // set up rsurface.batchlightmapcolor4f
543 #define BATCHNEED_ARRAY_TEXCOORD              (1<< 5) // set up rsurface.batchtexcoordtexture2f
544 #define BATCHNEED_ARRAY_LIGHTMAP              (1<< 6) // set up rsurface.batchtexcoordlightmap2f
545 #define BATCHNEED_ARRAY_SKELETAL              (1<< 7) // set up skeletal index and weight data for vertex shader
546 #define BATCHNEED_NOGAPS                      (1<< 8) // force vertex copying if firstvertex is not zero or there are gaps
547 #define BATCHNEED_ALWAYSCOPY                  (1<< 9) // force vertex copying unconditionally - useful if you want to modify colors
548 #define BATCHNEED_ALLOWMULTIDRAW              (1<<10) // allow multiple draws
549 void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const msurface_t **texturesurfacelist);
550 void RSurf_UploadBuffersForBatch(void);
551 void RSurf_DrawBatch(void);
552
553 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);
554
555 typedef enum rsurfacepass_e
556 {
557         RSURFPASS_BASE,
558         RSURFPASS_BACKGROUND,
559         RSURFPASS_RTLIGHT,
560         RSURFPASS_DEFERREDGEOMETRY
561 }
562 rsurfacepass_t;
563
564 void R_SetupShader_Generic(rtexture_t *t, qboolean usegamma, qboolean notrippy, qboolean suppresstexalpha);
565 void R_SetupShader_Generic_NoTexture(qboolean usegamma, qboolean notrippy);
566 void R_SetupShader_DepthOrShadow(qboolean notrippy, qboolean depthrgb, qboolean skeletal);
567 void R_SetupShader_Surface(const float ambientcolor[3], const float diffusecolor[3], const float specularcolor[3], rsurfacepass_t rsurfacepass, int texturenumsurfaces, const msurface_t **texturesurfacelist, void *waterplane, qboolean notrippy);
568 void R_SetupShader_DeferredLight(const rtlight_t *rtlight);
569
570 typedef struct r_rendertarget_s {
571         // texcoords for sampling from the viewport (clockwise: 0,0 1,0 1,1 0,1)
572         float texcoord2f[8];
573         // textures are this size and type
574         int texturewidth;
575         int textureheight;
576         // TEXTYPE for each color target - usually TEXTYPE_COLORBUFFER16F
577         textype_t colortextype[4];
578         // TEXTYPE for depth target - usually TEXTYPE_DEPTHBUFFER24 or TEXTYPE_SHADOWMAP24_COMP
579         textype_t depthtextype;
580         // if true the depth target will be a renderbuffer rather than a texture (still rtexture_t though)
581         qboolean depthisrenderbuffer;
582         // framebuffer object referencing the textures
583         int fbo;
584         // there can be up to 4 color targets and 1 depth target, the depthtexture
585         // may be a real texture (readable) or just a renderbuffer (not readable,
586         // but potentially faster)
587         rtexture_t *colortexture[4];
588         rtexture_t *depthtexture;
589         // a rendertarget will not be reused in the same frame (realtime == lastusetime),
590         // on a new frame, matching rendertargets will be reused (texturewidth, textureheight, number of color and depth textures and their types),
591         // when a new frame arrives the rendertargets can be reused by requests for matching texturewidth,textureheight and fbo configuration (the number of color and depth textures), when a rendertarget is not reused for > 200ms (realtime - lastusetime > 0.2) the rendertarget's resources will be freed (fbo, textures) and it can be reused for any target in future frames
592         double lastusetime;
593 } r_rendertarget_t;
594
595 // called each frame after render to delete render targets that have not been used for a while
596 void R_RenderTarget_FreeUnused(qboolean force);
597 // returns a rendertarget, creates rendertarget if needed or intelligently reuses targets across frames if they match and have not been used already this frame
598 r_rendertarget_t *R_RenderTarget_Get(int texturewidth, int textureheight, textype_t depthtextype, qboolean depthisrenderbuffer, textype_t colortextype0, textype_t colortextype1, textype_t colortextype2, textype_t colortextype3);
599
600 typedef struct r_waterstate_waterplane_s
601 {
602         r_rendertarget_t *rt_refraction; // MATERIALFLAG_WATERSHADER or MATERIALFLAG_REFRACTION
603         r_rendertarget_t *rt_reflection; // MATERIALFLAG_WATERSHADER or MATERIALFLAG_REFLECTION
604         r_rendertarget_t *rt_camera; // MATERIALFLAG_CAMERA
605         mplane_t plane;
606         int materialflags; // combined flags of all water surfaces on this plane
607         unsigned char pvsbits[(MAX_MAP_LEAFS+7)>>3]; // FIXME: buffer overflow on huge maps
608         qboolean pvsvalid;
609         int camera_entity;
610         vec3_t mins, maxs;
611 }
612 r_waterstate_waterplane_t;
613
614 typedef struct r_waterstate_s
615 {
616         int waterwidth, waterheight;
617         int texturewidth, textureheight;
618         int camerawidth, cameraheight;
619
620         int maxwaterplanes; // same as MAX_WATERPLANES
621         int numwaterplanes;
622         r_waterstate_waterplane_t waterplanes[MAX_WATERPLANES];
623
624         float screenscale[2];
625         float screencenter[2];
626
627         qboolean enabled;
628
629         qboolean renderingscene; // true while rendering a refraction or reflection texture, disables water surfaces
630         qboolean hideplayer;
631 }
632 r_waterstate_t;
633
634 typedef struct r_framebufferstate_s
635 {
636         textype_t textype; // type of color buffer we're using (dependent on r_viewfbo cvar)
637         int screentexturewidth, screentextureheight; // dimensions of texture
638
639         // rt_* fields are per-RenderView so we reset them in R_Bloom_StartFrame
640         r_rendertarget_t *rt_screen;
641         r_rendertarget_t *rt_bloom;
642
643         rtexture_t *ghosttexture; // for r_motionblur (not recommended on multi-GPU hardware!)
644         float ghosttexcoord2f[8]; // for r_motionblur
645
646         int bloomwidth, bloomheight;
647
648         // arrays for rendering the screen passes
649         float offsettexcoord2f[8]; // temporary use while updating bloomtexture[]
650
651         r_waterstate_t water;
652
653         qboolean ghosttexture_valid; // don't draw garbage on first frame with motionblur
654         qboolean usedepthtextures; // use depth texture instead of depth renderbuffer (faster if you need to read it later anyway)
655
656         // rendertargets (fbo and viewport), these can be reused across frames
657         memexpandablearray_t rendertargets;
658 }
659 r_framebufferstate_t;
660
661 extern r_framebufferstate_t r_fb;
662
663 extern cvar_t r_viewfbo;
664
665 void R_ResetViewRendering2D_Common(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight, float x2, float y2); // this is called by R_ResetViewRendering2D and _DrawQ_Setup and internal
666 void R_ResetViewRendering2D(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
667 void R_ResetViewRendering3D(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
668 void R_SetupView(qboolean allowwaterclippingplane, int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
669 void R_DebugLine(vec3_t start, vec3_t end);
670 extern const float r_screenvertex3f[12];
671 extern cvar_t r_showspriteedges;
672 extern cvar_t r_showparticleedges;
673 extern cvar_t r_shadows;
674 extern cvar_t r_shadows_darken;
675 extern cvar_t r_shadows_drawafterrtlighting;
676 extern cvar_t r_shadows_castfrombmodels;
677 extern cvar_t r_shadows_throwdistance;
678 extern cvar_t r_shadows_throwdirection;
679 extern cvar_t r_shadows_focus;
680 extern cvar_t r_shadows_shadowmapscale;
681 extern cvar_t r_shadows_shadowmapbias;
682 extern cvar_t r_transparent_alphatocoverage;
683 extern cvar_t r_transparent_sortsurfacesbynearest;
684 extern cvar_t r_transparent_useplanardistance;
685 extern cvar_t r_transparent_sortarraysize;
686 extern cvar_t r_transparent_sortmindist;
687 extern cvar_t r_transparent_sortmaxdist;
688
689 extern qboolean r_shadow_usingdeferredprepass;
690 extern rtexture_t *r_shadow_attenuationgradienttexture;
691 extern rtexture_t *r_shadow_attenuation2dtexture;
692 extern rtexture_t *r_shadow_attenuation3dtexture;
693 extern qboolean r_shadow_usingshadowmap2d;
694 extern qboolean r_shadow_usingshadowmaportho;
695 extern float r_shadow_modelshadowmap_texturescale[4];
696 extern float r_shadow_modelshadowmap_parameters[4];
697 extern float r_shadow_lightshadowmap_texturescale[4];
698 extern float r_shadow_lightshadowmap_parameters[4];
699 extern qboolean r_shadow_shadowmapvsdct;
700 extern rtexture_t *r_shadow_shadowmap2ddepthbuffer;
701 extern rtexture_t *r_shadow_shadowmap2ddepthtexture;
702 extern rtexture_t *r_shadow_shadowmapvsdcttexture;
703 extern matrix4x4_t r_shadow_shadowmapmatrix;
704 extern int r_shadow_prepass_width;
705 extern int r_shadow_prepass_height;
706 extern rtexture_t *r_shadow_prepassgeometrydepthbuffer;
707 extern rtexture_t *r_shadow_prepassgeometrynormalmaptexture;
708 extern rtexture_t *r_shadow_prepasslightingdiffusetexture;
709 extern rtexture_t *r_shadow_prepasslightingspeculartexture;
710 extern int r_shadow_viewfbo;
711 extern rtexture_t *r_shadow_viewdepthtexture;
712 extern rtexture_t *r_shadow_viewcolortexture;
713 extern int r_shadow_viewx;
714 extern int r_shadow_viewy;
715 extern int r_shadow_viewwidth;
716 extern int r_shadow_viewheight;
717
718 void R_RenderScene(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
719 void R_RenderWaterPlanes(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
720
721 void R_Model_Sprite_Draw(entity_render_t *ent);
722
723 struct prvm_prog_s;
724 void R_UpdateFog(void);
725 qboolean CL_VM_UpdateView(double frametime);
726 void SCR_DrawConsole(void);
727 void R_Shadow_EditLights_DrawSelectedLightProperties(void);
728 void R_DecalSystem_Reset(decalsystem_t *decalsystem);
729 void R_Shadow_UpdateBounceGridTexture(void);
730 void R_DrawPortals(void);
731 void R_BuildLightMap(const entity_render_t *ent, msurface_t *surface);
732 void R_Water_AddWaterPlane(msurface_t *surface, int entno);
733 int R_Shadow_GetRTLightInfo(unsigned int lightindex, float *origin, float *radius, float *color);
734 dp_font_t *FindFont(const char *title, qboolean allocate_new);
735 void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale, float voffset);
736
737 void Render_Init(void);
738
739 // these are called by Render_Init
740 void R_Textures_Init(void);
741 void GL_Draw_Init(void);
742 void GL_Main_Init(void);
743 void R_Shadow_Init(void);
744 void R_Sky_Init(void);
745 void GL_Surf_Init(void);
746 void R_Particles_Init(void);
747 void R_Explosion_Init(void);
748 void gl_backend_init(void);
749 void Sbar_Init(void);
750 void R_LightningBeams_Init(void);
751 void Mod_RenderInit(void);
752 void Font_Init(void);
753
754 qboolean R_CompileShader_CheckStaticParms(void);
755 void R_GLSL_Restart_f(void);
756
757 #endif