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.
27 typedef enum glsl_attrib_e
29 GLSLATTRIB_POSITION = 0,
31 GLSLATTRIB_TEXCOORD0 = 2,
32 GLSLATTRIB_TEXCOORD1 = 3,
33 GLSLATTRIB_TEXCOORD2 = 4,
34 GLSLATTRIB_TEXCOORD3 = 5,
35 GLSLATTRIB_TEXCOORD4 = 6,
36 GLSLATTRIB_TEXCOORD5 = 7,
37 GLSLATTRIB_TEXCOORD6 = 8,
38 GLSLATTRIB_TEXCOORD7 = 9,
42 typedef enum shaderlanguage_e
49 // this enum selects which of the glslshadermodeinfo entries should be used
50 typedef enum shadermode_e
52 SHADERMODE_GENERIC, ///< (particles/HUD/etc) vertex color, optionally multiplied by one texture
53 SHADERMODE_POSTPROCESS, ///< postprocessing shader (r_glsl_postprocess)
54 SHADERMODE_DEPTH_OR_SHADOW, ///< (depthfirst/shadows) vertex shader only
55 SHADERMODE_FLATCOLOR, ///< (lightmap) modulate texture by uniform color (q1bsp, q3bsp)
56 SHADERMODE_VERTEXCOLOR, ///< (lightmap) modulate texture by vertex colors (q3bsp)
57 SHADERMODE_LIGHTMAP, ///< (lightmap) modulate texture by lightmap texture (q1bsp, q3bsp)
58 SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE, ///< (lightmap) use directional pixel shading from texture containing modelspace light directions (q3bsp deluxemap)
59 SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE, ///< (lightmap) use directional pixel shading from texture containing tangentspace light directions (q1bsp deluxemap)
60 SHADERMODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP, // forced deluxemapping for lightmapped surfaces
61 SHADERMODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR, // forced deluxemapping for vertexlit surfaces
62 SHADERMODE_LIGHTGRID, ///< (lightmap) use directional pixel shading from lightgrid data (q3bsp)
63 SHADERMODE_LIGHTDIRECTION, ///< (lightmap) use directional pixel shading from fixed light direction (q3bsp)
64 SHADERMODE_LIGHTSOURCE, ///< (lightsource) use directional pixel shading from light source (rtlight)
65 SHADERMODE_REFRACTION, ///< refract background (the material is rendered normally after this pass)
66 SHADERMODE_WATER, ///< refract background and reflection (the material is rendered normally after this pass)
67 SHADERMODE_DEFERREDGEOMETRY, ///< (deferred) render material properties to screenspace geometry buffers
68 SHADERMODE_DEFERREDLIGHTSOURCE, ///< (deferred) use directional pixel shading from light source (rtlight) on screenspace geometry buffers
73 #define SHADERPERMUTATION_DIFFUSE (1<<0) ///< (lightsource) whether to use directional shading
74 #define SHADERPERMUTATION_VERTEXTEXTUREBLEND (1<<1) ///< indicates this is a two-layer material blend based on vertex alpha (q3bsp)
75 #define SHADERPERMUTATION_VIEWTINT (1<<2) ///< view tint (postprocessing only), use vertex colors (generic only)
76 #define SHADERPERMUTATION_COLORMAPPING (1<<3) ///< indicates this is a colormapped skin
77 #define SHADERPERMUTATION_SATURATION (1<<4) ///< saturation (postprocessing only)
78 #define SHADERPERMUTATION_FOGINSIDE (1<<5) ///< tint the color by fog color or black if using additive blend mode
79 #define SHADERPERMUTATION_FOGOUTSIDE (1<<6) ///< tint the color by fog color or black if using additive blend mode
80 #define SHADERPERMUTATION_FOGHEIGHTTEXTURE (1<<7) ///< fog color and density determined by texture mapped on vertical axis
81 #define SHADERPERMUTATION_FOGALPHAHACK (1<<8) ///< fog color and density determined by texture mapped on vertical axis
82 #define SHADERPERMUTATION_GAMMARAMPS (1<<9) ///< gamma (postprocessing only)
83 #define SHADERPERMUTATION_CUBEFILTER (1<<10) ///< (lightsource) use cubemap light filter
84 #define SHADERPERMUTATION_GLOW (1<<11) ///< (lightmap) blend in an additive glow texture
85 #define SHADERPERMUTATION_BLOOM (1<<12) ///< bloom (postprocessing only)
86 #define SHADERPERMUTATION_SPECULAR (1<<13) ///< (lightsource or deluxemapping) render specular effects
87 #define SHADERPERMUTATION_POSTPROCESSING (1<<14) ///< user defined postprocessing (postprocessing only)
88 #define SHADERPERMUTATION_REFLECTION (1<<15) ///< normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the surface
89 #define SHADERPERMUTATION_OFFSETMAPPING (1<<16) ///< adjust texcoords to roughly simulate a displacement mapped surface
90 #define SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING (1<<17) ///< adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also be set!)
91 #define SHADERPERMUTATION_SHADOWMAP2D (1<<18) ///< (lightsource) use shadowmap texture as light filter
92 #define SHADERPERMUTATION_SHADOWMAPVSDCT (1<<19) ///< (lightsource) use virtual shadow depth cube texture for shadowmap indexing
93 #define SHADERPERMUTATION_SHADOWMAPORTHO (1<<20) ///< (lightsource) use orthographic shadowmap projection
94 #define SHADERPERMUTATION_DEFERREDLIGHTMAP (1<<21) ///< (lightmap) read Texture_ScreenDiffuse/Specular textures and add them on top of lightmapping
95 #define SHADERPERMUTATION_ALPHAKILL (1<<22) ///< (deferredgeometry) discard pixel if diffuse texture alpha below 0.5, (generic) apply global alpha
96 #define SHADERPERMUTATION_REFLECTCUBE (1<<23) ///< fake reflections using global cubemap (not HDRI light probe)
97 #define SHADERPERMUTATION_NORMALMAPSCROLLBLEND (1<<24) ///< (water) counter-direction normalmaps scrolling
98 #define SHADERPERMUTATION_BOUNCEGRID (1<<25) ///< (lightmap) use Texture_BounceGrid as an additional source of ambient light
99 #define SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL (1<<26) ///< (lightmap) use 16-component pixels in bouncegrid texture for directional lighting rather than standard 4-component
100 #define SHADERPERMUTATION_TRIPPY (1<<27) ///< use trippy vertex shader effect
101 #define SHADERPERMUTATION_DEPTHRGB (1<<28) ///< read/write depth values in RGB color coded format for older hardware without depth samplers
102 #define SHADERPERMUTATION_ALPHAGEN_VERTEX (1<<29) ///< alphaGen vertex
103 #define SHADERPERMUTATION_SKELETAL (1<<30) ///< (skeletal models) use skeletal matrices to deform vertices (gpu-skinning)
104 #define SHADERPERMUTATION_OCCLUDE (1<<31) ///< use occlusion buffer for corona
105 #define SHADERPERMUTATION_COUNT 32 ///< size of shaderpermutationinfo array
108 extern float ixtable[4096];
111 void FOG_clear(void);
115 extern cvar_t r_skyscroll1;
116 extern cvar_t r_skyscroll2;
117 extern cvar_t r_sky_scissor;
118 extern cvar_t r_q3bsp_renderskydepth;
119 extern int skyrenderlater, skyrendermasked;
120 extern int skyscissor[4];
121 int R_SetSkyBox(const char *sky);
122 void R_SkyStartFrame(void);
124 void R_ResetSkyBox(void);
126 // SHOWLMP stuff (Nehahra)
127 void SHOWLMP_decodehide(void);
128 void SHOWLMP_decodeshow(void);
129 void SHOWLMP_drawall(void);
131 // render profiling stuff
132 extern int r_timereport_active;
135 extern cvar_t r_ambient;
136 extern cvar_t gl_flashblend;
139 extern cvar_t r_novis;
141 extern cvar_t r_trippy;
142 extern cvar_t r_fxaa;
144 extern cvar_t r_lerpsprites;
145 extern cvar_t r_lerpmodels;
146 extern cvar_t r_lerplightstyles;
147 extern cvar_t r_waterscroll;
149 extern cvar_t developer_texturelogging;
151 // shadow volume bsp struct with automatically growing nodes buffer
152 extern svbsp_t r_svbsp;
154 typedef struct rmesh_s
156 // vertices of this mesh
164 float *texcoordlightmap2f;
166 // triangles of this mesh
175 // useful functions for rendering
176 void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b);
177 void R_FillColors(float *out, int verts, float r, float g, float b, float a);
178 void R_Mesh_AddPolygon3f(rmesh_t *mesh, int numvertices, float *vertex3f);
179 void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *planes);
181 #define TOP_RANGE 16 // soldier uniform colors
182 #define BOTTOM_RANGE 96
184 //=============================================================================
186 extern cvar_t r_nearclip;
188 // forces all rendering to draw triangle outlines
189 extern cvar_t r_showoverdraw;
190 extern cvar_t r_showtris;
191 extern cvar_t r_shownormals;
192 extern cvar_t r_showlighting;
193 extern cvar_t r_showcollisionbrushes;
194 extern cvar_t r_showcollisionbrushes_polygonfactor;
195 extern cvar_t r_showcollisionbrushes_polygonoffset;
196 extern cvar_t r_showdisabledepthtest;
198 extern cvar_t r_drawentities;
199 extern cvar_t r_draw2d;
200 extern qbool r_draw2d_force;
201 extern cvar_t r_drawviewmodel;
202 extern cvar_t r_drawworld;
203 extern cvar_t r_speeds;
204 extern cvar_t r_fullbright;
205 extern cvar_t r_wateralpha;
206 extern cvar_t r_dynamic;
208 void R_NewExplosion(const vec3_t org);
209 void R_UpdateVariables(void); // must call after setting up most of r_refdef, but before calling R_RenderView
210 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
211 void R_RenderView_UpdateViewVectors(void); // just updates r_refdef.view.{forward,left,up,origin,right,inverse_matrix}
213 float RSurf_FogVertex(const vec3_t p);
214 float RSurf_FogPoint(const vec3_t p);
216 typedef enum r_refdef_scene_type_s {
220 } r_refdef_scene_type_t;
222 typedef enum r_viewport_type_e
224 R_VIEWPORTTYPE_ORTHO,
225 R_VIEWPORTTYPE_PERSPECTIVE,
226 R_VIEWPORTTYPE_PERSPECTIVE_INFINITEFARCLIP,
227 R_VIEWPORTTYPE_PERSPECTIVECUBESIDE,
232 typedef struct r_viewport_s
234 matrix4x4_t cameramatrix; // from entity (transforms from camera entity to world)
235 matrix4x4_t viewmatrix; // actual matrix for rendering (transforms to viewspace)
236 matrix4x4_t projectmatrix; // actual projection matrix (transforms from viewspace to screen)
243 r_viewport_type_t type;
244 float screentodepth[2]; // used by deferred renderer to calculate linear depth from device depth coordinates
248 typedef struct r_refdef_view_s
250 // view information (changes multiple times per frame)
251 // if any of these variables change then r_refdef.viewcache must be regenerated
252 // by calling R_View_Update
253 // (which also updates viewport, scissor, colormask)
255 // it is safe and expected to copy this into a structure on the stack and
256 // call the renderer recursively, then restore from the stack afterward
257 // (as long as R_View_Update is called)
259 // eye position information
260 matrix4x4_t matrix, inverse_matrix;
266 int numfrustumplanes;
269 qbool usecustompvs; // uses r_refdef.viewcache.pvsbits as-is rather than computing it
271 float frustum_x, frustum_y;
272 vec3_t frustumcorner[4];
273 // if turned off it renders an ortho view
275 // allows visibility culling based on the view origin (e.g. pvs and R_CanSeeBox)
276 // this is turned off by:
278 // !r_refdef.view.useperspective
279 // (sometimes) r_refdef.view.useclipplane
280 int usevieworiginculling;
281 float ortho_x, ortho_y;
283 // screen area to render in
290 r_viewport_t viewport; // note: if r_viewscale is used, the viewport.width and viewport.height may be less than width and height
292 // which color components to allow (for anaglyph glasses)
295 // global RGB color multiplier for rendering
298 // whether to call R_ClearScreen before rendering stuff
300 // if true, don't clear or do any post process effects (bloom, etc)
302 // if true, this is the MAIN view (which is, after CSQC, copied into the scene for use e.g. by r_speeds 1, showtex, prydon cursor)
305 // whether to draw r_showtris and such, this is only true for the main
306 // view render, all secondary renders (mirrors, portals, cameras,
307 // distortion effects, etc) omit such debugging information
310 // these define which values to use in GL_CullFace calls to request frontface or backface culling
314 // render quality (0 to 1) - affects r_drawparticles_drawdistance and others
319 typedef struct r_refdef_viewcache_s
321 // updated by gl_main_newmap()
323 int world_numclusters;
324 int world_numclusterbytes;
326 int world_numsurfaces;
328 // these properties are generated by R_View_Update()
330 // which entities are currently visible for this viewpoint
331 // (the used range is 0...r_refdef.scene.numentities)
332 unsigned char *entityvisible;
334 // flag arrays used for visibility checking on world model
335 // (all other entities have no per-surface/per-leaf visibility checks)
336 unsigned char *world_pvsbits;
337 unsigned char *world_leafvisible;
338 unsigned char *world_surfacevisible;
339 // if true, the view is currently in a leaf without pvs data
342 r_refdef_viewcache_t;
344 // TODO: really think about which fields should go into scene and which one should stay in refdef [1/7/2008 Black]
345 // maybe also refactor some of the functions to support different setting sources (ie. fogenabled, etc.) for different scenes
346 typedef struct r_refdef_scene_s {
347 // whether to call S_ExtraUpdate during render to reduce sound chop
350 // (client gameworld) time for rendering time based effects
354 entity_render_t *worldentity;
356 // same as worldentity->model
357 dp_model_t *worldmodel;
359 // renderable entities (excluding world)
360 entity_render_t **entities;
364 // field of temporary entities that is reset each (client) frame
365 entity_render_t *tempentities;
368 qbool expandtempentities;
370 // renderable dynamic lights
371 rtlight_t *lights[MAX_DLIGHTS];
372 rtlight_t templights[MAX_DLIGHTS];
375 // intensities for light styles right now, controls rtlights
376 float rtlightstylevalue[MAX_LIGHTSTYLES]; // float fraction of base light value
377 // 8.8bit fixed point intensities for light styles
378 // controls intensity lightmap layers
379 unsigned short lightstylevalue[MAX_LIGHTSTYLES]; // 8.8 fraction of base light value
381 // adds brightness to the whole scene, separate from lightmapintensity
382 // see CL_UpdateEntityShading
383 float ambientintensity;
384 // brightness of lightmap and modellight lighting on materials
385 // see CL_UpdateEntityShading
386 float lightmapintensity;
389 qbool rtworldshadows;
391 qbool rtdlightshadows;
394 typedef struct r_refdef_s
396 // these fields define the basic rendering information for the world
397 // but not the view, which could change multiple times in one rendered
398 // frame (for example when rendering textures for certain effects)
400 // these are set for water warping before
401 // frustum_x/frustum_y are calculated
402 float frustumscale_x, frustumscale_y;
404 // current view settings (these get reset a few times during rendering because of water rendering, reflections, etc)
405 r_refdef_view_t view;
406 r_refdef_viewcache_t viewcache;
408 // minimum visible distance (pixels closer than this disappear)
410 // maximum visible distance (pixels further than this disappear in 16bpp modes,
411 // in 32bpp an infinite-farclip matrix is used instead)
414 // fullscreen color blend
417 r_refdef_scene_t scene;
420 float fogplaneviewdist;
421 qbool fogplaneviewabove;
426 float fogmasktabledistmultiplier;
427 #define FOGMASKTABLEWIDTH 1024
428 float fogmasktable[FOGMASKTABLEWIDTH];
429 float fogmasktable_start, fogmasktable_alpha, fogmasktable_range, fogmasktable_density;
440 qbool oldgl_fogenable;
442 // new flexible texture height fog (overrides normal fog)
443 char fog_height_texturename[64]; // note: must be 64 for the sscanf code
444 unsigned char *fog_height_table1d;
445 unsigned char *fog_height_table2d;
446 int fog_height_tablesize; // enable
447 float fog_height_tablescale;
448 float fog_height_texcoordscale;
449 char fogheighttexturename[64]; // detects changes to active fog height texture
451 int draw2dstage; // 0 = no, 1 = yes, other value = needs setting up again
453 // true during envmap command capture
456 // whether to draw world lights realtime, dlights realtime, and their shadows
460 // how long R_RenderView took on the previous frame
461 double lastdrawscreentime;
463 // rendering stats for r_speeds display
464 // (these are incremented in many places)
465 int stats[r_stat_count];
469 extern r_refdef_t r_refdef;
471 void R_SelectScene( r_refdef_scene_type_t scenetype );
472 r_refdef_scene_t * R_GetScenePointer( r_refdef_scene_type_t scenetype );
474 void R_SkinFrame_PrepareForPurge(void);
475 void R_SkinFrame_MarkUsed(skinframe_t *skinframe);
476 void R_SkinFrame_PurgeSkinFrame(skinframe_t *skinframe);
477 void R_SkinFrame_Purge(void);
478 // set last to NULL to start from the beginning
479 skinframe_t *R_SkinFrame_FindNextByName( skinframe_t *last, const char *name );
480 skinframe_t *R_SkinFrame_Find(const char *name, int textureflags, int comparewidth, int compareheight, int comparecrc, qbool add);
481 skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qbool complain, qbool fallbacknotexture);
482 skinframe_t *R_SkinFrame_LoadExternal_SkinFrame(skinframe_t *skinframe, const char *name, int textureflags, qbool complain, qbool fallbacknotexture);
483 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);
484 skinframe_t *R_SkinFrame_LoadInternalQuake(const char *name, int textureflags, int loadpantsandshirt, int loadglowtexture, const unsigned char *skindata, int width, int height);
485 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);
486 skinframe_t *R_SkinFrame_LoadMissing(void);
487 skinframe_t *R_SkinFrame_LoadNoTexture(void);
488 skinframe_t *R_SkinFrame_LoadInternalUsingTexture(const char *name, int textureflags, rtexture_t *tex, int width, int height, qbool sRGB);
490 rtexture_t *R_GetCubemap(const char *basename);
492 void R_View_WorldVisibility(qbool forcenovis);
493 void R_DrawParticles(void);
494 void R_DrawExplosions(void);
496 #define gl_solid_format 3
497 #define gl_alpha_format 4
499 int R_CullBox(const vec3_t mins, const vec3_t maxs);
500 int R_CullBoxCustomPlanes(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes);
501 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);
503 #include "r_modules.h"
505 #include "meshqueue.h"
507 /// free all R_FrameData memory
508 void R_FrameData_Reset(void);
509 /// prepare for a new frame, recycles old buffers if a resize occurred previously
510 void R_FrameData_NewFrame(void);
511 /// allocate some temporary memory for your purposes
512 void *R_FrameData_Alloc(size_t size);
513 /// allocate some temporary memory and copy this data into it
514 void *R_FrameData_Store(size_t size, void *data);
515 /// set a marker that allows you to discard the following temporary memory allocations
516 void R_FrameData_SetMark(void);
517 /// discard recent memory allocations (rewind to marker)
518 void R_FrameData_ReturnToMark(void);
520 /// enum of the various types of hardware buffer object used in rendering
521 /// note that the r_buffermegs[] array must be maintained to match this
522 typedef enum r_bufferdata_type_e
524 R_BUFFERDATA_VERTEX, /// vertex buffer
525 R_BUFFERDATA_INDEX16, /// index buffer - 16bit (because D3D cares)
526 R_BUFFERDATA_INDEX32, /// index buffer - 32bit (because D3D cares)
527 R_BUFFERDATA_UNIFORM, /// uniform buffer
528 R_BUFFERDATA_COUNT /// how many kinds of buffer we have
532 /// free all dynamic vertex/index/uniform buffers
533 void R_BufferData_Reset(void);
534 /// begin a new frame (recycle old buffers)
535 void R_BufferData_NewFrame(void);
536 /// request space in a vertex/index/uniform buffer for the chosen data, returns the buffer pointer and offset, always successful
537 r_meshbuffer_t *R_BufferData_Store(size_t size, const void *data, r_bufferdata_type_t type, int *returnbufferoffset);
539 /// free all R_AnimCache memory
540 void R_AnimCache_Free(void);
541 /// clear the animcache pointers on all known render entities
542 void R_AnimCache_ClearCache(void);
543 /// get the skeletal data or cached animated mesh data for an entity (optionally with normals and tangents)
544 qbool R_AnimCache_GetEntity(entity_render_t *ent, qbool wantnormals, qbool wanttangents);
545 /// generate animcache data for all entities marked visible
546 void R_AnimCache_CacheVisibleEntities(void);
548 extern cvar_t r_render;
549 extern cvar_t r_renderview;
550 extern cvar_t r_waterwarp;
552 extern cvar_t r_textureunits;
554 extern cvar_t r_glsl_offsetmapping;
555 extern cvar_t r_glsl_offsetmapping_reliefmapping;
556 extern cvar_t r_glsl_offsetmapping_scale;
557 extern cvar_t r_glsl_offsetmapping_lod;
558 extern cvar_t r_glsl_offsetmapping_lod_distance;
559 extern cvar_t r_glsl_deluxemapping;
561 extern cvar_t gl_polyblend;
563 extern cvar_t cl_deathfade;
565 extern cvar_t r_smoothnormals_areaweighting;
567 extern cvar_t r_test;
569 #include "gl_backend.h"
571 extern rtexture_t *r_texture_blanknormalmap;
572 extern rtexture_t *r_texture_white;
573 extern rtexture_t *r_texture_grey128;
574 extern rtexture_t *r_texture_black;
575 extern rtexture_t *r_texture_notexture;
576 extern rtexture_t *r_texture_whitecube;
577 extern rtexture_t *r_texture_normalizationcube;
578 extern rtexture_t *r_texture_fogattenuation;
579 extern rtexture_t *r_texture_fogheighttexture;
581 extern unsigned int r_queries[MAX_OCCLUSION_QUERIES];
582 extern unsigned int r_numqueries;
583 extern unsigned int r_maxqueries;
585 void R_TimeReport(const char *name);
588 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);
590 void R_CalcBeam_Vertex3f(float *vert, const float *org1, const float *org2, float width);
591 void R_CalcSprite_Vertex3f(float *vertex3f, const float *origin, const float *left, const float *up, float scalex1, float scalex2, float scaley1, float scaley2);
593 extern mempool_t *r_main_mempool;
595 typedef struct rsurfacestate_s
597 // current model array pointers
598 // these may point to processing buffers if model is animated,
599 // otherwise they point to static data.
600 // these are not directly used for rendering, they are just another level
603 // these either point at array_model* buffers (if the model is animated)
604 // or the model->surfmesh.data_* buffers (if the model is not animated)
606 // these are only set when an entity render begins, they do not change on
607 // a per surface basis.
609 // this indicates the model* arrays are pointed at array_model* buffers
610 // (in other words, the model has been animated in software)
611 qbool forcecurrenttextureupdate; // set for RSurf_ActiveCustomEntity to force R_GetCurrentTexture to recalculate the texture parameters (such as entity alpha)
612 qbool modelgeneratedvertex;
613 // skeletal animation can be done by entity (animcache) or per batch,
614 // batch may be non-skeletal even if entity is skeletal, indicating that
615 // the dynamicvertex code path had to apply skeletal manually for a case
616 // where gpu-skinning is not possible, for this reason batch has its own
618 int entityskeletalnumtransforms; // how many transforms are used for this mesh
619 float *entityskeletaltransform3x4; // use gpu-skinning shader on this mesh
620 const r_meshbuffer_t *entityskeletaltransform3x4buffer; // uniform buffer
621 int entityskeletaltransform3x4offset;
622 int entityskeletaltransform3x4size;
623 float *modelvertex3f;
624 const r_meshbuffer_t *modelvertex3f_vertexbuffer;
625 int modelvertex3f_bufferoffset;
626 float *modelsvector3f;
627 const r_meshbuffer_t *modelsvector3f_vertexbuffer;
628 int modelsvector3f_bufferoffset;
629 float *modeltvector3f;
630 const r_meshbuffer_t *modeltvector3f_vertexbuffer;
631 int modeltvector3f_bufferoffset;
632 float *modelnormal3f;
633 const r_meshbuffer_t *modelnormal3f_vertexbuffer;
634 int modelnormal3f_bufferoffset;
635 float *modellightmapcolor4f;
636 const r_meshbuffer_t *modellightmapcolor4f_vertexbuffer;
637 int modellightmapcolor4f_bufferoffset;
638 float *modeltexcoordtexture2f;
639 const r_meshbuffer_t *modeltexcoordtexture2f_vertexbuffer;
640 int modeltexcoordtexture2f_bufferoffset;
641 float *modeltexcoordlightmap2f;
642 const r_meshbuffer_t *modeltexcoordlightmap2f_vertexbuffer;
643 int modeltexcoordlightmap2f_bufferoffset;
644 unsigned char *modelskeletalindex4ub;
645 const r_meshbuffer_t *modelskeletalindex4ub_vertexbuffer;
646 int modelskeletalindex4ub_bufferoffset;
647 unsigned char *modelskeletalweight4ub;
648 const r_meshbuffer_t *modelskeletalweight4ub_vertexbuffer;
649 int modelskeletalweight4ub_bufferoffset;
651 const r_meshbuffer_t *modelelement3i_indexbuffer;
652 int modelelement3i_bufferoffset;
653 unsigned short *modelelement3s;
654 const r_meshbuffer_t *modelelement3s_indexbuffer;
655 int modelelement3s_bufferoffset;
656 int *modellightmapoffsets;
657 int modelnumvertices;
658 int modelnumtriangles;
659 const msurface_t *modelsurfaces;
660 // current rendering array pointers
661 // these may point to any of several different buffers depending on how
662 // much processing was needed to prepare this model for rendering
663 // these usually equal the model* pointers, they only differ if
664 // deformvertexes is used in a q3 shader, and consequently these can
665 // change on a per-surface basis (according to rsurface.texture)
666 qbool batchgeneratedvertex;
667 qbool batchmultidraw;
668 int batchmultidrawnumsurfaces;
669 const msurface_t **batchmultidrawsurfacelist;
670 int batchfirstvertex;
671 int batchnumvertices;
672 int batchfirsttriangle;
673 int batchnumtriangles;
674 float *batchvertex3f;
675 const r_meshbuffer_t *batchvertex3f_vertexbuffer;
676 int batchvertex3f_bufferoffset;
677 float *batchsvector3f;
678 const r_meshbuffer_t *batchsvector3f_vertexbuffer;
679 int batchsvector3f_bufferoffset;
680 float *batchtvector3f;
681 const r_meshbuffer_t *batchtvector3f_vertexbuffer;
682 int batchtvector3f_bufferoffset;
683 float *batchnormal3f;
684 const r_meshbuffer_t *batchnormal3f_vertexbuffer;
685 int batchnormal3f_bufferoffset;
686 float *batchlightmapcolor4f;
687 const r_meshbuffer_t *batchlightmapcolor4f_vertexbuffer;
688 int batchlightmapcolor4f_bufferoffset;
689 float *batchtexcoordtexture2f;
690 const r_meshbuffer_t *batchtexcoordtexture2f_vertexbuffer;
691 int batchtexcoordtexture2f_bufferoffset;
692 float *batchtexcoordlightmap2f;
693 const r_meshbuffer_t *batchtexcoordlightmap2f_vertexbuffer;
694 int batchtexcoordlightmap2f_bufferoffset;
695 unsigned char *batchskeletalindex4ub;
696 const r_meshbuffer_t *batchskeletalindex4ub_vertexbuffer;
697 int batchskeletalindex4ub_bufferoffset;
698 unsigned char *batchskeletalweight4ub;
699 const r_meshbuffer_t *batchskeletalweight4ub_vertexbuffer;
700 int batchskeletalweight4ub_bufferoffset;
702 const r_meshbuffer_t *batchelement3i_indexbuffer;
703 int batchelement3i_bufferoffset;
704 unsigned short *batchelement3s;
705 const r_meshbuffer_t *batchelement3s_indexbuffer;
706 int batchelement3s_bufferoffset;
707 int batchskeletalnumtransforms;
708 float *batchskeletaltransform3x4;
709 const r_meshbuffer_t *batchskeletaltransform3x4buffer; // uniform buffer
710 int batchskeletaltransform3x4offset;
711 int batchskeletaltransform3x4size;
713 // some important fields from the entity
717 int ent_alttextures; // used by q1bsp animated textures (pressed buttons)
718 double shadertime; // r_refdef.scene.time - ent->shadertime
719 // transform matrices to render this entity and effects on this entity
721 matrix4x4_t inversematrix;
722 // scale factors for transforming lengths into/out of entity space
724 float inversematrixscale;
725 // animation blending state from entity
726 frameblend_t frameblend[MAX_FRAMEBLENDS];
727 skeleton_t *skeleton;
728 // view location in model space
729 vec3_t localvieworigin;
730 // polygon offset data for submodels
731 float basepolygonfactor;
732 float basepolygonoffset;
733 // current textures in batching code
735 rtexture_t *lightmaptexture;
736 rtexture_t *deluxemaptexture;
737 // whether lightmapping is active on this batch
738 // (otherwise vertex colored)
739 qbool uselightmaptexture;
740 // fog plane in model space for direct application to vertices
742 float fogmasktabledistmultiplier;
745 float fogplaneviewdist;
748 // light currently being rendered
749 const rtlight_t *rtlight;
751 // this is the location of the light in entity space
752 vec3_t entitylightorigin;
753 // this transforms entity coordinates to light filter cubemap coordinates
754 // (also often used for other purposes)
755 matrix4x4_t entitytolight;
756 // based on entitytolight this transforms -1 to +1 to 0 to 1 for purposes
757 // of attenuation texturing in full 3D (Z result often ignored)
758 matrix4x4_t entitytoattenuationxyz;
759 // this transforms only the Z to S, and T is always 0.5
760 matrix4x4_t entitytoattenuationz;
762 // user wavefunc parameters (from csqc)
763 float userwavefunc_param[Q3WAVEFUNC_USER_COUNT];
765 // pointer to an entity_render_t used only by R_GetCurrentTexture and
766 // RSurf_ActiveModelEntity as a unique id within each frame (see r_frame
768 entity_render_t *entity;
772 extern rsurfacestate_t rsurface;
774 void R_HDR_UpdateIrisAdaptation(const vec3_t point);
776 void RSurf_ActiveModelEntity(const entity_render_t *ent, qbool wantnormals, qbool wanttangents, qbool prepass);
777 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);
778 void RSurf_SetupDepthAndCulling(void);
780 extern int r_textureframe; ///< used only by R_GetCurrentTexture, incremented per view and per UI render
781 texture_t *R_GetCurrentTexture(texture_t *t);
782 void R_DrawModelSurfaces(entity_render_t *ent, qbool skysurfaces, qbool writedepth, qbool depthonly, qbool debug, qbool prepass, qbool ui);
783 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);
784 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);
786 #define BATCHNEED_ARRAY_VERTEX (1<< 0) // set up rsurface.batchvertex3f
787 #define BATCHNEED_ARRAY_NORMAL (1<< 1) // set up rsurface.batchnormal3f
788 #define BATCHNEED_ARRAY_VECTOR (1<< 2) // set up rsurface.batchsvector3f and rsurface.batchtvector3f
789 #define BATCHNEED_ARRAY_VERTEXTINTCOLOR (1<< 3) // set up rsurface.batchvertexcolor4f
790 #define BATCHNEED_ARRAY_VERTEXCOLOR (1<< 4) // set up rsurface.batchlightmapcolor4f
791 #define BATCHNEED_ARRAY_TEXCOORD (1<< 5) // set up rsurface.batchtexcoordtexture2f
792 #define BATCHNEED_ARRAY_LIGHTMAP (1<< 6) // set up rsurface.batchtexcoordlightmap2f
793 #define BATCHNEED_ARRAY_SKELETAL (1<< 7) // set up skeletal index and weight data for vertex shader
794 #define BATCHNEED_NOGAPS (1<< 8) // force vertex copying if firstvertex is not zero or there are gaps
795 #define BATCHNEED_ALWAYSCOPY (1<< 9) // force vertex copying unconditionally - useful if you want to modify colors
796 #define BATCHNEED_ALLOWMULTIDRAW (1<<10) // allow multiple draws
797 void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const msurface_t **texturesurfacelist);
798 void RSurf_UploadBuffersForBatch(void);
799 void RSurf_DrawBatch(void);
801 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);
803 typedef enum rsurfacepass_e
806 RSURFPASS_BACKGROUND,
808 RSURFPASS_DEFERREDGEOMETRY
812 void R_SetupShader_Generic(rtexture_t *t, qbool usegamma, qbool notrippy, qbool suppresstexalpha);
813 void R_SetupShader_Generic_NoTexture(qbool usegamma, qbool notrippy);
814 void R_SetupShader_DepthOrShadow(qbool notrippy, qbool depthrgb, qbool skeletal);
815 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);
816 void R_SetupShader_DeferredLight(const rtlight_t *rtlight);
818 typedef struct r_rendertarget_s {
819 // texcoords for sampling from the viewport (clockwise: 0,0 1,0 1,1 0,1)
821 // textures are this size and type
824 // TEXTYPE for each color target - usually TEXTYPE_COLORBUFFER16F
825 textype_t colortextype[4];
826 // TEXTYPE for depth target - usually TEXTYPE_DEPTHBUFFER24 or TEXTYPE_SHADOWMAP24_COMP
827 textype_t depthtextype;
828 // if true the depth target will be a renderbuffer rather than a texture (still rtexture_t though)
829 qbool depthisrenderbuffer;
830 // framebuffer object referencing the textures
832 // there can be up to 4 color targets and 1 depth target, the depthtexture
833 // may be a real texture (readable) or just a renderbuffer (not readable,
834 // but potentially faster)
835 rtexture_t *colortexture[4];
836 rtexture_t *depthtexture;
837 // a rendertarget will not be reused in the same frame (host.realtime == lastusetime),
838 // on a new frame, matching rendertargets will be reused (texturewidth, textureheight, number of color and depth textures and their types),
839 // 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
843 // called each frame after render to delete render targets that have not been used for a while
844 void R_RenderTarget_FreeUnused(qbool force);
845 // returns a rendertarget, creates rendertarget if needed or intelligently reuses targets across frames if they match and have not been used already this frame
846 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);
848 typedef struct r_waterstate_waterplane_s
850 r_rendertarget_t *rt_refraction; // MATERIALFLAG_WATERSHADER or MATERIALFLAG_REFRACTION
851 r_rendertarget_t *rt_reflection; // MATERIALFLAG_WATERSHADER or MATERIALFLAG_REFLECTION
852 r_rendertarget_t *rt_camera; // MATERIALFLAG_CAMERA
854 int materialflags; // combined flags of all water surfaces on this plane
855 unsigned char pvsbits[(MAX_MAP_LEAFS+7)>>3]; // FIXME: buffer overflow on huge maps
860 r_waterstate_waterplane_t;
862 typedef struct r_waterstate_s
864 int waterwidth, waterheight;
865 int texturewidth, textureheight;
866 int camerawidth, cameraheight;
868 int maxwaterplanes; // same as MAX_WATERPLANES
870 r_waterstate_waterplane_t waterplanes[MAX_WATERPLANES];
872 float screenscale[2];
873 float screencenter[2];
877 qbool renderingscene; // true while rendering a refraction or reflection texture, disables water surfaces
882 typedef struct r_framebufferstate_s
884 textype_t textype; // type of color buffer we're using (dependent on r_viewfbo cvar)
885 int screentexturewidth, screentextureheight; // dimensions of texture
887 // rt_* fields are per-RenderView so we reset them in R_Bloom_StartFrame
888 r_rendertarget_t *rt_screen;
889 r_rendertarget_t *rt_bloom;
891 rtexture_t *ghosttexture; // for r_motionblur (not recommended on multi-GPU hardware!)
892 float ghosttexcoord2f[8]; // for r_motionblur
894 int bloomwidth, bloomheight;
896 // arrays for rendering the screen passes
897 float offsettexcoord2f[8]; // temporary use while updating bloomtexture[]
899 r_waterstate_t water;
901 qbool ghosttexture_valid; // don't draw garbage on first frame with motionblur
902 qbool usedepthtextures; // use depth texture instead of depth renderbuffer (faster if you need to read it later anyway)
904 // rendertargets (fbo and viewport), these can be reused across frames
905 memexpandablearray_t rendertargets;
907 r_framebufferstate_t;
909 extern r_framebufferstate_t r_fb;
911 extern cvar_t r_viewfbo;
913 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
914 void R_ResetViewRendering2D(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
915 void R_ResetViewRendering3D(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
916 void R_SetupView(qbool allowwaterclippingplane, int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
917 void R_DebugLine(vec3_t start, vec3_t end);
918 extern const float r_screenvertex3f[12];
919 extern cvar_t r_showspriteedges;
920 extern cvar_t r_showparticleedges;
921 extern cvar_t r_shadows;
922 extern cvar_t r_shadows_darken;
923 extern cvar_t r_shadows_drawafterrtlighting;
924 extern cvar_t r_shadows_castfrombmodels;
925 extern cvar_t r_shadows_throwdistance;
926 extern cvar_t r_shadows_throwdirection;
927 extern cvar_t r_shadows_focus;
928 extern cvar_t r_shadows_shadowmapscale;
929 extern cvar_t r_shadows_shadowmapbias;
930 extern cvar_t r_transparent_alphatocoverage;
931 extern cvar_t r_transparent_sortsurfacesbynearest;
932 extern cvar_t r_transparent_useplanardistance;
933 extern cvar_t r_transparent_sortarraysize;
934 extern cvar_t r_transparent_sortmindist;
935 extern cvar_t r_transparent_sortmaxdist;
937 extern qbool r_shadow_usingdeferredprepass;
938 extern rtexture_t *r_shadow_attenuationgradienttexture;
939 extern rtexture_t *r_shadow_attenuation2dtexture;
940 extern rtexture_t *r_shadow_attenuation3dtexture;
941 extern qbool r_shadow_usingshadowmap2d;
942 extern qbool r_shadow_usingshadowmaportho;
943 extern float r_shadow_modelshadowmap_texturescale[4];
944 extern float r_shadow_modelshadowmap_parameters[4];
945 extern float r_shadow_lightshadowmap_texturescale[4];
946 extern float r_shadow_lightshadowmap_parameters[4];
947 extern qbool r_shadow_shadowmapvsdct;
948 extern rtexture_t *r_shadow_shadowmap2ddepthbuffer;
949 extern rtexture_t *r_shadow_shadowmap2ddepthtexture;
950 extern rtexture_t *r_shadow_shadowmapvsdcttexture;
951 extern matrix4x4_t r_shadow_shadowmapmatrix;
952 extern int r_shadow_prepass_width;
953 extern int r_shadow_prepass_height;
954 extern rtexture_t *r_shadow_prepassgeometrydepthbuffer;
955 extern rtexture_t *r_shadow_prepassgeometrynormalmaptexture;
956 extern rtexture_t *r_shadow_prepasslightingdiffusetexture;
957 extern rtexture_t *r_shadow_prepasslightingspeculartexture;
958 extern int r_shadow_viewfbo;
959 extern rtexture_t *r_shadow_viewdepthtexture;
960 extern rtexture_t *r_shadow_viewcolortexture;
961 extern int r_shadow_viewx;
962 extern int r_shadow_viewy;
963 extern int r_shadow_viewwidth;
964 extern int r_shadow_viewheight;
966 void R_RenderScene(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
967 void R_RenderWaterPlanes(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight);
969 void R_Model_Sprite_Draw(entity_render_t *ent);
972 void R_UpdateFog(void);
973 qbool CL_VM_UpdateView(double frametime);
974 void SCR_DrawConsole(void);
975 void R_Shadow_EditLights_DrawSelectedLightProperties(void);
976 void R_DecalSystem_Reset(decalsystem_t *decalsystem);
977 void R_Shadow_UpdateBounceGridTexture(void);
978 void R_DrawPortals(void);
979 void R_BuildLightMap(const entity_render_t *ent, msurface_t *surface);
980 void R_Water_AddWaterPlane(msurface_t *surface, int entno);
981 int R_Shadow_GetRTLightInfo(unsigned int lightindex, float *origin, float *radius, float *color);
982 dp_font_t *FindFont(const char *title, qbool allocate_new);
983 void LoadFont(qbool override, const char *name, dp_font_t *fnt, float scale, float voffset);
985 void Render_Init(void);
987 // these are called by Render_Init
988 void R_Textures_Init(void);
989 void GL_Draw_Init(void);
990 void GL_Main_Init(void);
991 void R_Shadow_Init(void);
992 void R_Sky_Init(void);
993 void GL_Surf_Init(void);
994 void R_Particles_Init(void);
995 void R_Explosion_Init(void);
996 void gl_backend_init(void);
997 void Sbar_Init(void);
998 void R_LightningBeams_Init(void);
999 void Mod_RenderInit(void);
1000 void Font_Init(void);
1002 qbool R_CompileShader_CheckStaticParms(void);
1003 void R_GLSL_Restart_f(cmd_state_t *cmd);