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