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