DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
gl_rmain.c
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20// r_main.c
21
22#include "quakedef.h"
23#include "r_shadow.h"
24#include "polygon.h"
25#include "image.h"
26#include "ft2.h"
27#include "csprogs.h"
28#include "cl_video.h"
29#include "cl_collision.h"
30
31#ifdef WIN32
32// Enable NVIDIA High Performance Graphics while using Integrated Graphics.
33#ifdef __cplusplus
34extern "C" {
35#endif
36__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
37#ifdef __cplusplus
38}
39#endif
40#endif
41
44
46
53
54//
55// screen size info
56//
58
59cvar_t r_motionblur = {CF_CLIENT | CF_ARCHIVE, "r_motionblur", "0", "screen motionblur - value represents intensity, somewhere around 0.5 recommended - NOTE: bad performance on multi-gpu!"};
60cvar_t r_damageblur = {CF_CLIENT | CF_ARCHIVE, "r_damageblur", "0", "screen motionblur based on damage - value represents intensity, somewhere around 0.5 recommended - NOTE: bad performance on multi-gpu!"};
61cvar_t r_motionblur_averaging = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_averaging", "0.1", "sliding average reaction time for velocity (higher = slower adaption to change)"};
62cvar_t r_motionblur_randomize = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_randomize", "0.1", "randomizing coefficient to workaround ghosting"};
63cvar_t r_motionblur_minblur = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_minblur", "0.5", "factor of blur to apply at all times (always have this amount of blur no matter what the other factors are)"};
64cvar_t r_motionblur_maxblur = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_maxblur", "0.9", "maxmimum amount of blur"};
65cvar_t r_motionblur_velocityfactor = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_velocityfactor", "1", "factoring in of player velocity to the blur equation - the faster the player moves around the map, the more blur they get"};
66cvar_t r_motionblur_velocityfactor_minspeed = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_velocityfactor_minspeed", "400", "lower value of velocity when it starts to factor into blur equation"};
67cvar_t r_motionblur_velocityfactor_maxspeed = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_velocityfactor_maxspeed", "800", "upper value of velocity when it reaches the peak factor into blur equation"};
68cvar_t r_motionblur_mousefactor = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_mousefactor", "2", "factoring in of mouse acceleration to the blur equation - the faster the player turns their mouse, the more blur they get"};
69cvar_t r_motionblur_mousefactor_minspeed = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_mousefactor_minspeed", "0", "lower value of mouse acceleration when it starts to factor into blur equation"};
70cvar_t r_motionblur_mousefactor_maxspeed = {CF_CLIENT | CF_ARCHIVE, "r_motionblur_mousefactor_maxspeed", "50", "upper value of mouse acceleration when it reaches the peak factor into blur equation"};
71
72cvar_t r_depthfirst = {CF_CLIENT | CF_ARCHIVE, "r_depthfirst", "0", "renders a depth-only version of the scene before normal rendering begins to eliminate overdraw, values: 0 = off, 1 = world depth, 2 = world and model depth"};
73cvar_t r_useinfinitefarclip = {CF_CLIENT | CF_ARCHIVE, "r_useinfinitefarclip", "1", "enables use of a special kind of projection matrix that has an extremely large farclip"};
74cvar_t r_farclip_base = {CF_CLIENT, "r_farclip_base", "65536", "farclip (furthest visible distance) for rendering when r_useinfinitefarclip is 0"};
75cvar_t r_farclip_world = {CF_CLIENT, "r_farclip_world", "2", "adds map size to farclip multiplied by this value"};
76cvar_t r_nearclip = {CF_CLIENT, "r_nearclip", "1", "distance from camera of nearclip plane" };
77cvar_t r_deformvertexes = {CF_CLIENT, "r_deformvertexes", "1", "allows use of deformvertexes in shader files (can be turned off to check performance impact)"};
78cvar_t r_transparent = {CF_CLIENT, "r_transparent", "1", "allows use of transparent surfaces (can be turned off to check performance impact)"};
79cvar_t r_transparent_alphatocoverage = {CF_CLIENT, "r_transparent_alphatocoverage", "1", "enables GL_ALPHA_TO_COVERAGE antialiasing technique on alphablend and alphatest surfaces when using vid_samples 2 or higher"};
80cvar_t r_transparent_sortsurfacesbynearest = {CF_CLIENT, "r_transparent_sortsurfacesbynearest", "1", "sort entity and world surfaces by nearest point on bounding box instead of using the center of the bounding box, usually reduces sorting artifacts"};
81cvar_t r_transparent_useplanardistance = {CF_CLIENT, "r_transparent_useplanardistance", "0", "sort transparent meshes by distance from view plane rather than spherical distance to the chosen point"};
82cvar_t r_showoverdraw = {CF_CLIENT, "r_showoverdraw", "0", "shows overlapping geometry"};
83cvar_t r_showbboxes = {CF_CLIENT, "r_showbboxes", "0", "shows bounding boxes of server entities, value controls opacity scaling (1 = 10%, 10 = 100%)"};
84cvar_t r_showbboxes_client = {CF_CLIENT, "r_showbboxes_client", "0", "shows bounding boxes of clientside qc entities, value controls opacity scaling (1 = 10%, 10 = 100%)"};
85cvar_t r_showsurfaces = {CF_CLIENT, "r_showsurfaces", "0", "1 shows surfaces as different colors, or a value of 3 shows an approximation to vertex or object color (for a very approximate view of the game)"};
86cvar_t r_showtris = {CF_CLIENT, "r_showtris", "0", "shows triangle outlines, value controls brightness (can be above 1)"};
87cvar_t r_shownormals = {CF_CLIENT, "r_shownormals", "0", "shows per-vertex surface normals and tangent vectors for bumpmapped lighting"};
88cvar_t r_showlighting = {CF_CLIENT, "r_showlighting", "0", "shows areas lit by lights, useful for finding out why some areas of a map render slowly (bright orange = lots of passes = slow), a value of 2 disables depth testing which can be interesting but not very useful"};
89cvar_t r_showcollisionbrushes = {CF_CLIENT, "r_showcollisionbrushes", "0", "draws collision brushes in quake3 maps (mode 1), mode 2 disables rendering of world (trippy!)"};
90cvar_t r_showcollisionbrushes_polygonfactor = {CF_CLIENT, "r_showcollisionbrushes_polygonfactor", "-1", "expands outward the brush polygons a little bit, used to make collision brushes appear infront of walls"};
91cvar_t r_showcollisionbrushes_polygonoffset = {CF_CLIENT, "r_showcollisionbrushes_polygonoffset", "0", "nudges brush polygon depth in hardware depth units, used to make collision brushes appear infront of walls"};
92cvar_t r_showdisabledepthtest = {CF_CLIENT, "r_showdisabledepthtest", "0", "disables depth testing on r_show* cvars, allowing you to see what hidden geometry the graphics card is processing"};
93cvar_t r_showspriteedges = {CF_CLIENT, "r_showspriteedges", "0", "renders a debug outline to show the polygon shape of each sprite frame rendered (may be 2 or more in case of interpolated animations), for debugging rendering bugs with specific view types"};
94cvar_t r_showparticleedges = {CF_CLIENT, "r_showparticleedges", "0", "renders a debug outline to show the polygon shape of each particle, for debugging rendering bugs with specific view types"};
95cvar_t r_drawportals = {CF_CLIENT, "r_drawportals", "0", "shows portals (separating polygons) in world interior in quake1 maps"};
96cvar_t r_drawentities = {CF_CLIENT, "r_drawentities","1", "draw entities (doors, players, projectiles, etc)"};
97cvar_t r_draw2d = {CF_CLIENT, "r_draw2d","1", "draw 2D stuff (dangerous to turn off)"};
98cvar_t r_drawworld = {CF_CLIENT, "r_drawworld","1", "draw world (most static stuff)"};
99cvar_t r_drawviewmodel = {CF_CLIENT, "r_drawviewmodel","1", "draw your weapon model"};
100cvar_t r_drawexteriormodel = {CF_CLIENT, "r_drawexteriormodel","1", "draw your player model (e.g. in chase cam, reflections)"};
101cvar_t r_cullentities_trace = {CF_CLIENT, "r_cullentities_trace", "1", "probabistically cull invisible entities"};
102cvar_t r_cullentities_trace_entityocclusion = {CF_CLIENT, "r_cullentities_trace_entityocclusion", "1", "check for occluding entities such as doors, not just world hull"};
103cvar_t r_cullentities_trace_samples = {CF_CLIENT, "r_cullentities_trace_samples", "2", "number of samples to test for entity culling (in addition to center sample)"};
104cvar_t r_cullentities_trace_tempentitysamples = {CF_CLIENT, "r_cullentities_trace_tempentitysamples", "-1", "number of samples to test for entity culling of temp entities (including all CSQC entities), -1 disables trace culling on these entities to prevent flicker (pvs still applies)"};
105cvar_t r_cullentities_trace_enlarge = {CF_CLIENT, "r_cullentities_trace_enlarge", "0", "box enlargement for entity culling"};
106cvar_t r_cullentities_trace_expand = {CF_CLIENT, "r_cullentities_trace_expand", "0", "box expanded by this many units for entity culling"};
107cvar_t r_cullentities_trace_pad = {CF_CLIENT, "r_cullentities_trace_pad", "8", "accept traces that hit within this many units of the box"};
108cvar_t r_cullentities_trace_delay = {CF_CLIENT, "r_cullentities_trace_delay", "1", "number of seconds until the entity gets actually culled"};
109cvar_t r_cullentities_trace_eyejitter = {CF_CLIENT, "r_cullentities_trace_eyejitter", "16", "randomly offset rays from the eye by this much to reduce the odds of flickering"};
110cvar_t r_sortentities = {CF_CLIENT, "r_sortentities", "0", "sort entities before drawing (might be faster)"};
111cvar_t r_speeds = {CF_CLIENT, "r_speeds","0", "displays rendering statistics and per-subsystem timings"};
112cvar_t r_fullbright = {CF_CLIENT, "r_fullbright","0", "makes map very bright and renders faster"};
113
114cvar_t r_fullbright_directed = {CF_CLIENT, "r_fullbright_directed", "0", "render fullbright things (unlit worldmodel and EF_FULLBRIGHT entities, but not fullbright shaders) using a constant light direction instead to add more depth while keeping uniform brightness"};
115cvar_t r_fullbright_directed_ambient = {CF_CLIENT, "r_fullbright_directed_ambient", "0.5", "ambient light multiplier for directed fullbright"};
116cvar_t r_fullbright_directed_diffuse = {CF_CLIENT, "r_fullbright_directed_diffuse", "0.75", "diffuse light multiplier for directed fullbright"};
117cvar_t r_fullbright_directed_pitch = {CF_CLIENT, "r_fullbright_directed_pitch", "20", "constant pitch direction ('height') of the fake light source to use for fullbright"};
118cvar_t r_fullbright_directed_pitch_relative = {CF_CLIENT, "r_fullbright_directed_pitch_relative", "0", "whether r_fullbright_directed_pitch is interpreted as absolute (0) or relative (1) pitch"};
119
120cvar_t r_wateralpha = {CF_CLIENT | CF_ARCHIVE, "r_wateralpha","1", "opacity of water polygons"};
121cvar_t r_dynamic = {CF_CLIENT | CF_ARCHIVE, "r_dynamic","1", "enables dynamic lights (rocket glow and such)"};
122cvar_t r_fullbrights = {CF_CLIENT | CF_ARCHIVE, "r_fullbrights", "1", "enables glowing pixels in quake textures (changes need r_restart to take effect)"};
123cvar_t r_shadows = {CF_CLIENT | CF_ARCHIVE, "r_shadows", "0", "casts fake stencil shadows from models onto the world (rtlights are unaffected by this); when set to 2, always cast the shadows in the direction set by r_shadows_throwdirection, otherwise use the model lighting."};
124cvar_t r_shadows_darken = {CF_CLIENT | CF_ARCHIVE, "r_shadows_darken", "0.5", "how much shadowed areas will be darkened"};
125cvar_t r_shadows_throwdistance = {CF_CLIENT | CF_ARCHIVE, "r_shadows_throwdistance", "500", "how far to cast shadows from models"};
126cvar_t r_shadows_throwdirection = {CF_CLIENT | CF_ARCHIVE, "r_shadows_throwdirection", "0 0 -1", "override throwing direction for r_shadows 2"};
127cvar_t r_shadows_drawafterrtlighting = {CF_CLIENT | CF_ARCHIVE, "r_shadows_drawafterrtlighting", "0", "draw fake shadows AFTER realtime lightning is drawn. May be useful for simulating fast sunlight on large outdoor maps with only one noshadow rtlight. The price is less realistic appearance of dynamic light shadows."};
128cvar_t r_shadows_castfrombmodels = {CF_CLIENT | CF_ARCHIVE, "r_shadows_castfrombmodels", "0", "do cast shadows from bmodels"};
129cvar_t r_shadows_focus = {CF_CLIENT | CF_ARCHIVE, "r_shadows_focus", "0 0 0", "offset the shadowed area focus"};
130cvar_t r_shadows_shadowmapscale = {CF_CLIENT | CF_ARCHIVE, "r_shadows_shadowmapscale", "0.25", "higher values increase shadowmap quality at a cost of area covered (multiply global shadowmap precision) for fake shadows. Needs shadowmapping ON."};
131cvar_t r_shadows_shadowmapbias = {CF_CLIENT | CF_ARCHIVE, "r_shadows_shadowmapbias", "-1", "sets shadowmap bias for fake shadows. -1 sets the value of r_shadow_shadowmapping_bias. Needs shadowmapping ON."};
132cvar_t r_q1bsp_skymasking = {CF_CLIENT, "r_q1bsp_skymasking", "1", "allows sky polygons in quake1 maps to obscure other geometry"};
133cvar_t r_polygonoffset_submodel_factor = {CF_CLIENT, "r_polygonoffset_submodel_factor", "0", "biases depth values of world submodels such as doors, to prevent z-fighting artifacts in Quake maps"};
134cvar_t r_polygonoffset_submodel_offset = {CF_CLIENT, "r_polygonoffset_submodel_offset", "14", "biases depth values of world submodels such as doors, to prevent z-fighting artifacts in Quake maps"};
135cvar_t r_polygonoffset_decals_factor = {CF_CLIENT, "r_polygonoffset_decals_factor", "0", "biases depth values of decals to prevent z-fighting artifacts"};
136cvar_t r_polygonoffset_decals_offset = {CF_CLIENT, "r_polygonoffset_decals_offset", "-14", "biases depth values of decals to prevent z-fighting artifacts"};
137cvar_t r_fog_exp2 = {CF_CLIENT, "r_fog_exp2", "0", "uses GL_EXP2 fog (as in Nehahra) rather than realistic GL_EXP fog"};
138cvar_t r_fog_clear = {CF_CLIENT, "r_fog_clear", "1", "clears renderbuffer with fog color before render starts"};
139cvar_t r_drawfog = {CF_CLIENT | CF_ARCHIVE, "r_drawfog", "1", "allows one to disable fog rendering"};
140cvar_t r_transparentdepthmasking = {CF_CLIENT | CF_ARCHIVE, "r_transparentdepthmasking", "0", "enables depth writes on transparent meshes whose materially is normally opaque, this prevents seeing the inside of a transparent mesh"};
141cvar_t r_transparent_sortmindist = {CF_CLIENT | CF_ARCHIVE, "r_transparent_sortmindist", "0", "lower distance limit for transparent sorting"};
142cvar_t r_transparent_sortmaxdist = {CF_CLIENT | CF_ARCHIVE, "r_transparent_sortmaxdist", "32768", "upper distance limit for transparent sorting"};
143cvar_t r_transparent_sortarraysize = {CF_CLIENT | CF_ARCHIVE, "r_transparent_sortarraysize", "4096", "number of distance-sorting layers"};
144cvar_t r_celshading = {CF_CLIENT | CF_ARCHIVE, "r_celshading", "0", "cartoon-style light shading (OpenGL 2.x only)"}; // FIXME remove OpenGL 2.x only once implemented for DX9
145cvar_t r_celoutlines = {CF_CLIENT | CF_ARCHIVE, "r_celoutlines", "0", "cartoon-style outlines (requires r_shadow_deferred)"};
146
147cvar_t gl_fogenable = {CF_CLIENT, "gl_fogenable", "0", "nehahra fog enable (for Nehahra compatibility only)"};
148cvar_t gl_fogdensity = {CF_CLIENT, "gl_fogdensity", "0.25", "nehahra fog density (recommend values below 0.1) (for Nehahra compatibility only)"};
149cvar_t gl_fogred = {CF_CLIENT, "gl_fogred","0.3", "nehahra fog color red value (for Nehahra compatibility only)"};
150cvar_t gl_foggreen = {CF_CLIENT, "gl_foggreen","0.3", "nehahra fog color green value (for Nehahra compatibility only)"};
151cvar_t gl_fogblue = {CF_CLIENT, "gl_fogblue","0.3", "nehahra fog color blue value (for Nehahra compatibility only)"};
152cvar_t gl_fogstart = {CF_CLIENT, "gl_fogstart", "0", "nehahra fog start distance (for Nehahra compatibility only)"};
153cvar_t gl_fogend = {CF_CLIENT, "gl_fogend","0", "nehahra fog end distance (for Nehahra compatibility only)"};
154cvar_t gl_skyclip = {CF_CLIENT, "gl_skyclip", "4608", "nehahra farclip distance - the real fog end (for Nehahra compatibility only)"};
155
156cvar_t r_texture_dds_load = {CF_CLIENT | CF_ARCHIVE, "r_texture_dds_load", "0", "load compressed dds/filename.dds texture instead of filename.tga, if the file exists (requires driver support)"};
157cvar_t r_texture_dds_save = {CF_CLIENT | CF_ARCHIVE, "r_texture_dds_save", "0", "save compressed dds/filename.dds texture when filename.tga is loaded, so that it can be loaded instead next time"};
158
159cvar_t r_usedepthtextures = {CF_CLIENT | CF_ARCHIVE, "r_usedepthtextures", "1", "use depth texture instead of depth renderbuffer where possible, uses less video memory but may render slower (or faster) depending on hardware"};
160cvar_t r_viewfbo = {CF_CLIENT | CF_ARCHIVE, "r_viewfbo", "0", "enables use of an 8bit (1) or 16bit (2) or 32bit (3) per component float framebuffer render, which may be at a different resolution than the video mode; the default setting of 0 uses a framebuffer render when required, and renders directly to the screen otherwise"};
161cvar_t r_rendertarget_debug = {CF_CLIENT, "r_rendertarget_debug", "-1", "replaces the view with the contents of the specified render target (by number - note that these can fluctuate depending on scene)"};
162cvar_t r_viewscale = {CF_CLIENT | CF_ARCHIVE, "r_viewscale", "1", "scaling factor for resolution of the fbo rendering method, must be > 0, can be above 1 for a costly antialiasing behavior, typical values are 0.5 for 1/4th as many pixels rendered, or 1 for normal rendering"};
163cvar_t r_viewscale_fpsscaling = {CF_CLIENT | CF_ARCHIVE, "r_viewscale_fpsscaling", "0", "change resolution based on framerate"};
164cvar_t r_viewscale_fpsscaling_min = {CF_CLIENT | CF_ARCHIVE, "r_viewscale_fpsscaling_min", "0.0625", "worst acceptable quality"};
165cvar_t r_viewscale_fpsscaling_multiply = {CF_CLIENT | CF_ARCHIVE, "r_viewscale_fpsscaling_multiply", "5", "adjust quality up or down by the frametime difference from 1.0/target, multiplied by this factor"};
166cvar_t r_viewscale_fpsscaling_stepsize = {CF_CLIENT | CF_ARCHIVE, "r_viewscale_fpsscaling_stepsize", "0.01", "smallest adjustment to hit the target framerate (this value prevents minute oscillations)"};
167cvar_t r_viewscale_fpsscaling_stepmax = {CF_CLIENT | CF_ARCHIVE, "r_viewscale_fpsscaling_stepmax", "1.00", "largest adjustment to hit the target framerate (this value prevents wild overshooting of the estimate)"};
168cvar_t r_viewscale_fpsscaling_target = {CF_CLIENT | CF_ARCHIVE, "r_viewscale_fpsscaling_target", "70", "desired framerate"};
169
170cvar_t r_glsl_skeletal = {CF_CLIENT | CF_ARCHIVE, "r_glsl_skeletal", "1", "render skeletal models faster using a gpu-skinning technique"};
171cvar_t r_glsl_deluxemapping = {CF_CLIENT | CF_ARCHIVE, "r_glsl_deluxemapping", "1", "use per pixel lighting on deluxemap-compiled q3bsp maps (or a value of 2 forces deluxemap shading even without deluxemaps)"};
172cvar_t r_glsl_offsetmapping = {CF_CLIENT | CF_ARCHIVE, "r_glsl_offsetmapping", "0", "offset mapping effect (also known as parallax mapping or virtual displacement mapping)"};
173cvar_t r_glsl_offsetmapping_steps = {CF_CLIENT | CF_ARCHIVE, "r_glsl_offsetmapping_steps", "2", "offset mapping steps (note: too high values may be not supported by your GPU)"};
174cvar_t r_glsl_offsetmapping_reliefmapping = {CF_CLIENT | CF_ARCHIVE, "r_glsl_offsetmapping_reliefmapping", "0", "relief mapping effect (higher quality)"};
175cvar_t r_glsl_offsetmapping_reliefmapping_steps = {CF_CLIENT | CF_ARCHIVE, "r_glsl_offsetmapping_reliefmapping_steps", "10", "relief mapping steps (note: too high values may be not supported by your GPU)"};
176cvar_t r_glsl_offsetmapping_reliefmapping_refinesteps = {CF_CLIENT | CF_ARCHIVE, "r_glsl_offsetmapping_reliefmapping_refinesteps", "5", "relief mapping refine steps (these are a binary search executed as the last step as given by r_glsl_offsetmapping_reliefmapping_steps)"};
177cvar_t r_glsl_offsetmapping_scale = {CF_CLIENT | CF_ARCHIVE, "r_glsl_offsetmapping_scale", "0.04", "how deep the offset mapping effect is"};
178cvar_t r_glsl_offsetmapping_lod = {CF_CLIENT | CF_ARCHIVE, "r_glsl_offsetmapping_lod", "0", "apply distance-based level-of-detail correction to number of offsetmappig steps, effectively making it render faster on large open-area maps"};
179cvar_t r_glsl_offsetmapping_lod_distance = {CF_CLIENT | CF_ARCHIVE, "r_glsl_offsetmapping_lod_distance", "32", "first LOD level distance, second level (-50% steps) is 2x of this, third (33%) - 3x etc."};
180cvar_t r_glsl_postprocess = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess", "0", "use a GLSL postprocessing shader"};
181cvar_t r_glsl_postprocess_uservec1 = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec1", "0 0 0 0", "a 4-component vector to pass as uservec1 to the postprocessing shader (only useful if default.glsl has been customized)"};
182cvar_t r_glsl_postprocess_uservec2 = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec2", "0 0 0 0", "a 4-component vector to pass as uservec2 to the postprocessing shader (only useful if default.glsl has been customized)"};
183cvar_t r_glsl_postprocess_uservec3 = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec3", "0 0 0 0", "a 4-component vector to pass as uservec3 to the postprocessing shader (only useful if default.glsl has been customized)"};
184cvar_t r_glsl_postprocess_uservec4 = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec4", "0 0 0 0", "a 4-component vector to pass as uservec4 to the postprocessing shader (only useful if default.glsl has been customized)"};
185cvar_t r_glsl_postprocess_uservec1_enable = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec1_enable", "1", "enables postprocessing uservec1 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
186cvar_t r_glsl_postprocess_uservec2_enable = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec2_enable", "1", "enables postprocessing uservec2 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
187cvar_t r_glsl_postprocess_uservec3_enable = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec3_enable", "1", "enables postprocessing uservec3 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
188cvar_t r_glsl_postprocess_uservec4_enable = {CF_CLIENT | CF_ARCHIVE, "r_glsl_postprocess_uservec4_enable", "1", "enables postprocessing uservec4 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
189cvar_t r_colorfringe = {CF_CLIENT | CF_ARCHIVE, "r_colorfringe", "0", "Chromatic aberration. Values higher than 0.025 will noticeably distort the image"};
190cvar_t r_fxaa = {CF_CLIENT | CF_ARCHIVE, "r_fxaa", "0", "fast approximate anti aliasing"};
191
192cvar_t r_water = {CF_CLIENT | CF_ARCHIVE, "r_water", "0", "whether to use reflections and refraction on water surfaces (note: r_wateralpha must be set below 1)"};
193cvar_t r_water_cameraentitiesonly = {CF_CLIENT | CF_ARCHIVE, "r_water_cameraentitiesonly", "0", "whether to only show QC-defined reflections/refractions (typically used for camera- or portal-like effects)"};
194cvar_t r_water_clippingplanebias = {CF_CLIENT | CF_ARCHIVE, "r_water_clippingplanebias", "1", "a rather technical setting which avoids black pixels around water edges"};
195cvar_t r_water_resolutionmultiplier = {CF_CLIENT | CF_ARCHIVE, "r_water_resolutionmultiplier", "0.5", "multiplier for screen resolution when rendering refracted/reflected scenes, 1 is full quality, lower values are faster"};
196cvar_t r_water_refractdistort = {CF_CLIENT | CF_ARCHIVE, "r_water_refractdistort", "0.01", "how much water refractions shimmer"};
197cvar_t r_water_reflectdistort = {CF_CLIENT | CF_ARCHIVE, "r_water_reflectdistort", "0.01", "how much water reflections shimmer"};
198cvar_t r_water_scissormode = {CF_CLIENT, "r_water_scissormode", "3", "scissor (1) or cull (2) or both (3) water renders"};
199cvar_t r_water_lowquality = {CF_CLIENT, "r_water_lowquality", "0", "special option to accelerate water rendering: 1 disables all dynamic lights, 2 disables particles too"};
200cvar_t r_water_hideplayer = {CF_CLIENT | CF_ARCHIVE, "r_water_hideplayer", "0", "if set to 1 then player will be hidden in refraction views, if set to 2 then player will also be hidden in reflection views, player is always visible in camera views"};
201
202cvar_t r_lerpsprites = {CF_CLIENT | CF_ARCHIVE, "r_lerpsprites", "0", "enables animation smoothing on sprites"};
203cvar_t r_lerpmodels = {CF_CLIENT | CF_ARCHIVE, "r_lerpmodels", "1", "enables animation smoothing on models"};
204cvar_t r_nolerp_list = {CF_CLIENT | CF_ARCHIVE, "r_nolerp_list", "progs/v_nail.mdl,progs/v_nail2.mdl,progs/flame.mdl,progs/flame2.mdl,progs/braztall.mdl,progs/brazshrt.mdl,progs/longtrch.mdl,progs/flame_pyre.mdl,progs/v_saw.mdl,progs/v_xfist.mdl,progs/h2stuff/newfire.mdl", "comma separated list of models that will not have their animations smoothed"};
205cvar_t r_lerplightstyles = {CF_CLIENT | CF_ARCHIVE, "r_lerplightstyles", "0", "enable animation smoothing on flickering lights"};
206cvar_t r_waterscroll = {CF_CLIENT | CF_ARCHIVE, "r_waterscroll", "1", "makes water scroll around, value controls how much"};
207
208cvar_t r_bloom = {CF_CLIENT | CF_ARCHIVE, "r_bloom", "0", "enables bloom effect (makes bright pixels affect neighboring pixels)"};
209cvar_t r_bloom_colorscale = {CF_CLIENT | CF_ARCHIVE, "r_bloom_colorscale", "1", "how bright the glow is"};
210
211cvar_t r_bloom_brighten = {CF_CLIENT | CF_ARCHIVE, "r_bloom_brighten", "1", "how bright the glow is, after subtract/power"};
212cvar_t r_bloom_blur = {CF_CLIENT | CF_ARCHIVE, "r_bloom_blur", "4", "how large the glow is"};
213cvar_t r_bloom_resolution = {CF_CLIENT | CF_ARCHIVE, "r_bloom_resolution", "320", "what resolution to perform the bloom effect at (independent of screen resolution)"};
214cvar_t r_bloom_colorexponent = {CF_CLIENT | CF_ARCHIVE, "r_bloom_colorexponent", "1", "how exaggerated the glow is"};
215cvar_t r_bloom_colorsubtract = {CF_CLIENT | CF_ARCHIVE, "r_bloom_colorsubtract", "0.1", "reduces bloom colors by a certain amount"};
216cvar_t r_bloom_scenebrightness = {CF_CLIENT | CF_ARCHIVE, "r_bloom_scenebrightness", "1", "global rendering brightness when bloom is enabled"};
217
218cvar_t r_hdr_scenebrightness = {CF_CLIENT | CF_ARCHIVE, "r_hdr_scenebrightness", "1", "global rendering brightness"};
219cvar_t r_hdr_glowintensity = {CF_CLIENT | CF_ARCHIVE, "r_hdr_glowintensity", "1", "how bright light emitting textures should appear"};
220cvar_t r_hdr_irisadaptation = {CF_CLIENT | CF_ARCHIVE, "r_hdr_irisadaptation", "0", "adjust scene brightness according to light intensity at player location"};
221cvar_t r_hdr_irisadaptation_multiplier = {CF_CLIENT | CF_ARCHIVE, "r_hdr_irisadaptation_multiplier", "2", "brightness at which value will be 1.0"};
222cvar_t r_hdr_irisadaptation_minvalue = {CF_CLIENT | CF_ARCHIVE, "r_hdr_irisadaptation_minvalue", "0.5", "minimum value that can result from multiplier / brightness"};
223cvar_t r_hdr_irisadaptation_maxvalue = {CF_CLIENT | CF_ARCHIVE, "r_hdr_irisadaptation_maxvalue", "4", "maximum value that can result from multiplier / brightness"};
224cvar_t r_hdr_irisadaptation_value = {CF_CLIENT, "r_hdr_irisadaptation_value", "1", "current value as scenebrightness multiplier, changes continuously when irisadaptation is active"};
225cvar_t r_hdr_irisadaptation_fade_up = {CF_CLIENT | CF_ARCHIVE, "r_hdr_irisadaptation_fade_up", "0.1", "fade rate at which value adjusts to darkness"};
226cvar_t r_hdr_irisadaptation_fade_down = {CF_CLIENT | CF_ARCHIVE, "r_hdr_irisadaptation_fade_down", "0.5", "fade rate at which value adjusts to brightness"};
227cvar_t r_hdr_irisadaptation_radius = {CF_CLIENT | CF_ARCHIVE, "r_hdr_irisadaptation_radius", "15", "lighting within this many units of the eye is averaged"};
228
229cvar_t r_smoothnormals_areaweighting = {CF_CLIENT, "r_smoothnormals_areaweighting", "1", "uses significantly faster (and supposedly higher quality) area-weighted vertex normals and tangent vectors rather than summing normalized triangle normals and tangents"};
230
231cvar_t developer_texturelogging = {CF_CLIENT, "developer_texturelogging", "0", "produces a textures.log file containing names of skins and map textures the engine tried to load"};
232
233cvar_t gl_lightmaps = {CF_CLIENT, "gl_lightmaps", "0", "draws only lightmaps, no texture (for level designers), a value of 2 keeps normalmap shading"};
234
235cvar_t r_test = {CF_CLIENT, "r_test", "0", "internal development use only, leave it alone (usually does nothing anyway)"};
236
237cvar_t r_batch_multidraw = {CF_CLIENT | CF_ARCHIVE, "r_batch_multidraw", "1", "issue multiple glDrawElements calls when rendering a batch of surfaces with the same texture (otherwise the index data is copied to make it one draw)"};
238cvar_t r_batch_multidraw_mintriangles = {CF_CLIENT | CF_ARCHIVE, "r_batch_multidraw_mintriangles", "0", "minimum number of triangles to activate multidraw path (copying small groups of triangles may be faster)"};
239cvar_t r_batch_debugdynamicvertexpath = {CF_CLIENT | CF_ARCHIVE, "r_batch_debugdynamicvertexpath", "0", "force the dynamic batching code path for debugging purposes"};
240cvar_t r_batch_dynamicbuffer = {CF_CLIENT | CF_ARCHIVE, "r_batch_dynamicbuffer", "0", "use vertex/index buffers for drawing dynamic and copytriangles batches"};
241
242cvar_t r_glsl_saturation = {CF_CLIENT | CF_ARCHIVE, "r_glsl_saturation", "1", "saturation multiplier (only working in glsl!)"};
243cvar_t r_glsl_saturation_redcompensate = {CF_CLIENT | CF_ARCHIVE, "r_glsl_saturation_redcompensate", "0", "a 'vampire sight' addition to desaturation effect, does compensation for red color, r_glsl_restart is required"};
244
245cvar_t r_glsl_vertextextureblend_usebothalphas = {CF_CLIENT | CF_ARCHIVE, "r_glsl_vertextextureblend_usebothalphas", "0", "use both alpha layers on vertex blended surfaces, each alpha layer sets amount of 'blend leak' on another layer, requires mod_q3shader_force_terrain_alphaflag on."};
246
247// FIXME: This cvar would grow to a ridiculous size after several launches and clean exits when used during surface sorting.
248cvar_t r_framedatasize = {CF_CLIENT | CF_ARCHIVE, "r_framedatasize", "0.5", "size of renderer data cache used during one frame (for skeletal animation caching, light processing, etc)"};
250{
251 {CF_CLIENT | CF_ARCHIVE, "r_buffermegs_vertex", "4", "vertex buffer size for one frame"},
252 {CF_CLIENT | CF_ARCHIVE, "r_buffermegs_index16", "1", "index buffer size for one frame (16bit indices)"},
253 {CF_CLIENT | CF_ARCHIVE, "r_buffermegs_index32", "1", "index buffer size for one frame (32bit indices)"},
254 {CF_CLIENT | CF_ARCHIVE, "r_buffermegs_uniform", "0.25", "uniform buffer size for one frame"},
255};
256
257cvar_t r_q1bsp_lightmap_updates_enabled = {CF_CLIENT, "r_q1bsp_lightmap_updates_enabled", "1", "allow lightmaps to be updated on Q1BSP maps (don't turn this off except for debugging)"};
258cvar_t r_q1bsp_lightmap_updates_combine = {CF_CLIENT | CF_ARCHIVE, "r_q1bsp_lightmap_updates_combine", "2", "combine lightmap texture updates to make fewer glTexSubImage2D calls, modes: 0 = immediately upload lightmaps (may be thousands of small 3x3 updates), 1 = combine to one call, 2 = combine to one full texture update (glTexImage2D) which tells the driver it does not need to lock the resource (faster on most drivers)"};
259cvar_t r_q1bsp_lightmap_updates_hidden_surfaces = {CF_CLIENT | CF_ARCHIVE, "r_q1bsp_lightmap_updates_hidden_surfaces", "0", "update lightmaps on surfaces that are not visible, so that updates only occur on frames where lightstyles changed value (animation or light switches), only makes sense with combine = 2"};
260
262
264
266
269
270int r_uniformbufferalignment = 32; // dynamically updated to match GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT
271
283//rtexture_t *r_texture_fogintensity;
285
286// TODO: hash lookups?
287typedef struct cubemapinfo_s
288{
289 char basename[64];
291}
293
296
298unsigned int r_numqueries;
299unsigned int r_maxqueries;
300
301typedef struct r_qwskincache_s
302{
305}
307
310
312extern const float r_screenvertex3f[12];
313const float r_screenvertex3f[12] =
314{
315 0, 0, 0,
316 1, 0, 0,
317 1, 1, 0,
318 0, 1, 0
319};
320
321void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b)
322{
323 int i;
324 for (i = 0;i < verts;i++)
325 {
326 out[0] = in[0] * r;
327 out[1] = in[1] * g;
328 out[2] = in[2] * b;
329 out[3] = in[3];
330 in += 4;
331 out += 4;
332 }
333}
334
335void R_FillColors(float *out, int verts, float r, float g, float b, float a)
336{
337 int i;
338 for (i = 0;i < verts;i++)
339 {
340 out[0] = r;
341 out[1] = g;
342 out[2] = b;
343 out[3] = a;
344 out += 4;
345 }
346}
347
348// FIXME: move this to client?
349void FOG_clear(void)
350{
351 if (gamemode == GAME_NEHAHRA)
352 {
355 Cvar_SetQuick(&gl_fogred, "0.3");
356 Cvar_SetQuick(&gl_foggreen, "0.3");
357 Cvar_SetQuick(&gl_fogblue, "0.3");
358 }
360 r_refdef.fog_red = 0;
362 r_refdef.fog_blue = 0;
365 r_refdef.fog_end = 16384;
366 r_refdef.fog_height = 1<<30;
369}
370
371static void R_BuildBlankTextures(void)
372{
373 unsigned char data[4];
374 data[2] = 128; // normal X
375 data[1] = 128; // normal Y
376 data[0] = 255; // normal Z
377 data[3] = 255; // height
379 data[0] = 255;
380 data[1] = 255;
381 data[2] = 255;
382 data[3] = 255;
384 data[0] = 128;
385 data[1] = 128;
386 data[2] = 128;
387 data[3] = 255;
389 data[0] = 0;
390 data[1] = 0;
391 data[2] = 0;
392 data[3] = 255;
394}
395
400
401static void R_BuildWhiteCube(void)
402{
403 unsigned char data[6*1*1*4];
404 memset(data, 255, sizeof(data));
406}
407
409{
410 int x, y, side;
411 vec3_t v;
412 vec_t s, t, intensity;
413#define NORMSIZE 64
414 unsigned char *data;
415 data = (unsigned char *)Mem_Alloc(tempmempool, 6*NORMSIZE*NORMSIZE*4);
416 for (side = 0;side < 6;side++)
417 {
418 for (y = 0;y < NORMSIZE;y++)
419 {
420 for (x = 0;x < NORMSIZE;x++)
421 {
422 s = (x + 0.5f) * (2.0f / NORMSIZE) - 1.0f;
423 t = (y + 0.5f) * (2.0f / NORMSIZE) - 1.0f;
424 switch(side)
425 {
426 default:
427 case 0:
428 v[0] = 1;
429 v[1] = -t;
430 v[2] = -s;
431 break;
432 case 1:
433 v[0] = -1;
434 v[1] = -t;
435 v[2] = s;
436 break;
437 case 2:
438 v[0] = s;
439 v[1] = 1;
440 v[2] = t;
441 break;
442 case 3:
443 v[0] = s;
444 v[1] = -1;
445 v[2] = -t;
446 break;
447 case 4:
448 v[0] = s;
449 v[1] = -t;
450 v[2] = 1;
451 break;
452 case 5:
453 v[0] = -s;
454 v[1] = -t;
455 v[2] = -1;
456 break;
457 }
458 intensity = 127.0f / sqrt(DotProduct(v, v));
459 data[((side*64+y)*64+x)*4+2] = (unsigned char)(128.0f + intensity * v[0]);
460 data[((side*64+y)*64+x)*4+1] = (unsigned char)(128.0f + intensity * v[1]);
461 data[((side*64+y)*64+x)*4+0] = (unsigned char)(128.0f + intensity * v[2]);
462 data[((side*64+y)*64+x)*4+3] = 255;
463 }
464 }
465 }
467 Mem_Free(data);
468}
469
470static void R_BuildFogTexture(void)
471{
472 int x, b;
473#define FOGWIDTH 256
474 unsigned char data1[FOGWIDTH][4];
475 //unsigned char data2[FOGWIDTH][4];
476 double d, r, alpha;
477
482
484 for (x = 0;x < FOGMASKTABLEWIDTH;x++)
485 {
486 d = (x * r - r_refdef.fogmasktable_start);
488 Con_DPrintf("%f ", d);
489 d = max(0, d);
492 else
493 alpha = exp(-r_refdef.fogmasktable_density * 0.004 * d);
495 Con_DPrintf(" : %f ", alpha);
498 Con_DPrintf(" = %f\n", alpha);
500 }
501
502 for (x = 0;x < FOGWIDTH;x++)
503 {
504 b = (int)(r_refdef.fogmasktable[x * (FOGMASKTABLEWIDTH - 1) / (FOGWIDTH - 1)] * 255);
505 data1[x][0] = b;
506 data1[x][1] = b;
507 data1[x][2] = b;
508 data1[x][3] = 255;
509 //data2[x][0] = 255 - b;
510 //data2[x][1] = 255 - b;
511 //data2[x][2] = 255 - b;
512 //data2[x][3] = 255;
513 }
515 {
516 R_UpdateTexture(r_texture_fogattenuation, &data1[0][0], 0, 0, 0, FOGWIDTH, 1, 1, 0);
517 //R_UpdateTexture(r_texture_fogattenuation, &data2[0][0], 0, 0, 0, FOGWIDTH, 1, 1, 0);
518 }
519 else
520 {
522 //r_texture_fogintensity = R_LoadTexture2D(r_main_texturepool, "fogintensity", FOGWIDTH, 1, &data2[0][0], TEXTYPE_BGRA, TEXF_FORCELINEAR | TEXF_CLAMP, NULL);
523 }
524}
525
526static void R_BuildFogHeightTexture(void)
527{
528 unsigned char *inpixels;
529 int size;
530 int x;
531 int y;
532 int j;
533 float c[4];
534 float f;
535 inpixels = NULL;
538 inpixels = loadimagepixelsbgra(r_refdef.fogheighttexturename, true, false, false, NULL);
539 if (!inpixels)
540 {
551 return;
552 }
556 r_refdef.fog_height_table2d = (unsigned char *)Mem_Alloc(r_main_mempool, size * size * 4);
557 memcpy(r_refdef.fog_height_table1d, inpixels, size * 4);
558 Mem_Free(inpixels);
559 // LadyHavoc: now the magic - what is that table2d for? it is a cooked
560 // average fog color table accounting for every fog layer between a point
561 // and the camera. (Note: attenuation is handled separately!)
562 for (y = 0;y < size;y++)
563 {
564 for (x = 0;x < size;x++)
565 {
566 Vector4Clear(c);
567 f = 0;
568 if (x < y)
569 {
570 for (j = x;j <= y;j++)
571 {
573 f++;
574 }
575 }
576 else
577 {
578 for (j = x;j >= y;j--)
579 {
581 f++;
582 }
583 }
584 f = 1.0f / f;
585 r_refdef.fog_height_table2d[(y*size+x)*4+0] = (unsigned char)(c[0] * f);
586 r_refdef.fog_height_table2d[(y*size+x)*4+1] = (unsigned char)(c[1] * f);
587 r_refdef.fog_height_table2d[(y*size+x)*4+2] = (unsigned char)(c[2] * f);
588 r_refdef.fog_height_table2d[(y*size+x)*4+3] = (unsigned char)(c[3] * f);
589 }
590 }
592}
593
594//=======================================================================================================================================================
595
596static const char *builtinshaderstrings[] =
597{
598#include "shader_glsl.h"
5990
600};
601
602//=======================================================================================================================================================
603
604typedef struct shaderpermutationinfo_s
605{
606 const char *pretext;
607 const char *name;
608}
610
611typedef struct shadermodeinfo_s
612{
613 const char *sourcebasename;
614 const char *extension;
616 const char *pretext;
617 const char *name;
618 char *filename;
621}
623
624// NOTE: MUST MATCH ORDER OF SHADERPERMUTATION_* DEFINES!
626{
627 {"#define USEDIFFUSE\n", " diffuse"},
628 {"#define USEVERTEXTEXTUREBLEND\n", " vertextextureblend"},
629 {"#define USEVIEWTINT\n", " viewtint"},
630 {"#define USECOLORMAPPING\n", " colormapping"},
631 {"#define USESATURATION\n", " saturation"},
632 {"#define USEFOGINSIDE\n", " foginside"},
633 {"#define USEFOGOUTSIDE\n", " fogoutside"},
634 {"#define USEFOGHEIGHTTEXTURE\n", " fogheighttexture"},
635 {"#define USEFOGALPHAHACK\n", " fogalphahack"},
636 {"#define USEGAMMARAMPS\n", " gammaramps"},
637 {"#define USECUBEFILTER\n", " cubefilter"},
638 {"#define USEGLOW\n", " glow"},
639 {"#define USEBLOOM\n", " bloom"},
640 {"#define USESPECULAR\n", " specular"},
641 {"#define USEPOSTPROCESSING\n", " postprocessing"},
642 {"#define USEREFLECTION\n", " reflection"},
643 {"#define USEOFFSETMAPPING\n", " offsetmapping"},
644 {"#define USEOFFSETMAPPING_RELIEFMAPPING\n", " reliefmapping"},
645 {"#define USESHADOWMAP2D\n", " shadowmap2d"},
646 {"#define USESHADOWMAPVSDCT\n", " shadowmapvsdct"}, // TODO make this a static parm
647 {"#define USESHADOWMAPORTHO\n", " shadowmaportho"},
648 {"#define USEDEFERREDLIGHTMAP\n", " deferredlightmap"},
649 {"#define USEALPHAKILL\n", " alphakill"},
650 {"#define USEREFLECTCUBE\n", " reflectcube"},
651 {"#define USENORMALMAPSCROLLBLEND\n", " normalmapscrollblend"},
652 {"#define USEBOUNCEGRID\n", " bouncegrid"},
653 {"#define USEBOUNCEGRIDDIRECTIONAL\n", " bouncegriddirectional"}, // TODO make this a static parm
654 {"#define USETRIPPY\n", " trippy"},
655 {"#define USEDEPTHRGB\n", " depthrgb"},
656 {"#define USEALPHAGENVERTEX\n", " alphagenvertex"},
657 {"#define USESKELETAL\n", " skeletal"},
658 {"#define USEOCCLUDE\n", " occlude"}
659};
660
661// NOTE: MUST MATCH ORDER OF SHADERMODE_* ENUMS!
663{
664 // SHADERLANGUAGE_GLSL
665 {
666 {"combined", "glsl", builtinshaderstrings, "#define MODE_GENERIC\n", " generic"},
667 {"combined", "glsl", builtinshaderstrings, "#define MODE_POSTPROCESS\n", " postprocess"},
668 {"combined", "glsl", builtinshaderstrings, "#define MODE_DEPTH_OR_SHADOW\n", " depth/shadow"},
669 {"combined", "glsl", builtinshaderstrings, "#define MODE_FLATCOLOR\n", " flatcolor"},
670 {"combined", "glsl", builtinshaderstrings, "#define MODE_VERTEXCOLOR\n", " vertexcolor"},
671 {"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTMAP\n", " lightmap"},
672 {"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_MODELSPACE\n", " lightdirectionmap_modelspace"},
673 {"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n", " lightdirectionmap_tangentspace"},
674 {"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP\n", " lightdirectionmap_forced_lightmap"},
675 {"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR\n", " lightdirectionmap_forced_vertexcolor"},
676 {"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTGRID\n", " lightgrid"},
677 {"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTDIRECTION\n", " lightdirection"},
678 {"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTSOURCE\n", " lightsource"},
679 {"combined", "glsl", builtinshaderstrings, "#define MODE_REFRACTION\n", " refraction"},
680 {"combined", "glsl", builtinshaderstrings, "#define MODE_WATER\n", " water"},
681 {"combined", "glsl", builtinshaderstrings, "#define MODE_DEFERREDGEOMETRY\n", " deferredgeometry"},
682 {"combined", "glsl", builtinshaderstrings, "#define MODE_DEFERREDLIGHTSOURCE\n", " deferredlightsource"},
683 },
684};
685
686struct r_glsl_permutation_s;
687typedef struct r_glsl_permutation_s
688{
690 struct r_glsl_permutation_s *hashnext;
691 unsigned int mode;
692 uint64_t permutation;
693
698 // texture units assigned to each detected uniform
825}
827
828#define SHADERPERMUTATION_HASHSIZE 256
829
830
831// non-degradable "lightweight" shader parameters to keep the permutations simpler
832// these can NOT degrade! only use for simple stuff
833enum
834{
841 SHADERSTATICPARM_VERTEXTEXTUREBLEND_USEBOTHALPHAS = 6, // use both alpha layers while blending materials, allows more advanced microblending
851#define SHADERSTATICPARMS_COUNT 15
852
855
856static unsigned int r_compileshader_staticparms[(SHADERSTATICPARMS_COUNT + 0x1F) >> 5] = {0};
857#define R_COMPILESHADER_STATICPARM_ENABLE(p) r_compileshader_staticparms[(p) >> 5] |= (1 << ((p) & 0x1F))
858
860extern int r_shadow_shadowmappcf;
862{
863 static int r_compileshader_staticparms_save[(SHADERSTATICPARMS_COUNT + 0x1F) >> 5];
864 memcpy(r_compileshader_staticparms_save, r_compileshader_staticparms, sizeof(r_compileshader_staticparms));
866
867 // detect all
875 {
884 }
885 if (r_fxaa.integer)
889
892 if (r_shadow_shadowmappcf > 1)
894 else if (r_shadow_shadowmappcf)
902
903 return memcmp(r_compileshader_staticparms, r_compileshader_staticparms_save, sizeof(r_compileshader_staticparms)) != 0;
904}
905
906#define R_COMPILESHADER_STATICPARM_EMIT(p, n) \
907 if(r_compileshader_staticparms[(p) >> 5] & (1 << ((p) & 0x1F))) \
908 shaderstaticparmstrings_list[shaderstaticparms_count++] = "#define " n "\n"; \
909 else \
910 shaderstaticparmstrings_list[shaderstaticparms_count++] = "\n"
911static void R_CompileShader_AddStaticParms(unsigned int mode, uint64_t permutation)
912{
914
915 // emit all
931}
932
939
940static r_glsl_permutation_t *R_GLSL_FindPermutation(unsigned int mode, uint64_t permutation)
941{
942 //unsigned int hashdepth = 0;
943 unsigned int hashindex = (permutation * 0x1021) & (SHADERPERMUTATION_HASHSIZE - 1);
945 for (p = r_glsl_permutationhash[mode][hashindex];p;p = p->hashnext)
946 {
947 if (p->mode == mode && p->permutation == permutation)
948 {
949 //if (hashdepth > 10)
950 // Con_Printf("R_GLSL_FindPermutation: Warning: %i:%i has hashdepth %i\n", mode, permutation, hashdepth);
951 return p;
952 }
953 //hashdepth++;
954 }
956 p->mode = mode;
957 p->permutation = permutation;
958 p->hashnext = r_glsl_permutationhash[mode][hashindex];
959 r_glsl_permutationhash[mode][hashindex] = p;
960 //if (hashdepth > 10)
961 // Con_Printf("R_GLSL_FindPermutation: Warning: %i:%i has hashdepth %i\n", mode, permutation, hashdepth);
962 return p;
963}
964
965static char *R_ShaderStrCat(const char **strings)
966{
967 char *string, *s;
968 const char **p = strings;
969 const char *t;
970 size_t len = 0;
971 for (p = strings;(t = *p);p++)
972 len += strlen(t);
973 len++;
974 s = string = (char *)Mem_Alloc(r_main_mempool, len);
975 len = 0;
976 for (p = strings;(t = *p);p++)
977 {
978 len = strlen(t);
979 memcpy(s, t, len);
980 s += len;
981 }
982 *s = 0;
983 return string;
984}
985
986static char *R_ShaderStrCat(const char **strings);
987static void R_InitShaderModeInfo(void)
988{
989 int i, language;
990 shadermodeinfo_t *modeinfo;
991 // we have a bunch of things to compute that weren't calculated at engine compile time - all filenames should have a crc of the builtin strings to prevent accidental overrides (any customization must be updated to match engine)
992 for (language = 0; language < SHADERLANGUAGE_COUNT; language++)
993 {
994 for (i = 0; i < SHADERMODE_COUNT; i++)
995 {
996 char filename[MAX_QPATH];
997 modeinfo = &shadermodeinfo[language][i];
999 modeinfo->builtincrc = CRC_Block((const unsigned char *)modeinfo->builtinstring, strlen(modeinfo->builtinstring));
1000 dpsnprintf(filename, sizeof(filename), "%s/%s_crc%i.%s", modeinfo->extension, modeinfo->sourcebasename, modeinfo->builtincrc, modeinfo->extension);
1001 modeinfo->filename = Mem_strdup(r_main_mempool, filename);
1002 }
1003 }
1004}
1005
1006static char *ShaderModeInfo_GetShaderText(shadermodeinfo_t *modeinfo, qbool printfromdisknotice, qbool builtinonly)
1007{
1008 char *shaderstring;
1009 // if the mode has no filename we have to return the builtin string
1010 if (builtinonly || !modeinfo->filename)
1011 return Mem_strdup(r_main_mempool, modeinfo->builtinstring);
1012 // note that FS_LoadFile appends a 0 byte to make it a valid string
1013 shaderstring = (char *)FS_LoadFile(modeinfo->filename, r_main_mempool, false, NULL);
1014 if (shaderstring)
1015 {
1016 if (printfromdisknotice)
1017 Con_DPrintf("Loading shaders from file %s...\n", modeinfo->filename);
1018 return shaderstring;
1019 }
1020 // fall back to builtinstring
1021 return Mem_strdup(r_main_mempool, modeinfo->builtinstring);
1022}
1023
1024static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode, uint64_t permutation)
1025{
1026 unsigned i;
1027 int ubibind;
1028 int sampler;
1030 char *sourcestring;
1031 char permutationname[256];
1032 int vertstrings_count = 0;
1033 int geomstrings_count = 0;
1034 int fragstrings_count = 0;
1035 const char *vertstrings_list[32+5+SHADERSTATICPARMS_COUNT+1];
1036 const char *geomstrings_list[32+5+SHADERSTATICPARMS_COUNT+1];
1037 const char *fragstrings_list[32+5+SHADERSTATICPARMS_COUNT+1];
1038
1039 if (p->compiled)
1040 return;
1041 p->compiled = true;
1042 p->program = 0;
1043
1044 permutationname[0] = 0;
1045 sourcestring = ShaderModeInfo_GetShaderText(modeinfo, true, false);
1046
1047 dp_strlcat(permutationname, modeinfo->filename, sizeof(permutationname));
1048
1049 // we need 140 for r_glsl_skeletal (GL_ARB_uniform_buffer_object)
1050 if(vid.support.glshaderversion >= 140)
1051 {
1052 vertstrings_list[vertstrings_count++] = "#version 140\n";
1053 geomstrings_list[geomstrings_count++] = "#version 140\n";
1054 fragstrings_list[fragstrings_count++] = "#version 140\n";
1055 vertstrings_list[vertstrings_count++] = "#define GLSL140\n";
1056 geomstrings_list[geomstrings_count++] = "#define GLSL140\n";
1057 fragstrings_list[fragstrings_count++] = "#define GLSL140\n";
1058 }
1059 // if we can do #version 130, we should (this improves quality of offset/reliefmapping thanks to textureGrad)
1060 else if(vid.support.glshaderversion >= 130)
1061 {
1062 vertstrings_list[vertstrings_count++] = "#version 130\n";
1063 geomstrings_list[geomstrings_count++] = "#version 130\n";
1064 fragstrings_list[fragstrings_count++] = "#version 130\n";
1065 vertstrings_list[vertstrings_count++] = "#define GLSL130\n";
1066 geomstrings_list[geomstrings_count++] = "#define GLSL130\n";
1067 fragstrings_list[fragstrings_count++] = "#define GLSL130\n";
1068 }
1069 // if we can do #version 120, we should (this adds the invariant keyword)
1070 else if(vid.support.glshaderversion >= 120)
1071 {
1072 vertstrings_list[vertstrings_count++] = "#version 120\n";
1073 geomstrings_list[geomstrings_count++] = "#version 120\n";
1074 fragstrings_list[fragstrings_count++] = "#version 120\n";
1075 vertstrings_list[vertstrings_count++] = "#define GLSL120\n";
1076 geomstrings_list[geomstrings_count++] = "#define GLSL120\n";
1077 fragstrings_list[fragstrings_count++] = "#define GLSL120\n";
1078 }
1079 // GLES also adds several things from GLSL120
1080 switch(vid.renderpath)
1081 {
1082 case RENDERPATH_GLES2:
1083 vertstrings_list[vertstrings_count++] = "#define GLES\n";
1084 geomstrings_list[geomstrings_count++] = "#define GLES\n";
1085 fragstrings_list[fragstrings_count++] = "#define GLES\n";
1086 break;
1087 default:
1088 break;
1089 }
1090
1091 // the first pretext is which type of shader to compile as
1092 // (later these will all be bound together as a program object)
1093 vertstrings_list[vertstrings_count++] = "#define VERTEX_SHADER\n";
1094 geomstrings_list[geomstrings_count++] = "#define GEOMETRY_SHADER\n";
1095 fragstrings_list[fragstrings_count++] = "#define FRAGMENT_SHADER\n";
1096
1097 // the second pretext is the mode (for example a light source)
1098 vertstrings_list[vertstrings_count++] = modeinfo->pretext;
1099 geomstrings_list[geomstrings_count++] = modeinfo->pretext;
1100 fragstrings_list[fragstrings_count++] = modeinfo->pretext;
1101 dp_strlcat(permutationname, modeinfo->name, sizeof(permutationname));
1102
1103 // now add all the permutation pretexts
1104 for (i = 0;i < SHADERPERMUTATION_COUNT;i++)
1105 {
1106 if (permutation & (1ll<<i))
1107 {
1108 vertstrings_list[vertstrings_count++] = shaderpermutationinfo[i].pretext;
1109 geomstrings_list[geomstrings_count++] = shaderpermutationinfo[i].pretext;
1110 fragstrings_list[fragstrings_count++] = shaderpermutationinfo[i].pretext;
1111 dp_strlcat(permutationname, shaderpermutationinfo[i].name, sizeof(permutationname));
1112 }
1113 else
1114 {
1115 // keep line numbers correct
1116 vertstrings_list[vertstrings_count++] = "\n";
1117 geomstrings_list[geomstrings_count++] = "\n";
1118 fragstrings_list[fragstrings_count++] = "\n";
1119 }
1120 }
1121
1122 // add static parms
1124 memcpy((char *)(vertstrings_list + vertstrings_count), shaderstaticparmstrings_list, sizeof(*vertstrings_list) * shaderstaticparms_count);
1125 vertstrings_count += shaderstaticparms_count;
1126 memcpy((char *)(geomstrings_list + geomstrings_count), shaderstaticparmstrings_list, sizeof(*vertstrings_list) * shaderstaticparms_count);
1127 geomstrings_count += shaderstaticparms_count;
1128 memcpy((char *)(fragstrings_list + fragstrings_count), shaderstaticparmstrings_list, sizeof(*vertstrings_list) * shaderstaticparms_count);
1129 fragstrings_count += shaderstaticparms_count;
1130
1131 // now append the shader text itself
1132 vertstrings_list[vertstrings_count++] = sourcestring;
1133 geomstrings_list[geomstrings_count++] = sourcestring;
1134 fragstrings_list[fragstrings_count++] = sourcestring;
1135
1136 // we don't currently use geometry shaders for anything, so just empty the list
1137 geomstrings_count = 0;
1138
1139 // compile the shader program
1140 if (vertstrings_count + geomstrings_count + fragstrings_count)
1141 p->program = GL_Backend_CompileProgram(vertstrings_count, vertstrings_list, geomstrings_count, geomstrings_list, fragstrings_count, fragstrings_list);
1142 if (p->program)
1143 {
1145 qglUseProgram(p->program);CHECKGLERROR
1146 // look up all the uniform variable names we care about, so we don't
1147 // have to look them up every time we set them
1148
1149#if 0
1150 // debugging aid
1151 {
1152 GLint activeuniformindex = 0;
1153 GLint numactiveuniforms = 0;
1154 char uniformname[128];
1155 GLsizei uniformnamelength = 0;
1156 GLint uniformsize = 0;
1157 GLenum uniformtype = 0;
1158 memset(uniformname, 0, sizeof(uniformname));
1159 qglGetProgramiv(p->program, GL_ACTIVE_UNIFORMS, &numactiveuniforms);
1160 Con_Printf("Shader has %i uniforms\n", numactiveuniforms);
1161 for (activeuniformindex = 0;activeuniformindex < numactiveuniforms;activeuniformindex++)
1162 {
1163 qglGetActiveUniform(p->program, activeuniformindex, sizeof(uniformname) - 1, &uniformnamelength, &uniformsize, &uniformtype, uniformname);
1164 Con_Printf("Uniform %i name \"%s\" size %i type %i\n", (int)activeuniformindex, uniformname, (int)uniformsize, (int)uniformtype);
1165 }
1166 }
1167#endif
1168
1169 p->loc_Texture_First = qglGetUniformLocation(p->program, "Texture_First");
1170 p->loc_Texture_Second = qglGetUniformLocation(p->program, "Texture_Second");
1171 p->loc_Texture_GammaRamps = qglGetUniformLocation(p->program, "Texture_GammaRamps");
1172 p->loc_Texture_Normal = qglGetUniformLocation(p->program, "Texture_Normal");
1173 p->loc_Texture_Color = qglGetUniformLocation(p->program, "Texture_Color");
1174 p->loc_Texture_Gloss = qglGetUniformLocation(p->program, "Texture_Gloss");
1175 p->loc_Texture_Glow = qglGetUniformLocation(p->program, "Texture_Glow");
1176 p->loc_Texture_SecondaryNormal = qglGetUniformLocation(p->program, "Texture_SecondaryNormal");
1177 p->loc_Texture_SecondaryColor = qglGetUniformLocation(p->program, "Texture_SecondaryColor");
1178 p->loc_Texture_SecondaryGloss = qglGetUniformLocation(p->program, "Texture_SecondaryGloss");
1179 p->loc_Texture_SecondaryGlow = qglGetUniformLocation(p->program, "Texture_SecondaryGlow");
1180 p->loc_Texture_Pants = qglGetUniformLocation(p->program, "Texture_Pants");
1181 p->loc_Texture_Shirt = qglGetUniformLocation(p->program, "Texture_Shirt");
1182 p->loc_Texture_FogHeightTexture = qglGetUniformLocation(p->program, "Texture_FogHeightTexture");
1183 p->loc_Texture_FogMask = qglGetUniformLocation(p->program, "Texture_FogMask");
1184 p->loc_Texture_LightGrid = qglGetUniformLocation(p->program, "Texture_LightGrid");
1185 p->loc_Texture_Lightmap = qglGetUniformLocation(p->program, "Texture_Lightmap");
1186 p->loc_Texture_Deluxemap = qglGetUniformLocation(p->program, "Texture_Deluxemap");
1187 p->loc_Texture_Attenuation = qglGetUniformLocation(p->program, "Texture_Attenuation");
1188 p->loc_Texture_Cube = qglGetUniformLocation(p->program, "Texture_Cube");
1189 p->loc_Texture_Refraction = qglGetUniformLocation(p->program, "Texture_Refraction");
1190 p->loc_Texture_Reflection = qglGetUniformLocation(p->program, "Texture_Reflection");
1191 p->loc_Texture_ShadowMap2D = qglGetUniformLocation(p->program, "Texture_ShadowMap2D");
1192 p->loc_Texture_CubeProjection = qglGetUniformLocation(p->program, "Texture_CubeProjection");
1193 p->loc_Texture_ScreenNormalMap = qglGetUniformLocation(p->program, "Texture_ScreenNormalMap");
1194 p->loc_Texture_ScreenDiffuse = qglGetUniformLocation(p->program, "Texture_ScreenDiffuse");
1195 p->loc_Texture_ScreenSpecular = qglGetUniformLocation(p->program, "Texture_ScreenSpecular");
1196 p->loc_Texture_ReflectMask = qglGetUniformLocation(p->program, "Texture_ReflectMask");
1197 p->loc_Texture_ReflectCube = qglGetUniformLocation(p->program, "Texture_ReflectCube");
1198 p->loc_Texture_BounceGrid = qglGetUniformLocation(p->program, "Texture_BounceGrid");
1199 p->loc_Alpha = qglGetUniformLocation(p->program, "Alpha");
1200 p->loc_BloomBlur_Parameters = qglGetUniformLocation(p->program, "BloomBlur_Parameters");
1201 p->loc_ClientTime = qglGetUniformLocation(p->program, "ClientTime");
1202 p->loc_Color_Ambient = qglGetUniformLocation(p->program, "Color_Ambient");
1203 p->loc_Color_Diffuse = qglGetUniformLocation(p->program, "Color_Diffuse");
1204 p->loc_Color_Specular = qglGetUniformLocation(p->program, "Color_Specular");
1205 p->loc_Color_Glow = qglGetUniformLocation(p->program, "Color_Glow");
1206 p->loc_Color_Pants = qglGetUniformLocation(p->program, "Color_Pants");
1207 p->loc_Color_Shirt = qglGetUniformLocation(p->program, "Color_Shirt");
1208 p->loc_DeferredColor_Ambient = qglGetUniformLocation(p->program, "DeferredColor_Ambient");
1209 p->loc_DeferredColor_Diffuse = qglGetUniformLocation(p->program, "DeferredColor_Diffuse");
1210 p->loc_DeferredColor_Specular = qglGetUniformLocation(p->program, "DeferredColor_Specular");
1211 p->loc_DeferredMod_Diffuse = qglGetUniformLocation(p->program, "DeferredMod_Diffuse");
1212 p->loc_DeferredMod_Specular = qglGetUniformLocation(p->program, "DeferredMod_Specular");
1213 p->loc_DistortScaleRefractReflect = qglGetUniformLocation(p->program, "DistortScaleRefractReflect");
1214 p->loc_EyePosition = qglGetUniformLocation(p->program, "EyePosition");
1215 p->loc_FogColor = qglGetUniformLocation(p->program, "FogColor");
1216 p->loc_FogHeightFade = qglGetUniformLocation(p->program, "FogHeightFade");
1217 p->loc_FogPlane = qglGetUniformLocation(p->program, "FogPlane");
1218 p->loc_FogPlaneViewDist = qglGetUniformLocation(p->program, "FogPlaneViewDist");
1219 p->loc_FogRangeRecip = qglGetUniformLocation(p->program, "FogRangeRecip");
1220 p->loc_LightColor = qglGetUniformLocation(p->program, "LightColor");
1221 p->loc_LightGridMatrix = qglGetUniformLocation(p->program, "LightGridMatrix");
1222 p->loc_LightGridNormalMatrix = qglGetUniformLocation(p->program, "LightGridNormalMatrix");
1223 p->loc_LightDir = qglGetUniformLocation(p->program, "LightDir");
1224 p->loc_LightPosition = qglGetUniformLocation(p->program, "LightPosition");
1225 p->loc_OffsetMapping_ScaleSteps = qglGetUniformLocation(p->program, "OffsetMapping_ScaleSteps");
1226 p->loc_OffsetMapping_LodDistance = qglGetUniformLocation(p->program, "OffsetMapping_LodDistance");
1227 p->loc_OffsetMapping_Bias = qglGetUniformLocation(p->program, "OffsetMapping_Bias");
1228 p->loc_PixelSize = qglGetUniformLocation(p->program, "PixelSize");
1229 p->loc_ReflectColor = qglGetUniformLocation(p->program, "ReflectColor");
1230 p->loc_ReflectFactor = qglGetUniformLocation(p->program, "ReflectFactor");
1231 p->loc_ReflectOffset = qglGetUniformLocation(p->program, "ReflectOffset");
1232 p->loc_RefractColor = qglGetUniformLocation(p->program, "RefractColor");
1233 p->loc_Saturation = qglGetUniformLocation(p->program, "Saturation");
1234 p->loc_ScreenCenterRefractReflect = qglGetUniformLocation(p->program, "ScreenCenterRefractReflect");
1235 p->loc_ScreenScaleRefractReflect = qglGetUniformLocation(p->program, "ScreenScaleRefractReflect");
1236 p->loc_ScreenToDepth = qglGetUniformLocation(p->program, "ScreenToDepth");
1237 p->loc_ShadowMap_Parameters = qglGetUniformLocation(p->program, "ShadowMap_Parameters");
1238 p->loc_ShadowMap_TextureScale = qglGetUniformLocation(p->program, "ShadowMap_TextureScale");
1239 p->loc_SpecularPower = qglGetUniformLocation(p->program, "SpecularPower");
1240 p->loc_UserVec1 = qglGetUniformLocation(p->program, "UserVec1");
1241 p->loc_UserVec2 = qglGetUniformLocation(p->program, "UserVec2");
1242 p->loc_UserVec3 = qglGetUniformLocation(p->program, "UserVec3");
1243 p->loc_UserVec4 = qglGetUniformLocation(p->program, "UserVec4");
1244 p->loc_ColorFringe = qglGetUniformLocation(p->program, "ColorFringe");
1245 p->loc_ViewTintColor = qglGetUniformLocation(p->program, "ViewTintColor");
1246 p->loc_ViewToLight = qglGetUniformLocation(p->program, "ViewToLight");
1247 p->loc_ModelToLight = qglGetUniformLocation(p->program, "ModelToLight");
1248 p->loc_TexMatrix = qglGetUniformLocation(p->program, "TexMatrix");
1249 p->loc_BackgroundTexMatrix = qglGetUniformLocation(p->program, "BackgroundTexMatrix");
1250 p->loc_ModelViewMatrix = qglGetUniformLocation(p->program, "ModelViewMatrix");
1251 p->loc_ModelViewProjectionMatrix = qglGetUniformLocation(p->program, "ModelViewProjectionMatrix");
1252 p->loc_PixelToScreenTexCoord = qglGetUniformLocation(p->program, "PixelToScreenTexCoord");
1253 p->loc_ModelToReflectCube = qglGetUniformLocation(p->program, "ModelToReflectCube");
1254 p->loc_ShadowMapMatrix = qglGetUniformLocation(p->program, "ShadowMapMatrix");
1255 p->loc_BloomColorSubtract = qglGetUniformLocation(p->program, "BloomColorSubtract");
1256 p->loc_NormalmapScrollBlend = qglGetUniformLocation(p->program, "NormalmapScrollBlend");
1257 p->loc_BounceGridMatrix = qglGetUniformLocation(p->program, "BounceGridMatrix");
1258 p->loc_BounceGridIntensity = qglGetUniformLocation(p->program, "BounceGridIntensity");
1259 // initialize the samplers to refer to the texture units we use
1260 p->tex_Texture_First = -1;
1261 p->tex_Texture_Second = -1;
1262 p->tex_Texture_GammaRamps = -1;
1263 p->tex_Texture_Normal = -1;
1264 p->tex_Texture_Color = -1;
1265 p->tex_Texture_Gloss = -1;
1266 p->tex_Texture_Glow = -1;
1271 p->tex_Texture_Pants = -1;
1272 p->tex_Texture_Shirt = -1;
1274 p->tex_Texture_FogMask = -1;
1275 p->tex_Texture_LightGrid = -1;
1276 p->tex_Texture_Lightmap = -1;
1277 p->tex_Texture_Deluxemap = -1;
1279 p->tex_Texture_Cube = -1;
1280 p->tex_Texture_Refraction = -1;
1281 p->tex_Texture_Reflection = -1;
1289 p->tex_Texture_BounceGrid = -1;
1290 // bind the texture samplers in use
1291 sampler = 0;
1292 if (p->loc_Texture_First >= 0) {p->tex_Texture_First = sampler;qglUniform1i(p->loc_Texture_First , sampler);sampler++;}
1293 if (p->loc_Texture_Second >= 0) {p->tex_Texture_Second = sampler;qglUniform1i(p->loc_Texture_Second , sampler);sampler++;}
1294 if (p->loc_Texture_GammaRamps >= 0) {p->tex_Texture_GammaRamps = sampler;qglUniform1i(p->loc_Texture_GammaRamps , sampler);sampler++;}
1295 if (p->loc_Texture_Normal >= 0) {p->tex_Texture_Normal = sampler;qglUniform1i(p->loc_Texture_Normal , sampler);sampler++;}
1296 if (p->loc_Texture_Color >= 0) {p->tex_Texture_Color = sampler;qglUniform1i(p->loc_Texture_Color , sampler);sampler++;}
1297 if (p->loc_Texture_Gloss >= 0) {p->tex_Texture_Gloss = sampler;qglUniform1i(p->loc_Texture_Gloss , sampler);sampler++;}
1298 if (p->loc_Texture_Glow >= 0) {p->tex_Texture_Glow = sampler;qglUniform1i(p->loc_Texture_Glow , sampler);sampler++;}
1299 if (p->loc_Texture_SecondaryNormal >= 0) {p->tex_Texture_SecondaryNormal = sampler;qglUniform1i(p->loc_Texture_SecondaryNormal , sampler);sampler++;}
1300 if (p->loc_Texture_SecondaryColor >= 0) {p->tex_Texture_SecondaryColor = sampler;qglUniform1i(p->loc_Texture_SecondaryColor , sampler);sampler++;}
1301 if (p->loc_Texture_SecondaryGloss >= 0) {p->tex_Texture_SecondaryGloss = sampler;qglUniform1i(p->loc_Texture_SecondaryGloss , sampler);sampler++;}
1302 if (p->loc_Texture_SecondaryGlow >= 0) {p->tex_Texture_SecondaryGlow = sampler;qglUniform1i(p->loc_Texture_SecondaryGlow , sampler);sampler++;}
1303 if (p->loc_Texture_Pants >= 0) {p->tex_Texture_Pants = sampler;qglUniform1i(p->loc_Texture_Pants , sampler);sampler++;}
1304 if (p->loc_Texture_Shirt >= 0) {p->tex_Texture_Shirt = sampler;qglUniform1i(p->loc_Texture_Shirt , sampler);sampler++;}
1305 if (p->loc_Texture_FogHeightTexture>= 0) {p->tex_Texture_FogHeightTexture = sampler;qglUniform1i(p->loc_Texture_FogHeightTexture, sampler);sampler++;}
1306 if (p->loc_Texture_FogMask >= 0) {p->tex_Texture_FogMask = sampler;qglUniform1i(p->loc_Texture_FogMask , sampler);sampler++;}
1307 if (p->loc_Texture_LightGrid >= 0) {p->tex_Texture_LightGrid = sampler;qglUniform1i(p->loc_Texture_LightGrid , sampler);sampler++;}
1308 if (p->loc_Texture_Lightmap >= 0) {p->tex_Texture_Lightmap = sampler;qglUniform1i(p->loc_Texture_Lightmap , sampler);sampler++;}
1309 if (p->loc_Texture_Deluxemap >= 0) {p->tex_Texture_Deluxemap = sampler;qglUniform1i(p->loc_Texture_Deluxemap , sampler);sampler++;}
1310 if (p->loc_Texture_Attenuation >= 0) {p->tex_Texture_Attenuation = sampler;qglUniform1i(p->loc_Texture_Attenuation , sampler);sampler++;}
1311 if (p->loc_Texture_Cube >= 0) {p->tex_Texture_Cube = sampler;qglUniform1i(p->loc_Texture_Cube , sampler);sampler++;}
1312 if (p->loc_Texture_Refraction >= 0) {p->tex_Texture_Refraction = sampler;qglUniform1i(p->loc_Texture_Refraction , sampler);sampler++;}
1313 if (p->loc_Texture_Reflection >= 0) {p->tex_Texture_Reflection = sampler;qglUniform1i(p->loc_Texture_Reflection , sampler);sampler++;}
1314 if (p->loc_Texture_ShadowMap2D >= 0) {p->tex_Texture_ShadowMap2D = sampler;qglUniform1i(p->loc_Texture_ShadowMap2D , sampler);sampler++;}
1315 if (p->loc_Texture_CubeProjection >= 0) {p->tex_Texture_CubeProjection = sampler;qglUniform1i(p->loc_Texture_CubeProjection , sampler);sampler++;}
1316 if (p->loc_Texture_ScreenNormalMap >= 0) {p->tex_Texture_ScreenNormalMap = sampler;qglUniform1i(p->loc_Texture_ScreenNormalMap , sampler);sampler++;}
1317 if (p->loc_Texture_ScreenDiffuse >= 0) {p->tex_Texture_ScreenDiffuse = sampler;qglUniform1i(p->loc_Texture_ScreenDiffuse , sampler);sampler++;}
1318 if (p->loc_Texture_ScreenSpecular >= 0) {p->tex_Texture_ScreenSpecular = sampler;qglUniform1i(p->loc_Texture_ScreenSpecular , sampler);sampler++;}
1319 if (p->loc_Texture_ReflectMask >= 0) {p->tex_Texture_ReflectMask = sampler;qglUniform1i(p->loc_Texture_ReflectMask , sampler);sampler++;}
1320 if (p->loc_Texture_ReflectCube >= 0) {p->tex_Texture_ReflectCube = sampler;qglUniform1i(p->loc_Texture_ReflectCube , sampler);sampler++;}
1321 if (p->loc_Texture_BounceGrid >= 0) {p->tex_Texture_BounceGrid = sampler;qglUniform1i(p->loc_Texture_BounceGrid , sampler);sampler++;}
1322 // get the uniform block indices so we can bind them
1324#ifndef USE_GLES2 /* FIXME: GLES3 only */
1325 p->ubiloc_Skeletal_Transform12_UniformBlock = qglGetUniformBlockIndex(p->program, "Skeletal_Transform12_UniformBlock");
1326#endif
1327 // clear the uniform block bindings
1329 // bind the uniform blocks in use
1330 ubibind = 0;
1331#ifndef USE_GLES2 /* FIXME: GLES3 only */
1332 if (p->ubiloc_Skeletal_Transform12_UniformBlock >= 0) {p->ubibind_Skeletal_Transform12_UniformBlock = ubibind;qglUniformBlockBinding(p->program, p->ubiloc_Skeletal_Transform12_UniformBlock, ubibind);ubibind++;}
1333#endif
1334 // we're done compiling and setting up the shader, at least until it is used
1336 Con_DPrintf("^5GLSL shader %s compiled (%i textures).\n", permutationname, sampler);
1337 }
1338 else
1339 Con_Printf("^1GLSL shader %s failed! some features may not work properly.\n", permutationname);
1340
1341 // free the strings
1342 if (sourcestring)
1343 Mem_Free(sourcestring);
1344}
1345
1346static void R_SetupShader_SetPermutationGLSL(unsigned int mode, uint64_t permutation)
1347{
1348 r_glsl_permutation_t *perm = R_GLSL_FindPermutation(mode, permutation);
1349 if (r_glsl_permutation != perm)
1350 {
1351 r_glsl_permutation = perm;
1353 {
1355 {
1356 Con_DPrintf("Compiling shader mode %u permutation %" PRIx64 "\n", mode, permutation);
1357 R_GLSL_CompilePermutation(perm, mode, permutation);
1358 }
1360 {
1361 // remove features until we find a valid permutation
1362 unsigned i;
1363 for (i = 0;i < SHADERPERMUTATION_COUNT;i++)
1364 {
1365 // reduce i more quickly whenever it would not remove any bits
1366 uint64_t j = 1ll<<(SHADERPERMUTATION_COUNT-1-i);
1367 if (!(permutation & j))
1368 continue;
1369 permutation -= j;
1372 R_GLSL_CompilePermutation(perm, mode, permutation);
1374 break;
1375 }
1377 {
1378 //Con_Printf("Could not find a working OpenGL 2.0 shader for permutation %s %s\n", shadermodeinfo[mode].filename, shadermodeinfo[mode].pretext);
1380 qglUseProgram(0);CHECKGLERROR
1381 return; // no bit left to clear, entire mode is broken
1382 }
1383 }
1384 }
1387 }
1392}
1393
1395{
1396 unsigned int i, limit;
1397 switch(vid.renderpath)
1398 {
1399 case RENDERPATH_GL32:
1400 case RENDERPATH_GLES2:
1401 {
1405 for (i = 0;i < limit;i++)
1406 {
1408 {
1411 }
1412 }
1414 }
1415 break;
1416 }
1417}
1418
1420{
1421 unsigned i;
1422 int language, mode, dupe;
1423 char *text;
1424 shadermodeinfo_t *modeinfo;
1425 qfile_t *file;
1426
1427 for (language = 0;language < SHADERLANGUAGE_COUNT;language++)
1428 {
1429 modeinfo = shadermodeinfo[language];
1430 for (mode = 0;mode < SHADERMODE_COUNT;mode++)
1431 {
1432 // don't dump the same file multiple times (most or all shaders come from the same file)
1433 for (dupe = mode - 1;dupe >= 0;dupe--)
1434 if (!strcmp(modeinfo[mode].filename, modeinfo[dupe].filename))
1435 break;
1436 if (dupe >= 0)
1437 continue;
1438 text = modeinfo[mode].builtinstring;
1439 if (!text)
1440 continue;
1441 file = FS_OpenRealFile(modeinfo[mode].filename, "w", false);
1442 if (file)
1443 {
1444 FS_Print(file, "/* The engine may define the following macros:\n");
1445 FS_Print(file, "#define VERTEX_SHADER\n#define GEOMETRY_SHADER\n#define FRAGMENT_SHADER\n");
1446 for (i = 0;i < SHADERMODE_COUNT;i++)
1447 FS_Print(file, modeinfo[i].pretext);
1448 for (i = 0;i < SHADERPERMUTATION_COUNT;i++)
1449 FS_Print(file, shaderpermutationinfo[i].pretext);
1450 FS_Print(file, "*/\n");
1451 FS_Print(file, text);
1452 FS_Close(file);
1453 Con_Printf("%s written\n", modeinfo[mode].filename);
1454 }
1455 else
1456 Con_Printf(CON_ERROR "failed to write to %s\n", modeinfo[mode].filename);
1457 }
1458 }
1459}
1460
1461void R_SetupShader_Generic(rtexture_t *t, qbool usegamma, qbool notrippy, qbool suppresstexalpha)
1462{
1463 uint64_t permutation = 0;
1464 if (r_trippy.integer && !notrippy)
1465 permutation |= SHADERPERMUTATION_TRIPPY;
1466 permutation |= SHADERPERMUTATION_VIEWTINT;
1467 if (t)
1468 permutation |= SHADERPERMUTATION_DIFFUSE;
1470 permutation |= SHADERPERMUTATION_GAMMARAMPS;
1471 if (suppresstexalpha)
1472 permutation |= SHADERPERMUTATION_REFLECTCUBE;
1474 GL_AlphaToCoverage(false);
1475 switch (vid.renderpath)
1476 {
1477 case RENDERPATH_GL32:
1478 case RENDERPATH_GLES2:
1484 break;
1485 }
1486}
1487
1489{
1490 R_SetupShader_Generic(NULL, usegamma, notrippy, false);
1491}
1492
1493void R_SetupShader_DepthOrShadow(qbool notrippy, qbool depthrgb, qbool skeletal)
1494{
1495 uint64_t permutation = 0;
1496 if (r_trippy.integer && !notrippy)
1497 permutation |= SHADERPERMUTATION_TRIPPY;
1498 if (depthrgb)
1499 permutation |= SHADERPERMUTATION_DEPTHRGB;
1500 if (skeletal)
1501 permutation |= SHADERPERMUTATION_SKELETAL;
1502
1504 GL_AlphaToCoverage(false);
1505 switch (vid.renderpath)
1506 {
1507 case RENDERPATH_GL32:
1508 case RENDERPATH_GLES2:
1510#ifndef USE_GLES2 /* FIXME: GLES3 only */
1512#endif
1513 break;
1514 }
1515}
1516
1517#define BLENDFUNC_ALLOWS_COLORMOD 1
1518#define BLENDFUNC_ALLOWS_FOG 2
1519#define BLENDFUNC_ALLOWS_FOG_HACK0 4
1520#define BLENDFUNC_ALLOWS_FOG_HACKALPHA 8
1521#define BLENDFUNC_ALLOWS_ANYFOG (BLENDFUNC_ALLOWS_FOG | BLENDFUNC_ALLOWS_FOG_HACK0 | BLENDFUNC_ALLOWS_FOG_HACKALPHA)
1522static int R_BlendFuncFlags(int src, int dst)
1523{
1524 int r = 0;
1525
1526 // a blendfunc allows colormod if:
1527 // a) it can never keep the destination pixel invariant, or
1528 // b) it can keep the destination pixel invariant, and still can do so if colormodded
1529 // this is to prevent unintended side effects from colormod
1530
1531 // a blendfunc allows fog if:
1532 // blend(fog(src), fog(dst)) == fog(blend(src, dst))
1533 // this is to prevent unintended side effects from fog
1534
1535 // these checks are the output of fogeval.pl
1536
1540 if(src == GL_DST_COLOR && dst == GL_ONE_MINUS_SRC_ALPHA) r &= ~BLENDFUNC_ALLOWS_COLORMOD;
1542 if(src == GL_DST_COLOR && dst == GL_SRC_ALPHA) r &= ~BLENDFUNC_ALLOWS_COLORMOD;
1543 if(src == GL_DST_COLOR && dst == GL_SRC_COLOR) r &= ~BLENDFUNC_ALLOWS_COLORMOD;
1544 if(src == GL_DST_COLOR && dst == GL_ZERO) r &= ~BLENDFUNC_ALLOWS_COLORMOD;
1545 if(src == GL_ONE && dst == GL_ONE) r |= BLENDFUNC_ALLOWS_FOG_HACK0;
1547 if(src == GL_ONE && dst == GL_ZERO) r |= BLENDFUNC_ALLOWS_FOG;
1553 if(src == GL_ONE_MINUS_SRC_ALPHA && dst == GL_SRC_COLOR) r &= ~BLENDFUNC_ALLOWS_COLORMOD;
1554 if(src == GL_ONE_MINUS_SRC_COLOR && dst == GL_SRC_COLOR) r &= ~BLENDFUNC_ALLOWS_COLORMOD;
1557 if(src == GL_ZERO && dst == GL_ONE) r |= BLENDFUNC_ALLOWS_FOG;
1558 if(src == GL_ZERO && dst == GL_SRC_COLOR) r &= ~BLENDFUNC_ALLOWS_COLORMOD;
1559
1560 return r;
1561}
1562
1563void R_SetupShader_Surface(const float rtlightambient[3], const float rtlightdiffuse[3], const float rtlightspecular[3], rsurfacepass_t rsurfacepass, int texturenumsurfaces, const msurface_t **texturesurfacelist, void *surfacewaterplane, qbool notrippy, qbool ui)
1564{
1565 // select a permutation of the lighting shader appropriate to this
1566 // combination of texture, entity, light source, and fogging, only use the
1567 // minimum features necessary to avoid wasting rendering time in the
1568 // fragment shader on features that are not being used
1569 uint64_t permutation = 0;
1570 unsigned int mode = 0;
1571 int blendfuncflags;
1573 float m16f[16];
1574 matrix4x4_t tempmatrix;
1575 r_waterstate_waterplane_t *waterplane = (r_waterstate_waterplane_t *)surfacewaterplane;
1576 if (r_trippy.integer && !notrippy)
1577 permutation |= SHADERPERMUTATION_TRIPPY;
1579 permutation |= SHADERPERMUTATION_ALPHAKILL;
1581 permutation |= SHADERPERMUTATION_OCCLUDE;
1582 if (t->r_water_waterscroll[0] && t->r_water_waterscroll[1])
1583 permutation |= SHADERPERMUTATION_NORMALMAPSCROLLBLEND; // todo: make generic
1584 if (rsurfacepass == RSURFPASS_BACKGROUND)
1585 {
1586 // distorted background
1588 {
1591 permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
1593 {
1594 // this is the right thing to do for wateralpha
1596 blendfuncflags = R_BlendFuncFlags(GL_ONE, GL_ZERO);
1597 }
1598 else
1599 {
1600 // this is the right thing to do for entity alpha
1603 }
1604 }
1606 {
1609 permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
1612 }
1613 else
1614 {
1619 }
1621 GL_AlphaToCoverage(false);
1622 }
1623 else if (rsurfacepass == RSURFPASS_DEFERREDGEOMETRY)
1624 {
1626 {
1627 switch(t->offsetmapping)
1628 {
1629 case OFFSETMAPPING_LINEAR: permutation |= SHADERPERMUTATION_OFFSETMAPPING;break;
1632 case OFFSETMAPPING_OFF: break;
1633 }
1634 }
1637 // normalmap (deferred prepass), may use alpha test on diffuse
1640 blendfuncflags = R_BlendFuncFlags(GL_ONE, GL_ZERO);
1642 GL_AlphaToCoverage(false);
1643 }
1644 else if (rsurfacepass == RSURFPASS_RTLIGHT)
1645 {
1647 {
1648 switch(t->offsetmapping)
1649 {
1650 case OFFSETMAPPING_LINEAR: permutation |= SHADERPERMUTATION_OFFSETMAPPING;break;
1653 case OFFSETMAPPING_OFF: break;
1654 }
1655 }
1659 permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
1660 // light source
1663 permutation |= SHADERPERMUTATION_CUBEFILTER;
1664 if (VectorLength2(rtlightdiffuse) > 0)
1665 permutation |= SHADERPERMUTATION_DIFFUSE;
1666 if (VectorLength2(rtlightspecular) > 0)
1668 if (r_refdef.fogenabled)
1670 if (t->colormapping)
1671 permutation |= SHADERPERMUTATION_COLORMAPPING;
1673 {
1674 permutation |= SHADERPERMUTATION_SHADOWMAP2D;
1676 permutation |= SHADERPERMUTATION_SHADOWMAPVSDCT;
1677
1679 permutation |= SHADERPERMUTATION_DEPTHRGB;
1680 }
1681 if (t->reflectmasktexture)
1682 permutation |= SHADERPERMUTATION_REFLECTCUBE;
1684 blendfuncflags = R_BlendFuncFlags(GL_SRC_ALPHA, GL_ONE);
1686 GL_AlphaToCoverage(false);
1687 }
1689 {
1691 {
1692 switch(t->offsetmapping)
1693 {
1694 case OFFSETMAPPING_LINEAR: permutation |= SHADERPERMUTATION_OFFSETMAPPING;break;
1697 case OFFSETMAPPING_OFF: break;
1698 }
1699 }
1703 permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
1704 // directional model lighting
1707 permutation |= SHADERPERMUTATION_GLOW;
1708 permutation |= SHADERPERMUTATION_DIFFUSE;
1710 permutation |= SHADERPERMUTATION_SPECULAR;
1711 if (r_refdef.fogenabled)
1713 if (t->colormapping)
1714 permutation |= SHADERPERMUTATION_COLORMAPPING;
1716 {
1717 permutation |= SHADERPERMUTATION_SHADOWMAPORTHO;
1718 permutation |= SHADERPERMUTATION_SHADOWMAP2D;
1719
1721 permutation |= SHADERPERMUTATION_DEPTHRGB;
1722 }
1724 permutation |= SHADERPERMUTATION_REFLECTION;
1727 if (t->reflectmasktexture)
1728 permutation |= SHADERPERMUTATION_REFLECTCUBE;
1730 {
1731 permutation |= SHADERPERMUTATION_BOUNCEGRID;
1734 }
1736 blendfuncflags = R_BlendFuncFlags(t->currentblendfunc[0], t->currentblendfunc[1]);
1737 // when using alphatocoverage, we don't need alphakill
1739 {
1741 {
1743 permutation &= ~SHADERPERMUTATION_ALPHAKILL;
1744 }
1745 else
1746 GL_AlphaToCoverage(false);
1747 }
1748 }
1750 {
1752 {
1753 switch(t->offsetmapping)
1754 {
1755 case OFFSETMAPPING_LINEAR: permutation |= SHADERPERMUTATION_OFFSETMAPPING;break;
1758 case OFFSETMAPPING_OFF: break;
1759 }
1760 }
1764 permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
1765 // directional model lighting
1768 permutation |= SHADERPERMUTATION_GLOW;
1770 permutation |= SHADERPERMUTATION_DIFFUSE;
1772 permutation |= SHADERPERMUTATION_SPECULAR;
1773 if (r_refdef.fogenabled)
1775 if (t->colormapping)
1776 permutation |= SHADERPERMUTATION_COLORMAPPING;
1778 {
1779 permutation |= SHADERPERMUTATION_SHADOWMAPORTHO;
1780 permutation |= SHADERPERMUTATION_SHADOWMAP2D;
1781
1783 permutation |= SHADERPERMUTATION_DEPTHRGB;
1784 }
1786 permutation |= SHADERPERMUTATION_REFLECTION;
1789 if (t->reflectmasktexture)
1790 permutation |= SHADERPERMUTATION_REFLECTCUBE;
1792 {
1793 permutation |= SHADERPERMUTATION_BOUNCEGRID;
1796 }
1798 blendfuncflags = R_BlendFuncFlags(t->currentblendfunc[0], t->currentblendfunc[1]);
1799 // when using alphatocoverage, we don't need alphakill
1801 {
1803 {
1805 permutation &= ~SHADERPERMUTATION_ALPHAKILL;
1806 }
1807 else
1808 GL_AlphaToCoverage(false);
1809 }
1810 }
1811 else
1812 {
1814 {
1815 switch(t->offsetmapping)
1816 {
1817 case OFFSETMAPPING_LINEAR: permutation |= SHADERPERMUTATION_OFFSETMAPPING;break;
1820 case OFFSETMAPPING_OFF: break;
1821 }
1822 }
1826 permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
1827 // lightmapped wall
1829 permutation |= SHADERPERMUTATION_GLOW;
1830 if (r_refdef.fogenabled && !ui)
1832 if (t->colormapping)
1833 permutation |= SHADERPERMUTATION_COLORMAPPING;
1835 {
1836 permutation |= SHADERPERMUTATION_SHADOWMAPORTHO;
1837 permutation |= SHADERPERMUTATION_SHADOWMAP2D;
1838
1840 permutation |= SHADERPERMUTATION_DEPTHRGB;
1841 }
1843 permutation |= SHADERPERMUTATION_REFLECTION;
1846 if (t->reflectmasktexture)
1847 permutation |= SHADERPERMUTATION_REFLECTCUBE;
1849 {
1850 // deluxemapping (light direction texture)
1853 else
1855 permutation |= SHADERPERMUTATION_DIFFUSE;
1858 }
1859 else if (r_glsl_deluxemapping.integer >= 2)
1860 {
1861 // fake deluxemapping (uniform light direction in tangentspace)
1864 else
1866 permutation |= SHADERPERMUTATION_DIFFUSE;
1869 }
1871 {
1872 // ordinary lightmapping (q1bsp, q3bsp)
1874 }
1875 else
1876 {
1877 // ordinary vertex coloring (q3bsp)
1879 }
1881 {
1882 permutation |= SHADERPERMUTATION_BOUNCEGRID;
1885 }
1887 blendfuncflags = R_BlendFuncFlags(t->currentblendfunc[0], t->currentblendfunc[1]);
1888 // when using alphatocoverage, we don't need alphakill
1890 {
1892 {
1894 permutation &= ~SHADERPERMUTATION_ALPHAKILL;
1895 }
1896 else
1897 GL_AlphaToCoverage(false);
1898 }
1899 }
1900 if(!(blendfuncflags & BLENDFUNC_ALLOWS_ANYFOG))
1902 if(blendfuncflags & BLENDFUNC_ALLOWS_FOG_HACKALPHA && !ui)
1903 permutation |= SHADERPERMUTATION_FOGALPHAHACK;
1904 switch(vid.renderpath)
1905 {
1906 case RENDERPATH_GL32:
1907 case RENDERPATH_GLES2:
1910 // this has to be after RSurf_PrepareVerticesForBatch
1912 permutation |= SHADERPERMUTATION_SKELETAL;
1914#ifndef USE_GLES2 /* FIXME: GLES3 only */
1916#endif
1919 {
1922 if (r_glsl_permutation->loc_LightColor >= 0) qglUniform3f(r_glsl_permutation->loc_LightColor, 1, 1, 1); // DEPRECATED
1923 if (r_glsl_permutation->loc_Color_Ambient >= 0) qglUniform3f(r_glsl_permutation->loc_Color_Ambient, rtlightambient[0], rtlightambient[1], rtlightambient[2]);
1924 if (r_glsl_permutation->loc_Color_Diffuse >= 0) qglUniform3f(r_glsl_permutation->loc_Color_Diffuse, rtlightdiffuse[0], rtlightdiffuse[1], rtlightdiffuse[2]);
1925 if (r_glsl_permutation->loc_Color_Specular >= 0) qglUniform3f(r_glsl_permutation->loc_Color_Specular, rtlightspecular[0], rtlightspecular[1], rtlightspecular[2]);
1926
1927 // additive passes are only darkened by fog, not tinted
1929 qglUniform3f(r_glsl_permutation->loc_FogColor, 0, 0, 0);
1931 }
1932 else
1933 {
1935 {
1937 }
1938 else if (mode == SHADERMODE_LIGHTGRID)
1939 {
1943 // other LightGrid uniforms handled below
1944 }
1945 else if (mode == SHADERMODE_LIGHTDIRECTION)
1946 {
1952 if (r_glsl_permutation->loc_LightColor >= 0) qglUniform3f(r_glsl_permutation->loc_LightColor, 1, 1, 1); // DEPRECATED
1954 }
1955 else
1956 {
1962 }
1963 // additive passes are only darkened by fog, not tinted
1964 if (r_glsl_permutation->loc_FogColor >= 0 && !ui)
1965 {
1966 if(blendfuncflags & BLENDFUNC_ALLOWS_FOG_HACK0)
1967 qglUniform3f(r_glsl_permutation->loc_FogColor, 0, 0, 0);
1968 else
1970 }
1980 }
1981 if (r_glsl_permutation->loc_TexMatrix >= 0) {Matrix4x4_ToArrayFloatGL(&t->currenttexmatrix, m16f);qglUniformMatrix4fv(r_glsl_permutation->loc_TexMatrix, 1, false, m16f);}
1984 if (permutation & SHADERPERMUTATION_SHADOWMAPORTHO)
1985 {
1988 }
1989 else
1990 {
1993 }
1994
1999 {
2000 if (t->pantstexture)
2002 else
2003 qglUniform3f(r_glsl_permutation->loc_Color_Pants, 0, 0, 0);
2004 }
2006 {
2007 if (t->shirttexture)
2009 else
2010 qglUniform3f(r_glsl_permutation->loc_Color_Shirt, 0, 0, 0);
2011 }
2021 );
2029 {
2030 float m9f[9];
2032 Matrix4x4_ToArrayFloatGL(&tempmatrix, m16f);
2033 qglUniformMatrix4fv(r_glsl_permutation->loc_LightGridMatrix, 1, false, m16f);
2034 Matrix4x4_Normalize3(&tempmatrix, &rsurface.matrix);
2035 Matrix4x4_ToArrayFloatGL(&tempmatrix, m16f);
2036 m9f[0] = m16f[0];m9f[1] = m16f[1];m9f[2] = m16f[2];
2037 m9f[3] = m16f[4];m9f[4] = m16f[5];m9f[5] = m16f[6];
2038 m9f[6] = m16f[8];m9f[7] = m16f[9];m9f[8] = m16f[10];
2039 qglUniformMatrix3fv(r_glsl_permutation->loc_LightGridNormalMatrix, 1, false, m9f);
2040 }
2041
2062 if (rsurfacepass == RSURFPASS_BACKGROUND)
2063 {
2067 }
2068 else
2069 {
2071 }
2076 {
2078 if (rsurface.rtlight)
2079 {
2082 }
2083 }
2087 break;
2088 }
2089}
2090
2092{
2093 // select a permutation of the lighting shader appropriate to this
2094 // combination of texture, entity, light source, and fogging, only use the
2095 // minimum features necessary to avoid wasting rendering time in the
2096 // fragment shader on features that are not being used
2097 uint64_t permutation = 0;
2098 unsigned int mode = 0;
2099 const float *lightcolorbase = rtlight->currentcolor;
2100 float ambientscale = rtlight->ambientscale;
2101 float diffusescale = rtlight->diffusescale;
2102 float specularscale = rtlight->specularscale;
2103 // this is the location of the light in view space
2104 vec3_t viewlightorigin;
2105 // this transforms from view space (camera) to light space (cubemap)
2106 matrix4x4_t viewtolight;
2107 matrix4x4_t lighttoview;
2108 float viewtolight16f[16];
2109 // light source
2111 if (rtlight->currentcubemap != r_texture_whitecube)
2112 permutation |= SHADERPERMUTATION_CUBEFILTER;
2113 if (diffusescale > 0)
2114 permutation |= SHADERPERMUTATION_DIFFUSE;
2115 if (specularscale > 0 && r_shadow_gloss.integer > 0)
2118 {
2119 permutation |= SHADERPERMUTATION_SHADOWMAP2D;
2121 permutation |= SHADERPERMUTATION_SHADOWMAPVSDCT;
2122
2124 permutation |= SHADERPERMUTATION_DEPTHRGB;
2125 }
2127 GL_AlphaToCoverage(false);
2128 Matrix4x4_Transform(&r_refdef.view.viewport.viewmatrix, rtlight->shadoworigin, viewlightorigin);
2130 Matrix4x4_Invert_Full(&viewtolight, &lighttoview);
2131 Matrix4x4_ToArrayFloatGL(&viewtolight, viewtolight16f);
2132 switch(vid.renderpath)
2133 {
2134 case RENDERPATH_GL32:
2135 case RENDERPATH_GLES2:
2137 if (r_glsl_permutation->loc_LightPosition >= 0) qglUniform3f( r_glsl_permutation->loc_LightPosition , viewlightorigin[0], viewlightorigin[1], viewlightorigin[2]);
2138 if (r_glsl_permutation->loc_ViewToLight >= 0) qglUniformMatrix4fv(r_glsl_permutation->loc_ViewToLight , 1, false, viewtolight16f);
2139 if (r_glsl_permutation->loc_DeferredColor_Ambient >= 0) qglUniform3f( r_glsl_permutation->loc_DeferredColor_Ambient , lightcolorbase[0] * ambientscale , lightcolorbase[1] * ambientscale , lightcolorbase[2] * ambientscale );
2140 if (r_glsl_permutation->loc_DeferredColor_Diffuse >= 0) qglUniform3f( r_glsl_permutation->loc_DeferredColor_Diffuse , lightcolorbase[0] * diffusescale , lightcolorbase[1] * diffusescale , lightcolorbase[2] * diffusescale );
2141 if (r_glsl_permutation->loc_DeferredColor_Specular >= 0) qglUniform3f( r_glsl_permutation->loc_DeferredColor_Specular , lightcolorbase[0] * specularscale, lightcolorbase[1] * specularscale, lightcolorbase[2] * specularscale);
2147
2153 break;
2154 }
2155}
2156
2157#define SKINFRAME_HASH 1024
2158
2159typedef struct
2160{
2161 unsigned int loadsequence; // incremented each level change
2164}
2167
2169{
2171 // wrap it without hitting zero
2172 if (r_skinframe.loadsequence >= 200)
2174}
2175
2177{
2178 if (!skinframe)
2179 return;
2180 // mark the skinframe as used for the purging code
2182}
2183
2185{
2186 if (s == NULL)
2187 return;
2188 if (s->merged == s->base)
2189 s->merged = NULL;
2190 R_PurgeTexture(s->stain); s->stain = NULL;
2191 R_PurgeTexture(s->merged); s->merged = NULL;
2192 R_PurgeTexture(s->base); s->base = NULL;
2193 R_PurgeTexture(s->pants); s->pants = NULL;
2194 R_PurgeTexture(s->shirt); s->shirt = NULL;
2195 R_PurgeTexture(s->nmap); s->nmap = NULL;
2196 R_PurgeTexture(s->gloss); s->gloss = NULL;
2197 R_PurgeTexture(s->glow); s->glow = NULL;
2198 R_PurgeTexture(s->fog); s->fog = NULL;
2200 s->loadsequence = 0;
2201}
2202
2204{
2205 int i;
2206 skinframe_t *s;
2207 for (i = 0;i < SKINFRAME_HASH;i++)
2208 {
2209 for (s = r_skinframe.hash[i];s;s = s->next)
2210 {
2213 }
2214 }
2215}
2216
2218 skinframe_t *item;
2219 char basename[MAX_QPATH];
2220
2221 Image_StripImageExtension(name, basename, sizeof(basename));
2222
2223 if( last == NULL ) {
2224 int hashindex;
2225 hashindex = CRC_Block((unsigned char *)basename, strlen(basename)) & (SKINFRAME_HASH - 1);
2226 item = r_skinframe.hash[hashindex];
2227 } else {
2228 item = last->next;
2229 }
2230
2231 // linearly search through the hash bucket
2232 for( ; item ; item = item->next ) {
2233 if( !strcmp( item->basename, basename ) ) {
2234 return item;
2235 }
2236 }
2237 return NULL;
2238}
2239
2240skinframe_t *R_SkinFrame_Find(const char *name, int textureflags, int comparewidth, int compareheight, int comparecrc, qbool add)
2241{
2242 skinframe_t *item;
2243 int compareflags = textureflags & TEXF_IMPORTANTBITS;
2244 int hashindex;
2245 char basename[MAX_QPATH];
2246
2247 Image_StripImageExtension(name, basename, sizeof(basename));
2248
2249 hashindex = CRC_Block((unsigned char *)basename, strlen(basename)) & (SKINFRAME_HASH - 1);
2250 for (item = r_skinframe.hash[hashindex];item;item = item->next)
2251 if (!strcmp(item->basename, basename) &&
2252 item->textureflags == compareflags &&
2253 item->comparewidth == comparewidth &&
2254 item->compareheight == compareheight &&
2255 item->comparecrc == comparecrc)
2256 break;
2257
2258 if (!item)
2259 {
2260 if (!add)
2261 return NULL;
2263 memset(item, 0, sizeof(*item));
2264 dp_strlcpy(item->basename, basename, sizeof(item->basename));
2265 item->textureflags = compareflags;
2266 item->comparewidth = comparewidth;
2267 item->compareheight = compareheight;
2268 item->comparecrc = comparecrc;
2269 item->next = r_skinframe.hash[hashindex];
2270 r_skinframe.hash[hashindex] = item;
2271 }
2272 else if (textureflags & TEXF_FORCE_RELOAD)
2274
2276 return item;
2277}
2278
2279#define R_SKINFRAME_LOAD_AVERAGE_COLORS(cnt, getpixel) \
2280 { \
2281 unsigned long long avgcolor[5], wsum; \
2282 int pix, comp, w; \
2283 avgcolor[0] = 0; \
2284 avgcolor[1] = 0; \
2285 avgcolor[2] = 0; \
2286 avgcolor[3] = 0; \
2287 avgcolor[4] = 0; \
2288 wsum = 0; \
2289 for(pix = 0; pix < cnt; ++pix) \
2290 { \
2291 w = 0; \
2292 for(comp = 0; comp < 3; ++comp) \
2293 w += getpixel; \
2294 if(w) /* ignore perfectly black pixels because that is better for model skins */ \
2295 { \
2296 ++wsum; \
2297 /* comp = 3; -- not needed, comp is always 3 when we get here */ \
2298 w = getpixel; \
2299 for(comp = 0; comp < 3; ++comp) \
2300 avgcolor[comp] += getpixel * w; \
2301 avgcolor[3] += w; \
2302 } \
2303 /* comp = 3; -- not needed, comp is always 3 when we get here */ \
2304 avgcolor[4] += getpixel; \
2305 } \
2306 if(avgcolor[3] == 0) /* no pixels seen? even worse */ \
2307 avgcolor[3] = 1; \
2308 skinframe->avgcolor[0] = avgcolor[2] / (255.0 * avgcolor[3]); \
2309 skinframe->avgcolor[1] = avgcolor[1] / (255.0 * avgcolor[3]); \
2310 skinframe->avgcolor[2] = avgcolor[0] / (255.0 * avgcolor[3]); \
2311 skinframe->avgcolor[3] = avgcolor[4] / (255.0 * cnt); \
2312 }
2313
2314skinframe_t *R_SkinFrame_LoadExternal(const char *name, int textureflags, qbool complain, qbool fallbacknotexture)
2315{
2316 skinframe_t *skinframe;
2317
2318 if (cls.state == ca_dedicated)
2319 return NULL;
2320
2321 // return an existing skinframe if already loaded
2322 skinframe = R_SkinFrame_Find(name, textureflags, 0, 0, 0, false);
2323 if (skinframe && skinframe->base)
2324 return skinframe;
2325
2326 // if the skinframe doesn't exist this will create it
2327 return R_SkinFrame_LoadExternal_SkinFrame(skinframe, name, textureflags, complain, fallbacknotexture);
2328}
2329
2330extern cvar_t gl_picmip;
2331skinframe_t *R_SkinFrame_LoadExternal_SkinFrame(skinframe_t *skinframe, const char *name, int textureflags, qbool complain, qbool fallbacknotexture)
2332{
2333 int j;
2334 unsigned char *pixels;
2335 unsigned char *bumppixels;
2336 unsigned char *basepixels = NULL;
2337 int basepixels_width = 0;
2338 int basepixels_height = 0;
2339 rtexture_t *ddsbase = NULL;
2340 qbool ddshasalpha = false;
2341 float ddsavgcolor[4];
2342 char basename[MAX_QPATH];
2343 int miplevel = R_PicmipForFlags(textureflags);
2344 int savemiplevel = miplevel;
2345 int mymiplevel;
2346 char vabuf[1024];
2347
2348 if (cls.state == ca_dedicated)
2349 return NULL;
2350
2351 Image_StripImageExtension(name, basename, sizeof(basename));
2352
2353 // check for DDS texture file first
2354 if (!r_loaddds || !(ddsbase = R_LoadTextureDDSFile(r_main_texturepool, va(vabuf, sizeof(vabuf), "dds/%s.dds", basename), vid.sRGB3D, textureflags, &ddshasalpha, ddsavgcolor, miplevel, false)))
2355 {
2356 basepixels = loadimagepixelsbgra(name, complain, true, false, &miplevel);
2357 if (basepixels == NULL && fallbacknotexture)
2358 basepixels = Image_GenerateNoTexture();
2359 if (basepixels == NULL)
2360 return NULL;
2361 }
2362
2363 // FIXME handle miplevel
2364
2366 Con_Printf("loading skin \"%s\"\n", name);
2367
2368 // we've got some pixels to store, so really allocate this new texture now
2369 if (!skinframe)
2370 skinframe = R_SkinFrame_Find(name, textureflags, 0, 0, 0, true);
2371 textureflags &= ~TEXF_FORCE_RELOAD;
2372 skinframe->stain = NULL;
2373 skinframe->merged = NULL;
2374 skinframe->base = NULL;
2375 skinframe->pants = NULL;
2376 skinframe->shirt = NULL;
2377 skinframe->nmap = NULL;
2378 skinframe->gloss = NULL;
2379 skinframe->glow = NULL;
2380 skinframe->fog = NULL;
2381 skinframe->reflect = NULL;
2382 skinframe->hasalpha = false;
2383 // we could store the q2animname here too
2384
2385 if (ddsbase)
2386 {
2387 skinframe->base = ddsbase;
2388 skinframe->hasalpha = ddshasalpha;
2389 VectorCopy(ddsavgcolor, skinframe->avgcolor);
2390 if (r_loadfog && skinframe->hasalpha)
2391 skinframe->fog = R_LoadTextureDDSFile(r_main_texturepool, va(vabuf, sizeof(vabuf), "dds/%s_mask.dds", skinframe->basename), false, textureflags | TEXF_ALPHA, NULL, NULL, miplevel, true);
2392 //Con_Printf("Texture %s has average colors %f %f %f alpha %f\n", name, skinframe->avgcolor[0], skinframe->avgcolor[1], skinframe->avgcolor[2], skinframe->avgcolor[3]);
2393 }
2394 else
2395 {
2396 basepixels_width = image_width;
2397 basepixels_height = image_height;
2398 skinframe->base = R_LoadTexture2D (r_main_texturepool, skinframe->basename, basepixels_width, basepixels_height, basepixels, vid.sRGB3D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, textureflags & (gl_texturecompression_color.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), miplevel, NULL);
2399 if (textureflags & TEXF_ALPHA)
2400 {
2401 for (j = 3;j < basepixels_width * basepixels_height * 4;j += 4)
2402 {
2403 if (basepixels[j] < 255)
2404 {
2405 skinframe->hasalpha = true;
2406 break;
2407 }
2408 }
2409 if (r_loadfog && skinframe->hasalpha)
2410 {
2411 // has transparent pixels
2412 pixels = (unsigned char *)Mem_Alloc(tempmempool, image_width * image_height * 4);
2413 for (j = 0;j < image_width * image_height * 4;j += 4)
2414 {
2415 pixels[j+0] = 255;
2416 pixels[j+1] = 255;
2417 pixels[j+2] = 255;
2418 pixels[j+3] = basepixels[j+3];
2419 }
2420 skinframe->fog = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_mask", skinframe->basename), image_width, image_height, pixels, TEXTYPE_BGRA, textureflags & (gl_texturecompression_color.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), miplevel, NULL);
2422 }
2423 }
2424 R_SKINFRAME_LOAD_AVERAGE_COLORS(basepixels_width * basepixels_height, basepixels[4 * pix + comp]);
2425#ifndef USE_GLES2
2426 //Con_Printf("Texture %s has average colors %f %f %f alpha %f\n", name, skinframe->avgcolor[0], skinframe->avgcolor[1], skinframe->avgcolor[2], skinframe->avgcolor[3]);
2427 if (r_savedds && skinframe->base)
2428 R_SaveTextureDDSFile(skinframe->base, va(vabuf, sizeof(vabuf), "dds/%s.dds", skinframe->basename), r_texture_dds_save.integer < 2, skinframe->hasalpha);
2429 if (r_savedds && skinframe->fog)
2430 R_SaveTextureDDSFile(skinframe->fog, va(vabuf, sizeof(vabuf), "dds/%s_mask.dds", skinframe->basename), r_texture_dds_save.integer < 2, true);
2431#endif
2432 }
2433
2434 if (r_loaddds)
2435 {
2436 mymiplevel = savemiplevel;
2437 if (r_loadnormalmap)
2438 skinframe->nmap = R_LoadTextureDDSFile(r_main_texturepool, va(vabuf, sizeof(vabuf), "dds/%s_norm.dds", skinframe->basename), false, (TEXF_ALPHA | textureflags) & (r_mipnormalmaps.integer ? ~0 : ~TEXF_MIPMAP), NULL, NULL, mymiplevel, true);
2439 skinframe->glow = R_LoadTextureDDSFile(r_main_texturepool, va(vabuf, sizeof(vabuf), "dds/%s_glow.dds", skinframe->basename), vid.sRGB3D, textureflags, NULL, NULL, mymiplevel, true);
2440 if (r_loadgloss)
2441 skinframe->gloss = R_LoadTextureDDSFile(r_main_texturepool, va(vabuf, sizeof(vabuf), "dds/%s_gloss.dds", skinframe->basename), vid.sRGB3D, textureflags, NULL, NULL, mymiplevel, true);
2442 skinframe->pants = R_LoadTextureDDSFile(r_main_texturepool, va(vabuf, sizeof(vabuf), "dds/%s_pants.dds", skinframe->basename), vid.sRGB3D, textureflags, NULL, NULL, mymiplevel, true);
2443 skinframe->shirt = R_LoadTextureDDSFile(r_main_texturepool, va(vabuf, sizeof(vabuf), "dds/%s_shirt.dds", skinframe->basename), vid.sRGB3D, textureflags, NULL, NULL, mymiplevel, true);
2444 skinframe->reflect = R_LoadTextureDDSFile(r_main_texturepool, va(vabuf, sizeof(vabuf), "dds/%s_reflect.dds", skinframe->basename), vid.sRGB3D, textureflags, NULL, NULL, mymiplevel, true);
2445 }
2446
2447 // _norm is the name used by tenebrae and has been adopted as standard
2448 if (r_loadnormalmap && skinframe->nmap == NULL)
2449 {
2450 mymiplevel = savemiplevel;
2451 if ((pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_norm", skinframe->basename), false, false, false, &mymiplevel)) != NULL)
2452 {
2453 skinframe->nmap = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_nmap", skinframe->basename), image_width, image_height, pixels, TEXTYPE_BGRA, (TEXF_ALPHA | textureflags) & (r_mipnormalmaps.integer ? ~0 : ~TEXF_MIPMAP) & (gl_texturecompression_normal.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
2455 pixels = NULL;
2456 }
2457 else if (r_shadow_bumpscale_bumpmap.value > 0 && (bumppixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_bump", skinframe->basename), false, false, false, &mymiplevel)) != NULL)
2458 {
2459 pixels = (unsigned char *)Mem_Alloc(tempmempool, image_width * image_height * 4);
2461 skinframe->nmap = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_nmap", skinframe->basename), image_width, image_height, pixels, TEXTYPE_BGRA, (TEXF_ALPHA | textureflags) & (r_mipnormalmaps.integer ? ~0 : ~TEXF_MIPMAP) & (gl_texturecompression_normal.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
2463 Mem_Free(bumppixels);
2464 }
2466 {
2467 pixels = (unsigned char *)Mem_Alloc(tempmempool, basepixels_width * basepixels_height * 4);
2468 Image_HeightmapToNormalmap_BGRA(basepixels, pixels, basepixels_width, basepixels_height, false, r_shadow_bumpscale_basetexture.value);
2469 skinframe->nmap = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_nmap", skinframe->basename), basepixels_width, basepixels_height, pixels, TEXTYPE_BGRA, (TEXF_ALPHA | textureflags) & (r_mipnormalmaps.integer ? ~0 : ~TEXF_MIPMAP) & (gl_texturecompression_normal.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
2471 }
2472#ifndef USE_GLES2
2473 if (r_savedds && skinframe->nmap)
2474 R_SaveTextureDDSFile(skinframe->nmap, va(vabuf, sizeof(vabuf), "dds/%s_norm.dds", skinframe->basename), r_texture_dds_save.integer < 2, true);
2475#endif
2476 }
2477
2478 // _luma is supported only for tenebrae compatibility
2479 // _blend and .blend are supported only for Q3 & QL compatibility, this hack can be removed if better Q3 shader support is implemented
2480 // _glow is the preferred name
2481 mymiplevel = savemiplevel;
2482 if (skinframe->glow == NULL && ((pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_glow", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s.blend", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_blend", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_luma", skinframe->basename), false, false, false, &mymiplevel))))
2483 {
2484 skinframe->glow = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_glow", skinframe->basename), image_width, image_height, pixels, vid.sRGB3D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, textureflags & (gl_texturecompression_glow.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
2485#ifndef USE_GLES2
2486 if (r_savedds && skinframe->glow)
2487 R_SaveTextureDDSFile(skinframe->glow, va(vabuf, sizeof(vabuf), "dds/%s_glow.dds", skinframe->basename), r_texture_dds_save.integer < 2, true);
2488#endif
2490 }
2491
2492 mymiplevel = savemiplevel;
2493 if (skinframe->gloss == NULL && r_loadgloss && (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_gloss", skinframe->basename), false, false, false, &mymiplevel)))
2494 {
2495 skinframe->gloss = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_gloss", skinframe->basename), image_width, image_height, pixels, vid.sRGB3D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, (TEXF_ALPHA | textureflags) & (gl_texturecompression_gloss.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
2496#ifndef USE_GLES2
2497 if (r_savedds && skinframe->gloss)
2498 R_SaveTextureDDSFile(skinframe->gloss, va(vabuf, sizeof(vabuf), "dds/%s_gloss.dds", skinframe->basename), r_texture_dds_save.integer < 2, true);
2499#endif
2501 pixels = NULL;
2502 }
2503
2504 mymiplevel = savemiplevel;
2505 if (skinframe->pants == NULL && (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_pants", skinframe->basename), false, false, false, &mymiplevel)))
2506 {
2507 skinframe->pants = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_pants", skinframe->basename), image_width, image_height, pixels, vid.sRGB3D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, textureflags & (gl_texturecompression_color.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
2508#ifndef USE_GLES2
2509 if (r_savedds && skinframe->pants)
2510 R_SaveTextureDDSFile(skinframe->pants, va(vabuf, sizeof(vabuf), "dds/%s_pants.dds", skinframe->basename), r_texture_dds_save.integer < 2, false);
2511#endif
2513 pixels = NULL;
2514 }
2515
2516 mymiplevel = savemiplevel;
2517 if (skinframe->shirt == NULL && (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_shirt", skinframe->basename), false, false, false, &mymiplevel)))
2518 {
2519 skinframe->shirt = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_shirt", skinframe->basename), image_width, image_height, pixels, vid.sRGB3D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, textureflags & (gl_texturecompression_color.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
2520#ifndef USE_GLES2
2521 if (r_savedds && skinframe->shirt)
2522 R_SaveTextureDDSFile(skinframe->shirt, va(vabuf, sizeof(vabuf), "dds/%s_shirt.dds", skinframe->basename), r_texture_dds_save.integer < 2, false);
2523#endif
2525 pixels = NULL;
2526 }
2527
2528 mymiplevel = savemiplevel;
2529 if (skinframe->reflect == NULL && (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_reflect", skinframe->basename), false, false, false, &mymiplevel)))
2530 {
2531 skinframe->reflect = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_reflect", skinframe->basename), image_width, image_height, pixels, vid.sRGB3D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, textureflags & (gl_texturecompression_reflectmask.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
2532#ifndef USE_GLES2
2533 if (r_savedds && skinframe->reflect)
2534 R_SaveTextureDDSFile(skinframe->reflect, va(vabuf, sizeof(vabuf), "dds/%s_reflect.dds", skinframe->basename), r_texture_dds_save.integer < 2, true);
2535#endif
2537 pixels = NULL;
2538 }
2539
2540 if (basepixels)
2541 Mem_Free(basepixels);
2542
2543 return skinframe;
2544}
2545
2546skinframe_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)
2547{
2548 int i;
2549 skinframe_t *skinframe;
2550 char vabuf[1024];
2551
2552 if (cls.state == ca_dedicated)
2553 return NULL;
2554
2555 // if already loaded just return it, otherwise make a new skinframe
2556 skinframe = R_SkinFrame_Find(name, textureflags, comparewidth, compareheight, comparecrc, true);
2557 if (skinframe->base)
2558 return skinframe;
2559 textureflags &= ~TEXF_FORCE_RELOAD;
2560
2561 skinframe->stain = NULL;
2562 skinframe->merged = NULL;
2563 skinframe->base = NULL;
2564 skinframe->pants = NULL;
2565 skinframe->shirt = NULL;
2566 skinframe->nmap = NULL;
2567 skinframe->gloss = NULL;
2568 skinframe->glow = NULL;
2569 skinframe->fog = NULL;
2570 skinframe->reflect = NULL;
2571 skinframe->hasalpha = false;
2572
2573 // if no data was provided, then clearly the caller wanted to get a blank skinframe
2574 if (!skindata)
2575 return NULL;
2576
2578 Con_Printf("loading 32bit skin \"%s\"\n", name);
2579
2581 {
2582 unsigned char *a = (unsigned char *)Mem_Alloc(tempmempool, width * height * 8);
2583 unsigned char *b = a + width * height * 4;
2585 skinframe->nmap = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_nmap", skinframe->basename), width, height, b, TEXTYPE_BGRA, (textureflags | TEXF_ALPHA) & (r_mipnormalmaps.integer ? ~0 : ~TEXF_MIPMAP), -1, NULL);
2586 Mem_Free(a);
2587 }
2588 skinframe->base = skinframe->merged = R_LoadTexture2D(r_main_texturepool, skinframe->basename, width, height, skindata, sRGB ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, textureflags, -1, NULL);
2589 if (textureflags & TEXF_ALPHA)
2590 {
2591 for (i = 3;i < width * height * 4;i += 4)
2592 {
2593 if (skindata[i] < 255)
2594 {
2595 skinframe->hasalpha = true;
2596 break;
2597 }
2598 }
2599 if (r_loadfog && skinframe->hasalpha)
2600 {
2601 unsigned char *fogpixels = (unsigned char *)Mem_Alloc(tempmempool, width * height * 4);
2602 memcpy(fogpixels, skindata, width * height * 4);
2603 for (i = 0;i < width * height * 4;i += 4)
2604 fogpixels[i] = fogpixels[i+1] = fogpixels[i+2] = 255;
2605 skinframe->fog = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_fog", skinframe->basename), width, height, fogpixels, TEXTYPE_BGRA, textureflags, -1, NULL);
2606 Mem_Free(fogpixels);
2607 }
2608 }
2609
2610 R_SKINFRAME_LOAD_AVERAGE_COLORS(width * height, skindata[4 * pix + comp]);
2611 //Con_Printf("Texture %s has average colors %f %f %f alpha %f\n", name, skinframe->avgcolor[0], skinframe->avgcolor[1], skinframe->avgcolor[2], skinframe->avgcolor[3]);
2612
2613 return skinframe;
2614}
2615
2616skinframe_t *R_SkinFrame_LoadInternalQuake(const char *name, int textureflags, int loadpantsandshirt, int loadglowtexture, const unsigned char *skindata, int width, int height)
2617{
2618 int i;
2619 int featuresmask;
2620 skinframe_t *skinframe;
2621
2622 if (cls.state == ca_dedicated)
2623 return NULL;
2624
2625 // if already loaded just return it, otherwise make a new skinframe
2626 skinframe = R_SkinFrame_Find(name, textureflags, width, height, skindata ? CRC_Block(skindata, width*height) : 0, true);
2627 if (skinframe->base)
2628 return skinframe;
2629 //textureflags &= ~TEXF_FORCE_RELOAD;
2630
2631 skinframe->stain = NULL;
2632 skinframe->merged = NULL;
2633 skinframe->base = NULL;
2634 skinframe->pants = NULL;
2635 skinframe->shirt = NULL;
2636 skinframe->nmap = NULL;
2637 skinframe->gloss = NULL;
2638 skinframe->glow = NULL;
2639 skinframe->fog = NULL;
2640 skinframe->reflect = NULL;
2641 skinframe->hasalpha = false;
2642
2643 // if no data was provided, then clearly the caller wanted to get a blank skinframe
2644 if (!skindata)
2645 return NULL;
2646
2648 Con_Printf("loading quake skin \"%s\"\n", name);
2649
2650 // we actually don't upload anything until the first use, because mdl skins frequently go unused, and are almost never used in both modes (colormapped and non-colormapped)
2651 skinframe->qpixels = (unsigned char *)Mem_Alloc(r_main_mempool, width*height); // FIXME LEAK
2652 memcpy(skinframe->qpixels, skindata, width*height);
2653 skinframe->qwidth = width;
2654 skinframe->qheight = height;
2655
2656 featuresmask = 0;
2657 for (i = 0;i < width * height;i++)
2658 featuresmask |= palette_featureflags[skindata[i]];
2659
2660 skinframe->hasalpha = false;
2661 // fence textures
2662 if (name[0] == '{')
2663 skinframe->hasalpha = true;
2664 skinframe->qhascolormapping = loadpantsandshirt && (featuresmask & (PALETTEFEATURE_PANTS | PALETTEFEATURE_SHIRT));
2666 skinframe->qgeneratemerged = true;
2667 skinframe->qgeneratebase = skinframe->qhascolormapping;
2668 skinframe->qgenerateglow = loadglowtexture && (featuresmask & PALETTEFEATURE_GLOW);
2669
2670 R_SKINFRAME_LOAD_AVERAGE_COLORS(width * height, ((unsigned char *)palette_bgra_complete)[skindata[pix]*4 + comp]);
2671 //Con_Printf("Texture %s has average colors %f %f %f alpha %f\n", name, skinframe->avgcolor[0], skinframe->avgcolor[1], skinframe->avgcolor[2], skinframe->avgcolor[3]);
2672
2673 return skinframe;
2674}
2675
2677{
2678 int width;
2679 int height;
2680 unsigned char *skindata;
2681 char vabuf[1024];
2682
2683 if (!skinframe->qpixels)
2684 return;
2685
2686 if (!skinframe->qhascolormapping)
2687 colormapped = false;
2688
2689 if (colormapped)
2690 {
2691 if (!skinframe->qgeneratebase)
2692 return;
2693 }
2694 else
2695 {
2696 if (!skinframe->qgeneratemerged)
2697 return;
2698 }
2699
2700 width = skinframe->qwidth;
2701 height = skinframe->qheight;
2702 skindata = skinframe->qpixels;
2703
2704 if (skinframe->qgeneratenmap)
2705 {
2706 unsigned char *a, *b;
2707 skinframe->qgeneratenmap = false;
2708 a = (unsigned char *)Mem_Alloc(tempmempool, width * height * 8);
2709 b = a + width * height * 4;
2710 // use either a custom palette or the quake palette
2713 skinframe->nmap = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_nmap", skinframe->basename), width, height, b, TEXTYPE_BGRA, (skinframe->textureflags | TEXF_ALPHA) & (r_mipnormalmaps.integer ? ~0 : ~TEXF_MIPMAP), -1, NULL);
2714 Mem_Free(a);
2715 }
2716
2717 if (skinframe->qgenerateglow)
2718 {
2719 skinframe->qgenerateglow = false;
2720 if (skinframe->hasalpha) // fence textures
2721 skinframe->glow = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_glow", skinframe->basename), width, height, skindata, vid.sRGB3D ? TEXTYPE_SRGB_PALETTE : TEXTYPE_PALETTE, skinframe->textureflags | TEXF_ALPHA, -1, palette_bgra_onlyfullbrights_transparent); // glow
2722 else
2723 skinframe->glow = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_glow", skinframe->basename), width, height, skindata, vid.sRGB3D ? TEXTYPE_SRGB_PALETTE : TEXTYPE_PALETTE, skinframe->textureflags, -1, palette_bgra_onlyfullbrights); // glow
2724 }
2725
2726 if (colormapped)
2727 {
2728 skinframe->qgeneratebase = false;
2729 skinframe->base = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_nospecial", skinframe->basename), width, height, skindata, vid.sRGB3D ? TEXTYPE_SRGB_PALETTE : TEXTYPE_PALETTE, skinframe->textureflags, -1, skinframe->glow ? palette_bgra_nocolormapnofullbrights : palette_bgra_nocolormap);
2730 skinframe->pants = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_pants", skinframe->basename), width, height, skindata, vid.sRGB3D ? TEXTYPE_SRGB_PALETTE : TEXTYPE_PALETTE, skinframe->textureflags, -1, palette_bgra_pantsaswhite);
2731 skinframe->shirt = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_shirt", skinframe->basename), width, height, skindata, vid.sRGB3D ? TEXTYPE_SRGB_PALETTE : TEXTYPE_PALETTE, skinframe->textureflags, -1, palette_bgra_shirtaswhite);
2732 }
2733 else
2734 {
2735 skinframe->qgeneratemerged = false;
2736 if (skinframe->hasalpha) // fence textures
2738 else
2740 }
2741
2742 if (!skinframe->qgeneratemerged && !skinframe->qgeneratebase)
2743 {
2744 Mem_Free(skinframe->qpixels);
2745 skinframe->qpixels = NULL;
2746 }
2747}
2748
2749skinframe_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)
2750{
2751 int i;
2752 skinframe_t *skinframe;
2753 char vabuf[1024];
2754
2755 if (cls.state == ca_dedicated)
2756 return NULL;
2757
2758 // if already loaded just return it, otherwise make a new skinframe
2759 skinframe = R_SkinFrame_Find(name, textureflags, width, height, skindata ? CRC_Block(skindata, width*height) : 0, true);
2760 if (skinframe->base)
2761 return skinframe;
2762 textureflags &= ~TEXF_FORCE_RELOAD;
2763
2764 skinframe->stain = NULL;
2765 skinframe->merged = NULL;
2766 skinframe->base = NULL;
2767 skinframe->pants = NULL;
2768 skinframe->shirt = NULL;
2769 skinframe->nmap = NULL;
2770 skinframe->gloss = NULL;
2771 skinframe->glow = NULL;
2772 skinframe->fog = NULL;
2773 skinframe->reflect = NULL;
2774 skinframe->hasalpha = false;
2775
2776 // if no data was provided, then clearly the caller wanted to get a blank skinframe
2777 if (!skindata)
2778 return NULL;
2779
2781 Con_Printf("loading embedded 8bit image \"%s\"\n", name);
2782
2783 skinframe->base = skinframe->merged = R_LoadTexture2D(r_main_texturepool, skinframe->basename, width, height, skindata, TEXTYPE_PALETTE, textureflags, -1, palette);
2784 if ((textureflags & TEXF_ALPHA) && alphapalette)
2785 {
2786 for (i = 0;i < width * height;i++)
2787 {
2788 if (((unsigned char *)palette)[skindata[i]*4+3] < 255)
2789 {
2790 skinframe->hasalpha = true;
2791 break;
2792 }
2793 }
2794 if (r_loadfog && skinframe->hasalpha)
2795 skinframe->fog = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_fog", skinframe->basename), width, height, skindata, TEXTYPE_PALETTE, textureflags, -1, alphapalette);
2796 }
2797
2798 R_SKINFRAME_LOAD_AVERAGE_COLORS(width * height, ((unsigned char *)palette)[skindata[pix]*4 + comp]);
2799 //Con_Printf("Texture %s has average colors %f %f %f alpha %f\n", name, skinframe->avgcolor[0], skinframe->avgcolor[1], skinframe->avgcolor[2], skinframe->avgcolor[3]);
2800
2801 return skinframe;
2802}
2803
2805{
2806 skinframe_t *skinframe;
2807
2808 if (cls.state == ca_dedicated)
2809 return NULL;
2810
2811 skinframe = R_SkinFrame_Find("missing", TEXF_FORCENEAREST, 0, 0, 0, true);
2812 skinframe->stain = NULL;
2813 skinframe->merged = NULL;
2814 skinframe->base = NULL;
2815 skinframe->pants = NULL;
2816 skinframe->shirt = NULL;
2817 skinframe->nmap = NULL;
2818 skinframe->gloss = NULL;
2819 skinframe->glow = NULL;
2820 skinframe->fog = NULL;
2821 skinframe->reflect = NULL;
2822 skinframe->hasalpha = false;
2823
2824 skinframe->avgcolor[0] = rand() / RAND_MAX;
2825 skinframe->avgcolor[1] = rand() / RAND_MAX;
2826 skinframe->avgcolor[2] = rand() / RAND_MAX;
2827 skinframe->avgcolor[3] = 1;
2828
2829 return skinframe;
2830}
2831
2833{
2834 if (cls.state == ca_dedicated)
2835 return NULL;
2836
2837 return R_SkinFrame_LoadInternalBGRA("notexture", TEXF_FORCENEAREST, Image_GenerateNoTexture(), 16, 16, 0, 0, 0, false);
2838}
2839
2840skinframe_t *R_SkinFrame_LoadInternalUsingTexture(const char *name, int textureflags, rtexture_t *tex, int width, int height, qbool sRGB)
2841{
2842 skinframe_t *skinframe;
2843 if (cls.state == ca_dedicated)
2844 return NULL;
2845 // if already loaded just return it, otherwise make a new skinframe
2846 skinframe = R_SkinFrame_Find(name, textureflags, width, height, 0, true);
2847 if (skinframe->base)
2848 return skinframe;
2849 textureflags &= ~TEXF_FORCE_RELOAD;
2850 skinframe->stain = NULL;
2851 skinframe->merged = NULL;
2852 skinframe->base = NULL;
2853 skinframe->pants = NULL;
2854 skinframe->shirt = NULL;
2855 skinframe->nmap = NULL;
2856 skinframe->gloss = NULL;
2857 skinframe->glow = NULL;
2858 skinframe->fog = NULL;
2859 skinframe->reflect = NULL;
2860 skinframe->hasalpha = (textureflags & TEXF_ALPHA) != 0;
2861 // if no data was provided, then clearly the caller wanted to get a blank skinframe
2862 if (!tex)
2863 return NULL;
2865 Con_Printf("loading 32bit skin \"%s\"\n", name);
2866 skinframe->base = skinframe->merged = tex;
2867 Vector4Set(skinframe->avgcolor, 1, 1, 1, 1); // bogus placeholder
2868 return skinframe;
2869}
2870
2871//static char *suffix[6] = {"ft", "bk", "rt", "lf", "up", "dn"};
2872typedef struct suffixinfo_s
2873{
2874 const char *suffix;
2875 qbool flipx, flipy, flipdiagonal;
2876}
2878static suffixinfo_t suffix[3][6] =
2879{
2880 {
2881 {"px", false, false, false},
2882 {"nx", false, false, false},
2883 {"py", false, false, false},
2884 {"ny", false, false, false},
2885 {"pz", false, false, false},
2886 {"nz", false, false, false}
2887 },
2888 {
2889 {"posx", false, false, false},
2890 {"negx", false, false, false},
2891 {"posy", false, false, false},
2892 {"negy", false, false, false},
2893 {"posz", false, false, false},
2894 {"negz", false, false, false}
2895 },
2896 {
2897 {"rt", true, false, true},
2898 {"lf", false, true, true},
2899 {"ft", true, true, false},
2900 {"bk", false, false, false},
2901 {"up", true, false, true},
2902 {"dn", true, false, true}
2903 }
2904};
2905
2906static int componentorder[4] = {0, 1, 2, 3};
2907
2908static rtexture_t *R_LoadCubemap(const char *basename)
2909{
2910 int i, j, cubemapsize, forcefilter;
2911 unsigned char *cubemappixels, *image_buffer;
2912 rtexture_t *cubemaptexture;
2913 char name[256];
2914
2915 // HACK: if the cubemap name starts with a !, the cubemap is nearest-filtered
2916 forcefilter = TEXF_FORCELINEAR;
2917 if (basename && basename[0] == '!')
2918 {
2919 basename++;
2920 forcefilter = TEXF_FORCENEAREST;
2921 }
2922 // must start 0 so the first loadimagepixels has no requested width/height
2923 cubemapsize = 0;
2924 cubemappixels = NULL;
2925 cubemaptexture = NULL;
2926 // keep trying different suffix groups (posx, px, rt) until one loads
2927 for (j = 0;j < 3 && !cubemappixels;j++)
2928 {
2929 // load the 6 images in the suffix group
2930 for (i = 0;i < 6;i++)
2931 {
2932 // generate an image name based on the base and and suffix
2933 dpsnprintf(name, sizeof(name), "%s%s", basename, suffix[j][i].suffix);
2934 // load it
2935 if ((image_buffer = loadimagepixelsbgra(name, false, false, false, NULL)))
2936 {
2937 // an image loaded, make sure width and height are equal
2938 if (image_width == image_height && (!cubemappixels || image_width == cubemapsize))
2939 {
2940 // if this is the first image to load successfully, allocate the cubemap memory
2941 if (!cubemappixels && image_width >= 1)
2942 {
2943 cubemapsize = image_width;
2944 // note this clears to black, so unavailable sides are black
2945 cubemappixels = (unsigned char *)Mem_Alloc(tempmempool, 6*cubemapsize*cubemapsize*4);
2946 }
2947 // copy the image with any flipping needed by the suffix (px and posx types don't need flipping)
2948 if (cubemappixels)
2949 Image_CopyMux(cubemappixels+i*cubemapsize*cubemapsize*4, image_buffer, cubemapsize, cubemapsize, suffix[j][i].flipx, suffix[j][i].flipy, suffix[j][i].flipdiagonal, 4, 4, componentorder);
2950 }
2951 else
2952 Con_Printf("Cubemap image \"%s\" (%ix%i) is not square, OpenGL requires square cubemaps.\n", name, image_width, image_height);
2953 // free the image
2954 Mem_Free(image_buffer);
2955 }
2956 }
2957 }
2958 // if a cubemap loaded, upload it
2959 if (cubemappixels)
2960 {
2962 Con_Printf("loading cubemap \"%s\"\n", basename);
2963
2965 Mem_Free(cubemappixels);
2966 }
2967 else
2968 {
2969 Con_DPrintf("failed to load cubemap \"%s\"\n", basename);
2971 {
2972 Con_Printf("(tried tried images ");
2973 for (j = 0;j < 3;j++)
2974 for (i = 0;i < 6;i++)
2975 Con_Printf("%s\"%s%s.tga\"", j + i > 0 ? ", " : "", basename, suffix[j][i].suffix);
2976 Con_Print(" and was unable to find any of them).\n");
2977 }
2978 }
2979 return cubemaptexture;
2980}
2981
2982rtexture_t *R_GetCubemap(const char *basename)
2983{
2984 int i;
2985 for (i = 0;i < r_texture_numcubemaps;i++)
2986 if (r_texture_cubemaps[i] != NULL)
2987 if (!strcasecmp(r_texture_cubemaps[i]->basename, basename))
2989 if (i >= MAX_CUBEMAPS || !r_main_mempool)
2990 return r_texture_whitecube;
2993 dp_strlcpy(r_texture_cubemaps[i]->basename, basename, sizeof(r_texture_cubemaps[i]->basename));
2995 return r_texture_cubemaps[i]->texture;
2996}
2997
3010
3011static void R_Main_ResizeViewCache(void)
3012{
3013 int numentities = r_refdef.scene.numentities;
3016 if (r_refdef.viewcache.maxentities < numentities)
3017 {
3018 r_refdef.viewcache.maxentities = numentities;
3022 }
3023 // bones_was_here: r_refdef.viewcache.world_pvsbits was (re)allocated here, now done in Mod_BSP_FatPVS()
3024 if (r_refdef.viewcache.world_numleafs != numleafs)
3025 {
3030 }
3031 if (r_refdef.viewcache.world_numsurfaces != numsurfaces)
3032 {
3033 r_refdef.viewcache.world_numsurfaces = numsurfaces;
3037 }
3038}
3039
3041static void gl_main_start(void)
3042{
3055
3058
3059 switch(vid.renderpath)
3060 {
3061 case RENDERPATH_GL32:
3062 case RENDERPATH_GLES2:
3063 r_loadnormalmap = true;
3064 r_loadgloss = true;
3065 r_loadfog = false;
3066#ifdef GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT
3068#endif
3069 break;
3070 }
3071
3075
3076 r_numqueries = 0;
3077 r_maxqueries = 0;
3078 memset(r_queries, 0, sizeof(r_queries));
3079
3082
3083 // due to caching of texture_t references, the collision cache must be reset
3085
3086 // set up r_skinframe loading system for textures
3087 memset(&r_skinframe, 0, sizeof(r_skinframe));
3090
3095#ifndef USE_GLES2
3097#endif //USE_GLES2
3101 //r_texture_fogintensity = NULL;
3102 memset(&r_fb, 0, sizeof(r_fb));
3107 memset(&r_svbsp, 0, sizeof (r_svbsp));
3108
3109 memset(r_texture_cubemaps, 0, sizeof(r_texture_cubemaps));
3111
3113
3114#ifdef __ANDROID__
3115 // For Steelstorm Android
3116 // FIXME CACHE the program and reload
3117 // FIXME see possible combinations for SS:BR android
3118 Con_DPrintf("Compiling most used shaders for SS:BR android... START\n");
3132 Con_DPrintf("Compiling most used shaders for SS:BR android... END\n");
3133#endif
3134}
3135
3136extern unsigned int r_shadow_occlusion_buf;
3137
3138static void gl_main_shutdown(void)
3139{
3145
3147
3148 switch(vid.renderpath)
3149 {
3150 case RENDERPATH_GL32:
3151 case RENDERPATH_GLES2:
3152#if defined(GL_SAMPLES_PASSED) && !defined(USE_GLES2)
3153 if (r_maxqueries)
3154 qglDeleteQueries(r_maxqueries, r_queries);
3155#endif
3156 break;
3157 }
3159 r_numqueries = 0;
3160 r_maxqueries = 0;
3161 memset(r_queries, 0, sizeof(r_queries));
3162
3165
3166 // clear out the r_skinframe state
3168 memset(&r_skinframe, 0, sizeof(r_skinframe));
3169
3170 if (r_svbsp.nodes)
3172 memset(&r_svbsp, 0, sizeof (r_svbsp));
3185 //r_texture_fogintensity = NULL;
3186 memset(&r_fb, 0, sizeof(r_fb));
3188
3192}
3193
3194static void gl_main_newmap(void)
3195{
3196 // FIXME: move this code to client
3197 char *entities, entname[MAX_QPATH];
3198 if (r_qwskincache)
3202 if (cl.worldmodel)
3203 {
3204 dpsnprintf(entname, sizeof(entname), "%s.ent", cl.worldnamenoextension);
3205 if ((entities = (char *)FS_LoadFile(entname, tempmempool, true, NULL)))
3206 {
3207 CL_ParseEntityLump(entities);
3208 Mem_Free(entities);
3209 return;
3210 }
3211 if (cl.worldmodel->brush.entities)
3212 CL_ParseEntityLump(cl.worldmodel->brush.entities);
3213 }
3215
3218}
3219
3221{
3222 int i;
3223 r_main_mempool = Mem_AllocPool("Renderer", 0, NULL);
3225
3226 Cmd_AddCommand(CF_CLIENT, "r_glsl_restart", R_GLSL_Restart_f, "unloads GLSL shaders, they will then be reloaded as needed");
3227 Cmd_AddCommand(CF_CLIENT, "r_glsl_dumpshader", R_GLSL_DumpShader_f, "dumps the engine internal default.glsl shader into glsl/default.glsl");
3228 // FIXME: the client should set up r_refdef.fog stuff including the fogmasktable
3229 if (gamemode == GAME_NEHAHRA)
3230 {
3239 }
3355
3365
3402 for (i = 0;i < R_BUFFERDATA_COUNT;i++)
3410#ifdef DP_MOBILETOUCH
3411 // GLES devices have terrible depth precision in general, so...
3416#endif
3418}
3419
3420void Render_Init(void)
3421{
3424 GL_Main_Init();
3425 Font_Init();
3426 GL_Draw_Init();
3427 R_Shadow_Init();
3428 R_Sky_Init();
3429 GL_Surf_Init();
3430 Sbar_Init();
3436}
3437
3438static void R_GetCornerOfBox(vec3_t out, const vec3_t mins, const vec3_t maxs, int signbits)
3439{
3440 out[0] = ((signbits & 1) ? mins : maxs)[0];
3441 out[1] = ((signbits & 2) ? mins : maxs)[1];
3442 out[2] = ((signbits & 4) ? mins : maxs)[2];
3443}
3444
3445static qbool _R_CullBox(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes, int ignore)
3446{
3447 int i;
3448 const mplane_t *p;
3449 vec3_t corner;
3450 if (r_trippy.integer)
3451 return false;
3452 for (i = 0;i < numplanes;i++)
3453 {
3454 if(i == ignore)
3455 continue;
3456 p = planes + i;
3457 R_GetCornerOfBox(corner, mins, maxs, p->signbits);
3458 if (DotProduct(p->normal, corner) < p->dist)
3459 return true;
3460 }
3461 return false;
3462}
3463
3465{
3466 // skip nearclip plane, it often culls portals when you are very close, and is almost never useful
3468}
3469
3470qbool R_CullBox(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes)
3471{
3472 // nothing to ignore
3473 return _R_CullBox(mins, maxs, numplanes, planes, -1);
3474}
3475
3476//==================================================================================
3477
3478// LadyHavoc: this stores temporary data used within the same frame
3479
3480typedef struct r_framedata_mem_s
3481{
3482 struct r_framedata_mem_s *purge; // older mem block to free on next frame
3483 size_t size; // how much usable space
3484 size_t current; // how much space in use
3485 size_t mark; // last "mark" location, temporary memory can be freed by returning to this
3486 size_t wantedsize; // how much space was allocated
3487 unsigned char *data; // start of real data (16byte aligned)
3488}
3490
3492
3494{
3495 while (r_framedata_mem)
3496 {
3499 r_framedata_mem = next;
3500 }
3501}
3502
3503static void R_FrameData_Resize(qbool mustgrow)
3504{
3505 size_t wantedsize;
3506 wantedsize = (size_t)(r_framedatasize.value * 1024*1024);
3507 wantedsize = bound(65536, wantedsize, 1000*1024*1024);
3508 if (!r_framedata_mem || r_framedata_mem->wantedsize != wantedsize || mustgrow)
3509 {
3511 newmem->wantedsize = wantedsize;
3512 newmem->data = (unsigned char *)(((size_t)(newmem+1) + 15) & ~15);
3513 newmem->size = (unsigned char *)newmem + wantedsize - newmem->data;
3514 newmem->current = 0;
3515 newmem->mark = 0;
3516 newmem->purge = r_framedata_mem;
3517 r_framedata_mem = newmem;
3518 }
3519}
3520
3522{
3523 R_FrameData_Resize(false);
3524 if (!r_framedata_mem)
3525 return;
3526 // if we ran out of space on the last frame, free the old memory now
3527 while (r_framedata_mem->purge)
3528 {
3529 // repeatedly remove the second item in the list, leaving only head
3530 r_framedata_mem_t *next = r_framedata_mem->purge->purge;
3532 r_framedata_mem->purge = next;
3533 }
3534 // reset the current mem pointer
3536 r_framedata_mem->mark = 0;
3537}
3538
3540{
3541 void *data;
3542 float newvalue;
3543
3544 // align to 16 byte boundary - the data pointer is already aligned, so we
3545 // only need to ensure the size of every allocation is also aligned
3546 size = (size + 15) & ~15;
3547
3549 {
3550 // emergency - we ran out of space, allocate more memory
3551 // note: this has no upper-bound, we'll fail to allocate memory eventually and just die
3552 newvalue = r_framedatasize.value * 2.0f;
3553 // upper bound based on architecture - if we try to allocate more than this we could overflow, better to loop until we error out on allocation failure
3554 if (sizeof(size_t) >= 8)
3555 newvalue = bound(0.25f, newvalue, (float)(1ll << 42));
3556 else
3557 newvalue = bound(0.25f, newvalue, (float)(1 << 10));
3558 // this might not be a growing it, but we'll allocate another buffer every time
3560 R_FrameData_Resize(true);
3561 }
3562
3565
3566 // count the usage for stats
3569
3570 return (void *)data;
3571}
3572
3573void *R_FrameData_Store(size_t size, void *data)
3574{
3575 void *d = R_FrameData_Alloc(size);
3576 if (d && data)
3577 memcpy(d, data, size);
3578 return d;
3579}
3580
3582{
3583 if (!r_framedata_mem)
3584 return;
3586}
3587
3589{
3590 if (!r_framedata_mem)
3591 return;
3593}
3594
3595//==================================================================================
3596
3597// avoid reusing the same buffer objects on consecutive frames
3598#define R_BUFFERDATA_CYCLE 3
3599
3600typedef struct r_bufferdata_buffer_s
3601{
3602 struct r_bufferdata_buffer_s *purge; // older buffer to free on next frame
3603 size_t size; // how much usable space
3604 size_t current; // how much space in use
3605 r_meshbuffer_t *buffer; // the buffer itself
3606}
3608
3609static int r_bufferdata_cycle = 0; // incremented and wrapped each frame
3611
3614{
3615 int cycle, type;
3616 r_bufferdata_buffer_t **p, *mem;
3617 for (cycle = 0;cycle < R_BUFFERDATA_CYCLE;cycle++)
3618 {
3619 for (type = 0;type < R_BUFFERDATA_COUNT;type++)
3620 {
3621 // free all buffers
3622 p = &r_bufferdata_buffer[cycle][type];
3623 while (*p)
3624 {
3625 mem = *p;
3626 *p = (*p)->purge;
3627 if (mem->buffer)
3629 Mem_Free(mem);
3630 }
3631 }
3632 }
3633}
3634
3635// resize buffer as needed (this actually makes a new one, the old one will be recycled next frame)
3636static void R_BufferData_Resize(r_bufferdata_type_t type, qbool mustgrow, size_t minsize)
3637{
3639 size_t size;
3640 float newvalue = r_buffermegs[type].value;
3641
3642 // increase the cvar if we have to (but only if we already have a mem)
3643 if (mustgrow && mem)
3644 newvalue *= 2.0f;
3645 newvalue = bound(0.25f, newvalue, 256.0f);
3646 while (newvalue * 1024*1024 < minsize)
3647 newvalue *= 2.0f;
3648
3649 // clamp the cvar to valid range
3650 newvalue = bound(0.25f, newvalue, 256.0f);
3651 if (r_buffermegs[type].value != newvalue)
3653
3654 // calculate size in bytes
3655 size = (size_t)(newvalue * 1024*1024);
3656 size = bound(131072, size, 256*1024*1024);
3657
3658 // allocate a new buffer if the size is different (purge old one later)
3659 // or if we were told we must grow the buffer
3660 if (!mem || mem->size != size || mustgrow)
3661 {
3662 mem = (r_bufferdata_buffer_t *)Mem_Alloc(r_main_mempool, sizeof(*mem));
3663 mem->size = size;
3664 mem->current = 0;
3666 mem->buffer = R_Mesh_CreateMeshBuffer(NULL, mem->size, "dynamicbuffervertex", false, false, true, false);
3667 else if (type == R_BUFFERDATA_INDEX16)
3668 mem->buffer = R_Mesh_CreateMeshBuffer(NULL, mem->size, "dynamicbufferindex16", true, false, true, true);
3669 else if (type == R_BUFFERDATA_INDEX32)
3670 mem->buffer = R_Mesh_CreateMeshBuffer(NULL, mem->size, "dynamicbufferindex32", true, false, true, false);
3671 else if (type == R_BUFFERDATA_UNIFORM)
3672 mem->buffer = R_Mesh_CreateMeshBuffer(NULL, mem->size, "dynamicbufferuniform", false, true, true, false);
3675 }
3676}
3677
3679{
3680 int type;
3681 r_bufferdata_buffer_t **p, *mem;
3682 // cycle to the next frame's buffers
3684 // if we ran out of space on the last time we used these buffers, free the old memory now
3685 for (type = 0;type < R_BUFFERDATA_COUNT;type++)
3686 {
3688 {
3690 // free all but the head buffer, this is how we recycle obsolete
3691 // buffers after they are no longer in use
3693 while (*p)
3694 {
3695 mem = *p;
3696 *p = (*p)->purge;
3697 if (mem->buffer)
3699 Mem_Free(mem);
3700 }
3701 // reset the current offset
3703 }
3704 }
3705}
3706
3707r_meshbuffer_t *R_BufferData_Store(size_t datasize, const void *data, r_bufferdata_type_t type, int *returnbufferoffset)
3708{
3710 int offset = 0;
3711 int padsize;
3712
3713 *returnbufferoffset = 0;
3714
3715 // align size to a byte boundary appropriate for the buffer type, this
3716 // makes all allocations have aligned start offsets
3718 padsize = (datasize + r_uniformbufferalignment - 1) & ~(r_uniformbufferalignment - 1);
3719 else
3720 padsize = (datasize + 15) & ~15;
3721
3722 // if we ran out of space in this buffer we must allocate a new one
3724 R_BufferData_Resize(type, true, padsize);
3725
3726 // if the resize did not give us enough memory, fail
3728 Sys_Error("R_BufferData_Store: failed to create a new buffer of sufficient size\n");
3729
3731 offset = (int)mem->current;
3732 mem->current += padsize;
3733
3734 // upload the data to the buffer at the chosen offset
3735 if (offset == 0)
3736 R_Mesh_UpdateMeshBuffer(mem->buffer, NULL, mem->size, false, 0);
3737 R_Mesh_UpdateMeshBuffer(mem->buffer, data, datasize, true, offset);
3738
3739 // count the usage for stats
3742
3743 // return the buffer offset
3744 *returnbufferoffset = offset;
3745
3746 return mem->buffer;
3747}
3748
3749//==================================================================================
3750
3751// LadyHavoc: animcache originally written by Echon, rewritten since then
3752
3759{
3760}
3761
3788
3790{
3791 model_t *model = ent->model;
3792 int numvertices;
3793
3794 // see if this ent is worth caching
3795 if (!model || !model->Draw || !model->AnimateVertices)
3796 return false;
3797 // nothing to cache if it contains no animations and has no skeleton
3798 if (!model->surfmesh.isanimated && !(model->num_bones && ent->skeleton && ent->skeleton->relativetransforms))
3799 return false;
3800 // see if it is already cached for gpuskeletal
3802 return false;
3803 // see if it is already cached as a mesh
3804 if (ent->animcache_vertex3f)
3805 {
3806 // check if we need to add normals or tangents
3807 if (ent->animcache_normal3f)
3808 wantnormals = false;
3809 if (ent->animcache_svector3f)
3810 wanttangents = false;
3811 if (!wantnormals && !wanttangents)
3812 return false;
3813 }
3814
3815 // check which kind of cache we need to generate
3816 if (r_gpuskeletal && model->num_bones > 0 && model->surfmesh.data_skeletalindex4ub)
3817 {
3818 // cache the skeleton so the vertex shader can use it
3822 ent->animcache_skeletaltransform3x4 = (float *)R_FrameData_Alloc(sizeof(float[3][4]) * model->num_bones);
3824 // note: this can fail if the buffer is at the grow limit
3825 ent->animcache_skeletaltransform3x4size = sizeof(float[3][4]) * model->num_bones;
3827 }
3828 else if (ent->animcache_vertex3f)
3829 {
3830 // mesh was already cached but we may need to add normals/tangents
3831 // (this only happens with multiple views, reflections, cameras, etc)
3832 if (wantnormals || wanttangents)
3833 {
3834 numvertices = model->surfmesh.num_vertices;
3835 if (wantnormals)
3836 ent->animcache_normal3f = (float *)R_FrameData_Alloc(sizeof(float[3])*numvertices);
3837 if (wanttangents)
3838 {
3839 ent->animcache_svector3f = (float *)R_FrameData_Alloc(sizeof(float[3])*numvertices);
3840 ent->animcache_tvector3f = (float *)R_FrameData_Alloc(sizeof(float[3])*numvertices);
3841 }
3842 model->AnimateVertices(model, ent->frameblend, ent->skeleton, NULL, wantnormals ? ent->animcache_normal3f : NULL, wanttangents ? ent->animcache_svector3f : NULL, wanttangents ? ent->animcache_tvector3f : NULL);
3846 }
3847 }
3848 else
3849 {
3850 // generate mesh cache
3851 numvertices = model->surfmesh.num_vertices;
3852 ent->animcache_vertex3f = (float *)R_FrameData_Alloc(sizeof(float[3])*numvertices);
3853 if (wantnormals)
3854 ent->animcache_normal3f = (float *)R_FrameData_Alloc(sizeof(float[3])*numvertices);
3855 if (wanttangents)
3856 {
3857 ent->animcache_svector3f = (float *)R_FrameData_Alloc(sizeof(float[3])*numvertices);
3858 ent->animcache_tvector3f = (float *)R_FrameData_Alloc(sizeof(float[3])*numvertices);
3859 }
3860 model->AnimateVertices(model, ent->frameblend, ent->skeleton, ent->animcache_vertex3f, ent->animcache_normal3f, ent->animcache_svector3f, ent->animcache_tvector3f);
3861 if (wantnormals || wanttangents)
3862 {
3866 }
3870 }
3871 return true;
3872}
3873
3875{
3876 int i;
3877
3878 // TODO: thread this
3879 // NOTE: R_PrepareRTLights() also caches entities
3880
3881 for (i = 0;i < r_refdef.scene.numentities;i++)
3884}
3885
3886//==================================================================================
3887
3888qbool 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)
3889{
3890 long unsigned int i;
3891 int j;
3892 vec3_t eyemins, eyemaxs;
3893 vec3_t boxmins, boxmaxs;
3894 vec3_t padmins, padmaxs;
3895 vec3_t start;
3896 vec3_t end;
3898 static vec3_t positions[] = {
3899 { 0.5f, 0.5f, 0.5f },
3900 { 0.0f, 0.0f, 0.0f },
3901 { 0.0f, 0.0f, 1.0f },
3902 { 0.0f, 1.0f, 0.0f },
3903 { 0.0f, 1.0f, 1.0f },
3904 { 1.0f, 0.0f, 0.0f },
3905 { 1.0f, 0.0f, 1.0f },
3906 { 1.0f, 1.0f, 0.0f },
3907 { 1.0f, 1.0f, 1.0f },
3908 };
3909
3910 // sample count can be set to -1 to skip this logic, for flicker-prone objects
3911 if (numsamples < 0)
3912 return true;
3913
3914 // view origin is not used for culling in portal/reflection/refraction renders or isometric views
3916 return true;
3917
3918 if (!r_cullentities_trace_entityocclusion.integer && (!model || !model->brush.TraceLineOfSight))
3919 return true;
3920
3921 // expand the eye box a little
3922 eyemins[0] = eye[0] - eyejitter;
3923 eyemaxs[0] = eye[0] + eyejitter;
3924 eyemins[1] = eye[1] - eyejitter;
3925 eyemaxs[1] = eye[1] + eyejitter;
3926 eyemins[2] = eye[2] - eyejitter;
3927 eyemaxs[2] = eye[2] + eyejitter;
3928 // expand the box a little
3929 boxmins[0] = (entboxenlarge + 1) * entboxmins[0] - entboxenlarge * entboxmaxs[0] - entboxexpand;
3930 boxmaxs[0] = (entboxenlarge + 1) * entboxmaxs[0] - entboxenlarge * entboxmins[0] + entboxexpand;
3931 boxmins[1] = (entboxenlarge + 1) * entboxmins[1] - entboxenlarge * entboxmaxs[1] - entboxexpand;
3932 boxmaxs[1] = (entboxenlarge + 1) * entboxmaxs[1] - entboxenlarge * entboxmins[1] + entboxexpand;
3933 boxmins[2] = (entboxenlarge + 1) * entboxmins[2] - entboxenlarge * entboxmaxs[2] - entboxexpand;
3934 boxmaxs[2] = (entboxenlarge + 1) * entboxmaxs[2] - entboxenlarge * entboxmins[2] + entboxexpand;
3935 // make an even larger box for the acceptable area
3936 padmins[0] = boxmins[0] - pad;
3937 padmaxs[0] = boxmaxs[0] + pad;
3938 padmins[1] = boxmins[1] - pad;
3939 padmaxs[1] = boxmaxs[1] + pad;
3940 padmins[2] = boxmins[2] - pad;
3941 padmaxs[2] = boxmaxs[2] + pad;
3942
3943 // return true if eye overlaps enlarged box
3944 if (BoxesOverlap(boxmins, boxmaxs, eyemins, eyemaxs))
3945 return true;
3946
3947 VectorCopy(eye, start);
3948 // try specific positions in the box first - note that these can be cached
3950 {
3951 for (i = 0; i < sizeof(positions) / sizeof(positions[0]); i++)
3952 {
3953 trace_t trace;
3954 end[0] = boxmins[0] + (boxmaxs[0] - boxmins[0]) * positions[i][0];
3955 end[1] = boxmins[1] + (boxmaxs[1] - boxmins[1]) * positions[i][1];
3956 end[2] = boxmins[2] + (boxmaxs[2] - boxmins[2]) * positions[i][2];
3957 //trace_t trace = CL_TraceLine(start, end, MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID, SUPERCONTENTS_SKY, MATERIALFLAGMASK_TRANSLUCENT, 0.0f, true, false, NULL, true, true);
3959 // not picky - if the trace ended anywhere in the box we're good
3960 if (BoxesOverlap(trace.endpos, trace.endpos, padmins, padmaxs))
3961 return true;
3962 }
3963 }
3964 else
3965 {
3966 // try center
3967 VectorMAM(0.5f, boxmins, 0.5f, boxmaxs, end);
3968 if (model->brush.TraceLineOfSight(model, start, end, padmins, padmaxs))
3969 return true;
3970 }
3971
3972 // try various random positions
3973 for (j = 0; j < numsamples; j++)
3974 {
3975 VectorSet(start, lhrandom(eyemins[0], eyemaxs[0]), lhrandom(eyemins[1], eyemaxs[1]), lhrandom(eyemins[2], eyemaxs[2]));
3976 VectorSet(end, lhrandom(boxmins[0], boxmaxs[0]), lhrandom(boxmins[1], boxmaxs[1]), lhrandom(boxmins[2], boxmaxs[2]));
3978 {
3979 trace_t trace = CL_TraceLine(start, end, MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID, SUPERCONTENTS_SKY, MATERIALFLAGMASK_TRANSLUCENT, 0.0f, true, false, NULL, true, true);
3980 // not picky - if the trace ended anywhere in the box we're good
3981 if (BoxesOverlap(trace.endpos, trace.endpos, padmins, padmaxs))
3982 return true;
3983 }
3984 else if (model->brush.TraceLineOfSight(model, start, end, padmins, padmaxs))
3985 return true;
3986 }
3987
3988 return false;
3989}
3990
3991
3993{
3994 int i;
3995 int renderimask;
3996 int samples;
3997 entity_render_t *ent;
3998
4000 renderimask = RENDER_EXTERIORMODEL | RENDER_VIEWMODEL;
4002 renderimask = RENDER_VIEWMODEL;
4003 else
4004 renderimask = RENDER_EXTERIORMODEL;
4006 renderimask |= RENDER_VIEWMODEL;
4008 renderimask |= RENDER_EXTERIORMODEL;
4011 {
4012 // worldmodel can check visibility
4013 for (i = 0;i < r_refdef.scene.numentities;i++)
4014 {
4015 ent = r_refdef.scene.entities[i];
4017 {
4019 continue;
4020 }
4021 if (!(ent->flags & renderimask))
4022 if (!R_CullFrustum(ent->mins, ent->maxs) || (ent->model && ent->model->type == mod_sprite && (ent->model->sprite.sprnum_type == SPR_LABEL || ent->model->sprite.sprnum_type == SPR_LABEL_SCALE)))
4025 }
4026 }
4027 else
4028 {
4029 // no worldmodel or it can't check visibility
4030 for (i = 0;i < r_refdef.scene.numentities;i++)
4031 {
4032 ent = r_refdef.scene.entities[i];
4033 if (!(ent->flags & renderimask))
4034 if (!R_CullFrustum(ent->mins, ent->maxs) || (ent->model && ent->model->type == mod_sprite && (ent->model->sprite.sprnum_type == SPR_LABEL || ent->model->sprite.sprnum_type == SPR_LABEL_SCALE)))
4036 }
4037 }
4039 {
4040 for (i = 0;i < r_refdef.scene.numentities;i++)
4041 {
4043 continue;
4044 ent = r_refdef.scene.entities[i];
4045 if (!(ent->flags & (RENDER_VIEWMODEL | RENDER_WORLDOBJECT | RENDER_NODEPTHTEST)) && !(ent->model && (ent->model->name[0] == '*')))
4046 {
4052 }
4053 }
4054 }
4055}
4056
4058static int R_DrawBrushModelsSky (void)
4059{
4060 int i, sky;
4061 entity_render_t *ent;
4062
4063 sky = false;
4064 for (i = 0;i < r_refdef.scene.numentities;i++)
4065 {
4067 continue;
4068 ent = r_refdef.scene.entities[i];
4069 if (!ent->model || !ent->model->DrawSky)
4070 continue;
4071 ent->model->DrawSky(ent);
4072 sky = true;
4073 }
4074 return sky;
4075}
4076
4077static void R_DrawNoModel(entity_render_t *ent);
4078static void R_DrawModels(void)
4079{
4080 int i;
4081 entity_render_t *ent;
4082
4083 for (i = 0;i < r_refdef.scene.numentities;i++)
4084 {
4086 continue;
4087 ent = r_refdef.scene.entities[i];
4089
4090 if (ent->model && ent->model->Draw != NULL)
4091 ent->model->Draw(ent);
4092 else
4093 R_DrawNoModel(ent);
4094 }
4095}
4096
4097static void R_DrawModelsDepth(void)
4098{
4099 int i;
4100 entity_render_t *ent;
4101
4102 for (i = 0;i < r_refdef.scene.numentities;i++)
4103 {
4105 continue;
4106 ent = r_refdef.scene.entities[i];
4107 if (ent->model && ent->model->DrawDepth != NULL)
4108 ent->model->DrawDepth(ent);
4109 }
4110}
4111
4112static void R_DrawModelsDebug(void)
4113{
4114 int i;
4115 entity_render_t *ent;
4116
4117 for (i = 0;i < r_refdef.scene.numentities;i++)
4118 {
4120 continue;
4121 ent = r_refdef.scene.entities[i];
4122 if (ent->model && ent->model->DrawDebug != NULL)
4123 ent->model->DrawDebug(ent);
4124 }
4125}
4126
4128{
4129 int i;
4130 entity_render_t *ent;
4131
4132 for (i = 0;i < r_refdef.scene.numentities;i++)
4133 {
4135 continue;
4136 ent = r_refdef.scene.entities[i];
4137 if (ent->model && ent->model->DrawAddWaterPlanes != NULL)
4138 ent->model->DrawAddWaterPlanes(ent);
4139 }
4140}
4141
4142static float irisvecs[7][3] = {{0, 0, 0}, {-1, 0, 0}, {1, 0, 0}, {0, -1, 0}, {0, 1, 0}, {0, 0, -1}, {0, 0, 1}};
4143
4145{
4147 {
4148 vec3_t p;
4149 vec3_t ambient;
4150 vec3_t diffuse;
4151 vec3_t diffusenormal;
4153 vec_t brightness = 0.0f;
4154 vec_t goal;
4155 vec_t current;
4156 vec_t d;
4157 int c;
4159 for (c = 0;c < (int)(sizeof(irisvecs)/sizeof(irisvecs[0]));c++)
4160 {
4161 p[0] = point[0] + irisvecs[c][0] * r_hdr_irisadaptation_radius.value;
4162 p[1] = point[1] + irisvecs[c][1] * r_hdr_irisadaptation_radius.value;
4163 p[2] = point[2] + irisvecs[c][2] * r_hdr_irisadaptation_radius.value;
4165 d = DotProduct(forward, diffusenormal);
4166 brightness += VectorLength(ambient);
4167 if (d > 0)
4168 brightness += d * VectorLength(diffuse);
4169 }
4170 brightness *= 1.0f / c;
4171 brightness += 0.00001f; // make sure it's never zero
4172 goal = r_hdr_irisadaptation_multiplier.value / brightness;
4175 if (current < goal)
4176 current = min(current + r_hdr_irisadaptation_fade_up.value * cl.realframetime, goal);
4177 else if (current > goal)
4178 current = max(current - r_hdr_irisadaptation_fade_down.value * cl.realframetime, goal);
4179 if (fabs(r_hdr_irisadaptation_value.value - current) > 0.0001f)
4181 }
4182 else if (r_hdr_irisadaptation_value.value != 1.0f)
4184}
4185
4187extern cvar_t r_lockpvs;
4188
4189static void R_View_SetFrustum(const int *scissor)
4190{
4191 int i;
4192 double fpx = +1, fnx = -1, fpy = +1, fny = -1;
4193 vec3_t forward, left, up, origin, v;
4195 return;
4196 if(scissor)
4197 {
4198 // flipped x coordinates (because x points left here)
4199 fpx = 1.0 - 2.0 * (scissor[0] - r_refdef.view.viewport.x) / (double) (r_refdef.view.viewport.width);
4200 fnx = 1.0 - 2.0 * (scissor[0] + scissor[2] - r_refdef.view.viewport.x) / (double) (r_refdef.view.viewport.width);
4201 // non-flipped y coordinates
4202 fny = -1.0 + 2.0 * (scissor[1] - r_refdef.view.viewport.y) / (double) (r_refdef.view.viewport.height);
4203 fpy = -1.0 + 2.0 * (scissor[1] + scissor[3] - r_refdef.view.viewport.y) / (double) (r_refdef.view.viewport.height);
4204 }
4205
4206 // we can't trust r_refdef.view.forward and friends in reflected scenes
4208
4209#if 0
4210 r_refdef.view.frustum[0].normal[0] = 0 - 1.0 / r_refdef.view.frustum_x;
4211 r_refdef.view.frustum[0].normal[1] = 0 - 0;
4212 r_refdef.view.frustum[0].normal[2] = -1 - 0;
4213 r_refdef.view.frustum[1].normal[0] = 0 + 1.0 / r_refdef.view.frustum_x;
4214 r_refdef.view.frustum[1].normal[1] = 0 + 0;
4215 r_refdef.view.frustum[1].normal[2] = -1 + 0;
4216 r_refdef.view.frustum[2].normal[0] = 0 - 0;
4217 r_refdef.view.frustum[2].normal[1] = 0 - 1.0 / r_refdef.view.frustum_y;
4218 r_refdef.view.frustum[2].normal[2] = -1 - 0;
4219 r_refdef.view.frustum[3].normal[0] = 0 + 0;
4220 r_refdef.view.frustum[3].normal[1] = 0 + 1.0 / r_refdef.view.frustum_y;
4221 r_refdef.view.frustum[3].normal[2] = -1 + 0;
4222#endif
4223
4224#if 0
4225 zNear = r_refdef.nearclip;
4226 nudge = 1.0 - 1.0 / (1<<23);
4227 r_refdef.view.frustum[4].normal[0] = 0 - 0;
4228 r_refdef.view.frustum[4].normal[1] = 0 - 0;
4229 r_refdef.view.frustum[4].normal[2] = -1 - -nudge;
4230 r_refdef.view.frustum[4].dist = 0 - -2 * zNear * nudge;
4231 r_refdef.view.frustum[5].normal[0] = 0 + 0;
4232 r_refdef.view.frustum[5].normal[1] = 0 + 0;
4233 r_refdef.view.frustum[5].normal[2] = -1 + -nudge;
4234 r_refdef.view.frustum[5].dist = 0 + -2 * zNear * nudge;
4235#endif
4236
4237
4238
4239#if 0
4240 r_refdef.view.frustum[0].normal[0] = m[3] - m[0];
4241 r_refdef.view.frustum[0].normal[1] = m[7] - m[4];
4242 r_refdef.view.frustum[0].normal[2] = m[11] - m[8];
4243 r_refdef.view.frustum[0].dist = m[15] - m[12];
4244
4245 r_refdef.view.frustum[1].normal[0] = m[3] + m[0];
4246 r_refdef.view.frustum[1].normal[1] = m[7] + m[4];
4247 r_refdef.view.frustum[1].normal[2] = m[11] + m[8];
4248 r_refdef.view.frustum[1].dist = m[15] + m[12];
4249
4250 r_refdef.view.frustum[2].normal[0] = m[3] - m[1];
4251 r_refdef.view.frustum[2].normal[1] = m[7] - m[5];
4252 r_refdef.view.frustum[2].normal[2] = m[11] - m[9];
4253 r_refdef.view.frustum[2].dist = m[15] - m[13];
4254
4255 r_refdef.view.frustum[3].normal[0] = m[3] + m[1];
4256 r_refdef.view.frustum[3].normal[1] = m[7] + m[5];
4257 r_refdef.view.frustum[3].normal[2] = m[11] + m[9];
4258 r_refdef.view.frustum[3].dist = m[15] + m[13];
4259
4260 r_refdef.view.frustum[4].normal[0] = m[3] - m[2];
4261 r_refdef.view.frustum[4].normal[1] = m[7] - m[6];
4262 r_refdef.view.frustum[4].normal[2] = m[11] - m[10];
4263 r_refdef.view.frustum[4].dist = m[15] - m[14];
4264
4265 r_refdef.view.frustum[5].normal[0] = m[3] + m[2];
4266 r_refdef.view.frustum[5].normal[1] = m[7] + m[6];
4267 r_refdef.view.frustum[5].normal[2] = m[11] + m[10];
4268 r_refdef.view.frustum[5].dist = m[15] + m[14];
4269#endif
4270
4272 {
4273 // calculate frustum corners, which are used to calculate deformed frustum planes for shadow caster culling
4274 VectorMAMAM(1024, forward, fnx * 1024.0 * r_refdef.view.frustum_x, left, fny * 1024.0 * r_refdef.view.frustum_y, up, r_refdef.view.frustumcorner[0]);
4275 VectorMAMAM(1024, forward, fpx * 1024.0 * r_refdef.view.frustum_x, left, fny * 1024.0 * r_refdef.view.frustum_y, up, r_refdef.view.frustumcorner[1]);
4276 VectorMAMAM(1024, forward, fnx * 1024.0 * r_refdef.view.frustum_x, left, fpy * 1024.0 * r_refdef.view.frustum_y, up, r_refdef.view.frustumcorner[2]);
4277 VectorMAMAM(1024, forward, fpx * 1024.0 * r_refdef.view.frustum_x, left, fpy * 1024.0 * r_refdef.view.frustum_y, up, r_refdef.view.frustumcorner[3]);
4278
4279 // then the normals from the corners relative to origin
4284
4285 // in a NORMAL view, forward cross left == up
4286 // in a REFLECTED view, forward cross left == down
4287 // so our cross products above need to be adjusted for a left handed coordinate system
4288 CrossProduct(forward, left, v);
4289 if(DotProduct(v, up) < 0)
4290 {
4295 }
4296
4297 // Leaving those out was a mistake, those were in the old code, and they
4298 // fix a reproducable bug in this one: frustum culling got fucked up when viewmatrix was an identity matrix
4299 // I couldn't reproduce it after adding those normalizations. --blub
4304
4305 // make the corners absolute
4310
4311 // one more normal
4313
4319 }
4320 else
4321 {
4322 VectorScale(left, -1.0f, r_refdef.view.frustum[0].normal);
4323 VectorScale(left, 1.0f, r_refdef.view.frustum[1].normal);
4332 }
4334
4336 {
4339 }
4340
4341 for (i = 0;i < r_refdef.view.numfrustumplanes;i++)
4343
4344 // LadyHavoc: note to all quake engine coders, Quake had a special case
4345 // for 90 degrees which assumed a square view (wrong), so I removed it,
4346 // Quake2 has it disabled as well.
4347
4348 // rotate R_VIEWFORWARD right by FOV_X/2 degrees
4349 //RotatePointAroundVector( r_refdef.view.frustum[0].normal, up, forward, -(90 - r_refdef.fov_x / 2));
4350 //r_refdef.view.frustum[0].dist = DotProduct (r_refdef.view.origin, frustum[0].normal);
4351 //PlaneClassify(&frustum[0]);
4352
4353 // rotate R_VIEWFORWARD left by FOV_X/2 degrees
4354 //RotatePointAroundVector( r_refdef.view.frustum[1].normal, up, forward, (90 - r_refdef.fov_x / 2));
4355 //r_refdef.view.frustum[1].dist = DotProduct (r_refdef.view.origin, frustum[1].normal);
4356 //PlaneClassify(&frustum[1]);
4357
4358 // rotate R_VIEWFORWARD up by FOV_X/2 degrees
4359 //RotatePointAroundVector( r_refdef.view.frustum[2].normal, left, forward, -(90 - r_refdef.fov_y / 2));
4360 //r_refdef.view.frustum[2].dist = DotProduct (r_refdef.view.origin, frustum[2].normal);
4361 //PlaneClassify(&frustum[2]);
4362
4363 // rotate R_VIEWFORWARD down by FOV_X/2 degrees
4364 //RotatePointAroundVector( r_refdef.view.frustum[3].normal, left, forward, (90 - r_refdef.fov_y / 2));
4365 //r_refdef.view.frustum[3].dist = DotProduct (r_refdef.view.origin, frustum[3].normal);
4366 //PlaneClassify(&frustum[3]);
4367
4368 // nearclip plane
4369 //VectorCopy(forward, r_refdef.view.frustum[4].normal);
4370 //r_refdef.view.frustum[4].dist = DotProduct (r_refdef.view.origin, frustum[4].normal) + r_nearclip.value;
4371 //PlaneClassify(&frustum[4]);
4372}
4373
4374static void R_View_Update(const int *myscissor)
4375{
4377 R_View_SetFrustum(myscissor);
4380}
4381
4383
4384void R_SetupView(qbool allowwaterclippingplane, int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
4385{
4386 const float *customclipplane = NULL;
4387 float plane[4];
4388 int viewy_adjusted;
4389 if (r_refdef.view.useclipplane && allowwaterclippingplane)
4390 {
4391 // LadyHavoc: couldn't figure out how to make this approach work the same in DPSOFTRAST
4395 dist = r_refdef.view.clipplane.dist;
4396 plane[0] = r_refdef.view.clipplane.normal[0];
4397 plane[1] = r_refdef.view.clipplane.normal[1];
4398 plane[2] = r_refdef.view.clipplane.normal[2];
4399 plane[3] = -dist;
4400 customclipplane = plane;
4401 }
4402
4403 // GL is weird because it's bottom to top, r_refdef.view.y is top to bottom.
4404 // Unless the render target is a FBO...
4405 viewy_adjusted = viewfbo ? viewy : vid.mode.height - viewheight - viewy;
4406
4408 R_Viewport_InitOrtho3D(&r_refdef.view.viewport, &r_refdef.view.matrix, viewx, viewy_adjusted, viewwidth, viewheight, r_refdef.view.ortho_x, r_refdef.view.ortho_y, -r_refdef.farclip, r_refdef.farclip, customclipplane);
4410 R_Viewport_InitPerspectiveInfinite(&r_refdef.view.viewport, &r_refdef.view.matrix, viewx, viewy_adjusted, viewwidth, viewheight, r_refdef.view.frustum_x, r_refdef.view.frustum_y, r_refdef.nearclip, customclipplane);
4411 else
4412 R_Viewport_InitPerspective(&r_refdef.view.viewport, &r_refdef.view.matrix, viewx, viewy_adjusted, viewwidth, viewheight, r_refdef.view.frustum_x, r_refdef.view.frustum_y, r_refdef.nearclip, r_refdef.farclip, customclipplane);
4413 R_Mesh_SetRenderTargets(viewfbo);
4415}
4416
4438
4439void R_ResetViewRendering2D_Common(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight, float x2, float y2)
4440{
4441 r_viewport_t viewport;
4442 int viewy_adjusted;
4443
4445
4446 // GL is weird because it's bottom to top, r_refdef.view.y is top to bottom.
4447 // Unless the render target is a FBO...
4448 viewy_adjusted = viewfbo ? viewy : vid.mode.height - viewheight - viewy;
4449
4450 R_Viewport_InitOrtho(&viewport, &identitymatrix, viewx, viewy_adjusted, viewwidth, viewheight, 0, 0, x2, y2, -10, 100, NULL);
4451 R_Mesh_SetRenderTargets(viewfbo);
4452 R_SetViewport(&viewport);
4453 GL_Scissor(viewport.x, viewport.y, viewport.width, viewport.height);
4454 GL_Color(1, 1, 1, 1);
4457 GL_ScissorTest(false);
4458 GL_DepthMask(false);
4459 GL_DepthRange(0, 1);
4460 GL_DepthTest(false);
4464 GL_PolygonOffset(0, 0);
4465 switch(vid.renderpath)
4466 {
4467 case RENDERPATH_GL32:
4468 case RENDERPATH_GLES2:
4470 break;
4471 }
4473
4475}
4476
4477void R_ResetViewRendering2D(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
4478{
4479 R_ResetViewRendering2D_Common(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight, 1.0f, 1.0f);
4480}
4481
4482void R_ResetViewRendering3D(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
4483{
4484 R_SetupView(true, viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
4486 GL_Color(1, 1, 1, 1);
4489 GL_ScissorTest(true);
4490 GL_DepthMask(true);
4491 GL_DepthRange(0, 1);
4492 GL_DepthTest(true);
4497 switch(vid.renderpath)
4498 {
4499 case RENDERPATH_GL32:
4500 case RENDERPATH_GLES2:
4502 break;
4503 }
4505}
4506
4507/*
4508================
4509R_RenderView_UpdateViewVectors
4510================
4511*/
4513{
4514 // break apart the view matrix into vectors for various purposes
4515 // it is important that this occurs outside the RenderScene function because that can be called from reflection renders, where the vectors come out wrong
4516 // however the r_refdef.view.origin IS updated in RenderScene intentionally - otherwise the sky renders at the wrong origin, etc
4519 // make an inverted copy of the view matrix for tracking sprites
4521}
4522
4524{
4525 unsigned int i, j, end;
4526 end = (unsigned int)Mem_ExpandableArray_IndexRange(&r_fb.rendertargets); // checked
4527 for (i = 0; i < end; i++)
4528 {
4530 // free resources for rendertargets that have not been used for a while
4531 // (note: this check is run after the frame render, so any targets used
4532 // this frame will not be affected even at low framerates)
4533 if (r && (host.realtime - r->lastusetime > 0.2 || force))
4534 {
4535 if (r->fbo)
4537 for (j = 0; j < sizeof(r->colortexture) / sizeof(r->colortexture[0]); j++)
4538 if (r->colortexture[j])
4539 R_FreeTexture(r->colortexture[j]);
4540 if (r->depthtexture)
4541 R_FreeTexture(r->depthtexture);
4543 }
4544 }
4545}
4546
4547static void R_CalcTexCoordsForView(float x, float y, float w, float h, float tw, float th, float *texcoord2f)
4548{
4549 float iw = 1.0f / tw, ih = 1.0f / th, x1, y1, x2, y2;
4550 x1 = x * iw;
4551 x2 = (x + w) * iw;
4552 y1 = (th - y) * ih;
4553 y2 = (th - y - h) * ih;
4554 texcoord2f[0] = x1;
4555 texcoord2f[2] = x2;
4556 texcoord2f[4] = x2;
4557 texcoord2f[6] = x1;
4558 texcoord2f[1] = y1;
4559 texcoord2f[3] = y1;
4560 texcoord2f[5] = y2;
4561 texcoord2f[7] = y2;
4562}
4563
4564r_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)
4565{
4566 unsigned int i, j, end;
4568 char vabuf[256];
4569 // first try to reuse an existing slot if possible
4570 end = (unsigned int)Mem_ExpandableArray_IndexRange(&r_fb.rendertargets); // checked
4571 for (i = 0; i < end; i++)
4572 {
4574 if (r && r->lastusetime != host.realtime && r->texturewidth == texturewidth && r->textureheight == textureheight && r->depthtextype == depthtextype && r->colortextype[0] == colortextype0 && r->colortextype[1] == colortextype1 && r->colortextype[2] == colortextype2 && r->colortextype[3] == colortextype3)
4575 break;
4576 }
4577 if (i == end)
4578 {
4579 // no unused exact match found, so we have to make one in the first unused slot
4581 r->texturewidth = texturewidth;
4582 r->textureheight = textureheight;
4583 r->colortextype[0] = colortextype0;
4584 r->colortextype[1] = colortextype1;
4585 r->colortextype[2] = colortextype2;
4586 r->colortextype[3] = colortextype3;
4587 r->depthtextype = depthtextype;
4588 r->depthisrenderbuffer = depthisrenderbuffer;
4589 for (j = 0; j < 4; j++)
4590 if (r->colortextype[j])
4591 r->colortexture[j] = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "rendertarget%i_%i_type%i", i, j, (int)r->colortextype[j]), r->texturewidth, r->textureheight, NULL, r->colortextype[j], TEXF_RENDERTARGET | TEXF_FORCELINEAR | TEXF_CLAMP, -1, NULL);
4592 if (r->depthtextype)
4593 {
4594 if (r->depthisrenderbuffer)
4595 r->depthtexture = R_LoadTextureRenderBuffer(r_main_texturepool, va(vabuf, sizeof(vabuf), "renderbuffer%i_depth_type%i", i, (int)r->depthtextype), r->texturewidth, r->textureheight, r->depthtextype);
4596 else
4597 r->depthtexture = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "rendertarget%i_depth_type%i", i, (int)r->depthtextype), r->texturewidth, r->textureheight, NULL, r->depthtextype, TEXF_RENDERTARGET | TEXF_FORCELINEAR | TEXF_CLAMP, -1, NULL);
4598 }
4599 r->fbo = R_Mesh_CreateFramebufferObject(r->depthtexture, r->colortexture[0], r->colortexture[1], r->colortexture[2], r->colortexture[3]);
4600 }
4602 r_refdef.stats[r_stat_rendertargets_pixels] += r->texturewidth * r->textureheight;
4603 r->lastusetime = host.realtime;
4604 R_CalcTexCoordsForView(0, 0, r->texturewidth, r->textureheight, r->texturewidth, r->textureheight, r->texcoord2f);
4605 return r;
4606}
4607
4608static void R_Water_StartFrame(int viewwidth, int viewheight)
4609{
4610 int waterwidth, waterheight;
4611
4612 if (viewwidth > (int)vid.maxtexturesize_2d || viewheight > (int)vid.maxtexturesize_2d)
4613 return;
4614
4615 // set waterwidth and waterheight to the water resolution that will be
4616 // used (often less than the screen resolution for faster rendering)
4617 waterwidth = (int)bound(16, viewwidth * r_water_resolutionmultiplier.value, viewwidth);
4618 waterheight = (int)bound(16, viewheight * r_water_resolutionmultiplier.value, viewheight);
4619
4621 waterwidth = waterheight = 0;
4622
4623 // set up variables that will be used in shader setup
4624 r_fb.water.waterwidth = waterwidth;
4625 r_fb.water.waterheight = waterheight;
4626 r_fb.water.texturewidth = waterwidth;
4627 r_fb.water.textureheight = waterheight;
4628 r_fb.water.camerawidth = waterwidth;
4629 r_fb.water.cameraheight = waterheight;
4630 r_fb.water.screenscale[0] = 0.5f;
4631 r_fb.water.screenscale[1] = 0.5f;
4632 r_fb.water.screencenter[0] = 0.5f;
4633 r_fb.water.screencenter[1] = 0.5f;
4634 r_fb.water.enabled = waterwidth != 0;
4635
4638}
4639
4640void R_Water_AddWaterPlane(msurface_t *surface, int entno)
4641{
4642 int planeindex, bestplaneindex, vertexindex;
4643 vec3_t mins, maxs, normal, center, v, n;
4644 vec_t planescore, bestplanescore;
4645 mplane_t plane;
4647 texture_t *t = R_GetCurrentTexture(surface->texture);
4648
4649 rsurface.texture = t;
4651 // if the model has no normals, it's probably off-screen and they were not generated, so don't add it anyway
4653 return;
4654 // average the vertex normals, find the surface bounds (after deformvertexes)
4658 VectorCopy(v, mins);
4659 VectorCopy(v, maxs);
4660 for (vertexindex = 1;vertexindex < rsurface.batchnumvertices;vertexindex++)
4661 {
4665 mins[0] = min(mins[0], v[0]);
4666 mins[1] = min(mins[1], v[1]);
4667 mins[2] = min(mins[2], v[2]);
4668 maxs[0] = max(maxs[0], v[0]);
4669 maxs[1] = max(maxs[1], v[1]);
4670 maxs[2] = max(maxs[2], v[2]);
4671 }
4673 VectorMAM(0.5f, mins, 0.5f, maxs, center);
4674
4675 VectorCopy(normal, plane.normal);
4676 VectorNormalize(plane.normal);
4677 plane.dist = DotProduct(center, plane.normal);
4678 PlaneClassify(&plane);
4679 if (PlaneDiff(r_refdef.view.origin, &plane) < 0)
4680 {
4681 // skip backfaces (except if nocullface is set)
4682// if (!(t->currentmaterialflags & MATERIALFLAG_NOCULLFACE))
4683// return;
4684 VectorNegate(plane.normal, plane.normal);
4685 plane.dist *= -1;
4686 PlaneClassify(&plane);
4687 }
4688
4689
4690 // find a matching plane if there is one
4691 bestplaneindex = -1;
4692 bestplanescore = 1048576.0f;
4693 for (planeindex = 0, p = r_fb.water.waterplanes;planeindex < r_fb.water.numwaterplanes;planeindex++, p++)
4694 {
4695 if(p->camera_entity == t->camera_entity)
4696 {
4697 planescore = 1.0f - DotProduct(plane.normal, p->plane.normal) + fabs(plane.dist - p->plane.dist) * 0.001f;
4698 if (bestplaneindex < 0 || bestplanescore > planescore)
4699 {
4700 bestplaneindex = planeindex;
4701 bestplanescore = planescore;
4702 }
4703 }
4704 }
4705 planeindex = bestplaneindex;
4706
4707 // if this surface does not fit any known plane rendered this frame, add one
4708 if (planeindex < 0 || bestplanescore > 0.001f)
4709 {
4711 {
4712 // store the new plane
4713 planeindex = r_fb.water.numwaterplanes++;
4714 p = r_fb.water.waterplanes + planeindex;
4715 p->plane = plane;
4716 // clear materialflags and pvs
4717 p->materialflags = 0;
4718 p->pvsvalid = false;
4720 VectorCopy(mins, p->mins);
4721 VectorCopy(maxs, p->maxs);
4722 }
4723 else
4724 {
4725 // We're totally screwed.
4726 return;
4727 }
4728 }
4729 else
4730 {
4731 // merge mins/maxs when we're adding this surface to the plane
4732 p = r_fb.water.waterplanes + planeindex;
4733 p->mins[0] = min(p->mins[0], mins[0]);
4734 p->mins[1] = min(p->mins[1], mins[1]);
4735 p->mins[2] = min(p->mins[2], mins[2]);
4736 p->maxs[0] = max(p->maxs[0], maxs[0]);
4737 p->maxs[1] = max(p->maxs[1], maxs[1]);
4738 p->maxs[2] = max(p->maxs[2], maxs[2]);
4739 }
4740 // merge this surface's materialflags into the waterplane
4743 {
4744 // merge this surface's PVS into the waterplane
4747 {
4749 p->pvsvalid = true;
4750 }
4751 }
4752}
4753
4754extern cvar_t r_drawparticles;
4755extern cvar_t r_drawdecals;
4756
4757static void R_Water_ProcessPlanes(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, int viewx, int viewy, int viewwidth, int viewheight)
4758{
4759 int myscissor[4];
4760 r_refdef_view_t originalview;
4761 r_refdef_view_t myview;
4762 int planeindex, qualityreduction = 0, old_r_dynamic = 0, old_r_shadows = 0, old_r_worldrtlight = 0, old_r_dlight = 0, old_r_particles = 0, old_r_decals = 0;
4764 vec3_t visorigin;
4765 r_rendertarget_t *rt;
4766
4767 originalview = r_refdef.view;
4768
4769 // lowquality hack, temporarily shut down some cvars and restore afterwards
4770 qualityreduction = r_water_lowquality.integer;
4771 if (qualityreduction > 0)
4772 {
4773 if (qualityreduction >= 1)
4774 {
4775 old_r_shadows = r_shadows.integer;
4776 old_r_worldrtlight = r_shadow_realtime_world.integer;
4777 old_r_dlight = r_shadow_realtime_dlight.integer;
4781 }
4782 if (qualityreduction >= 2)
4783 {
4784 old_r_dynamic = r_dynamic.integer;
4785 old_r_particles = r_drawparticles.integer;
4786 old_r_decals = r_drawdecals.integer;
4790 }
4791 }
4792
4793 for (planeindex = 0, p = r_fb.water.waterplanes; planeindex < r_fb.water.numwaterplanes; planeindex++, p++)
4794 {
4795 p->rt_reflection = NULL;
4796 p->rt_refraction = NULL;
4797 p->rt_camera = NULL;
4798 }
4799
4800 // render views
4801 r_refdef.view = originalview;
4802 r_refdef.view.showdebug = false;
4805 r_refdef.view.useclipplane = true;
4806 myview = r_refdef.view;
4807 r_fb.water.renderingscene = true;
4808 for (planeindex = 0, p = r_fb.water.waterplanes;planeindex < r_fb.water.numwaterplanes;planeindex++, p++)
4809 {
4811 continue;
4812
4814 {
4816 if (rt->colortexture[0] == NULL || rt->depthtexture == NULL)
4817 goto error;
4818 r_refdef.view = myview;
4822 {
4824 if (R_ScissorForBBox(p->mins, p->maxs, myscissor))
4825 {
4826 p->rt_reflection = NULL;
4827 p->rt_refraction = NULL;
4828 p->rt_camera = NULL;
4829 continue;
4830 }
4831 }
4832
4834 // reflected view origin may be in solid, so don't cull with it
4836 // reverse the cullface settings for this render
4839 // combined pvs (based on what can be seen from each surface center)
4841 {
4842 r_refdef.view.usecustompvs = true;
4843 if (p->pvsvalid)
4845 else
4847 }
4848
4851 GL_ScissorTest(false);
4853 GL_ScissorTest(true);
4854 R_View_Update(r_water_scissormode.integer & 2 ? myscissor : NULL);
4857 GL_Scissor(myscissor[0], myscissor[1], myscissor[2], myscissor[3]);
4858 R_RenderScene(rt->fbo, rt->depthtexture, rt->colortexture[0], 0, 0, rt->texturewidth, rt->textureheight);
4859
4860 r_fb.water.hideplayer = false;
4861 p->rt_reflection = rt;
4862 }
4863
4864 // render the normal view scene and copy into texture
4865 // (except that a clipping plane should be used to hide everything on one side of the water, and the viewer's weapon model should be omitted)
4867 {
4869 if (rt->colortexture[0] == NULL || rt->depthtexture == NULL)
4870 goto error;
4871 r_refdef.view = myview;
4873 {
4875 if (R_ScissorForBBox(p->mins, p->maxs, myscissor))
4876 {
4877 p->rt_reflection = NULL;
4878 p->rt_refraction = NULL;
4879 p->rt_camera = NULL;
4880 continue;
4881 }
4882 }
4883
4884 // combined pvs (based on what can be seen from each surface center)
4886 {
4887 r_refdef.view.usecustompvs = true;
4888 if (p->pvsvalid)
4890 else
4892 }
4893
4895
4899
4901 {
4902 // we need to perform a matrix transform to render the view... so let's get the transformation matrix
4903 r_fb.water.hideplayer = false; // we don't want to hide the player model from these ones
4907 {
4908 r_refdef.view.usecustompvs = true;
4910 }
4911 }
4912
4914
4916 GL_ScissorTest(false);
4918 GL_ScissorTest(true);
4919 R_View_Update(r_water_scissormode.integer & 2 ? myscissor : NULL);
4922 GL_Scissor(myscissor[0], myscissor[1], myscissor[2], myscissor[3]);
4923 R_RenderScene(rt->fbo, rt->depthtexture, rt->colortexture[0], 0, 0, rt->texturewidth, rt->textureheight);
4924
4925 r_fb.water.hideplayer = false;
4926 p->rt_refraction = rt;
4927 }
4928 else if (p->materialflags & MATERIALFLAG_CAMERA)
4929 {
4931 if (rt->colortexture[0] == NULL || rt->depthtexture == NULL)
4932 goto error;
4933 r_refdef.view = myview;
4934
4938
4941 r_refdef.view.frustum_x = 1; // tan(45 * M_PI / 180.0);
4942 r_refdef.view.frustum_y = 1; // tan(45 * M_PI / 180.0);
4943 r_refdef.view.ortho_x = 90; // abused as angle by VM_CL_R_SetView
4944 r_refdef.view.ortho_y = 90; // abused as angle by VM_CL_R_SetView
4945
4946 if(p->camera_entity)
4947 {
4948 // we need to perform a matrix transform to render the view... so let's get the transformation matrix
4950 }
4951
4952 // note: all of the view is used for displaying... so
4953 // there is no use in scissoring
4954
4955 // reverse the cullface settings for this render
4958 // also reverse the view matrix
4959 Matrix4x4_ConcatScale3(&r_refdef.view.matrix, 1, 1, -1); // this serves to invert texcoords in the result, as the copied texture is mapped the wrong way round
4962 {
4963 r_refdef.view.usecustompvs = true;
4965 }
4966
4967 // camera needs no clipplane
4968 r_refdef.view.useclipplane = false;
4969 // TODO: is the camera origin always valid? if so we don't need to clear this
4971
4973
4974 r_fb.water.hideplayer = false;
4975
4977 GL_ScissorTest(false);
4979 GL_ScissorTest(true);
4982 R_RenderScene(rt->fbo, rt->depthtexture, rt->colortexture[0], 0, 0, rt->texturewidth, rt->textureheight);
4983
4984 r_fb.water.hideplayer = false;
4985 p->rt_camera = rt;
4986 }
4987
4988 }
4989 r_fb.water.renderingscene = false;
4990 r_refdef.view = originalview;
4991 R_ResetViewRendering3D(fbo, depthtexture, colortexture, viewx, viewy, viewwidth, viewheight);
4994 goto finish;
4995error:
4996 r_refdef.view = originalview;
4997 r_fb.water.renderingscene = false;
4999 Con_Printf("R_Water_ProcessPlanes: Error: texture creation failed! Turned off r_water.\n");
5000finish:
5001 // lowquality hack, restore cvars
5002 if (qualityreduction > 0)
5003 {
5004 if (qualityreduction >= 1)
5005 {
5006 Cvar_SetValueQuick(&r_shadows, old_r_shadows);
5007 Cvar_SetValueQuick(&r_shadow_realtime_world, old_r_worldrtlight);
5009 }
5010 if (qualityreduction >= 2)
5011 {
5012 Cvar_SetValueQuick(&r_dynamic, old_r_dynamic);
5013 Cvar_SetValueQuick(&r_drawparticles, old_r_particles);
5014 Cvar_SetValueQuick(&r_drawdecals, old_r_decals);
5015 }
5016 }
5017}
5018
5019static void R_Bloom_StartFrame(void)
5020{
5021 int screentexturewidth, screentextureheight;
5023 double scale;
5024
5025 // clear the pointers to rendertargets from last frame as they're stale
5027 r_fb.rt_bloom = NULL;
5028
5029 switch (vid.renderpath)
5030 {
5031 case RENDERPATH_GL32:
5033 if (r_viewfbo.integer == 2) textype = TEXTYPE_COLORBUFFER16F;
5034 if (r_viewfbo.integer == 3) textype = TEXTYPE_COLORBUFFER32F;
5035 break;
5036 case RENDERPATH_GLES2:
5037 r_fb.usedepthtextures = false;
5038 break;
5039 }
5040
5042 {
5043 double actualframetime;
5044 double targetframetime;
5045 double adjust;
5046 actualframetime = r_refdef.lastdrawscreentime;
5047 targetframetime = (1.0 / r_viewscale_fpsscaling_target.value);
5048 adjust = (targetframetime - actualframetime) * r_viewscale_fpsscaling_multiply.value;
5051 {
5052 if (adjust > 0)
5054 else
5056 }
5057 viewscalefpsadjusted += adjust;
5059 }
5060 else
5061 viewscalefpsadjusted = 1.0f;
5062
5064 if (vid.mode.samples)
5065 scale *= sqrt(vid.mode.samples); // supersampling
5066 scale = bound(0.03125f, scale, 4.0f);
5067 screentexturewidth = (int)ceil(r_refdef.view.width * scale);
5068 screentextureheight = (int)ceil(r_refdef.view.height * scale);
5069 screentexturewidth = bound(1, screentexturewidth, (int)vid.maxtexturesize_2d);
5070 screentextureheight = bound(1, screentextureheight, (int)vid.maxtexturesize_2d);
5071
5072 // set bloomwidth and bloomheight to the bloom resolution that will be
5073 // used (often less than the screen resolution for faster rendering)
5074 r_fb.bloomheight = bound(1, r_bloom_resolution.value * 0.75f, screentextureheight);
5075 r_fb.bloomwidth = r_fb.bloomheight * screentexturewidth / screentextureheight;
5076 r_fb.bloomwidth = bound(1, r_fb.bloomwidth, screentexturewidth);
5079
5081 {
5085 }
5086 if (!r_bloom.integer)
5088
5089 // allocate motionblur ghost texture if needed - this is the only persistent texture and is only useful on the main view
5090 if (r_refdef.view.ismain && (r_fb.screentexturewidth != screentexturewidth || r_fb.screentextureheight != screentextureheight || r_fb.textype != textype))
5091 {
5092 if (r_fb.ghosttexture)
5095
5096 r_fb.screentexturewidth = screentexturewidth;
5097 r_fb.screentextureheight = screentextureheight;
5098 r_fb.textype = textype;
5099
5101 {
5102 if (r_motionblur.value > 0 || r_damageblur.value > 0)
5104 r_fb.ghosttexture_valid = false;
5105 }
5106 }
5107
5108 r_fb.rt_screen = R_RenderTarget_Get(screentexturewidth, screentextureheight, TEXTYPE_DEPTHBUFFER24STENCIL8, true, textype, TEXTYPE_UNUSED, TEXTYPE_UNUSED, TEXTYPE_UNUSED);
5109
5110 r_refdef.view.clear = true;
5111}
5112
5113static void R_Bloom_MakeTexture(void)
5114{
5115 int x, range, dir;
5116 float xoffset, yoffset, r, brighten;
5117 float colorscale = r_bloom_colorscale.value;
5118 r_viewport_t bloomviewport;
5119 r_rendertarget_t *prev, *cur;
5120 textype_t textype = r_fb.rt_screen->colortextype[0];
5121
5123
5124 R_Viewport_InitOrtho(&bloomviewport, &identitymatrix, 0, 0, r_fb.bloomwidth, r_fb.bloomheight, 0, 0, 1, 1, -10, 100, NULL);
5125
5126 // scale down screen texture to the bloom texture size
5128 prev = r_fb.rt_screen;
5131 R_SetViewport(&bloomviewport);
5133 GL_DepthTest(false);
5135 GL_Color(colorscale, colorscale, colorscale, 1);
5137 // TODO: do boxfilter scale-down in shader?
5138 R_SetupShader_Generic(prev->colortexture[0], false, true, true);
5141 // we now have a properly scaled bloom image
5142
5143 // multiply bloom image by itself as many times as desired to darken it
5144 // TODO: if people actually use this it could be done more quickly in the previous shader pass
5145 for (x = 1;x < min(r_bloom_colorexponent.value, 32);)
5146 {
5147 prev = cur;
5150 x *= 2;
5151 r = bound(0, r_bloom_colorexponent.value / x, 1); // always 0.5 to 1
5152 if(x <= 2)
5154 GL_BlendFunc(GL_SRC_COLOR, GL_ZERO); // square it
5155 GL_Color(1,1,1,1); // no fix factor supported here
5157 R_SetupShader_Generic(prev->colortexture[0], false, true, false);
5160 }
5162
5163 range = r_bloom_blur.integer * r_fb.bloomwidth / 320;
5164 brighten = r_bloom_brighten.value;
5165 brighten = sqrt(brighten);
5166 if(range >= 1)
5167 brighten *= (3 * range) / (2 * range - 1); // compensate for the "dot particle"
5168
5169 for (dir = 0;dir < 2;dir++)
5170 {
5171 prev = cur;
5174 // blend on at multiple vertical offsets to achieve a vertical blur
5175 // TODO: do offset blends using GLSL
5176 // TODO instead of changing the texcoords, change the target positions to prevent artifacts at edges
5180 R_SetupShader_Generic(prev->colortexture[0], false, true, false);
5182 for (x = -range;x <= range;x++)
5183 {
5184 if (!dir){xoffset = 0;yoffset = x;}
5185 else {xoffset = x;yoffset = 0;}
5186 xoffset /= (float)prev->texturewidth;
5187 yoffset /= (float)prev->textureheight;
5188 // compute a texcoord array with the specified x and y offset
5197 // this r value looks like a 'dot' particle, fading sharply to
5198 // black at the edges
5199 // (probably not realistic but looks good enough)
5200 //r = ((range*range+1)/((float)(x*x+1)))/(range*2+1);
5201 //r = brighten/(range*2+1);
5202 r = brighten / (range * 2 + 1);
5203 if(range >= 1)
5204 r *= (1 - x*x/(float)((range+1)*(range+1)));
5205 if (r <= 0)
5206 continue;
5208 GL_Color(r, r, r, 1);
5217 }
5218 }
5219
5220 // now we have the bloom image, so keep track of it
5221 r_fb.rt_bloom = cur;
5222}
5223
5224static qbool R_BlendView_IsTrivial(int viewwidth, int viewheight, int width, int height)
5225{
5226 // Scaling requested?
5227 if (viewwidth != width || viewheight != height)
5228 return false;
5229 // Higher bit depth or explicit FBO requested?
5230 if (r_viewfbo.integer)
5231 return false;
5232 // Non-trivial postprocessing shader permutation?
5233 if (r_fb.bloomwidth
5234 || r_refdef.viewblend[3] > 0
5238 return false;
5239 // Other reasons for a non-trivial default postprocessing shader?
5240 // (See R_CompileShader_CheckStaticParms but only those relevant for MODE_POSTPROCESS in shader_glsl.h)
5241 // Skip: if (r_glsl_saturation_redcompensate.integer) (already covered by saturation above).
5242 // Skip: if (r_glsl_postprocess.integer) (already covered by r_glsl_postprocess above).
5243 // Skip: if (r_glsl_postprocess_uservec1_enable.integer) (already covered by r_glsl_postprocessing above).
5244 if (r_fxaa.integer)
5245 return false;
5246 if (r_colorfringe.value)
5247 return false;
5248 return true;
5249}
5250
5251static void R_MotionBlurView(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
5252{
5254
5256 {
5257 // declare variables
5258 float blur_factor, blur_mouseaccel, blur_velocity;
5259 static float blur_average;
5260 static vec3_t blur_oldangles; // used to see how quickly the mouse is moving
5261
5262 // set a goal for the factoring
5265 blur_mouseaccel = bound(0, ((fabs(VectorLength(cl.viewangles) - VectorLength(blur_oldangles)) * 10) - r_motionblur_mousefactor_minspeed.value)
5267 blur_factor = ((blur_velocity * r_motionblur_velocityfactor.value)
5268 + (blur_mouseaccel * r_motionblur_mousefactor.value));
5269
5270 // from the goal, pick an averaged value between goal and last value
5272 blur_average = blur_average * (1 - cl.motionbluralpha) + blur_factor * cl.motionbluralpha;
5273
5274 // enforce minimum amount of blur
5275 blur_factor = blur_average * (1 - r_motionblur_minblur.value) + r_motionblur_minblur.value;
5276
5277 //Con_Printf("motionblur: direct factor: %f, averaged factor: %f, velocity: %f, mouse accel: %f \n", blur_factor, blur_average, blur_velocity, blur_mouseaccel);
5278
5279 // calculate values into a standard alpha
5280 cl.motionbluralpha = 1 - exp(-
5281 (
5282 (r_motionblur.value * blur_factor / 80)
5283 +
5285 )
5286 /
5287 max(0.0001, cl.time - cl.oldtime) // fps independent
5288 );
5289
5290 // randomization for the blur value to combat persistent ghosting
5293
5294 // apply the blur on top of the current view
5295 R_ResetViewRendering2D(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
5297 {
5299 GL_Color(1, 1, 1, cl.motionbluralpha);
5300 R_CalcTexCoordsForView(0, 0, viewwidth, viewheight, viewwidth, viewheight, r_fb.ghosttexcoord2f);
5302 R_SetupShader_Generic(r_fb.ghosttexture, false, true, true);
5304 r_refdef.stats[r_stat_bloom_drawpixels] += viewwidth * viewheight;
5305 }
5306
5307 // updates old view angles for next pass
5308 VectorCopy(cl.viewangles, blur_oldangles);
5309
5310 // copy view into the ghost texture
5311 R_Mesh_CopyToTexture(r_fb.ghosttexture, 0, 0, viewx, viewy, viewwidth, viewheight);
5312 r_refdef.stats[r_stat_bloom_copypixels] += viewwidth * viewheight;
5313 r_fb.ghosttexture_valid = true;
5314 }
5315}
5316
5317static void R_BlendView(rtexture_t *viewcolortexture, int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, int x, int y, int width, int height)
5318{
5319 uint64_t permutation;
5320 float uservecs[4][4];
5321 rtexture_t *viewtexture;
5322 rtexture_t *bloomtexture;
5323
5325
5326 if (r_fb.bloomwidth)
5327 {
5328 // make the bloom texture
5330 }
5331
5332#if _MSC_VER >= 1400
5333#define sscanf sscanf_s
5334#endif
5335 memset(uservecs, 0, sizeof(uservecs));
5337 sscanf(r_glsl_postprocess_uservec1.string, "%f %f %f %f", &uservecs[0][0], &uservecs[0][1], &uservecs[0][2], &uservecs[0][3]);
5339 sscanf(r_glsl_postprocess_uservec2.string, "%f %f %f %f", &uservecs[1][0], &uservecs[1][1], &uservecs[1][2], &uservecs[1][3]);
5341 sscanf(r_glsl_postprocess_uservec3.string, "%f %f %f %f", &uservecs[2][0], &uservecs[2][1], &uservecs[2][2], &uservecs[2][3]);
5343 sscanf(r_glsl_postprocess_uservec4.string, "%f %f %f %f", &uservecs[3][0], &uservecs[3][1], &uservecs[3][2], &uservecs[3][3]);
5344
5345 // render to the screen fbo
5346 R_ResetViewRendering2D(fbo, depthtexture, colortexture, x, y, width, height);
5347 GL_Color(1, 1, 1, 1);
5349
5350 viewtexture = viewcolortexture;
5351 bloomtexture = r_fb.rt_bloom ? r_fb.rt_bloom->colortexture[0] : NULL;
5352
5354 {
5356 if (rt && rt->colortexture[0])
5357 {
5358 viewtexture = rt->colortexture[0];
5359 bloomtexture = NULL;
5360 }
5361 }
5362
5364 switch(vid.renderpath)
5365 {
5366 case RENDERPATH_GL32:
5367 case RENDERPATH_GLES2:
5368 permutation =
5380 if (r_glsl_permutation->loc_UserVec1 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec1 , uservecs[0][0], uservecs[0][1], uservecs[0][2], uservecs[0][3]);
5381 if (r_glsl_permutation->loc_UserVec2 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec2 , uservecs[1][0], uservecs[1][1], uservecs[1][2], uservecs[1][3]);
5382 if (r_glsl_permutation->loc_UserVec3 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec3 , uservecs[2][0], uservecs[2][1], uservecs[2][2], uservecs[2][3]);
5383 if (r_glsl_permutation->loc_UserVec4 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec4 , uservecs[3][0], uservecs[3][1], uservecs[3][2], uservecs[3][3]);
5388 break;
5389 }
5392}
5393
5395
5396void R_UpdateFog(void)
5397{
5398 // Nehahra fog
5399 if (gamemode == GAME_NEHAHRA)
5400 {
5402 {
5408 r_refdef.fog_alpha = 1;
5409 r_refdef.fog_start = 0;
5411 r_refdef.fog_height = 1<<30;
5412 r_refdef.fog_fadedepth = 128;
5413 }
5414 else if (r_refdef.oldgl_fogenable)
5415 {
5416 r_refdef.oldgl_fogenable = false;
5418 r_refdef.fog_red = 0;
5419 r_refdef.fog_green = 0;
5420 r_refdef.fog_blue = 0;
5421 r_refdef.fog_alpha = 0;
5422 r_refdef.fog_start = 0;
5423 r_refdef.fog_end = 0;
5424 r_refdef.fog_height = 1<<30;
5425 r_refdef.fog_fadedepth = 128;
5426 }
5427 }
5428
5429 // fog parms
5433
5435 {
5436 r_refdef.fogenabled = true;
5437 // this is the point where the fog reaches 0.9986 alpha, which we
5438 // consider a good enough cutoff point for the texture
5439 // (0.9986 * 256 == 255.6)
5440 if (r_fog_exp2.integer)
5442 else
5449 // fog color was already set
5450 // update the fog texture
5455 }
5456 else
5457 r_refdef.fogenabled = false;
5458
5459 // fog color
5461 {
5465
5470
5471 {
5472 vec3_t fogvec;
5473 VectorCopy(r_refdef.fogcolor, fogvec);
5474 // color.rgb *= ContrastBoost * SceneBrightness;
5475 VectorScale(fogvec, r_refdef.view.colorscale, fogvec);
5476 r_refdef.fogcolor[0] = bound(0.0f, fogvec[0], 1.0f);
5477 r_refdef.fogcolor[1] = bound(0.0f, fogvec[1], 1.0f);
5478 r_refdef.fogcolor[2] = bound(0.0f, fogvec[2], 1.0f);
5479 }
5480 }
5481}
5482
5484{
5486
5487 r_refdef.scene.ambientintensity = r_ambient.value * (1.0f / 64.0f);
5488
5493
5498
5505 {
5507
5508 // Apply the default lightstyle to the lightmap even on q3bsp
5509 if (cl.worldmodel && cl.worldmodel->type == mod_brushq3) {
5511 }
5512 }
5514 {
5515 r_refdef.scene.rtworld = false;
5517 r_refdef.scene.rtdlight = false;
5520 }
5521
5522 r_gpuskeletal = false;
5523 switch(vid.renderpath)
5524 {
5525 case RENDERPATH_GL32:
5527 case RENDERPATH_GLES2:
5529 {
5531 {
5532 // build GLSL gamma texture
5533#define RAMPWIDTH 256
5534 unsigned short ramp[RAMPWIDTH * 3];
5535 unsigned char rampbgr[RAMPWIDTH][4];
5536 int i;
5537
5539
5541 for(i = 0; i < RAMPWIDTH; ++i)
5542 {
5543 rampbgr[i][0] = (unsigned char) (ramp[i + 2 * RAMPWIDTH] * 255.0 / 65535.0 + 0.5);
5544 rampbgr[i][1] = (unsigned char) (ramp[i + RAMPWIDTH] * 255.0 / 65535.0 + 0.5);
5545 rampbgr[i][2] = (unsigned char) (ramp[i] * 255.0 / 65535.0 + 0.5);
5546 rampbgr[i][3] = 0;
5547 }
5549 {
5550 R_UpdateTexture(r_texture_gammaramps, &rampbgr[0][0], 0, 0, 0, RAMPWIDTH, 1, 1, 0);
5551 }
5552 else
5553 {
5555 }
5556 }
5557 }
5558 else
5559 {
5560 // remove GLSL gamma texture
5561 }
5562 break;
5563 }
5564}
5565
5568/*
5569================
5570R_SelectScene
5571================
5572*/
5574 if( scenetype != r_currentscenetype ) {
5575 // store the old scenetype
5577 r_currentscenetype = scenetype;
5578 // move in the new scene
5580 }
5581}
5582
5583/*
5584================
5585R_GetScenePointer
5586================
5587*/
5589{
5590 // of course, we could also add a qbool that provides a lock state and a ReleaseScenePointer function..
5591 if( scenetype == r_currentscenetype ) {
5592 return &r_refdef.scene;
5593 } else {
5594 return &r_scenes_store[ scenetype ];
5595 }
5596}
5597
5598static int R_SortEntities_Compare(const void *ap, const void *bp)
5599{
5600 const entity_render_t *a = *(const entity_render_t **)ap;
5601 const entity_render_t *b = *(const entity_render_t **)bp;
5602
5603 // 1. compare model
5604 if(a->model < b->model)
5605 return -1;
5606 if(a->model > b->model)
5607 return +1;
5608
5609 // 2. compare skin
5610 // TODO possibly calculate the REAL skinnum here first using
5611 // skinscenes?
5612 if(a->skinnum < b->skinnum)
5613 return -1;
5614 if(a->skinnum > b->skinnum)
5615 return +1;
5616
5617 // everything we compared is equal
5618 return 0;
5619}
5620static void R_SortEntities(void)
5621{
5622 // below or equal 2 ents, sorting never gains anything
5623 if(r_refdef.scene.numentities <= 2)
5624 return;
5625 // sort
5627}
5628
5629/*
5630================
5631R_RenderView
5632================
5633*/
5635extern cvar_t v_isometric;
5636extern void V_MakeViewIsometric(void);
5637void R_RenderView(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, int x, int y, int width, int height)
5638{
5639 matrix4x4_t originalmatrix = r_refdef.view.matrix, offsetmatrix;
5640 int viewfbo = 0;
5641 rtexture_t *viewdepthtexture = NULL;
5642 rtexture_t *viewcolortexture = NULL;
5643 int viewx = r_refdef.view.x, viewy = r_refdef.view.y, viewwidth = r_refdef.view.width, viewheight = r_refdef.view.height;
5644 qbool skipblend;
5645
5646 // finish any 2D rendering that was queued
5647 DrawQ_Finish();
5648
5650 R_TimeReport("start");
5651 r_textureframe++; // used only by R_GetCurrentTexture
5652 rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveModelEntity
5653
5656
5659 else if (r_sortentities.integer)
5661
5663
5664 /* adjust for stereo display */
5665 if(R_Stereo_Active())
5666 {
5667 Matrix4x4_CreateFromQuakeEntity(&offsetmatrix, 0, r_stereo_separation.value * (0.5f - r_stereo_side), 0, 0, r_stereo_angle.value * (0.5f - r_stereo_side), 0, 1);
5668 Matrix4x4_Concat(&r_refdef.view.matrix, &originalmatrix, &offsetmatrix);
5669 }
5670
5672 {
5673 // TODO: FIXME: move this into its own backend function maybe? [2/5/2008 Andreas]
5676 R_TimeReport("depthclear");
5677
5678 r_refdef.view.showdebug = false;
5679
5680 r_fb.water.enabled = false;
5682
5684
5685 r_refdef.view.matrix = originalmatrix;
5686
5688 return;
5689 }
5690
5691 if (!r_refdef.scene.entities || r_refdef.view.width * r_refdef.view.height == 0 || !r_renderview.integer || cl_videoplaying/* || !r_refdef.scene.worldmodel*/)
5692 {
5693 r_refdef.view.matrix = originalmatrix;
5694 return;
5695 }
5696
5700
5702
5704 // in sRGB fallback, behave similar to true sRGB: convert this
5705 // value from linear to sRGB
5707
5709
5711
5712 // this will set up r_fb.rt_screen
5714
5715 // apply bloom brightness offset
5716 if(r_fb.rt_bloom)
5718
5720 if (skipblend)
5721 {
5722 // Render to the screen right away.
5723 viewfbo = fbo;
5724 viewdepthtexture = depthtexture;
5725 viewcolortexture = colortexture;
5726 viewx = x;
5727 viewy = y;
5728 viewwidth = width;
5729 viewheight = height;
5730 }
5731 else if (r_fb.rt_screen)
5732 {
5733 // R_Bloom_StartFrame probably set up an fbo for us to render into, it will be rendered to the window later in R_BlendView
5734 viewfbo = r_fb.rt_screen->fbo;
5735 viewdepthtexture = r_fb.rt_screen->depthtexture;
5736 viewcolortexture = r_fb.rt_screen->colortexture[0];
5737 viewx = 0;
5738 viewy = 0;
5739 viewwidth = r_fb.rt_screen->texturewidth;
5740 viewheight = r_fb.rt_screen->textureheight;
5741 }
5742
5743 R_Water_StartFrame(viewwidth, viewheight);
5744
5747 R_TimeReport("viewsetup");
5748
5749 R_ResetViewRendering3D(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
5750
5751 // clear the whole fbo every frame - otherwise the driver will consider
5752 // it to be an inter-frame texture and stall in multi-gpu configurations
5753 if (r_fb.rt_screen)
5754 GL_ScissorTest(false);
5757 R_TimeReport("viewclear");
5758
5759 r_refdef.view.clear = true;
5760
5761 r_refdef.view.showdebug = true;
5762
5765 R_TimeReport("visibility");
5766
5769 R_TimeReport("animcache");
5770
5772 // R_Shadow_UpdateBounceGridTexture called R_TimeReport a few times internally, so we don't need to do that here.
5773
5775 if (r_fb.water.enabled)
5776 R_RenderWaterPlanes(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
5777
5778 // for the actual view render we use scissoring a fair amount, so scissor
5779 // test needs to be on
5780 if (r_fb.rt_screen)
5781 GL_ScissorTest(true);
5783 R_RenderScene(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
5785
5786 // postprocess uses textures that are not aligned with the viewport we're rendering, so no scissoring
5787 GL_ScissorTest(false);
5788
5789 R_MotionBlurView(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
5790 if (!skipblend)
5791 R_BlendView(viewcolortexture, fbo, depthtexture, colortexture, x, y, width, height);
5793 R_TimeReport("blendview");
5794
5795 r_refdef.view.matrix = originalmatrix;
5796
5798
5799 // go back to 2d rendering
5800 DrawQ_Start();
5801}
5802
5803void R_RenderWaterPlanes(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
5804{
5806 {
5809 R_TimeReport("waterworld");
5810 }
5811
5814 R_TimeReport("watermodels");
5815
5817 {
5818 R_Water_ProcessPlanes(viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
5820 R_TimeReport("waterscenes");
5821 }
5822}
5823
5824extern cvar_t cl_locs_show;
5825static void R_DrawLocs(void);
5826static void R_DrawEntityBBoxes(prvm_prog_t *prog);
5827static void R_DrawModelDecals(void);
5830void R_RenderScene(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
5831{
5832 qbool shadowmapping = false;
5833
5835 R_TimeReport("beginscene");
5836
5838
5839 R_UpdateFog();
5840
5842
5844
5846
5848 R_TimeReport("skystartframe");
5849
5851 {
5853 {
5856 R_TimeReport("worldsky");
5857 }
5858
5860 R_TimeReport("bmodelsky");
5861
5863 {
5864 // we have to force off the water clipping plane while rendering sky
5865 R_SetupView(false, viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
5866 R_Sky();
5867 R_SetupView(true, viewfbo, viewdepthtexture, viewcolortexture, viewx, viewy, viewwidth, viewheight);
5869 R_TimeReport("sky");
5870 }
5871 }
5872
5873 // save the framebuffer info for R_Shadow_RenderMode_Reset during this view render
5874 r_shadow_viewfbo = viewfbo;
5875 r_shadow_viewdepthtexture = viewdepthtexture;
5876 r_shadow_viewcolortexture = viewcolortexture;
5877 r_shadow_viewx = viewx;
5878 r_shadow_viewy = viewy;
5879 r_shadow_viewwidth = viewwidth;
5880 r_shadow_viewheight = viewheight;
5881
5885 R_TimeReport("preparelights");
5886
5887 // render all the shadowmaps that will be used for this view
5888 shadowmapping = R_Shadow_ShadowMappingEnabled();
5889 if (shadowmapping || r_shadow_shadowmapatlas_modelshadows_size)
5890 {
5893 R_TimeReport("shadowmaps");
5894 }
5895
5896 // render prepass deferred lighting if r_shadow_deferred is on, this produces light buffers that will be sampled in forward pass
5899
5900 // now we begin the forward pass of the view render
5902 {
5905 R_TimeReport("worlddepth");
5906 }
5907 if (r_depthfirst.integer >= 2)
5908 {
5911 R_TimeReport("modeldepth");
5912 }
5913
5915 {
5918 R_TimeReport("world");
5919 }
5920
5921 R_DrawModels();
5923 R_TimeReport("models");
5924
5926 {
5929 R_TimeReport("rtlights");
5930 }
5931
5933 {
5936 R_TimeReport("modeldecals");
5937
5940 R_TimeReport("particles");
5941
5944 R_TimeReport("explosions");
5945 }
5946
5948 {
5950 {
5951 R_DrawLocs();
5953 R_TimeReport("showlocs");
5954 }
5955
5957 {
5958 R_DrawPortals();
5960 R_TimeReport("portals");
5961 }
5962
5963 if (r_showbboxes_client.value > 0)
5964 {
5967 R_TimeReport("clbboxes");
5968 }
5969 if (r_showbboxes.value > 0)
5970 {
5973 R_TimeReport("svbboxes");
5974 }
5975 }
5976
5978 {
5981 R_TimeReport("drawtrans");
5982 }
5983
5985 {
5988 R_TimeReport("worlddebug");
5991 R_TimeReport("modeldebug");
5992 }
5993
5995 {
5998 R_TimeReport("coronas");
5999 }
6000}
6001
6002static const unsigned short bboxelements[36] =
6003{
6004 5, 1, 3, 5, 3, 7,
6005 6, 2, 0, 6, 0, 4,
6006 7, 3, 2, 7, 2, 6,
6007 4, 0, 1, 4, 1, 5,
6008 4, 5, 7, 4, 7, 6,
6009 1, 0, 2, 1, 2, 3,
6010};
6011
6012#define BBOXEDGES 13
6013static const float bboxedges[BBOXEDGES][6] =
6014{
6015 // whole box
6016 { 0, 0, 0, 1, 1, 1 },
6017 // bottom edges
6018 { 0, 0, 0, 0, 1, 0 },
6019 { 0, 0, 0, 1, 0, 0 },
6020 { 0, 1, 0, 1, 1, 0 },
6021 { 1, 0, 0, 1, 1, 0 },
6022 // top edges
6023 { 0, 0, 1, 0, 1, 1 },
6024 { 0, 0, 1, 1, 0, 1 },
6025 { 0, 1, 1, 1, 1, 1 },
6026 { 1, 0, 1, 1, 1, 1 },
6027 // vertical edges
6028 { 0, 0, 0, 0, 0, 1 },
6029 { 1, 0, 0, 1, 0, 1 },
6030 { 0, 1, 0, 0, 1, 1 },
6031 { 1, 1, 0, 1, 1, 1 },
6032};
6033
6034static void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, float ca)
6035{
6036 int numvertices = BBOXEDGES * 8;
6037 float vertex3f[BBOXEDGES * 8 * 3], color4f[BBOXEDGES * 8 * 4];
6038 int numtriangles = BBOXEDGES * 12;
6039 unsigned short elements[BBOXEDGES * 36];
6040 int i, edge;
6041 float *v, *c, f1, f2, edgemins[3], edgemaxs[3];
6042
6043 RSurf_ActiveModelEntity(r_refdef.scene.worldentity, false, false, false);
6044
6046 GL_DepthMask(false);
6047 GL_DepthRange(0, 1);
6049
6050 for (edge = 0; edge < BBOXEDGES; edge++)
6051 {
6052 for (i = 0; i < 3; i++)
6053 {
6054 edgemins[i] = mins[i] + (maxs[i] - mins[i]) * bboxedges[edge][i] - 0.25f;
6055 edgemaxs[i] = mins[i] + (maxs[i] - mins[i]) * bboxedges[edge][3 + i] + 0.25f;
6056 }
6057 vertex3f[edge * 24 + 0] = edgemins[0]; vertex3f[edge * 24 + 1] = edgemins[1]; vertex3f[edge * 24 + 2] = edgemins[2];
6058 vertex3f[edge * 24 + 3] = edgemaxs[0]; vertex3f[edge * 24 + 4] = edgemins[1]; vertex3f[edge * 24 + 5] = edgemins[2];
6059 vertex3f[edge * 24 + 6] = edgemins[0]; vertex3f[edge * 24 + 7] = edgemaxs[1]; vertex3f[edge * 24 + 8] = edgemins[2];
6060 vertex3f[edge * 24 + 9] = edgemaxs[0]; vertex3f[edge * 24 + 10] = edgemaxs[1]; vertex3f[edge * 24 + 11] = edgemins[2];
6061 vertex3f[edge * 24 + 12] = edgemins[0]; vertex3f[edge * 24 + 13] = edgemins[1]; vertex3f[edge * 24 + 14] = edgemaxs[2];
6062 vertex3f[edge * 24 + 15] = edgemaxs[0]; vertex3f[edge * 24 + 16] = edgemins[1]; vertex3f[edge * 24 + 17] = edgemaxs[2];
6063 vertex3f[edge * 24 + 18] = edgemins[0]; vertex3f[edge * 24 + 19] = edgemaxs[1]; vertex3f[edge * 24 + 20] = edgemaxs[2];
6064 vertex3f[edge * 24 + 21] = edgemaxs[0]; vertex3f[edge * 24 + 22] = edgemaxs[1]; vertex3f[edge * 24 + 23] = edgemaxs[2];
6065 for (i = 0; i < 36; i++)
6066 elements[edge * 36 + i] = edge * 8 + bboxelements[i];
6067 }
6068 R_FillColors(color4f, numvertices, cr, cg, cb, ca);
6069 if (r_refdef.fogenabled)
6070 {
6071 for (i = 0, v = vertex3f, c = color4f; i < numvertices; i++, v += 3, c += 4)
6072 {
6073 f1 = RSurf_FogVertex(v);
6074 f2 = 1 - f1;
6075 c[0] = c[0] * f1 + r_refdef.fogcolor[0] * f2;
6076 c[1] = c[1] * f1 + r_refdef.fogcolor[1] * f2;
6077 c[2] = c[2] * f1 + r_refdef.fogcolor[2] * f2;
6078 }
6079 }
6080 R_Mesh_PrepareVertices_Generic_Arrays(numvertices, vertex3f, color4f, NULL);
6082 R_SetupShader_Generic_NoTexture(false, false);
6083 R_Mesh_Draw(0, numvertices, 0, numtriangles, NULL, NULL, 0, elements, NULL, 0);
6084}
6085
6086static void R_DrawEntityBBoxes_Callback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
6087{
6088 // hacky overloading of the parameters
6089 prvm_prog_t *prog = (prvm_prog_t *)rtlight;
6090 int i;
6091 float color[4];
6092 prvm_edict_t *edict;
6093
6095 R_SetupShader_Generic_NoTexture(false, false);
6096
6097 for (i = 0;i < numsurfaces;i++)
6098 {
6099 edict = PRVM_EDICT_NUM(surfacelist[i]);
6100 switch ((int)PRVM_serveredictfloat(edict, solid))
6101 {
6102 case SOLID_NOT: Vector4Set(color, 1, 1, 1, 0.05);break;
6103 case SOLID_TRIGGER: Vector4Set(color, 1, 0, 1, 0.10);break;
6104 case SOLID_BBOX: Vector4Set(color, 0, 1, 0, 0.10);break;
6105 case SOLID_SLIDEBOX: Vector4Set(color, 1, 0, 0, 0.10);break;
6106 case SOLID_BSP: Vector4Set(color, 0, 0, 1, 0.05);break;
6107 case SOLID_CORPSE: Vector4Set(color, 1, 0.5, 0, 0.05);break;
6108 default: Vector4Set(color, 0, 0, 0, 0.50);break;
6109 }
6110 if (prog == CLVM_prog)
6112 else
6113 color[3] *= r_showbboxes.value;
6114 color[3] = bound(0, color[3], 1);
6116 R_DrawBBoxMesh(edict->priv.server->areamins, edict->priv.server->areamaxs, color[0], color[1], color[2], color[3]);
6117 }
6118}
6119
6121{
6122 int i;
6123 prvm_edict_t *edict;
6124 vec3_t center;
6125
6126 if (prog == NULL)
6127 return;
6128
6129 for (i = 0; i < prog->num_edicts; i++)
6130 {
6131 edict = PRVM_EDICT_NUM(i);
6132 if (edict->free)
6133 continue;
6134 // exclude the following for now, as they don't live in world coordinate space and can't be solid:
6135 if (PRVM_gameedictedict(edict, tag_entity) != 0)
6136 continue;
6137 if (prog == SVVM_prog && PRVM_serveredictedict(edict, viewmodelforclient) != 0)
6138 continue;
6139 VectorLerp(edict->priv.server->areamins, 0.5f, edict->priv.server->areamaxs, center);
6141 }
6142}
6143
6144static const int nomodelelement3i[24] =
6145{
6146 5, 2, 0,
6147 5, 1, 2,
6148 5, 0, 3,
6149 5, 3, 1,
6150 0, 2, 4,
6151 2, 1, 4,
6152 3, 0, 4,
6153 1, 3, 4
6154};
6155
6156static const unsigned short nomodelelement3s[24] =
6157{
6158 5, 2, 0,
6159 5, 1, 2,
6160 5, 0, 3,
6161 5, 3, 1,
6162 0, 2, 4,
6163 2, 1, 4,
6164 3, 0, 4,
6165 1, 3, 4
6166};
6167
6168static const float nomodelvertex3f[6*3] =
6169{
6170 -16, 0, 0,
6171 16, 0, 0,
6172 0, -16, 0,
6173 0, 16, 0,
6174 0, 0, -16,
6175 0, 0, 16
6176};
6177
6178static const float nomodelcolor4f[6*4] =
6179{
6180 0.0f, 0.0f, 0.5f, 1.0f,
6181 0.0f, 0.0f, 0.5f, 1.0f,
6182 0.0f, 0.5f, 0.0f, 1.0f,
6183 0.0f, 0.5f, 0.0f, 1.0f,
6184 0.5f, 0.0f, 0.0f, 1.0f,
6185 0.5f, 0.0f, 0.0f, 1.0f
6186};
6187
6188static void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
6189{
6190 int i;
6191 float f1, f2, *c;
6192 float color4f[6*4];
6193
6194 RSurf_ActiveCustomEntity(&ent->matrix, &ent->inversematrix, ent->flags, ent->shadertime, ent->colormod[0], ent->colormod[1], ent->colormod[2], ent->alpha, 6, nomodelvertex3f, NULL, NULL, NULL, NULL, nomodelcolor4f, 8, nomodelelement3i, nomodelelement3s, false, false);
6195
6196 // this is only called once per entity so numsurfaces is always 1, and
6197 // surfacelist is always {0}, so this code does not handle batches
6198
6200 {
6202 GL_DepthMask(false);
6203 }
6204 else if (ent->alpha < 1)
6205 {
6207 GL_DepthMask(false);
6208 }
6209 else
6210 {
6212 GL_DepthMask(true);
6213 }
6214 GL_DepthRange(0, (rsurface.ent_flags & RENDER_VIEWMODEL) ? 0.0625 : 1);
6218 memcpy(color4f, nomodelcolor4f, sizeof(float[6*4]));
6219 for (i = 0, c = color4f;i < 6;i++, c += 4)
6220 {
6221 c[0] *= ent->render_fullbright[0] * r_refdef.view.colorscale;
6222 c[1] *= ent->render_fullbright[1] * r_refdef.view.colorscale;
6223 c[2] *= ent->render_fullbright[2] * r_refdef.view.colorscale;
6224 c[3] *= ent->alpha;
6225 }
6226 if (r_refdef.fogenabled)
6227 {
6228 for (i = 0, c = color4f;i < 6;i++, c += 4)
6229 {
6231 f2 = 1 - f1;
6232 c[0] = (c[0] * f1 + r_refdef.fogcolor[0] * f2);
6233 c[1] = (c[1] * f1 + r_refdef.fogcolor[1] * f2);
6234 c[2] = (c[2] * f1 + r_refdef.fogcolor[2] * f2);
6235 }
6236 }
6237// R_Mesh_ResetTextureState();
6238 R_SetupShader_Generic_NoTexture(false, false);
6241}
6242
6252
6253void R_CalcBeam_Vertex3f (float *vert, const float *org1, const float *org2, float width)
6254{
6255 vec3_t right1, right2, diff, normal;
6256
6257 VectorSubtract (org2, org1, normal);
6258
6259 // calculate 'right' vector for start
6260 VectorSubtract (r_refdef.view.origin, org1, diff);
6261 CrossProduct (normal, diff, right1);
6262 VectorNormalize (right1);
6263
6264 // calculate 'right' vector for end
6265 VectorSubtract (r_refdef.view.origin, org2, diff);
6266 CrossProduct (normal, diff, right2);
6267 VectorNormalize (right2);
6268
6269 vert[ 0] = org1[0] + width * right1[0];
6270 vert[ 1] = org1[1] + width * right1[1];
6271 vert[ 2] = org1[2] + width * right1[2];
6272 vert[ 3] = org1[0] - width * right1[0];
6273 vert[ 4] = org1[1] - width * right1[1];
6274 vert[ 5] = org1[2] - width * right1[2];
6275 vert[ 6] = org2[0] - width * right2[0];
6276 vert[ 7] = org2[1] - width * right2[1];
6277 vert[ 8] = org2[2] - width * right2[2];
6278 vert[ 9] = org2[0] + width * right2[0];
6279 vert[10] = org2[1] + width * right2[1];
6280 vert[11] = org2[2] + width * right2[2];
6281}
6282
6283void R_CalcSprite_Vertex3f(float *vertex3f, const vec3_t origin, const vec3_t left, const vec3_t up, float scalex1, float scalex2, float scaley1, float scaley2)
6284{
6285 vertex3f[ 0] = origin[0] + left[0] * scalex2 + up[0] * scaley1;
6286 vertex3f[ 1] = origin[1] + left[1] * scalex2 + up[1] * scaley1;
6287 vertex3f[ 2] = origin[2] + left[2] * scalex2 + up[2] * scaley1;
6288 vertex3f[ 3] = origin[0] + left[0] * scalex2 + up[0] * scaley2;
6289 vertex3f[ 4] = origin[1] + left[1] * scalex2 + up[1] * scaley2;
6290 vertex3f[ 5] = origin[2] + left[2] * scalex2 + up[2] * scaley2;
6291 vertex3f[ 6] = origin[0] + left[0] * scalex1 + up[0] * scaley2;
6292 vertex3f[ 7] = origin[1] + left[1] * scalex1 + up[1] * scaley2;
6293 vertex3f[ 8] = origin[2] + left[2] * scalex1 + up[2] * scaley2;
6294 vertex3f[ 9] = origin[0] + left[0] * scalex1 + up[0] * scaley1;
6295 vertex3f[10] = origin[1] + left[1] * scalex1 + up[1] * scaley1;
6296 vertex3f[11] = origin[2] + left[2] * scalex1 + up[2] * scaley1;
6297}
6298
6299static int R_Mesh_AddVertex(rmesh_t *mesh, float x, float y, float z)
6300{
6301 int i;
6302 float *vertex3f;
6303 float v[3];
6304 VectorSet(v, x, y, z);
6305 for (i = 0, vertex3f = mesh->vertex3f;i < mesh->numvertices;i++, vertex3f += 3)
6306 if (VectorDistance2(v, vertex3f) < mesh->epsilon2)
6307 break;
6308 if (i == mesh->numvertices)
6309 {
6310 if (mesh->numvertices < mesh->maxvertices)
6311 {
6312 VectorCopy(v, vertex3f);
6313 mesh->numvertices++;
6314 }
6315 return mesh->numvertices;
6316 }
6317 else
6318 return i;
6319}
6320
6321void R_Mesh_AddPolygon3f(rmesh_t *mesh, int numvertices, float *vertex3f)
6322{
6323 int i;
6324 int *e, element[3];
6325 element[0] = R_Mesh_AddVertex(mesh, vertex3f[0], vertex3f[1], vertex3f[2]);vertex3f += 3;
6326 element[1] = R_Mesh_AddVertex(mesh, vertex3f[0], vertex3f[1], vertex3f[2]);vertex3f += 3;
6327 e = mesh->element3i + mesh->numtriangles * 3;
6328 for (i = 0;i < numvertices - 2;i++, vertex3f += 3)
6329 {
6330 element[2] = R_Mesh_AddVertex(mesh, vertex3f[0], vertex3f[1], vertex3f[2]);
6331 if (mesh->numtriangles < mesh->maxtriangles)
6332 {
6333 *e++ = element[0];
6334 *e++ = element[1];
6335 *e++ = element[2];
6336 mesh->numtriangles++;
6337 }
6338 element[1] = element[2];
6339 }
6340}
6341
6342static void R_Mesh_AddPolygon3d(rmesh_t *mesh, int numvertices, double *vertex3d)
6343{
6344 int i;
6345 int *e, element[3];
6346 element[0] = R_Mesh_AddVertex(mesh, vertex3d[0], vertex3d[1], vertex3d[2]);vertex3d += 3;
6347 element[1] = R_Mesh_AddVertex(mesh, vertex3d[0], vertex3d[1], vertex3d[2]);vertex3d += 3;
6348 e = mesh->element3i + mesh->numtriangles * 3;
6349 for (i = 0;i < numvertices - 2;i++, vertex3d += 3)
6350 {
6351 element[2] = R_Mesh_AddVertex(mesh, vertex3d[0], vertex3d[1], vertex3d[2]);
6352 if (mesh->numtriangles < mesh->maxtriangles)
6353 {
6354 *e++ = element[0];
6355 *e++ = element[1];
6356 *e++ = element[2];
6357 mesh->numtriangles++;
6358 }
6359 element[1] = element[2];
6360 }
6361}
6362
6363#define R_MESH_PLANE_DIST_EPSILON (1.0 / 32.0)
6364void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *planes)
6365{
6366 int planenum, planenum2;
6367 int w;
6368 int tempnumpoints;
6369 mplane_t *plane, *plane2;
6370 double maxdist;
6371 double temppoints[2][256*3];
6372 // figure out how large a bounding box we need to properly compute this brush
6373 maxdist = 0;
6374 for (w = 0;w < numplanes;w++)
6375 maxdist = max(maxdist, fabs(planes[w].dist));
6376 // now make it large enough to enclose the entire brush, and round it off to a reasonable multiple of 1024
6377 maxdist = floor(maxdist * (4.0 / 1024.0) + 1) * 1024.0;
6378 for (planenum = 0, plane = planes;planenum < numplanes;planenum++, plane++)
6379 {
6380 w = 0;
6381 tempnumpoints = 4;
6382 PolygonD_QuadForPlane(temppoints[w], plane->normal[0], plane->normal[1], plane->normal[2], plane->dist, maxdist);
6383 for (planenum2 = 0, plane2 = planes;planenum2 < numplanes && tempnumpoints >= 3;planenum2++, plane2++)
6384 {
6385 if (planenum2 == planenum)
6386 continue;
6387 PolygonD_Divide(tempnumpoints, temppoints[w], plane2->normal[0], plane2->normal[1], plane2->normal[2], plane2->dist, R_MESH_PLANE_DIST_EPSILON, 0, NULL, NULL, 256, temppoints[!w], &tempnumpoints, NULL);
6388 w = !w;
6389 }
6390 if (tempnumpoints < 3)
6391 continue;
6392 // generate elements forming a triangle fan for this polygon
6393 R_Mesh_AddPolygon3d(mesh, tempnumpoints, temppoints[w]);
6394 }
6395}
6396
6397static qbool R_TestQ3WaveFunc(q3wavefunc_t func, const float *parms)
6398{
6399 if(parms[0] == 0 && parms[1] == 0)
6400 return false;
6401 if(func >> Q3WAVEFUNC_USER_SHIFT) // assumes rsurface to be set!
6403 return false;
6404 return true;
6405}
6406
6407static float R_EvaluateQ3WaveFunc(q3wavefunc_t func, const float *parms)
6408{
6409 double index, f;
6410 index = parms[2] + rsurface.shadertime * parms[3];
6411 index -= floor(index);
6412 switch (func & ((1 << Q3WAVEFUNC_USER_SHIFT) - 1))
6413 {
6414 default:
6415 case Q3WAVEFUNC_NONE:
6416 case Q3WAVEFUNC_NOISE:
6417 case Q3WAVEFUNC_COUNT:
6418 f = 0;
6419 break;
6420 case Q3WAVEFUNC_SIN: f = sin(index * M_PI * 2);break;
6421 case Q3WAVEFUNC_SQUARE: f = index < 0.5 ? 1 : -1;break;
6422 case Q3WAVEFUNC_SAWTOOTH: f = index;break;
6423 case Q3WAVEFUNC_INVERSESAWTOOTH: f = 1 - index;break;
6425 index *= 4;
6426 f = index - floor(index);
6427 if (index < 1)
6428 {
6429 // f = f;
6430 }
6431 else if (index < 2)
6432 f = 1 - f;
6433 else if (index < 3)
6434 f = -f;
6435 else
6436 f = -(1 - f);
6437 break;
6438 }
6439 f = parms[0] + parms[1] * f;
6440 if(func >> Q3WAVEFUNC_USER_SHIFT) // assumes rsurface to be set!
6442 return (float) f;
6443}
6444
6445static void R_tcMod_ApplyToMatrix(matrix4x4_t *texmatrix, q3shaderinfo_layer_tcmod_t *tcmod, int currentmaterialflags)
6446{
6447 int w, h, idx;
6448 float shadertime;
6449 float f;
6450 float offsetd[2];
6451 float tcmat[12];
6452 matrix4x4_t matrix, temp;
6453 // if shadertime exceeds about 9 hours (32768 seconds), just wrap it,
6454 // it's better to have one huge fixup every 9 hours than gradual
6455 // degradation over time which looks consistently bad after many hours.
6456 //
6457 // tcmod scroll in particular suffers from this degradation which can't be
6458 // effectively worked around even with floor() tricks because we don't
6459 // know if tcmod scroll is the last tcmod being applied, and for clampmap
6460 // a workaround involving floor() would be incorrect anyway...
6461 shadertime = rsurface.shadertime;
6462 if (shadertime >= 32768.0f)
6463 shadertime -= floor(rsurface.shadertime * (1.0f / 32768.0f)) * 32768.0f;
6464 switch(tcmod->tcmod)
6465 {
6466 case Q3TCMOD_COUNT:
6467 case Q3TCMOD_NONE:
6468 if (currentmaterialflags & MATERIALFLAG_WATERSCROLL)
6469 matrix = r_waterscrollmatrix;
6470 else
6471 matrix = identitymatrix;
6472 break;
6474 // this is used in Q3 to allow the gamecode to control texcoord
6475 // scrolling on the entity, which is not supported in darkplaces yet.
6476 Matrix4x4_CreateTranslate(&matrix, 0, 0, 0);
6477 break;
6478 case Q3TCMOD_ROTATE:
6479 Matrix4x4_CreateTranslate(&matrix, 0.5, 0.5, 0);
6480 Matrix4x4_ConcatRotate(&matrix, tcmod->parms[0] * rsurface.shadertime, 0, 0, 1);
6481 Matrix4x4_ConcatTranslate(&matrix, -0.5, -0.5, 0);
6482 break;
6483 case Q3TCMOD_SCALE:
6484 Matrix4x4_CreateScale3(&matrix, tcmod->parms[0], tcmod->parms[1], 1);
6485 break;
6486 case Q3TCMOD_SCROLL:
6487 // this particular tcmod is a "bug for bug" compatible one with regards to
6488 // Quake3, the wrapping is unnecessary with our shadetime fix but quake3
6489 // specifically did the wrapping and so we must mimic that...
6490 offsetd[0] = tcmod->parms[0] * rsurface.shadertime;
6491 offsetd[1] = tcmod->parms[1] * rsurface.shadertime;
6492 Matrix4x4_CreateTranslate(&matrix, offsetd[0] - floor(offsetd[0]), offsetd[1] - floor(offsetd[1]), 0);
6493 break;
6494 case Q3TCMOD_PAGE: // poor man's animmap (to store animations into a single file, useful for HTTP downloaded textures)
6495 w = (int) tcmod->parms[0];
6496 h = (int) tcmod->parms[1];
6497 f = rsurface.shadertime / (tcmod->parms[2] * w * h);
6498 f = f - floor(f);
6499 idx = (int) floor(f * w * h);
6500 Matrix4x4_CreateTranslate(&matrix, (idx % w) / tcmod->parms[0], (idx / w) / tcmod->parms[1], 0);
6501 break;
6502 case Q3TCMOD_STRETCH:
6503 f = 1.0f / R_EvaluateQ3WaveFunc(tcmod->wavefunc, tcmod->waveparms);
6504 Matrix4x4_CreateFromQuakeEntity(&matrix, 0.5f * (1 - f), 0.5 * (1 - f), 0, 0, 0, 0, f);
6505 break;
6506 case Q3TCMOD_TRANSFORM:
6507 VectorSet(tcmat + 0, tcmod->parms[0], tcmod->parms[1], 0);
6508 VectorSet(tcmat + 3, tcmod->parms[2], tcmod->parms[3], 0);
6509 VectorSet(tcmat + 6, 0 , 0 , 1);
6510 VectorSet(tcmat + 9, tcmod->parms[4], tcmod->parms[5], 0);
6511 Matrix4x4_FromArray12FloatGL(&matrix, tcmat);
6512 break;
6513 case Q3TCMOD_TURBULENT:
6514 // this is handled in the RSurf_PrepareVertices function
6515 matrix = identitymatrix;
6516 break;
6517 }
6518 temp = *texmatrix;
6519 Matrix4x4_Concat(texmatrix, &matrix, &temp);
6520}
6521
6522static void R_LoadQWSkin(r_qwskincache_t *cache, const char *skinname)
6523{
6524 int textureflags = (r_mipskins.integer ? TEXF_MIPMAP : 0) | TEXF_PICMIP;
6525 char name[MAX_QPATH];
6526 skinframe_t *skinframe;
6527 unsigned char pixels[296*194];
6528 dp_strlcpy(cache->name, skinname, sizeof(cache->name));
6529 dpsnprintf(name, sizeof(name), "skins/%s.pcx", cache->name);
6531 Con_Printf("loading %s\n", name);
6532 skinframe = R_SkinFrame_Find(name, textureflags, 0, 0, 0, false);
6533 if (!skinframe || !skinframe->base)
6534 {
6535 unsigned char *f;
6536 fs_offset_t filesize;
6537 skinframe = NULL;
6538 f = FS_LoadFile(name, tempmempool, true, &filesize);
6539 if (f)
6540 {
6541 if (LoadPCX_QWSkin(f, (int)filesize, pixels, 296, 194))
6543 Mem_Free(f);
6544 }
6545 }
6546 cache->skinframe = skinframe;
6547}
6548
6550{
6551 int i, q;
6552 const entity_render_t *ent = rsurface.entity;
6553 model_t *model = ent->model; // when calling this, ent must not be NULL
6555 float specularscale = 0.0f;
6556
6558 return t->currentframe;
6560 t->update_lastrenderentity = (void *)ent;
6561
6562 if(ent->entitynumber >= MAX_EDICTS && ent->entitynumber < 2 * MAX_EDICTS)
6563 t->camera_entity = ent->entitynumber;
6564 else
6565 t->camera_entity = 0;
6566
6567 // switch to an alternate material if this is a q1bsp animated material
6568 {
6569 texture_t *texture = t;
6570 int s = rsurface.ent_skinnum;
6571 if ((unsigned int)s >= (unsigned int)model->numskins)
6572 s = 0;
6573 if (model->skinscenes)
6574 {
6575 if (model->skinscenes[s].framecount > 1)
6576 s = model->skinscenes[s].firstframe + (unsigned int) (rsurface.shadertime * model->skinscenes[s].framerate) % model->skinscenes[s].framecount;
6577 else
6578 s = model->skinscenes[s].firstframe;
6579 }
6580 if (s > 0)
6581 t = t + s * model->num_surfaces;
6582 if (t->animated)
6583 {
6584 // use an alternate animation if the entity's frame is not 0,
6585 // and only if the texture has an alternate animation
6586 if (t->animated == 2) // q2bsp
6587 t = t->anim_frames[0][ent->framegroupblend[0].frame % t->anim_total[0]];
6588 else if (rsurface.ent_alttextures && t->anim_total[1])
6589 t = t->anim_frames[1][(t->anim_total[1] >= 2) ? ((int)(rsurface.shadertime * 5.0f) % t->anim_total[1]) : 0];
6590 else
6591 t = t->anim_frames[0][(t->anim_total[0] >= 2) ? ((int)(rsurface.shadertime * 5.0f) % t->anim_total[0]) : 0];
6592 }
6593 texture->currentframe = t;
6594 }
6595
6596 // update currentskinframe to be a qw skin or animation frame
6597 if (rsurface.ent_qwskin >= 0)
6598 {
6601 {
6603 if (r_qwskincache)
6606 }
6607 if (strcmp(r_qwskincache[i].name, cl.scores[i].qw_skin))
6612 }
6613 else if (t->materialshaderpass && t->materialshaderpass->numframes >= 2)
6617
6620 if (t->basematerialflags & MATERIALFLAG_WATERALPHA && (model->brush.supportwateralpha || r_water.integer || r_novis.integer || r_trippy.integer))
6626
6627 // decide on which type of lighting to use for this surface
6635 {
6636 // some CUSTOMBLEND blendfuncs are too weird, we have to ignore colormod and view colorscale
6638 for (q = 0; q < 3; q++)
6639 {
6641 t->render_modellight_lightdir_world[q] = q == 2;
6642 t->render_modellight_lightdir_local[q] = q == 2;
6643 t->render_modellight_ambient[q] = 1;
6644 t->render_modellight_diffuse[q] = 0;
6646 t->render_lightmap_ambient[q] = 0;
6647 t->render_lightmap_diffuse[q] = 0;
6648 t->render_lightmap_specular[q] = 0;
6649 t->render_rtlight_diffuse[q] = 0;
6650 t->render_rtlight_specular[q] = 0;
6651 }
6652 }
6654 {
6655 // fullbright is basically MATERIALFLAG_MODELLIGHT but with ambient locked to 1,1,1 and no shading
6657 for (q = 0; q < 3; q++)
6658 {
6661 t->render_modellight_lightdir_world[q] = q == 2;
6662 t->render_modellight_lightdir_local[q] = q == 2;
6663 t->render_modellight_diffuse[q] = 0;
6665 t->render_lightmap_ambient[q] = 0;
6666 t->render_lightmap_diffuse[q] = 0;
6667 t->render_lightmap_specular[q] = 0;
6668 t->render_rtlight_diffuse[q] = 0;
6669 t->render_rtlight_specular[q] = 0;
6670 }
6671 }
6673 {
6674 t->currentmaterialflags &= ~MATERIALFLAG_MODELLIGHT;
6675 for (q = 0; q < 3; q++)
6676 {
6678 t->render_modellight_lightdir_world[q] = q == 2;
6679 t->render_modellight_lightdir_local[q] = q == 2;
6680 t->render_modellight_ambient[q] = 0;
6681 t->render_modellight_diffuse[q] = 0;
6688 }
6689 }
6691 {
6692 // ambient + single direction light (modellight)
6694 for (q = 0; q < 3; q++)
6695 {
6702 t->render_lightmap_ambient[q] = 0;
6703 t->render_lightmap_diffuse[q] = 0;
6704 t->render_lightmap_specular[q] = 0;
6707 }
6708 }
6709 else
6710 {
6711 // lightmap - 2x diffuse and specular brightness because bsp files have 0-2 colors as 0-1
6712 for (q = 0; q < 3; q++)
6713 {
6715 t->render_modellight_lightdir_world[q] = q == 2;
6716 t->render_modellight_lightdir_local[q] = q == 2;
6717 t->render_modellight_ambient[q] = 0;
6718 t->render_modellight_diffuse[q] = 0;
6725 }
6726 }
6727
6729 {
6730 // since MATERIALFLAG_VERTEXCOLOR uses the lightmapcolor4f vertex
6731 // attribute, we punt it to the lightmap path and hope for the best,
6732 // but lighting doesn't work.
6733 //
6734 // FIXME: this is fine for effects but CSQC polygons should be subject
6735 // to lighting.
6737 for (q = 0; q < 3; q++)
6738 {
6740 t->render_modellight_lightdir_world[q] = q == 2;
6741 t->render_modellight_lightdir_local[q] = q == 2;
6742 t->render_modellight_ambient[q] = 0;
6743 t->render_modellight_diffuse[q] = 0;
6745 t->render_lightmap_ambient[q] = 0;
6747 t->render_lightmap_specular[q] = 0;
6748 t->render_rtlight_diffuse[q] = 0;
6749 t->render_rtlight_specular[q] = 0;
6750 }
6751 }
6752
6753 for (q = 0; q < 3; q++)
6754 {
6757 }
6758
6761 else if (t->currentalpha < 1)
6763 // LadyHavoc: prevent bugs where code checks add or alpha at higher priority than customblend by clearing these flags
6770 if (t->backgroundshaderpass)
6773 {
6775 t->currentmaterialflags &= ~MATERIALFLAG_BLENDED;
6776 }
6777 else
6780 {
6781 // promote alphablend to alphatocoverage (a type of alphatest) if antialiasing is on
6783 }
6786
6787 // there is no tcmod
6789 {
6792 }
6794 {
6797 }
6798
6799 if (t->materialshaderpass)
6800 for (i = 0, tcmod = t->materialshaderpass->tcmods;i < Q3MAXTCMODS && tcmod->tcmod;i++, tcmod++)
6802
6804 if (t->currentskinframe->qpixels)
6806 t->basetexture = (!t->colormapping && t->currentskinframe->merged) ? t->currentskinframe->merged : t->currentskinframe->base;
6807 if (!t->basetexture)
6809 t->pantstexture = t->colormapping ? t->currentskinframe->pants : NULL;
6810 t->shirttexture = t->colormapping ? t->currentskinframe->shirt : NULL;
6811 t->nmaptexture = t->currentskinframe->nmap;
6812 if (!t->nmaptexture)
6815 t->glowtexture = t->currentskinframe->glow;
6816 t->fogtexture = t->currentskinframe->fog;
6817 t->reflectmasktexture = t->currentskinframe->reflect;
6818 if (t->backgroundshaderpass)
6819 {
6820 for (i = 0, tcmod = t->backgroundshaderpass->tcmods; i < Q3MAXTCMODS && tcmod->tcmod; i++, tcmod++)
6826 if (!t->backgroundnmaptexture)
6828 // make sure that if glow is going to be used, both textures are not NULL
6829 if (!t->backgroundglowtexture && t->glowtexture)
6831 if (!t->glowtexture && t->backgroundglowtexture)
6833 }
6834 else
6835 {
6840 }
6842 // TODO: store reference values for these in the texture?
6843 if (r_shadow_gloss.integer > 0)
6844 {
6846 {
6848 {
6851 specularscale = r_shadow_glossintensity.value;
6852 }
6853 }
6855 {
6858 specularscale = r_shadow_gloss2intensity.value;
6860 }
6861 }
6862 specularscale *= t->specularscalemod;
6864
6865 // lightmaps mode looks bad with dlights using actual texturing, so turn
6866 // off the colormap and glossmap, but leave the normalmap on as it still
6867 // accurately represents the shading involved
6869 {
6873 if (gl_lightmaps.integer < 2)
6876 t->glowtexture = NULL;
6877 t->fogtexture = NULL;
6880 if (gl_lightmaps.integer < 2)
6884 specularscale = 0;
6886 }
6887
6888 if (specularscale != 1.0f)
6889 {
6890 for (q = 0; q < 3; q++)
6891 {
6892 t->render_modellight_specular[q] *= specularscale;
6893 t->render_lightmap_specular[q] *= specularscale;
6894 t->render_rtlight_specular[q] *= specularscale;
6895 }
6896 }
6897
6898 t->currentblendfunc[0] = GL_ONE;
6899 t->currentblendfunc[1] = GL_ZERO;
6901 {
6903 t->currentblendfunc[1] = GL_ONE;
6904 }
6906 {
6909 }
6911 {
6912 t->currentblendfunc[0] = t->customblendfunc[0];
6913 t->currentblendfunc[1] = t->customblendfunc[1];
6914 }
6915
6916 return t;
6917}
6918
6920
6921void RSurf_ActiveModelEntity(const entity_render_t *ent, qbool wantnormals, qbool wanttangents, qbool prepass)
6922{
6923 model_t *model = ent->model;
6924 //if (rsurface.entity == ent && (!model->surfmesh.isanimated || (!wantnormals && !wanttangents)))
6925 // return;
6927 rsurface.skeleton = ent->skeleton;
6930 rsurface.ent_qwskin = (ent->entitynumber <= cl.maxclients && ent->entitynumber >= 1 && cls.protocol == PROTOCOL_QUAKEWORLD && cl.scores[ent->entitynumber - 1].qw_skin[0] && !strcmp(ent->model->name, "progs/player.mdl")) ? (ent->entitynumber - 1) : -1;
6931 rsurface.ent_flags = ent->flags;
6935 rsurface.matrix = ent->matrix;
6946 memcpy(rsurface.frameblend, ent->frameblend, sizeof(ent->frameblend));
6950 if (ent->model->brush.submodel && !prepass)
6951 {
6954 }
6955 // if the animcache code decided it should use the shader path, skip the deform step
6961 if (model->surfmesh.isanimated && model->AnimateVertices && !rsurface.entityskeletaltransform3x4)
6962 {
6963 if (ent->animcache_vertex3f)
6964 {
6967 r_refdef.stats[r_stat_batch_entitycache_vertices] += model->surfmesh.num_vertices;
6968 r_refdef.stats[r_stat_batch_entitycache_triangles] += model->surfmesh.num_triangles;
6972 rsurface.modelsvector3f = wanttangents ? ent->animcache_svector3f : NULL;
6975 rsurface.modeltvector3f = wanttangents ? ent->animcache_tvector3f : NULL;
6978 rsurface.modelnormal3f = wantnormals ? ent->animcache_normal3f : NULL;
6981 }
6982 else if (wanttangents)
6983 {
6986 r_refdef.stats[r_stat_batch_entityanimate_vertices] += model->surfmesh.num_vertices;
6987 r_refdef.stats[r_stat_batch_entityanimate_triangles] += model->surfmesh.num_triangles;
6988 rsurface.modelvertex3f = (float *)R_FrameData_Alloc(model->surfmesh.num_vertices * sizeof(float[3]));
6989 rsurface.modelsvector3f = (float *)R_FrameData_Alloc(model->surfmesh.num_vertices * sizeof(float[3]));
6990 rsurface.modeltvector3f = (float *)R_FrameData_Alloc(model->surfmesh.num_vertices * sizeof(float[3]));
6991 rsurface.modelnormal3f = (float *)R_FrameData_Alloc(model->surfmesh.num_vertices * sizeof(float[3]));
7003 }
7004 else if (wantnormals)
7005 {
7008 r_refdef.stats[r_stat_batch_entityanimate_vertices] += model->surfmesh.num_vertices;
7009 r_refdef.stats[r_stat_batch_entityanimate_triangles] += model->surfmesh.num_triangles;
7010 rsurface.modelvertex3f = (float *)R_FrameData_Alloc(model->surfmesh.num_vertices * sizeof(float[3]));
7013 rsurface.modelnormal3f = (float *)R_FrameData_Alloc(model->surfmesh.num_vertices * sizeof(float[3]));
7025 }
7026 else
7027 {
7030 r_refdef.stats[r_stat_batch_entityanimate_vertices] += model->surfmesh.num_vertices;
7031 r_refdef.stats[r_stat_batch_entityanimate_triangles] += model->surfmesh.num_triangles;
7032 rsurface.modelvertex3f = (float *)R_FrameData_Alloc(model->surfmesh.num_vertices * sizeof(float[3]));
7047 }
7049 }
7050 else
7051 {
7053 {
7056 r_refdef.stats[r_stat_batch_entityskeletal_vertices] += model->surfmesh.num_vertices;
7057 r_refdef.stats[r_stat_batch_entityskeletal_triangles] += model->surfmesh.num_triangles;
7058 }
7059 else
7060 {
7063 r_refdef.stats[r_stat_batch_entitystatic_vertices] += model->surfmesh.num_vertices;
7064 r_refdef.stats[r_stat_batch_entitystatic_triangles] += model->surfmesh.num_triangles;
7065 }
7066 rsurface.modelvertex3f = model->surfmesh.data_vertex3f;
7067 rsurface.modelvertex3f_vertexbuffer = model->surfmesh.data_vertex3f_vertexbuffer;
7068 rsurface.modelvertex3f_bufferoffset = model->surfmesh.data_vertex3f_bufferoffset;
7069 rsurface.modelsvector3f = model->surfmesh.data_svector3f;
7070 rsurface.modelsvector3f_vertexbuffer = model->surfmesh.data_svector3f_vertexbuffer;
7071 rsurface.modelsvector3f_bufferoffset = model->surfmesh.data_svector3f_bufferoffset;
7072 rsurface.modeltvector3f = model->surfmesh.data_tvector3f;
7073 rsurface.modeltvector3f_vertexbuffer = model->surfmesh.data_tvector3f_vertexbuffer;
7074 rsurface.modeltvector3f_bufferoffset = model->surfmesh.data_tvector3f_bufferoffset;
7075 rsurface.modelnormal3f = model->surfmesh.data_normal3f;
7076 rsurface.modelnormal3f_vertexbuffer = model->surfmesh.data_normal3f_vertexbuffer;
7077 rsurface.modelnormal3f_bufferoffset = model->surfmesh.data_normal3f_bufferoffset;
7079 }
7080 rsurface.modellightmapcolor4f = model->surfmesh.data_lightmapcolor4f;
7081 rsurface.modellightmapcolor4f_vertexbuffer = model->surfmesh.data_lightmapcolor4f_vertexbuffer;
7082 rsurface.modellightmapcolor4f_bufferoffset = model->surfmesh.data_lightmapcolor4f_bufferoffset;
7083 rsurface.modeltexcoordtexture2f = model->surfmesh.data_texcoordtexture2f;
7084 rsurface.modeltexcoordtexture2f_vertexbuffer = model->surfmesh.data_texcoordtexture2f_vertexbuffer;
7085 rsurface.modeltexcoordtexture2f_bufferoffset = model->surfmesh.data_texcoordtexture2f_bufferoffset;
7086 rsurface.modeltexcoordlightmap2f = model->surfmesh.data_texcoordlightmap2f;
7087 rsurface.modeltexcoordlightmap2f_vertexbuffer = model->surfmesh.data_texcoordlightmap2f_vertexbuffer;
7088 rsurface.modeltexcoordlightmap2f_bufferoffset = model->surfmesh.data_texcoordlightmap2f_bufferoffset;
7089 rsurface.modelskeletalindex4ub = model->surfmesh.data_skeletalindex4ub;
7090 rsurface.modelskeletalindex4ub_vertexbuffer = model->surfmesh.data_skeletalindex4ub_vertexbuffer;
7091 rsurface.modelskeletalindex4ub_bufferoffset = model->surfmesh.data_skeletalindex4ub_bufferoffset;
7092 rsurface.modelskeletalweight4ub = model->surfmesh.data_skeletalweight4ub;
7093 rsurface.modelskeletalweight4ub_vertexbuffer = model->surfmesh.data_skeletalweight4ub_vertexbuffer;
7094 rsurface.modelskeletalweight4ub_bufferoffset = model->surfmesh.data_skeletalweight4ub_bufferoffset;
7095 rsurface.modelelement3i = model->surfmesh.data_element3i;
7096 rsurface.modelelement3i_indexbuffer = model->surfmesh.data_element3i_indexbuffer;
7097 rsurface.modelelement3i_bufferoffset = model->surfmesh.data_element3i_bufferoffset;
7098 rsurface.modelelement3s = model->surfmesh.data_element3s;
7099 rsurface.modelelement3s_indexbuffer = model->surfmesh.data_element3s_indexbuffer;
7100 rsurface.modelelement3s_bufferoffset = model->surfmesh.data_element3s_bufferoffset;
7101 rsurface.modellightmapoffsets = model->surfmesh.data_lightmapoffsets;
7102 rsurface.modelnumvertices = model->surfmesh.num_vertices;
7103 rsurface.modelnumtriangles = model->surfmesh.num_triangles;
7104 rsurface.modelsurfaces = model->data_surfaces;
7144}
7145
7146void 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)
7147{
7149 if (r != 1.0f || g != 1.0f || b != 1.0f || a != 1.0f) {
7150 // HACK to provide a valid entity with modded colors to R_GetCurrentTexture.
7151 // A better approach could be making this copy only once per frame.
7152 static entity_render_t custom_entity;
7153 int q;
7154 custom_entity = *rsurface.entity;
7155 for (q = 0; q < 3; ++q) {
7156 float colormod = q == 0 ? r : q == 1 ? g : b;
7157 custom_entity.render_fullbright[q] *= colormod;
7158 custom_entity.render_modellight_ambient[q] *= colormod;
7159 custom_entity.render_modellight_diffuse[q] *= colormod;
7160 custom_entity.render_lightmap_ambient[q] *= colormod;
7161 custom_entity.render_lightmap_diffuse[q] *= colormod;
7162 custom_entity.render_rtlight_diffuse[q] *= colormod;
7163 }
7164 custom_entity.alpha *= a;
7165 rsurface.entity = &custom_entity;
7166 }
7169 rsurface.ent_qwskin = -1;
7170 rsurface.ent_flags = entflags;
7171 rsurface.shadertime = r_refdef.scene.time - shadertime;
7172 rsurface.modelnumvertices = numvertices;
7173 rsurface.modelnumtriangles = numtriangles;
7174 rsurface.matrix = *matrix;
7175 rsurface.inversematrix = *inversematrix;
7185 memset(rsurface.frameblend, 0, sizeof(rsurface.frameblend));
7186 rsurface.frameblend[0].lerp = 1;
7187 rsurface.ent_alttextures = false;
7199 if (wanttangents)
7200 {
7201 rsurface.modelvertex3f = (float *)vertex3f;
7202 rsurface.modelsvector3f = svector3f ? (float *)svector3f : (float *)R_FrameData_Alloc(rsurface.modelnumvertices * sizeof(float[3]));
7203 rsurface.modeltvector3f = tvector3f ? (float *)tvector3f : (float *)R_FrameData_Alloc(rsurface.modelnumvertices * sizeof(float[3]));
7204 rsurface.modelnormal3f = normal3f ? (float *)normal3f : (float *)R_FrameData_Alloc(rsurface.modelnumvertices * sizeof(float[3]));
7205 }
7206 else if (wantnormals)
7207 {
7208 rsurface.modelvertex3f = (float *)vertex3f;
7211 rsurface.modelnormal3f = normal3f ? (float *)normal3f : (float *)R_FrameData_Alloc(rsurface.modelnumvertices * sizeof(float[3]));
7212 }
7213 else
7214 {
7215 rsurface.modelvertex3f = (float *)vertex3f;
7219 }
7229 rsurface.modellightmapcolor4f = (float *)color4f;
7232 rsurface.modeltexcoordtexture2f = (float *)texcoord2f;
7244 rsurface.modelelement3i = (int *)element3i;
7247 rsurface.modelelement3s = (unsigned short *)element3s;
7291
7293 {
7294 if ((wantnormals || wanttangents) && !normal3f)
7295 {
7296 rsurface.modelnormal3f = (float *)R_FrameData_Alloc(rsurface.modelnumvertices * sizeof(float[3]));
7298 }
7299 if (wanttangents && !svector3f)
7300 {
7301 rsurface.modelsvector3f = (float *)R_FrameData_Alloc(rsurface.modelnumvertices * sizeof(float[3]));
7302 rsurface.modeltvector3f = (float *)R_FrameData_Alloc(rsurface.modelnumvertices * sizeof(float[3]));
7304 }
7305 }
7306}
7307
7308float RSurf_FogPoint(const float *v)
7309{
7310 // this code is identical to the USEFOGINSIDE/USEFOGOUTSIDE code in the shader
7314 float fogfrac;
7315 unsigned int fogmasktableindex;
7318 else
7320 fogmasktableindex = (unsigned int)(VectorDistance(r_refdef.view.origin, v) * fogfrac * r_refdef.fogmasktabledistmultiplier);
7321 return r_refdef.fogmasktable[min(fogmasktableindex, FOGMASKTABLEWIDTH - 1)];
7322}
7323
7324float RSurf_FogVertex(const float *v)
7325{
7326 // this code is identical to the USEFOGINSIDE/USEFOGOUTSIDE code in the shader
7330 float fogfrac;
7331 unsigned int fogmasktableindex;
7334 else
7337 return r_refdef.fogmasktable[min(fogmasktableindex, FOGMASKTABLEWIDTH - 1)];
7338}
7339
7341{
7342 // upload buffer data for generated vertex data (dynamicvertex case) or index data (copytriangles case) and models that lack it to begin with (e.g. DrawQ_FlushUI)
7343 // note that if rsurface.batchvertex3f_vertexbuffer is NULL, dynamicvertex is forced as we don't account for the proper base vertex here.
7362
7367
7375 R_Mesh_TexCoordPointer(5, 2, GL_FLOAT, sizeof(float[2]), NULL, NULL, 0);
7378}
7379
7380static void RSurf_RenumberElements(const int *inelement3i, int *outelement3i, int numelements, int adjust)
7381{
7382 int i;
7383 for (i = 0;i < numelements;i++)
7384 outelement3i[i] = inelement3i[i] + adjust;
7385}
7386
7387static const int quadedges[6][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}};
7388void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const msurface_t **texturesurfacelist)
7389{
7390 int deformindex;
7391 int firsttriangle;
7392 int numtriangles;
7393 int firstvertex;
7394 int endvertex;
7395 int numvertices;
7396 int surfacefirsttriangle;
7397 int surfacenumtriangles;
7398 int surfacefirstvertex;
7399 int surfaceendvertex;
7400 int surfacenumvertices;
7401 int batchnumsurfaces = texturenumsurfaces;
7402 int batchnumvertices;
7403 int batchnumtriangles;
7404 int i, j;
7405 qbool gaps;
7406 qbool dynamicvertex;
7407 float amplitude;
7408 float animpos;
7409 float center[3], forward[3], right[3], up[3], v[3], newforward[3], newright[3], newup[3];
7410 float waveparms[4];
7411 unsigned char *ub;
7412 q3shaderinfo_deform_t *deform;
7413 const msurface_t *surface, *firstsurface;
7414 if (!texturenumsurfaces)
7415 return;
7416 // find vertex range of this surface batch
7417 gaps = false;
7418 firstsurface = texturesurfacelist[0];
7419 firsttriangle = firstsurface->num_firsttriangle;
7420 batchnumvertices = 0;
7421 batchnumtriangles = 0;
7422 firstvertex = endvertex = firstsurface->num_firstvertex;
7423 for (i = 0;i < texturenumsurfaces;i++)
7424 {
7425 surface = texturesurfacelist[i];
7426 if (surface != firstsurface + i)
7427 gaps = true;
7428 surfacefirstvertex = surface->num_firstvertex;
7429 surfaceendvertex = surfacefirstvertex + surface->num_vertices;
7430 surfacenumvertices = surface->num_vertices;
7431 surfacenumtriangles = surface->num_triangles;
7432 if (firstvertex > surfacefirstvertex)
7433 firstvertex = surfacefirstvertex;
7434 if (endvertex < surfaceendvertex)
7435 endvertex = surfaceendvertex;
7436 batchnumvertices += surfacenumvertices;
7437 batchnumtriangles += surfacenumtriangles;
7438 }
7439
7441 if (gaps)
7443 r_refdef.stats[r_stat_batch_surfaces] += batchnumsurfaces;
7444 r_refdef.stats[r_stat_batch_vertices] += batchnumvertices;
7445 r_refdef.stats[r_stat_batch_triangles] += batchnumtriangles;
7446
7447 // we now know the vertex range used, and if there are any gaps in it
7448 rsurface.batchfirstvertex = firstvertex;
7449 rsurface.batchnumvertices = endvertex - firstvertex;
7450 rsurface.batchfirsttriangle = firsttriangle;
7451 rsurface.batchnumtriangles = batchnumtriangles;
7452
7453 // check if any dynamic vertex processing must occur
7454 dynamicvertex = false;
7455
7456 // we must use vertexbuffers for rendering, we can upload vertex buffers
7457 // easily enough but if the basevertex is non-zero it becomes more
7458 // difficult, so force dynamicvertex path in that case - it's suboptimal
7459 // but the most optimal case is to have the geometry sources provide their
7460 // own anyway.
7461 if (!rsurface.modelvertex3f_vertexbuffer && firstvertex != 0)
7462 dynamicvertex = true;
7463
7464 // a cvar to force the dynamic vertex path to be taken, for debugging
7466 {
7467 if (!dynamicvertex)
7468 {
7473 }
7474 dynamicvertex = true;
7475 }
7476
7477 // if there is a chance of animated vertex colors, it's a dynamic batch
7478 if ((batchneed & BATCHNEED_ARRAY_VERTEXCOLOR) && texturesurfacelist[0]->lightmapinfo)
7479 {
7480 if (!dynamicvertex)
7481 {
7486 }
7487 dynamicvertex = true;
7488 }
7489
7490 for (deformindex = 0, deform = rsurface.texture->deforms;deformindex < Q3MAXDEFORMS && deform->deform && r_deformvertexes.integer;deformindex++, deform++)
7491 {
7492 switch (deform->deform)
7493 {
7494 default:
7496 case Q3DEFORM_TEXT0:
7497 case Q3DEFORM_TEXT1:
7498 case Q3DEFORM_TEXT2:
7499 case Q3DEFORM_TEXT3:
7500 case Q3DEFORM_TEXT4:
7501 case Q3DEFORM_TEXT5:
7502 case Q3DEFORM_TEXT6:
7503 case Q3DEFORM_TEXT7:
7504 case Q3DEFORM_NONE:
7505 break;
7507 if (!dynamicvertex)
7508 {
7513 }
7514 dynamicvertex = true;
7516 break;
7518 if (!dynamicvertex)
7519 {
7524 }
7525 dynamicvertex = true;
7527 break;
7528 case Q3DEFORM_NORMAL:
7529 if (!dynamicvertex)
7530 {
7535 }
7536 dynamicvertex = true;
7538 break;
7539 case Q3DEFORM_WAVE:
7540 if(!R_TestQ3WaveFunc(deform->wavefunc, deform->waveparms))
7541 break; // if wavefunc is a nop, ignore this transform
7542 if (!dynamicvertex)
7543 {
7548 }
7549 dynamicvertex = true;
7551 break;
7552 case Q3DEFORM_BULGE:
7553 if (!dynamicvertex)
7554 {
7559 }
7560 dynamicvertex = true;
7562 break;
7563 case Q3DEFORM_MOVE:
7564 if(!R_TestQ3WaveFunc(deform->wavefunc, deform->waveparms))
7565 break; // if wavefunc is a nop, ignore this transform
7566 if (!dynamicvertex)
7567 {
7572 }
7573 dynamicvertex = true;
7574 batchneed |= BATCHNEED_ARRAY_VERTEX;
7575 break;
7576 }
7577 }
7579 {
7581 {
7582 default:
7583 case Q3TCGEN_TEXTURE:
7584 break;
7585 case Q3TCGEN_LIGHTMAP:
7586 if (!dynamicvertex)
7587 {
7592 }
7593 dynamicvertex = true;
7594 batchneed |= BATCHNEED_ARRAY_LIGHTMAP;
7595 break;
7596 case Q3TCGEN_VECTOR:
7597 if (!dynamicvertex)
7598 {
7603 }
7604 dynamicvertex = true;
7605 batchneed |= BATCHNEED_ARRAY_VERTEX;
7606 break;
7608 if (!dynamicvertex)
7609 {
7614 }
7615 dynamicvertex = true;
7617 break;
7618 }
7620 {
7621 if (!dynamicvertex)
7622 {
7627 }
7628 dynamicvertex = true;
7630 }
7631 }
7632
7633 // the caller can specify BATCHNEED_NOGAPS to force a batch with
7634 // firstvertex = 0 and endvertex = numvertices (no gaps, no firstvertex),
7635 // we ensure this by treating the vertex batch as dynamic...
7636 if ((batchneed & BATCHNEED_ALWAYSCOPY) || ((batchneed & BATCHNEED_NOGAPS) && (gaps || firstvertex > 0)))
7637 {
7638 if (!dynamicvertex)
7639 {
7644 }
7645 dynamicvertex = true;
7646 }
7647
7648 // if we're going to have to apply the skeletal transform manually, we need to batch the skeletal data
7649 if (dynamicvertex && rsurface.entityskeletaltransform3x4)
7650 batchneed |= BATCHNEED_ARRAY_SKELETAL;
7651
7690
7691 // if any dynamic vertex processing has to occur in software, we copy the
7692 // entire surface list together before processing to rebase the vertices
7693 // to start at 0 (otherwise we waste a lot of room in a vertex buffer).
7694 //
7695 // if any gaps exist and we do not have a static vertex buffer, we have to
7696 // copy the surface list together to avoid wasting upload bandwidth on the
7697 // vertices in the gaps.
7698 //
7699 // if gaps exist and we have a static vertex buffer, we can choose whether
7700 // to combine the index buffer ranges into one dynamic index buffer or
7701 // simply issue multiple glDrawElements calls (BATCHNEED_ALLOWMULTIDRAW).
7702 //
7703 // in many cases the batch is reduced to one draw call.
7704
7705 rsurface.batchmultidraw = false;
7708
7709 if (!dynamicvertex)
7710 {
7711 // static vertex data, just set pointers...
7713 // if there are gaps, we want to build a combined index buffer,
7714 // otherwise use the original static buffer with an appropriate offset
7715 if (gaps)
7716 {
7722 {
7723 rsurface.batchmultidraw = true;
7724 rsurface.batchmultidrawnumsurfaces = texturenumsurfaces;
7725 rsurface.batchmultidrawsurfacelist = texturesurfacelist;
7726 return;
7727 }
7728 // build a new triangle elements array for this batch
7729 rsurface.batchelement3i = (int *)R_FrameData_Alloc(batchnumtriangles * sizeof(int[3]));
7731 numtriangles = 0;
7732 for (i = 0;i < texturenumsurfaces;i++)
7733 {
7734 surfacefirsttriangle = texturesurfacelist[i]->num_firsttriangle;
7735 surfacenumtriangles = texturesurfacelist[i]->num_triangles;
7736 memcpy(rsurface.batchelement3i + 3*numtriangles, rsurface.modelelement3i + 3*surfacefirsttriangle, surfacenumtriangles*sizeof(int[3]));
7737 numtriangles += surfacenumtriangles;
7738 }
7744 if (endvertex <= 65536)
7745 {
7746 // make a 16bit (unsigned short) index array if possible
7747 rsurface.batchelement3s = (unsigned short *)R_FrameData_Alloc(batchnumtriangles * sizeof(unsigned short[3]));
7748 for (i = 0;i < numtriangles*3;i++)
7750 }
7751 }
7752 else
7753 {
7755 r_refdef.stats[r_stat_batch_fast_surfaces] += batchnumsurfaces;
7756 r_refdef.stats[r_stat_batch_fast_vertices] += batchnumvertices;
7757 r_refdef.stats[r_stat_batch_fast_triangles] += batchnumtriangles;
7758 }
7759 return;
7760 }
7761
7762 // something needs software processing, do it for real...
7763 // we only directly handle separate array data in this case and then
7764 // generate interleaved data if needed...
7767 r_refdef.stats[r_stat_batch_dynamic_surfaces] += batchnumsurfaces;
7768 r_refdef.stats[r_stat_batch_dynamic_vertices] += batchnumvertices;
7769 r_refdef.stats[r_stat_batch_dynamic_triangles] += batchnumtriangles;
7770
7771 // now copy the vertex data into a combined array and make an index array
7772 // (this is what Quake3 does all the time)
7773 // we also apply any skeletal animation here that would have been done in
7774 // the vertex shader, because most of the dynamic vertex animation cases
7775 // need actual vertex positions and normals
7776 //if (dynamicvertex)
7777 {
7805 rsurface.batchelement3i = (int *)R_FrameData_Alloc(batchnumtriangles * sizeof(int[3]));
7814 // we'll only be setting up certain arrays as needed
7815 if (batchneed & BATCHNEED_ARRAY_VERTEX)
7816 rsurface.batchvertex3f = (float *)R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
7817 if (batchneed & BATCHNEED_ARRAY_NORMAL)
7818 rsurface.batchnormal3f = (float *)R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
7819 if (batchneed & BATCHNEED_ARRAY_VECTOR)
7820 {
7821 rsurface.batchsvector3f = (float *)R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
7822 rsurface.batchtvector3f = (float *)R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
7823 }
7824 if (batchneed & BATCHNEED_ARRAY_VERTEXCOLOR)
7825 rsurface.batchlightmapcolor4f = (float *)R_FrameData_Alloc(batchnumvertices * sizeof(float[4]));
7826 if (batchneed & BATCHNEED_ARRAY_TEXCOORD)
7827 rsurface.batchtexcoordtexture2f = (float *)R_FrameData_Alloc(batchnumvertices * sizeof(float[2]));
7828 if (batchneed & BATCHNEED_ARRAY_LIGHTMAP)
7829 rsurface.batchtexcoordlightmap2f = (float *)R_FrameData_Alloc(batchnumvertices * sizeof(float[2]));
7830 if (batchneed & BATCHNEED_ARRAY_SKELETAL)
7831 {
7832 rsurface.batchskeletalindex4ub = (unsigned char *)R_FrameData_Alloc(batchnumvertices * sizeof(unsigned char[4]));
7833 rsurface.batchskeletalweight4ub = (unsigned char *)R_FrameData_Alloc(batchnumvertices * sizeof(unsigned char[4]));
7834 }
7835 numvertices = 0;
7836 numtriangles = 0;
7837 for (i = 0;i < texturenumsurfaces;i++)
7838 {
7839 surfacefirstvertex = texturesurfacelist[i]->num_firstvertex;
7840 surfacenumvertices = texturesurfacelist[i]->num_vertices;
7841 surfacefirsttriangle = texturesurfacelist[i]->num_firsttriangle;
7842 surfacenumtriangles = texturesurfacelist[i]->num_triangles;
7843 // copy only the data requested
7845 {
7846 if (batchneed & BATCHNEED_ARRAY_VERTEX)
7847 {
7849 memcpy(rsurface.batchvertex3f + 3*numvertices, rsurface.modelvertex3f + 3*surfacefirstvertex, surfacenumvertices * sizeof(float[3]));
7850 else
7851 memset(rsurface.batchvertex3f + 3*numvertices, 0, surfacenumvertices * sizeof(float[3]));
7852 }
7853 if (batchneed & BATCHNEED_ARRAY_NORMAL)
7854 {
7856 memcpy(rsurface.batchnormal3f + 3*numvertices, rsurface.modelnormal3f + 3*surfacefirstvertex, surfacenumvertices * sizeof(float[3]));
7857 else
7858 memset(rsurface.batchnormal3f + 3*numvertices, 0, surfacenumvertices * sizeof(float[3]));
7859 }
7860 if (batchneed & BATCHNEED_ARRAY_VECTOR)
7861 {
7863 {
7864 memcpy(rsurface.batchsvector3f + 3*numvertices, rsurface.modelsvector3f + 3*surfacefirstvertex, surfacenumvertices * sizeof(float[3]));
7865 memcpy(rsurface.batchtvector3f + 3*numvertices, rsurface.modeltvector3f + 3*surfacefirstvertex, surfacenumvertices * sizeof(float[3]));
7866 }
7867 else
7868 {
7869 memset(rsurface.batchsvector3f + 3*numvertices, 0, surfacenumvertices * sizeof(float[3]));
7870 memset(rsurface.batchtvector3f + 3*numvertices, 0, surfacenumvertices * sizeof(float[3]));
7871 }
7872 }
7873 if (batchneed & BATCHNEED_ARRAY_VERTEXCOLOR)
7874 {
7876 memcpy(rsurface.batchlightmapcolor4f + 4*numvertices, rsurface.modellightmapcolor4f + 4*surfacefirstvertex, surfacenumvertices * sizeof(float[4]));
7877 else
7878 memset(rsurface.batchlightmapcolor4f + 4*numvertices, 0, surfacenumvertices * sizeof(float[4]));
7879 }
7880 if (batchneed & BATCHNEED_ARRAY_TEXCOORD)
7881 {
7883 memcpy(rsurface.batchtexcoordtexture2f + 2*numvertices, rsurface.modeltexcoordtexture2f + 2*surfacefirstvertex, surfacenumvertices * sizeof(float[2]));
7884 else
7885 memset(rsurface.batchtexcoordtexture2f + 2*numvertices, 0, surfacenumvertices * sizeof(float[2]));
7886 }
7887 if (batchneed & BATCHNEED_ARRAY_LIGHTMAP)
7888 {
7890 memcpy(rsurface.batchtexcoordlightmap2f + 2*numvertices, rsurface.modeltexcoordlightmap2f + 2*surfacefirstvertex, surfacenumvertices * sizeof(float[2]));
7891 else
7892 memset(rsurface.batchtexcoordlightmap2f + 2*numvertices, 0, surfacenumvertices * sizeof(float[2]));
7893 }
7894 if (batchneed & BATCHNEED_ARRAY_SKELETAL)
7895 {
7897 {
7898 memcpy(rsurface.batchskeletalindex4ub + 4*numvertices, rsurface.modelskeletalindex4ub + 4*surfacefirstvertex, surfacenumvertices * sizeof(unsigned char[4]));
7899 memcpy(rsurface.batchskeletalweight4ub + 4*numvertices, rsurface.modelskeletalweight4ub + 4*surfacefirstvertex, surfacenumvertices * sizeof(unsigned char[4]));
7900 }
7901 else
7902 {
7903 memset(rsurface.batchskeletalindex4ub + 4*numvertices, 0, surfacenumvertices * sizeof(unsigned char[4]));
7904 memset(rsurface.batchskeletalweight4ub + 4*numvertices, 0, surfacenumvertices * sizeof(unsigned char[4]));
7905 ub = rsurface.batchskeletalweight4ub + 4*numvertices;
7906 for (j = 0;j < surfacenumvertices;j++)
7907 ub[j*4] = 255;
7908 }
7909 }
7910 }
7911 RSurf_RenumberElements(rsurface.modelelement3i + 3*surfacefirsttriangle, rsurface.batchelement3i + 3*numtriangles, 3*surfacenumtriangles, numvertices - surfacefirstvertex);
7912 numvertices += surfacenumvertices;
7913 numtriangles += surfacenumtriangles;
7914 }
7915
7916 // generate a 16bit index array as well if possible
7917 // (in general, dynamic batches fit)
7918 if (numvertices <= 65536)
7919 {
7920 rsurface.batchelement3s = (unsigned short *)R_FrameData_Alloc(batchnumtriangles * sizeof(unsigned short[3]));
7921 for (i = 0;i < numtriangles*3;i++)
7923 }
7924
7925 // since we've copied everything, the batch now starts at 0
7927 rsurface.batchnumvertices = batchnumvertices;
7929 rsurface.batchnumtriangles = batchnumtriangles;
7930 }
7931
7932 // apply skeletal animation that would have been done in the vertex shader
7934 {
7935 const unsigned char *si;
7936 const unsigned char *sw;
7937 const float *t[4];
7938 const float *b = rsurface.batchskeletaltransform3x4;
7939 float *vp, *vs, *vt, *vn;
7940 float w[4];
7941 float m[3][4], n[3][4];
7942 float tp[3], ts[3], tt[3], tn[3];
7953 memset(m[0], 0, sizeof(m));
7954 memset(n[0], 0, sizeof(n));
7955 for (i = 0;i < batchnumvertices;i++)
7956 {
7957 t[0] = b + si[0]*12;
7958 if (sw[0] == 255)
7959 {
7960 // common case - only one matrix
7961 m[0][0] = t[0][ 0];
7962 m[0][1] = t[0][ 1];
7963 m[0][2] = t[0][ 2];
7964 m[0][3] = t[0][ 3];
7965 m[1][0] = t[0][ 4];
7966 m[1][1] = t[0][ 5];
7967 m[1][2] = t[0][ 6];
7968 m[1][3] = t[0][ 7];
7969 m[2][0] = t[0][ 8];
7970 m[2][1] = t[0][ 9];
7971 m[2][2] = t[0][10];
7972 m[2][3] = t[0][11];
7973 }
7974 else if (sw[2] + sw[3])
7975 {
7976 // blend 4 matrices
7977 t[1] = b + si[1]*12;
7978 t[2] = b + si[2]*12;
7979 t[3] = b + si[3]*12;
7980 w[0] = sw[0] * (1.0f / 255.0f);
7981 w[1] = sw[1] * (1.0f / 255.0f);
7982 w[2] = sw[2] * (1.0f / 255.0f);
7983 w[3] = sw[3] * (1.0f / 255.0f);
7984 // blend the matrices
7985 m[0][0] = t[0][ 0] * w[0] + t[1][ 0] * w[1] + t[2][ 0] * w[2] + t[3][ 0] * w[3];
7986 m[0][1] = t[0][ 1] * w[0] + t[1][ 1] * w[1] + t[2][ 1] * w[2] + t[3][ 1] * w[3];
7987 m[0][2] = t[0][ 2] * w[0] + t[1][ 2] * w[1] + t[2][ 2] * w[2] + t[3][ 2] * w[3];
7988 m[0][3] = t[0][ 3] * w[0] + t[1][ 3] * w[1] + t[2][ 3] * w[2] + t[3][ 3] * w[3];
7989 m[1][0] = t[0][ 4] * w[0] + t[1][ 4] * w[1] + t[2][ 4] * w[2] + t[3][ 4] * w[3];
7990 m[1][1] = t[0][ 5] * w[0] + t[1][ 5] * w[1] + t[2][ 5] * w[2] + t[3][ 5] * w[3];
7991 m[1][2] = t[0][ 6] * w[0] + t[1][ 6] * w[1] + t[2][ 6] * w[2] + t[3][ 6] * w[3];
7992 m[1][3] = t[0][ 7] * w[0] + t[1][ 7] * w[1] + t[2][ 7] * w[2] + t[3][ 7] * w[3];
7993 m[2][0] = t[0][ 8] * w[0] + t[1][ 8] * w[1] + t[2][ 8] * w[2] + t[3][ 8] * w[3];
7994 m[2][1] = t[0][ 9] * w[0] + t[1][ 9] * w[1] + t[2][ 9] * w[2] + t[3][ 9] * w[3];
7995 m[2][2] = t[0][10] * w[0] + t[1][10] * w[1] + t[2][10] * w[2] + t[3][10] * w[3];
7996 m[2][3] = t[0][11] * w[0] + t[1][11] * w[1] + t[2][11] * w[2] + t[3][11] * w[3];
7997 }
7998 else
7999 {
8000 // blend 2 matrices
8001 t[1] = b + si[1]*12;
8002 w[0] = sw[0] * (1.0f / 255.0f);
8003 w[1] = sw[1] * (1.0f / 255.0f);
8004 // blend the matrices
8005 m[0][0] = t[0][ 0] * w[0] + t[1][ 0] * w[1];
8006 m[0][1] = t[0][ 1] * w[0] + t[1][ 1] * w[1];
8007 m[0][2] = t[0][ 2] * w[0] + t[1][ 2] * w[1];
8008 m[0][3] = t[0][ 3] * w[0] + t[1][ 3] * w[1];
8009 m[1][0] = t[0][ 4] * w[0] + t[1][ 4] * w[1];
8010 m[1][1] = t[0][ 5] * w[0] + t[1][ 5] * w[1];
8011 m[1][2] = t[0][ 6] * w[0] + t[1][ 6] * w[1];
8012 m[1][3] = t[0][ 7] * w[0] + t[1][ 7] * w[1];
8013 m[2][0] = t[0][ 8] * w[0] + t[1][ 8] * w[1];
8014 m[2][1] = t[0][ 9] * w[0] + t[1][ 9] * w[1];
8015 m[2][2] = t[0][10] * w[0] + t[1][10] * w[1];
8016 m[2][3] = t[0][11] * w[0] + t[1][11] * w[1];
8017 }
8018 si += 4;
8019 sw += 4;
8020 // modify the vertex
8021 VectorCopy(vp, tp);
8022 vp[0] = tp[0] * m[0][0] + tp[1] * m[0][1] + tp[2] * m[0][2] + m[0][3];
8023 vp[1] = tp[0] * m[1][0] + tp[1] * m[1][1] + tp[2] * m[1][2] + m[1][3];
8024 vp[2] = tp[0] * m[2][0] + tp[1] * m[2][1] + tp[2] * m[2][2] + m[2][3];
8025 vp += 3;
8026 if (vn)
8027 {
8028 // the normal transformation matrix is a set of cross products...
8029 CrossProduct(m[1], m[2], n[0]);
8030 CrossProduct(m[2], m[0], n[1]);
8031 CrossProduct(m[0], m[1], n[2]); // is actually transpose(inverse(m)) * det(m)
8032 VectorCopy(vn, tn);
8033 vn[0] = tn[0] * n[0][0] + tn[1] * n[0][1] + tn[2] * n[0][2];
8034 vn[1] = tn[0] * n[1][0] + tn[1] * n[1][1] + tn[2] * n[1][2];
8035 vn[2] = tn[0] * n[2][0] + tn[1] * n[2][1] + tn[2] * n[2][2];
8036 VectorNormalize(vn);
8037 vn += 3;
8038 if (vs)
8039 {
8040 VectorCopy(vs, ts);
8041 vs[0] = ts[0] * n[0][0] + ts[1] * n[0][1] + ts[2] * n[0][2];
8042 vs[1] = ts[0] * n[1][0] + ts[1] * n[1][1] + ts[2] * n[1][2];
8043 vs[2] = ts[0] * n[2][0] + ts[1] * n[2][1] + ts[2] * n[2][2];
8044 VectorNormalize(vs);
8045 vs += 3;
8046 VectorCopy(vt, tt);
8047 vt[0] = tt[0] * n[0][0] + tt[1] * n[0][1] + tt[2] * n[0][2];
8048 vt[1] = tt[0] * n[1][0] + tt[1] * n[1][1] + tt[2] * n[1][2];
8049 vt[2] = tt[0] * n[2][0] + tt[1] * n[2][1] + tt[2] * n[2][2];
8050 VectorNormalize(vt);
8051 vt += 3;
8052 }
8053 }
8054 }
8057 }
8058
8059 // q1bsp surfaces rendered in vertex color mode have to have colors
8060 // calculated based on lightstyles
8061 if ((batchneed & BATCHNEED_ARRAY_VERTEXCOLOR) && texturesurfacelist[0]->lightmapinfo)
8062 {
8063 // generate color arrays for the surfaces in this list
8064 int c[4];
8065 int scale;
8066 int size3;
8067 const int *offsets;
8068 const unsigned char *lm;
8069 rsurface.batchlightmapcolor4f = (float *)R_FrameData_Alloc(batchnumvertices * sizeof(float[4]));
8072 numvertices = 0;
8073 for (i = 0;i < texturenumsurfaces;i++)
8074 {
8075 surface = texturesurfacelist[i];
8077 surfacenumvertices = surface->num_vertices;
8078 if (surface->lightmapinfo->samples)
8079 {
8080 for (j = 0;j < surfacenumvertices;j++)
8081 {
8082 lm = surface->lightmapinfo->samples + offsets[j];
8084 VectorScale(lm, scale, c);
8085 if (surface->lightmapinfo->styles[1] != 255)
8086 {
8087 size3 = ((surface->lightmapinfo->extents[0]>>4)+1)*((surface->lightmapinfo->extents[1]>>4)+1)*3;
8088 lm += size3;
8090 VectorMA(c, scale, lm, c);
8091 if (surface->lightmapinfo->styles[2] != 255)
8092 {
8093 lm += size3;
8095 VectorMA(c, scale, lm, c);
8096 if (surface->lightmapinfo->styles[3] != 255)
8097 {
8098 lm += size3;
8100 VectorMA(c, scale, lm, c);
8101 }
8102 }
8103 }
8104 c[0] >>= 7;
8105 c[1] >>= 7;
8106 c[2] >>= 7;
8107 Vector4Set(rsurface.batchlightmapcolor4f + 4*numvertices, min(c[0], 255) * (1.0f / 255.0f), min(c[1], 255) * (1.0f / 255.0f), min(c[2], 255) * (1.0f / 255.0f), 1);
8108 numvertices++;
8109 }
8110 }
8111 else
8112 {
8113 for (j = 0;j < surfacenumvertices;j++)
8114 {
8115 Vector4Set(rsurface.batchlightmapcolor4f + 4*numvertices, 0, 0, 0, 1);
8116 numvertices++;
8117 }
8118 }
8119 }
8120 }
8121
8122 // if vertices are deformed (sprite flares and things in maps, possibly
8123 // water waves, bulges and other deformations), modify the copied vertices
8124 // in place
8125 for (deformindex = 0, deform = rsurface.texture->deforms;deformindex < Q3MAXDEFORMS && deform->deform && r_deformvertexes.integer;deformindex++, deform++)
8126 {
8127 float scale;
8128 switch (deform->deform)
8129 {
8130 default:
8132 case Q3DEFORM_TEXT0:
8133 case Q3DEFORM_TEXT1:
8134 case Q3DEFORM_TEXT2:
8135 case Q3DEFORM_TEXT3:
8136 case Q3DEFORM_TEXT4:
8137 case Q3DEFORM_TEXT5:
8138 case Q3DEFORM_TEXT6:
8139 case Q3DEFORM_TEXT7:
8140 case Q3DEFORM_NONE:
8141 break;
8146 VectorNormalize(newforward);
8147 VectorNormalize(newright);
8148 VectorNormalize(newup);
8149// rsurface.batchvertex3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchvertex3f);
8150// rsurface.batchvertex3f_vertexbuffer = NULL;
8151// rsurface.batchvertex3f_bufferoffset = 0;
8152// rsurface.batchsvector3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchsvector3f);
8153// rsurface.batchsvector3f_vertexbuffer = NULL;
8154// rsurface.batchsvector3f_bufferoffset = 0;
8155// rsurface.batchtvector3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchtvector3f);
8156// rsurface.batchtvector3f_vertexbuffer = NULL;
8157// rsurface.batchtvector3f_bufferoffset = 0;
8158// rsurface.batchnormal3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchnormal3f);
8159// rsurface.batchnormal3f_vertexbuffer = NULL;
8160// rsurface.batchnormal3f_bufferoffset = 0;
8161 // sometimes we're on a renderpath that does not use vectors (GL11/GL13/GLES1)
8166 // a single autosprite surface can contain multiple sprites...
8167 for (j = 0;j < batchnumvertices - 3;j += 4)
8168 {
8169 VectorClear(center);
8170 for (i = 0;i < 4;i++)
8171 VectorAdd(center, rsurface.batchvertex3f + 3*(j+i), center);
8172 VectorScale(center, 0.25f, center);
8176 for (i = 0;i < 4;i++)
8177 {
8178 VectorSubtract(rsurface.batchvertex3f + 3*(j+i), center, v);
8179 VectorMAMAMAM(1, center, DotProduct(forward, v), newforward, DotProduct(right, v), newright, DotProduct(up, v), newup, rsurface.batchvertex3f + 3*(j+i));
8180 }
8181 }
8182 // if we get here, BATCHNEED_ARRAY_NORMAL and BATCHNEED_ARRAY_VECTOR are in batchneed, so no need to check
8185 break;
8190 VectorNormalize(newforward);
8191 VectorNormalize(newright);
8192 VectorNormalize(newup);
8193// rsurface.batchvertex3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchvertex3f);
8194// rsurface.batchvertex3f_vertexbuffer = NULL;
8195// rsurface.batchvertex3f_bufferoffset = 0;
8196 {
8197 const float *v1, *v2;
8198 vec3_t start, end;
8199 float f, l;
8200 struct
8201 {
8202 float length2;
8203 const float *v1;
8204 const float *v2;
8205 }
8206 shortest[2];
8207 memset(shortest, 0, sizeof(shortest));
8208 // a single autosprite surface can contain multiple sprites...
8209 for (j = 0;j < batchnumvertices - 3;j += 4)
8210 {
8211 VectorClear(center);
8212 for (i = 0;i < 4;i++)
8213 VectorAdd(center, rsurface.batchvertex3f + 3*(j+i), center);
8214 VectorScale(center, 0.25f, center);
8215 // find the two shortest edges, then use them to define the
8216 // axis vectors for rotating around the central axis
8217 for (i = 0;i < 6;i++)
8218 {
8219 v1 = rsurface.batchvertex3f + 3*(j+quadedges[i][0]);
8220 v2 = rsurface.batchvertex3f + 3*(j+quadedges[i][1]);
8221 l = VectorDistance2(v1, v2);
8222 // this length bias tries to make sense of square polygons, assuming they are meant to be upright
8223 if (v1[2] != v2[2])
8224 l += (1.0f / 1024.0f);
8225 if (shortest[0].length2 > l || i == 0)
8226 {
8227 shortest[1] = shortest[0];
8228 shortest[0].length2 = l;
8229 shortest[0].v1 = v1;
8230 shortest[0].v2 = v2;
8231 }
8232 else if (shortest[1].length2 > l || i == 1)
8233 {
8234 shortest[1].length2 = l;
8235 shortest[1].v1 = v1;
8236 shortest[1].v2 = v2;
8237 }
8238 }
8239 VectorLerp(shortest[0].v1, 0.5f, shortest[0].v2, start);
8240 VectorLerp(shortest[1].v1, 0.5f, shortest[1].v2, end);
8241 // this calculates the right vector from the shortest edge
8242 // and the up vector from the edge midpoints
8243 VectorSubtract(shortest[0].v1, shortest[0].v2, right);
8245 VectorSubtract(end, start, up);
8247 // calculate a forward vector to use instead of the original plane normal (this is how we get a new right vector)
8249 //Matrix4x4_Transform3x3(&rsurface.inversematrix, r_refdef.view.forward, forward);
8253 CrossProduct(up, forward, newright);
8254 VectorNormalize(newright);
8255 // rotate the quad around the up axis vector, this is made
8256 // especially easy by the fact we know the quad is flat,
8257 // so we only have to subtract the center position and
8258 // measure distance along the right vector, and then
8259 // multiply that by the newright vector and add back the
8260 // center position
8261 // we also need to subtract the old position to undo the
8262 // displacement from the center, which we do with a
8263 // DotProduct, the subtraction/addition of center is also
8264 // optimized into DotProducts here
8265 l = DotProduct(right, center);
8266 for (i = 0;i < 4;i++)
8267 {
8268 v1 = rsurface.batchvertex3f + 3*(j+i);
8269 f = DotProduct(right, v1) - l;
8270 VectorMAMAM(1, v1, -f, right, f, newright, rsurface.batchvertex3f + 3*(j+i));
8271 }
8272 }
8273 }
8274 if(batchneed & (BATCHNEED_ARRAY_NORMAL | BATCHNEED_ARRAY_VECTOR)) // otherwise these can stay NULL
8275 {
8276// rsurface.batchnormal3f = R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
8277// rsurface.batchnormal3f_vertexbuffer = NULL;
8278// rsurface.batchnormal3f_bufferoffset = 0;
8280 }
8281 if(batchneed & BATCHNEED_ARRAY_VECTOR) // otherwise these can stay NULL
8282 {
8283// rsurface.batchsvector3f = R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
8284// rsurface.batchsvector3f_vertexbuffer = NULL;
8285// rsurface.batchsvector3f_bufferoffset = 0;
8286// rsurface.batchtvector3f = R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
8287// rsurface.batchtvector3f_vertexbuffer = NULL;
8288// rsurface.batchtvector3f_bufferoffset = 0;
8290 }
8291 break;
8292 case Q3DEFORM_NORMAL:
8293 // deform the normals to make reflections wavey
8294 rsurface.batchnormal3f = (float *)R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchnormal3f);
8297 for (j = 0;j < batchnumvertices;j++)
8298 {
8299 float vertex[3];
8300 float *normal = rsurface.batchnormal3f + 3*j;
8301 VectorScale(rsurface.batchvertex3f + 3*j, 0.98f, vertex);
8302 normal[0] = rsurface.batchnormal3f[j*3+0] + deform->parms[0] * noise4f( vertex[0], vertex[1], vertex[2], rsurface.shadertime * deform->parms[1]);
8303 normal[1] = rsurface.batchnormal3f[j*3+1] + deform->parms[0] * noise4f( 98 + vertex[0], vertex[1], vertex[2], rsurface.shadertime * deform->parms[1]);
8304 normal[2] = rsurface.batchnormal3f[j*3+2] + deform->parms[0] * noise4f(196 + vertex[0], vertex[1], vertex[2], rsurface.shadertime * deform->parms[1]);
8306 }
8307 if(batchneed & BATCHNEED_ARRAY_VECTOR) // otherwise these can stay NULL
8308 {
8309// rsurface.batchsvector3f = R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
8310// rsurface.batchsvector3f_vertexbuffer = NULL;
8311// rsurface.batchsvector3f_bufferoffset = 0;
8312// rsurface.batchtvector3f = R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
8313// rsurface.batchtvector3f_vertexbuffer = NULL;
8314// rsurface.batchtvector3f_bufferoffset = 0;
8316 }
8317 break;
8318 case Q3DEFORM_WAVE:
8319 // deform vertex array to make wavey water and flags and such
8320 waveparms[0] = deform->waveparms[0];
8321 waveparms[1] = deform->waveparms[1];
8322 waveparms[2] = deform->waveparms[2];
8323 waveparms[3] = deform->waveparms[3];
8324 if(!R_TestQ3WaveFunc(deform->wavefunc, waveparms))
8325 break; // if wavefunc is a nop, don't make a dynamic vertex array
8326 // this is how a divisor of vertex influence on deformation
8327 animpos = deform->parms[0] ? 1.0f / deform->parms[0] : 100.0f;
8328 scale = R_EvaluateQ3WaveFunc(deform->wavefunc, waveparms);
8329// rsurface.batchvertex3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchvertex3f);
8330// rsurface.batchvertex3f_vertexbuffer = NULL;
8331// rsurface.batchvertex3f_bufferoffset = 0;
8332// rsurface.batchnormal3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchnormal3f);
8333// rsurface.batchnormal3f_vertexbuffer = NULL;
8334// rsurface.batchnormal3f_bufferoffset = 0;
8335 for (j = 0;j < batchnumvertices;j++)
8336 {
8337 // if the wavefunc depends on time, evaluate it per-vertex
8338 if (waveparms[3])
8339 {
8340 waveparms[2] = deform->waveparms[2] + (rsurface.batchvertex3f[j*3+0] + rsurface.batchvertex3f[j*3+1] + rsurface.batchvertex3f[j*3+2]) * animpos;
8341 scale = R_EvaluateQ3WaveFunc(deform->wavefunc, waveparms);
8342 }
8344 }
8345 // if we get here, BATCHNEED_ARRAY_NORMAL is in batchneed, so no need to check
8347 if(batchneed & BATCHNEED_ARRAY_VECTOR) // otherwise these can stay NULL
8348 {
8349// rsurface.batchsvector3f = R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
8350// rsurface.batchsvector3f_vertexbuffer = NULL;
8351// rsurface.batchsvector3f_bufferoffset = 0;
8352// rsurface.batchtvector3f = R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
8353// rsurface.batchtvector3f_vertexbuffer = NULL;
8354// rsurface.batchtvector3f_bufferoffset = 0;
8356 }
8357 break;
8358 case Q3DEFORM_BULGE:
8359 // deform vertex array to make the surface have moving bulges
8360// rsurface.batchvertex3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchvertex3f);
8361// rsurface.batchvertex3f_vertexbuffer = NULL;
8362// rsurface.batchvertex3f_bufferoffset = 0;
8363// rsurface.batchnormal3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchnormal3f);
8364// rsurface.batchnormal3f_vertexbuffer = NULL;
8365// rsurface.batchnormal3f_bufferoffset = 0;
8366 for (j = 0;j < batchnumvertices;j++)
8367 {
8368 scale = sin(rsurface.batchtexcoordtexture2f[j*2+0] * deform->parms[0] + rsurface.shadertime * deform->parms[2]) * deform->parms[1];
8370 }
8371 // if we get here, BATCHNEED_ARRAY_NORMAL is in batchneed, so no need to check
8373 if(batchneed & BATCHNEED_ARRAY_VECTOR) // otherwise these can stay NULL
8374 {
8375// rsurface.batchsvector3f = R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
8376// rsurface.batchsvector3f_vertexbuffer = NULL;
8377// rsurface.batchsvector3f_bufferoffset = 0;
8378// rsurface.batchtvector3f = R_FrameData_Alloc(batchnumvertices * sizeof(float[3]));
8379// rsurface.batchtvector3f_vertexbuffer = NULL;
8380// rsurface.batchtvector3f_bufferoffset = 0;
8382 }
8383 break;
8384 case Q3DEFORM_MOVE:
8385 // deform vertex array
8386 if(!R_TestQ3WaveFunc(deform->wavefunc, deform->waveparms))
8387 break; // if wavefunc is a nop, don't make a dynamic vertex array
8388 scale = R_EvaluateQ3WaveFunc(deform->wavefunc, deform->waveparms);
8389 VectorScale(deform->parms, scale, waveparms);
8390// rsurface.batchvertex3f = R_FrameData_Store(batchnumvertices * sizeof(float[3]), rsurface.batchvertex3f);
8391// rsurface.batchvertex3f_vertexbuffer = NULL;
8392// rsurface.batchvertex3f_bufferoffset = 0;
8393 for (j = 0;j < batchnumvertices;j++)
8394 VectorAdd(rsurface.batchvertex3f + 3*j, waveparms, rsurface.batchvertex3f + 3*j);
8395 break;
8396 }
8397 }
8398
8400 {
8401 // generate texcoords based on the chosen texcoord source
8403 {
8404 default:
8405 case Q3TCGEN_TEXTURE:
8406 break;
8407 case Q3TCGEN_LIGHTMAP:
8408 // rsurface.batchtexcoordtexture2f = R_FrameData_Alloc(batchnumvertices * sizeof(float[2]));
8409 // rsurface.batchtexcoordtexture2f_vertexbuffer = NULL;
8410 // rsurface.batchtexcoordtexture2f_bufferoffset = 0;
8412 memcpy(rsurface.batchtexcoordtexture2f, rsurface.batchtexcoordlightmap2f, batchnumvertices * sizeof(float[2]));
8413 break;
8414 case Q3TCGEN_VECTOR:
8415 // rsurface.batchtexcoordtexture2f = R_FrameData_Alloc(batchnumvertices * sizeof(float[2]));
8416 // rsurface.batchtexcoordtexture2f_vertexbuffer = NULL;
8417 // rsurface.batchtexcoordtexture2f_bufferoffset = 0;
8418 for (j = 0;j < batchnumvertices;j++)
8419 {
8422 }
8423 break;
8425 // make environment reflections using a spheremap
8426 rsurface.batchtexcoordtexture2f = (float *)R_FrameData_Alloc(batchnumvertices * sizeof(float[2]));
8429 for (j = 0;j < batchnumvertices;j++)
8430 {
8431 // identical to Q3A's method, but executed in worldspace so
8432 // carried models can be shiny too
8433
8434 float viewer[3], d, reflected[3], worldreflected[3];
8435
8437 // VectorNormalize(viewer);
8438
8439 d = DotProduct(rsurface.batchnormal3f + 3*j, viewer);
8440
8441 reflected[0] = rsurface.batchnormal3f[j*3+0]*2*d - viewer[0];
8442 reflected[1] = rsurface.batchnormal3f[j*3+1]*2*d - viewer[1];
8443 reflected[2] = rsurface.batchnormal3f[j*3+2]*2*d - viewer[2];
8444 // note: this is proportinal to viewer, so we can normalize later
8445
8446 Matrix4x4_Transform3x3(&rsurface.matrix, reflected, worldreflected);
8447 VectorNormalize(worldreflected);
8448
8449 // note: this sphere map only uses world x and z!
8450 // so positive and negative y will LOOK THE SAME.
8451 rsurface.batchtexcoordtexture2f[j*2+0] = 0.5 + 0.5 * worldreflected[1];
8452 rsurface.batchtexcoordtexture2f[j*2+1] = 0.5 - 0.5 * worldreflected[2];
8453 }
8454 break;
8455 }
8456 // the only tcmod that needs software vertex processing is turbulent, so
8457 // check for it here and apply the changes if needed
8458 // and we only support that as the first one
8459 // (handling a mixture of turbulent and other tcmods would be problematic
8460 // without punting it entirely to a software path)
8462 {
8463 amplitude = rsurface.texture->materialshaderpass->tcmods[0].parms[1];
8465 // rsurface.batchtexcoordtexture2f = R_FrameData_Alloc(batchnumvertices * sizeof(float[2]));
8466 // rsurface.batchtexcoordtexture2f_vertexbuffer = NULL;
8467 // rsurface.batchtexcoordtexture2f_bufferoffset = 0;
8468 for (j = 0;j < batchnumvertices;j++)
8469 {
8470 rsurface.batchtexcoordtexture2f[j*2+0] += amplitude * sin(((rsurface.batchvertex3f[j*3+0] + rsurface.batchvertex3f[j*3+2]) * 1.0 / 1024.0f + animpos) * M_PI * 2);
8471 rsurface.batchtexcoordtexture2f[j*2+1] += amplitude * sin(((rsurface.batchvertex3f[j*3+1] ) * 1.0 / 1024.0f + animpos) * M_PI * 2);
8472 }
8473 }
8474 }
8475}
8476
8478{
8479 // sometimes a zero triangle surface (usually a degenerate patch) makes it
8480 // through the pipeline, killing it earlier in the pipeline would have
8481 // per-surface overhead rather than per-batch overhead, so it's best to
8482 // reject it here, before it hits glDraw.
8483 if (rsurface.batchnumtriangles == 0)
8484 return;
8485#if 0
8486 // batch debugging code
8488 {
8489 int i;
8490 int j;
8491 int c;
8492 const int *e;
8494 for (i = 0;i < rsurface.batchnumtriangles*3;i++)
8495 {
8496 c = e[i];
8497 for (j = 0;j < rsurface.entity->model->num_surfaces;j++)
8498 {
8500 {
8502 Sys_Error("RSurf_DrawBatch: index %i uses different texture (%s) than surface %i which it belongs to (which uses %s)\n", c, rsurface.texture->name, j, rsurface.modelsurfaces[j].texture->name);
8503 break;
8504 }
8505 }
8506 }
8507 }
8508#endif
8510 {
8511 // issue multiple draws rather than copying index data
8512 int numsurfaces = rsurface.batchmultidrawnumsurfaces;
8513 const msurface_t **surfacelist = rsurface.batchmultidrawsurfacelist;
8514 int i, j, k, firstvertex, endvertex, firsttriangle, endtriangle;
8515 for (i = 0;i < numsurfaces;)
8516 {
8517 // combine consecutive surfaces as one draw
8518 for (k = i, j = i + 1;j < numsurfaces;k = j, j++)
8519 if (surfacelist[j] != surfacelist[k] + 1)
8520 break;
8521 firstvertex = surfacelist[i]->num_firstvertex;
8522 endvertex = surfacelist[k]->num_firstvertex + surfacelist[k]->num_vertices;
8523 firsttriangle = surfacelist[i]->num_firsttriangle;
8524 endtriangle = surfacelist[k]->num_firsttriangle + surfacelist[k]->num_triangles;
8526 i = j;
8527 }
8528 }
8529 else
8530 {
8531 // there is only one consecutive run of index data (may have been combined)
8533 }
8534}
8535
8537{
8538 // pick the closest matching water plane
8539 int planeindex, vertexindex, bestplaneindex = -1;
8540 float d, bestd;
8541 vec3_t vert;
8542 const float *v;
8544 qbool prepared = false;
8545 bestd = 0;
8546 for (planeindex = 0, p = r_fb.water.waterplanes;planeindex < r_fb.water.numwaterplanes;planeindex++, p++)
8547 {
8549 continue;
8550 d = 0;
8551 if(!prepared)
8552 {
8554 prepared = true;
8555 if(rsurface.batchnumvertices == 0)
8556 break;
8557 }
8558 for (vertexindex = 0, v = rsurface.batchvertex3f + rsurface.batchfirstvertex * 3;vertexindex < rsurface.batchnumvertices;vertexindex++, v += 3)
8559 {
8561 d += fabs(PlaneDiff(vert, &p->plane));
8562 }
8563 if (bestd > d || bestplaneindex < 0)
8564 {
8565 bestd = d;
8566 bestplaneindex = planeindex;
8567 }
8568 }
8569 return bestplaneindex;
8570 // NOTE: this MAY return a totally unrelated water plane; we can ignore
8571 // this situation though, as it might be better to render single larger
8572 // batches with useless stuff (backface culled for example) than to
8573 // render multiple smaller batches
8574}
8575
8577{
8578 // submodels are biased to avoid z-fighting with world surfaces that they
8579 // may be exactly overlapping (avoids z-fighting artifacts on certain
8580 // doors and things in Quake maps)
8585}
8586
8587static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, const msurface_t **texturesurfacelist)
8588{
8589 int j;
8590 const float *v;
8591 float p[3], mins[3], maxs[3];
8592 int scissor[4];
8593 // transparent sky would be ridiculous
8595 return;
8596 R_SetupShader_Generic_NoTexture(false, false);
8597 skyrenderlater = true;
8599 GL_DepthMask(true);
8600
8601 // add the vertices of the surfaces to a world bounding box so we can scissor the sky render later
8603 {
8604 RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
8605 for (j = 0, v = rsurface.batchvertex3f + 3 * rsurface.batchfirstvertex; j < rsurface.batchnumvertices; j++, v += 3)
8606 {
8608 if (j > 0)
8609 {
8610 if (mins[0] > p[0]) mins[0] = p[0];
8611 if (mins[1] > p[1]) mins[1] = p[1];
8612 if (mins[2] > p[2]) mins[2] = p[2];
8613 if (maxs[0] < p[0]) maxs[0] = p[0];
8614 if (maxs[1] < p[1]) maxs[1] = p[1];
8615 if (maxs[2] < p[2]) maxs[2] = p[2];
8616 }
8617 else
8618 {
8619 VectorCopy(p, mins);
8620 VectorCopy(p, maxs);
8621 }
8622 }
8623 if (!R_ScissorForBBox(mins, maxs, scissor))
8624 {
8625 if (skyscissor[2])
8626 {
8627 if (skyscissor[0] > scissor[0])
8628 {
8629 skyscissor[2] += skyscissor[0] - scissor[0];
8630 skyscissor[0] = scissor[0];
8631 }
8632 if (skyscissor[1] > scissor[1])
8633 {
8634 skyscissor[3] += skyscissor[1] - scissor[1];
8635 skyscissor[1] = scissor[1];
8636 }
8637 if (skyscissor[0] + skyscissor[2] < scissor[0] + scissor[2])
8638 skyscissor[2] = scissor[0] + scissor[2] - skyscissor[0];
8639 if (skyscissor[1] + skyscissor[3] < scissor[1] + scissor[3])
8640 skyscissor[3] = scissor[1] + scissor[3] - skyscissor[1];
8641 }
8642 else
8643 Vector4Copy(scissor, skyscissor);
8644 }
8645 }
8646
8647 // LadyHavoc: HalfLife maps have freaky skypolys so don't use
8648 // skymasking on them, and Quake3 never did sky masking (unlike
8649 // software Quake and software Quake2), so disable the sky masking
8650 // in Quake3 maps as it causes problems with q3map2 sky tricks,
8651 // and skymasking also looks very bad when noclipping outside the
8652 // level, so don't use it then either.
8654 {
8656 if (skyrendermasked)
8657 {
8658 R_SetupShader_DepthOrShadow(false, false, false);
8659 // depth-only (masking)
8660 GL_ColorMask(0, 0, 0, 0);
8661 // just to make sure that braindead drivers don't draw
8662 // anything despite that colormask...
8664 RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist);
8666 }
8667 else
8668 {
8669 R_SetupShader_Generic_NoTexture(false, false);
8670 // fog sky
8672 RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
8675 }
8677 if (skyrendermasked)
8679 }
8681 GL_Color(1, 1, 1, 1);
8682}
8683
8686static void R_DrawTextureSurfaceList_GL20(int texturenumsurfaces, const msurface_t **texturesurfacelist, qbool writedepth, qbool prepass, qbool ui)
8687{
8689 return;
8690 if (prepass)
8691 {
8692 // render screenspace normalmap to texture
8693 GL_DepthMask(true);
8694 R_SetupShader_Surface(vec3_origin, vec3_origin, vec3_origin, RSURFPASS_DEFERREDGEOMETRY, texturenumsurfaces, texturesurfacelist, NULL, false, false);
8696 return;
8697 }
8698
8699 // bind lightmap texture
8700
8701 // water/refraction/reflection/camera surfaces have to be handled specially
8703 {
8704 int start, end, startplaneindex;
8705 for (start = 0;start < texturenumsurfaces;start = end)
8706 {
8707 startplaneindex = RSurf_FindWaterPlaneForSurface(texturesurfacelist[start]);
8708 if(startplaneindex < 0)
8709 {
8710 // this happens if the plane e.g. got backface culled and thus didn't get a water plane. We can just ignore this.
8711 // Con_Printf("No matching water plane for surface with material flags 0x%08x - PLEASE DEBUG THIS\n", rsurface.texture->currentmaterialflags);
8712 end = start + 1;
8713 continue;
8714 }
8715 for (end = start + 1;end < texturenumsurfaces && startplaneindex == RSurf_FindWaterPlaneForSurface(texturesurfacelist[end]);end++)
8716 ;
8717 // now that we have a batch using the same planeindex, render it
8719 {
8720 // render water or distortion background
8721 GL_DepthMask(true);
8722 R_SetupShader_Surface(vec3_origin, vec3_origin, vec3_origin, RSURFPASS_BACKGROUND, end-start, texturesurfacelist + start, (void *)(r_fb.water.waterplanes + startplaneindex), false, false);
8724 // blend surface on top
8725 GL_DepthMask(false);
8726 R_SetupShader_Surface(vec3_origin, vec3_origin, vec3_origin, RSURFPASS_BASE, end-start, texturesurfacelist + start, NULL, false, false);
8728 }
8730 {
8731 // render surface with reflection texture as input
8733 R_SetupShader_Surface(vec3_origin, vec3_origin, vec3_origin, RSURFPASS_BASE, end-start, texturesurfacelist + start, (void *)(r_fb.water.waterplanes + startplaneindex), false, false);
8735 }
8736 }
8737 return;
8738 }
8739
8740 // render surface batch normally
8742 R_SetupShader_Surface(vec3_origin, vec3_origin, vec3_origin, RSURFPASS_BASE, texturenumsurfaces, texturesurfacelist, NULL, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SKY) != 0 || ui, ui);
8744}
8745
8746static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, const msurface_t **texturesurfacelist, qbool writedepth)
8747{
8748 int vi;
8749 int j;
8750 int texturesurfaceindex;
8751 int k;
8752 const msurface_t *surface;
8753 float surfacecolor4f[4];
8754 float c[4];
8756
8757// R_Mesh_ResetTextureState();
8758 R_SetupShader_Generic_NoTexture(false, false);
8759
8761 GL_DepthMask(writedepth);
8762
8763 switch (r_showsurfaces.integer)
8764 {
8765 case 1:
8766 default:
8768 vi = 0;
8769 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
8770 {
8771 surface = texturesurfacelist[texturesurfaceindex];
8772 k = (int)(((size_t)surface) / sizeof(msurface_t));
8773 Vector4Set(surfacecolor4f, (k & 0xF) * (1.0f / 16.0f), (k & 0xF0) * (1.0f / 256.0f), (k & 0xF00) * (1.0f / 4096.0f), 1);
8774 for (j = 0;j < surface->num_vertices;j++)
8775 {
8776 Vector4Copy(surfacecolor4f, rsurface.batchlightmapcolor4f + 4 * vi);
8777 vi++;
8778 }
8779 }
8780 break;
8781 case 3:
8782 if(t && t->currentskinframe)
8783 {
8784 Vector4Copy(t->currentskinframe->avgcolor, c);
8785 c[3] *= t->currentalpha;
8786 }
8787 else
8788 {
8789 Vector4Set(c, 1, 0, 1, 1);
8790 }
8791 if (t && (t->pantstexture || t->shirttexture))
8792 {
8794 }
8797 c[3] *= r_wateralpha.value;
8799 vi = 0;
8801 {
8802 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
8803 {
8804 surface = texturesurfacelist[texturesurfaceindex];
8805 for (j = 0;j < surface->num_vertices;j++)
8806 {
8807 float *ptr = rsurface.batchlightmapcolor4f + 4 * vi;
8808 Vector4Multiply(ptr, c, ptr);
8809 vi++;
8810 }
8811 }
8812 }
8813 else
8814 {
8815 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
8816 {
8817 surface = texturesurfacelist[texturesurfaceindex];
8818 for (j = 0;j < surface->num_vertices;j++)
8819 {
8820 float *ptr = rsurface.batchlightmapcolor4f + 4 * vi;
8821 Vector4Copy(c, ptr);
8822 vi++;
8823 }
8824 }
8825 }
8826 break;
8827 }
8830}
8831
8832static void R_DrawModelTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist, qbool writedepth, qbool prepass, qbool ui)
8833{
8837 {
8838 R_DrawTextureSurfaceList_ShowSurfaces(texturenumsurfaces, texturesurfacelist, writedepth);
8839 return;
8840 }
8841 switch (vid.renderpath)
8842 {
8843 case RENDERPATH_GL32:
8844 case RENDERPATH_GLES2:
8845 R_DrawTextureSurfaceList_GL20(texturenumsurfaces, texturesurfacelist, writedepth, prepass, ui);
8846 break;
8847 }
8849}
8850
8851static void R_DrawSurface_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
8852{
8853 int i, j;
8854 int texturenumsurfaces, endsurface;
8856 const msurface_t *surface;
8857 const msurface_t *texturesurfacelist[MESHQUEUE_TRANSPARENT_BATCHSIZE];
8858
8859 RSurf_ActiveModelEntity(ent, true, true, false);
8860
8862 {
8863 qbool setup = false;
8864 for (i = 0;i < numsurfaces;i = j)
8865 {
8866 j = i + 1;
8867 surface = rsurface.modelsurfaces + surfacelist[i];
8868 texture = surface->texture;
8873 // scan ahead until we find a different texture
8874 endsurface = min(i + 1024, numsurfaces);
8875 texturenumsurfaces = 0;
8876 texturesurfacelist[texturenumsurfaces++] = surface;
8877 for (;j < endsurface;j++)
8878 {
8879 surface = rsurface.modelsurfaces + surfacelist[j];
8880 if (texture != surface->texture)
8881 break;
8882 texturesurfacelist[texturenumsurfaces++] = surface;
8883 }
8885 continue;
8886 // render the range of surfaces as depth
8887 if (!setup)
8888 {
8889 setup = true;
8890 GL_ColorMask(0,0,0,0);
8891 GL_Color(1,1,1,1);
8892 GL_DepthTest(true);
8894 GL_DepthMask(true);
8895// R_Mesh_ResetTextureState();
8896 }
8898 RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist);
8902 }
8903 if (setup)
8905 }
8906
8907 for (i = 0;i < numsurfaces;i = j)
8908 {
8909 j = i + 1;
8910 surface = rsurface.modelsurfaces + surfacelist[i];
8911 texture = surface->texture;
8913 // scan ahead until we find a different texture
8914 endsurface = min(i + MESHQUEUE_TRANSPARENT_BATCHSIZE, numsurfaces);
8915 texturenumsurfaces = 0;
8916 texturesurfacelist[texturenumsurfaces++] = surface;
8920 for (;j < endsurface;j++)
8921 {
8922 surface = rsurface.modelsurfaces + surfacelist[j];
8923 if (texture != surface->texture || rsurface.lightmaptexture != surface->lightmaptexture)
8924 break;
8925 texturesurfacelist[texturenumsurfaces++] = surface;
8926 }
8927 // render the range of surfaces
8928 R_DrawModelTextureSurfaceList(texturenumsurfaces, texturesurfacelist, false, false, false);
8929 }
8930 rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveModelEntity
8931}
8932
8933static void R_ProcessTransparentTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist)
8934{
8935 // transparent surfaces get pushed off into the transparent queue
8936 int surfacelistindex;
8937 const msurface_t *surface;
8938 vec3_t tempcenter, center;
8939 for (surfacelistindex = 0;surfacelistindex < texturenumsurfaces;surfacelistindex++)
8940 {
8941 surface = texturesurfacelist[surfacelistindex];
8943 {
8944 tempcenter[0] = bound(surface->mins[0], rsurface.localvieworigin[0], surface->maxs[0]);
8945 tempcenter[1] = bound(surface->mins[1], rsurface.localvieworigin[1], surface->maxs[1]);
8946 tempcenter[2] = bound(surface->mins[2], rsurface.localvieworigin[2], surface->maxs[2]);
8947 }
8948 else
8949 {
8950 tempcenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
8951 tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
8952 tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
8953 }
8954 Matrix4x4_Transform(&rsurface.matrix, tempcenter, center);
8955 if (rsurface.entity->transparent_offset) // transparent offset
8956 {
8960 }
8962 }
8963}
8964
8977
8978static void R_ProcessModelTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist, qbool writedepth, qbool depthonly, qbool prepass, qbool ui)
8979{
8981 if (ui)
8982 R_DrawModelTextureSurfaceList(texturenumsurfaces, texturesurfacelist, writedepth, prepass, ui);
8983 else if (depthonly)
8984 R_DrawTextureSurfaceList_DepthOnly(texturenumsurfaces, texturesurfacelist);
8985 else if (prepass)
8986 {
8988 return;
8990 R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist);
8991 else
8992 R_DrawModelTextureSurfaceList(texturenumsurfaces, texturesurfacelist, writedepth, prepass, ui);
8993 }
8995 R_DrawTextureSurfaceList_Sky(texturenumsurfaces, texturesurfacelist);
8997 return;
8999 {
9000 // in the deferred case, transparent surfaces were queued during prepass
9002 R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist);
9003 }
9004 else
9005 {
9006 // the alphatest check is to make sure we write depth for anything we skipped on the depth-only pass earlier
9007 R_DrawModelTextureSurfaceList(texturenumsurfaces, texturesurfacelist, writedepth || (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST), prepass, ui);
9008 }
9010}
9011
9012static void R_QueueModelSurfaceList(entity_render_t *ent, int numsurfaces, const msurface_t **surfacelist, int flagsmask, qbool writedepth, qbool depthonly, qbool prepass, qbool ui)
9013{
9014 int i, j;
9017 // break the surface list down into batches by texture and use of lightmapping
9018 for (i = 0;i < numsurfaces;i = j)
9019 {
9020 j = i + 1;
9021 // texture is the base texture pointer, rsurface.texture is the
9022 // current frame/skin the texture is directing us to use (for example
9023 // if a model has 2 skins and it is on skin 1, then skin 0 tells us to
9024 // use skin 1 instead)
9025 texture = surfacelist[i]->texture;
9028 {
9029 // if this texture is not the kind we want, skip ahead to the next one
9030 for (;j < numsurfaces && texture == surfacelist[j]->texture;j++)
9031 ;
9032 continue;
9033 }
9034 if(depthonly || prepass)
9035 {
9039 // simply scan ahead until we find a different texture or lightmap state
9040 for (;j < numsurfaces && texture == surfacelist[j]->texture;j++)
9041 ;
9042 }
9043 else
9044 {
9045 rsurface.lightmaptexture = surfacelist[i]->lightmaptexture;
9048 // simply scan ahead until we find a different texture or lightmap state
9049 for (;j < numsurfaces && texture == surfacelist[j]->texture && rsurface.lightmaptexture == surfacelist[j]->lightmaptexture;j++)
9050 ;
9051 }
9052 // render the range of surfaces
9053 R_ProcessModelTextureSurfaceList(j - i, surfacelist + i, writedepth, depthonly, prepass, ui);
9054 }
9056}
9057
9058float locboxvertex3f[6*4*3] =
9059{
9060 1,0,1, 1,0,0, 1,1,0, 1,1,1,
9061 0,1,1, 0,1,0, 0,0,0, 0,0,1,
9062 1,1,1, 1,1,0, 0,1,0, 0,1,1,
9063 0,0,1, 0,0,0, 1,0,0, 1,0,1,
9064 0,0,1, 1,0,1, 1,1,1, 0,1,1,
9065 1,0,0, 0,0,0, 0,1,0, 1,1,0
9066};
9067
9068unsigned short locboxelements[6*2*3] =
9069{
9070 0, 1, 2, 0, 2, 3,
9071 4, 5, 6, 4, 6, 7,
9072 8, 9,10, 8,10,11,
9073 12,13,14, 12,14,15,
9074 16,17,18, 16,18,19,
9075 20,21,22, 20,22,23
9076};
9077
9078static void R_DrawLoc_Callback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
9079{
9080 int i, j;
9081 cl_locnode_t *loc = (cl_locnode_t *)ent;
9082 vec3_t mins, size;
9083 float vertex3f[6*4*3];
9086 GL_DepthMask(false);
9087 GL_DepthRange(0, 1);
9089 GL_DepthTest(true);
9092
9093// R_Mesh_ResetTextureState();
9094
9095 i = surfacelist[0];
9096 GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f) * r_refdef.view.colorscale,
9097 ((i & 0x0038) >> 3) * (1.0f / 7.0f) * r_refdef.view.colorscale,
9098 ((i & 0x01C0) >> 6) * (1.0f / 7.0f) * r_refdef.view.colorscale,
9099 surfacelist[0] < 0 ? 0.5f : 0.125f);
9100
9101 if (VectorCompare(loc->mins, loc->maxs))
9102 {
9103 VectorSet(size, 2, 2, 2);
9104 VectorMA(loc->mins, -0.5f, size, mins);
9105 }
9106 else
9107 {
9108 VectorCopy(loc->mins, mins);
9109 VectorSubtract(loc->maxs, loc->mins, size);
9110 }
9111
9112 for (i = 0;i < 6*4*3;)
9113 for (j = 0;j < 3;j++, i++)
9114 vertex3f[i] = mins[j] + size[j] * locboxvertex3f[i];
9115
9117 R_SetupShader_Generic_NoTexture(false, false);
9118 R_Mesh_Draw(0, 6*4, 0, 6*2, NULL, NULL, 0, locboxelements, NULL, 0);
9119}
9120
9121void R_DrawLocs(void)
9122{
9123 int index;
9124 cl_locnode_t *loc, *nearestloc;
9125 vec3_t center;
9127 for (loc = cl.locnodes, index = 0;loc;loc = loc->next, index++)
9128 {
9129 VectorLerp(loc->mins, 0.5f, loc->maxs, center);
9131 }
9132}
9133
9135{
9136 if (decalsystem->decals)
9137 Mem_Free(decalsystem->decals);
9138 memset(decalsystem, 0, sizeof(*decalsystem));
9139}
9140
9141static void R_DecalSystem_SpawnTriangle(decalsystem_t *decalsystem, const float *v0, const float *v1, const float *v2, const float *t0, const float *t1, const float *t2, const float *c0, const float *c1, const float *c2, int triangleindex, int surfaceindex, unsigned int decalsequence)
9142{
9143 tridecal_t *decal;
9144 int i;
9145
9146 // expand or initialize the system
9147 if (decalsystem->maxdecals <= decalsystem->numdecals)
9148 {
9149 decalsystem_t old = *decalsystem;
9150 qbool useshortelements;
9151 decalsystem->maxdecals = max(16, decalsystem->maxdecals * 2);
9152 useshortelements = decalsystem->maxdecals * 3 <= 65536;
9153 decalsystem->decals = (tridecal_t *)Mem_Alloc(cls.levelmempool, decalsystem->maxdecals * (sizeof(tridecal_t) + sizeof(float[3][3]) + sizeof(float[3][2]) + sizeof(float[3][4]) + sizeof(int[3]) + (useshortelements ? sizeof(unsigned short[3]) : 0)));
9154 decalsystem->color4f = (float *)(decalsystem->decals + decalsystem->maxdecals);
9155 decalsystem->texcoord2f = (float *)(decalsystem->color4f + decalsystem->maxdecals*12);
9156 decalsystem->vertex3f = (float *)(decalsystem->texcoord2f + decalsystem->maxdecals*6);
9157 decalsystem->element3i = (int *)(decalsystem->vertex3f + decalsystem->maxdecals*9);
9158 decalsystem->element3s = (useshortelements ? ((unsigned short *)(decalsystem->element3i + decalsystem->maxdecals*3)) : NULL);
9159 if (decalsystem->numdecals)
9160 memcpy(decalsystem->decals, old.decals, decalsystem->numdecals * sizeof(tridecal_t));
9161 if (old.decals)
9162 Mem_Free(old.decals);
9163 for (i = 0;i < decalsystem->maxdecals*3;i++)
9164 decalsystem->element3i[i] = i;
9165 if (useshortelements)
9166 for (i = 0;i < decalsystem->maxdecals*3;i++)
9167 decalsystem->element3s[i] = i;
9168 }
9169
9170 // grab a decal and search for another free slot for the next one
9171 decal = &decalsystem->decals[decalsystem->numdecals++];
9172
9173 // initialize the decal
9174 decal->lived = 0;
9175 decal->triangleindex = triangleindex;
9176 decal->surfaceindex = surfaceindex;
9177 decal->decalsequence = decalsequence;
9178 decal->color4f[0][0] = c0[0];
9179 decal->color4f[0][1] = c0[1];
9180 decal->color4f[0][2] = c0[2];
9181 decal->color4f[0][3] = 1;
9182 decal->color4f[1][0] = c1[0];
9183 decal->color4f[1][1] = c1[1];
9184 decal->color4f[1][2] = c1[2];
9185 decal->color4f[1][3] = 1;
9186 decal->color4f[2][0] = c2[0];
9187 decal->color4f[2][1] = c2[1];
9188 decal->color4f[2][2] = c2[2];
9189 decal->color4f[2][3] = 1;
9190 decal->vertex3f[0][0] = v0[0];
9191 decal->vertex3f[0][1] = v0[1];
9192 decal->vertex3f[0][2] = v0[2];
9193 decal->vertex3f[1][0] = v1[0];
9194 decal->vertex3f[1][1] = v1[1];
9195 decal->vertex3f[1][2] = v1[2];
9196 decal->vertex3f[2][0] = v2[0];
9197 decal->vertex3f[2][1] = v2[1];
9198 decal->vertex3f[2][2] = v2[2];
9199 decal->texcoord2f[0][0] = t0[0];
9200 decal->texcoord2f[0][1] = t0[1];
9201 decal->texcoord2f[1][0] = t1[0];
9202 decal->texcoord2f[1][1] = t1[1];
9203 decal->texcoord2f[2][0] = t2[0];
9204 decal->texcoord2f[2][1] = t2[1];
9205 TriangleNormal(v0, v1, v2, decal->plane);
9206 VectorNormalize(decal->plane);
9207 decal->plane[3] = DotProduct(v0, decal->plane);
9208}
9209
9210extern cvar_t cl_decals_bias;
9213// baseparms, parms, temps
9214static void R_DecalSystem_SplatTriangle(decalsystem_t *decalsystem, float r, float g, float b, float a, float s1, float t1, float s2, float t2, unsigned int decalsequence, qbool dynamic, float (*planes)[4], matrix4x4_t *projection, int triangleindex, int surfaceindex)
9215{
9216 int cornerindex;
9217 int index;
9218 float v[9][3];
9219 const float *vertex3f;
9220 const float *normal3f;
9221 int numpoints;
9222 float points[2][9][3];
9223 float temp[3];
9224 float tc[9][2];
9225 float f;
9226 float c[9][4];
9227 const int *e;
9228
9229 e = rsurface.modelelement3i + 3*triangleindex;
9230
9231 vertex3f = rsurface.modelvertex3f;
9232 normal3f = rsurface.modelnormal3f;
9233
9234 if (normal3f)
9235 {
9236 for (cornerindex = 0;cornerindex < 3;cornerindex++)
9237 {
9238 index = 3*e[cornerindex];
9239 VectorMA(vertex3f + index, cl_decals_bias.value, normal3f + index, v[cornerindex]);
9240 }
9241 }
9242 else
9243 {
9244 for (cornerindex = 0;cornerindex < 3;cornerindex++)
9245 {
9246 index = 3*e[cornerindex];
9247 VectorCopy(vertex3f + index, v[cornerindex]);
9248 }
9249 }
9250
9251 // cull backfaces
9252 //TriangleNormal(v[0], v[1], v[2], normal);
9253 //if (DotProduct(normal, localnormal) < 0.0f)
9254 // continue;
9255 // clip by each of the box planes formed from the projection matrix
9256 // if anything survives, we emit the decal
9257 numpoints = PolygonF_Clip(3 , v[0] , planes[0][0], planes[0][1], planes[0][2], planes[0][3], 1.0f/64.0f, sizeof(points[0])/sizeof(points[0][0]), points[1][0]);
9258 if (numpoints < 3)
9259 return;
9260 numpoints = PolygonF_Clip(numpoints, points[1][0], planes[1][0], planes[1][1], planes[1][2], planes[1][3], 1.0f/64.0f, sizeof(points[0])/sizeof(points[0][0]), points[0][0]);
9261 if (numpoints < 3)
9262 return;
9263 numpoints = PolygonF_Clip(numpoints, points[0][0], planes[2][0], planes[2][1], planes[2][2], planes[2][3], 1.0f/64.0f, sizeof(points[0])/sizeof(points[0][0]), points[1][0]);
9264 if (numpoints < 3)
9265 return;
9266 numpoints = PolygonF_Clip(numpoints, points[1][0], planes[3][0], planes[3][1], planes[3][2], planes[3][3], 1.0f/64.0f, sizeof(points[0])/sizeof(points[0][0]), points[0][0]);
9267 if (numpoints < 3)
9268 return;
9269 numpoints = PolygonF_Clip(numpoints, points[0][0], planes[4][0], planes[4][1], planes[4][2], planes[4][3], 1.0f/64.0f, sizeof(points[0])/sizeof(points[0][0]), points[1][0]);
9270 if (numpoints < 3)
9271 return;
9272 numpoints = PolygonF_Clip(numpoints, points[1][0], planes[5][0], planes[5][1], planes[5][2], planes[5][3], 1.0f/64.0f, sizeof(points[0])/sizeof(points[0][0]), v[0]);
9273 if (numpoints < 3)
9274 return;
9275 // some part of the triangle survived, so we have to accept it...
9276 if (dynamic)
9277 {
9278 // dynamic always uses the original triangle
9279 numpoints = 3;
9280 for (cornerindex = 0;cornerindex < 3;cornerindex++)
9281 {
9282 index = 3*e[cornerindex];
9283 VectorCopy(vertex3f + index, v[cornerindex]);
9284 }
9285 }
9286 for (cornerindex = 0;cornerindex < numpoints;cornerindex++)
9287 {
9288 // convert vertex positions to texcoords
9289 Matrix4x4_Transform(projection, v[cornerindex], temp);
9290 tc[cornerindex][0] = (temp[1]+1.0f)*0.5f * (s2-s1) + s1;
9291 tc[cornerindex][1] = (temp[2]+1.0f)*0.5f * (t2-t1) + t1;
9292 // calculate distance fade from the projection origin
9294 f = bound(0.0f, f, 1.0f);
9295 c[cornerindex][0] = r * f;
9296 c[cornerindex][1] = g * f;
9297 c[cornerindex][2] = b * f;
9298 c[cornerindex][3] = 1.0f;
9299 //VectorMA(v[cornerindex], cl_decals_bias.value, localnormal, v[cornerindex]);
9300 }
9301 if (dynamic)
9302 R_DecalSystem_SpawnTriangle(decalsystem, v[0], v[1], v[2], tc[0], tc[1], tc[2], c[0], c[1], c[2], triangleindex, surfaceindex, decalsequence);
9303 else
9304 for (cornerindex = 0;cornerindex < numpoints-2;cornerindex++)
9305 R_DecalSystem_SpawnTriangle(decalsystem, v[0], v[cornerindex+1], v[cornerindex+2], tc[0], tc[cornerindex+1], tc[cornerindex+2], c[0], c[cornerindex+1], c[cornerindex+2], -1, surfaceindex, decalsequence);
9306}
9307static void R_DecalSystem_SplatEntity(entity_render_t *ent, const vec3_t worldorigin, const vec3_t worldnormal, float r, float g, float b, float a, float s1, float t1, float s2, float t2, float worldsize, unsigned int decalsequence)
9308{
9309 matrix4x4_t projection;
9310 decalsystem_t *decalsystem;
9311 qbool dynamic;
9312 model_t *model;
9313 const msurface_t *surface;
9314 const msurface_t *surfaces;
9315 const texture_t *texture;
9316 int numtriangles;
9317 int surfaceindex;
9318 int triangleindex;
9319 float localorigin[3];
9320 float localnormal[3];
9321 float localmins[3];
9322 float localmaxs[3];
9323 float localsize;
9324 //float normal[3];
9325 float planes[6][4];
9326 float angles[3];
9327 bih_t *bih;
9328 int bih_triangles_count;
9329 int bih_triangles[256];
9330 int bih_surfaces[256];
9331
9332 decalsystem = &ent->decalsystem;
9333 model = ent->model;
9334 if (!model || !ent->allowdecals || ent->alpha < 1 || (ent->flags & (RENDER_ADDITIVE | RENDER_NODEPTHTEST)))
9335 {
9337 return;
9338 }
9339
9340 if (!model->brush.data_leafs && !cl_decals_models.integer)
9341 {
9342 if (decalsystem->model)
9343 R_DecalSystem_Reset(decalsystem);
9344 return;
9345 }
9346
9347 if (decalsystem->model != model)
9348 R_DecalSystem_Reset(decalsystem);
9349 decalsystem->model = model;
9350
9351 RSurf_ActiveModelEntity(ent, true, false, false);
9352
9353 Matrix4x4_Transform(&rsurface.inversematrix, worldorigin, localorigin);
9354 Matrix4x4_Transform3x3(&rsurface.inversematrix, worldnormal, localnormal);
9355 VectorNormalize(localnormal);
9356 localsize = worldsize*rsurface.inversematrixscale;
9357 localmins[0] = localorigin[0] - localsize;
9358 localmins[1] = localorigin[1] - localsize;
9359 localmins[2] = localorigin[2] - localsize;
9360 localmaxs[0] = localorigin[0] + localsize;
9361 localmaxs[1] = localorigin[1] + localsize;
9362 localmaxs[2] = localorigin[2] + localsize;
9363
9364 //VectorCopy(localnormal, planes[4]);
9365 //VectorVectors(planes[4], planes[2], planes[0]);
9366 AnglesFromVectors(angles, localnormal, NULL, false);
9367 AngleVectors(angles, planes[0], planes[2], planes[4]);
9368 VectorNegate(planes[0], planes[1]);
9369 VectorNegate(planes[2], planes[3]);
9370 VectorNegate(planes[4], planes[5]);
9371 planes[0][3] = DotProduct(planes[0], localorigin) - localsize;
9372 planes[1][3] = DotProduct(planes[1], localorigin) - localsize;
9373 planes[2][3] = DotProduct(planes[2], localorigin) - localsize;
9374 planes[3][3] = DotProduct(planes[3], localorigin) - localsize;
9375 planes[4][3] = DotProduct(planes[4], localorigin) - localsize;
9376 planes[5][3] = DotProduct(planes[5], localorigin) - localsize;
9377
9378#if 1
9379// works
9380{
9381 matrix4x4_t forwardprojection;
9382 Matrix4x4_CreateFromQuakeEntity(&forwardprojection, localorigin[0], localorigin[1], localorigin[2], angles[0], angles[1], angles[2], localsize);
9383 Matrix4x4_Invert_Simple(&projection, &forwardprojection);
9384}
9385#else
9386// broken
9387{
9388 float projectionvector[4][3];
9389 VectorScale(planes[0], ilocalsize, projectionvector[0]);
9390 VectorScale(planes[2], ilocalsize, projectionvector[1]);
9391 VectorScale(planes[4], ilocalsize, projectionvector[2]);
9392 projectionvector[0][0] = planes[0][0] * ilocalsize;
9393 projectionvector[0][1] = planes[1][0] * ilocalsize;
9394 projectionvector[0][2] = planes[2][0] * ilocalsize;
9395 projectionvector[1][0] = planes[0][1] * ilocalsize;
9396 projectionvector[1][1] = planes[1][1] * ilocalsize;
9397 projectionvector[1][2] = planes[2][1] * ilocalsize;
9398 projectionvector[2][0] = planes[0][2] * ilocalsize;
9399 projectionvector[2][1] = planes[1][2] * ilocalsize;
9400 projectionvector[2][2] = planes[2][2] * ilocalsize;
9401 projectionvector[3][0] = -(localorigin[0]*projectionvector[0][0]+localorigin[1]*projectionvector[1][0]+localorigin[2]*projectionvector[2][0]);
9402 projectionvector[3][1] = -(localorigin[0]*projectionvector[0][1]+localorigin[1]*projectionvector[1][1]+localorigin[2]*projectionvector[2][1]);
9403 projectionvector[3][2] = -(localorigin[0]*projectionvector[0][2]+localorigin[1]*projectionvector[1][2]+localorigin[2]*projectionvector[2][2]);
9404 Matrix4x4_FromVectors(&projection, projectionvector[0], projectionvector[1], projectionvector[2], projectionvector[3]);
9405}
9406#endif
9407
9408 dynamic = model->surfmesh.isanimated;
9409 surfaces = model->data_surfaces;
9410
9411 bih = NULL;
9412 bih_triangles_count = -1;
9413 if(!dynamic)
9414 {
9415 if(model->render_bih.numleafs)
9416 bih = &model->render_bih;
9417 else if(model->collision_bih.numleafs)
9418 bih = &model->collision_bih;
9419 }
9420 if(bih)
9421 bih_triangles_count = BIH_GetTriangleListForBox(bih, sizeof(bih_triangles) / sizeof(*bih_triangles), bih_triangles, bih_surfaces, localmins, localmaxs);
9422 if(bih_triangles_count == 0)
9423 return;
9424 if(bih_triangles_count > (int) (sizeof(bih_triangles) / sizeof(*bih_triangles))) // hit too many, likely bad anyway
9425 return;
9426 if(bih_triangles_count > 0)
9427 {
9428 for (triangleindex = 0; triangleindex < bih_triangles_count; ++triangleindex)
9429 {
9430 surfaceindex = bih_surfaces[triangleindex];
9431 surface = surfaces + surfaceindex;
9432 texture = surface->texture;
9433 if (!texture)
9434 continue;
9436 continue;
9437 if (texture->surfaceflags & Q3SURFACEFLAG_NOMARKS)
9438 continue;
9439 R_DecalSystem_SplatTriangle(decalsystem, r, g, b, a, s1, t1, s2, t2, decalsequence, dynamic, planes, &projection, bih_triangles[triangleindex], surfaceindex);
9440 }
9441 }
9442 else
9443 {
9444 for (surfaceindex = model->submodelsurfaces_start;surfaceindex < model->submodelsurfaces_end;surfaceindex++)
9445 {
9446 surface = surfaces + surfaceindex;
9447 // check cull box first because it rejects more than any other check
9448 if (!dynamic && !BoxesOverlap(surface->mins, surface->maxs, localmins, localmaxs))
9449 continue;
9450 // skip transparent surfaces
9451 texture = surface->texture;
9452 if (!texture)
9453 continue;
9455 continue;
9456 if (texture->surfaceflags & Q3SURFACEFLAG_NOMARKS)
9457 continue;
9458 numtriangles = surface->num_triangles;
9459 for (triangleindex = 0; triangleindex < numtriangles; triangleindex++)
9460 R_DecalSystem_SplatTriangle(decalsystem, r, g, b, a, s1, t1, s2, t2, decalsequence, dynamic, planes, &projection, triangleindex + surface->num_firsttriangle, surfaceindex);
9461 }
9462 }
9463}
9464
9465// do not call this outside of rendering code - use R_DecalSystem_SplatEntities instead
9466static void R_DecalSystem_ApplySplatEntities(const vec3_t worldorigin, const vec3_t worldnormal, float r, float g, float b, float a, float s1, float t1, float s2, float t2, float worldsize, unsigned int decalsequence)
9467{
9468 int renderentityindex;
9469 float worldmins[3];
9470 float worldmaxs[3];
9471 entity_render_t *ent;
9472
9473 worldmins[0] = worldorigin[0] - worldsize;
9474 worldmins[1] = worldorigin[1] - worldsize;
9475 worldmins[2] = worldorigin[2] - worldsize;
9476 worldmaxs[0] = worldorigin[0] + worldsize;
9477 worldmaxs[1] = worldorigin[1] + worldsize;
9478 worldmaxs[2] = worldorigin[2] + worldsize;
9479
9480 R_DecalSystem_SplatEntity(r_refdef.scene.worldentity, worldorigin, worldnormal, r, g, b, a, s1, t1, s2, t2, worldsize, decalsequence);
9481
9482 for (renderentityindex = 0;renderentityindex < r_refdef.scene.numentities;renderentityindex++)
9483 {
9484 ent = r_refdef.scene.entities[renderentityindex];
9485 if (!BoxesOverlap(ent->mins, ent->maxs, worldmins, worldmaxs))
9486 continue;
9487
9488 R_DecalSystem_SplatEntity(ent, worldorigin, worldnormal, r, g, b, a, s1, t1, s2, t2, worldsize, decalsequence);
9489 }
9490}
9491
9492typedef struct r_decalsystem_splatqueue_s
9493{
9496 float color[4];
9497 float tcrange[4];
9499 unsigned int decalsequence;
9500}
9502
9505
9506void R_DecalSystem_SplatEntities(const vec3_t worldorigin, const vec3_t worldnormal, float r, float g, float b, float a, float s1, float t1, float s2, float t2, float worldsize)
9507{
9509
9511 return;
9512
9514 VectorCopy(worldorigin, queue->worldorigin);
9515 VectorCopy(worldnormal, queue->worldnormal);
9516 Vector4Set(queue->color, r, g, b, a);
9517 Vector4Set(queue->tcrange, s1, t1, s2, t2);
9518 queue->worldsize = worldsize;
9519 queue->decalsequence = cl.decalsequence++;
9520}
9521
9523{
9524 int i;
9526
9527 for (i = 0, queue = r_decalsystem_queue;i < r_decalsystem_numqueued;i++, queue++)
9528 R_DecalSystem_ApplySplatEntities(queue->worldorigin, queue->worldnormal, queue->color[0], queue->color[1], queue->color[2], queue->color[3], queue->tcrange[0], queue->tcrange[1], queue->tcrange[2], queue->tcrange[3], queue->worldsize, queue->decalsequence);
9530}
9531
9532extern cvar_t cl_decals_max;
9534{
9535 int i;
9536 decalsystem_t *decalsystem = &ent->decalsystem;
9537 unsigned int killsequence;
9538 tridecal_t *decal;
9539 float frametime;
9540 float lifetime;
9541
9542 if (!decalsystem->numdecals)
9543 return;
9544
9546 return;
9547
9548 if (ent->model != decalsystem->model || ent->alpha < 1 || (ent->flags & RENDER_ADDITIVE))
9549 {
9550 R_DecalSystem_Reset(decalsystem);
9551 return;
9552 }
9553
9554 killsequence = cl.decalsequence - bound(1, (unsigned int) cl_decals_max.integer, cl.decalsequence);
9556
9557 if (decalsystem->lastupdatetime)
9558 frametime = (r_refdef.scene.time - decalsystem->lastupdatetime);
9559 else
9560 frametime = 0;
9561 decalsystem->lastupdatetime = r_refdef.scene.time;
9562
9563 for (i = 0, decal = decalsystem->decals;i < decalsystem->numdecals;i++, decal++)
9564 {
9565 decal->lived += frametime;
9566 if (killsequence > decal->decalsequence || decal->lived >= lifetime)
9567 {
9568 *decal = decalsystem->decals[--decalsystem->numdecals];
9569 --i, --decal; // Consider the just moved decal next.
9570 }
9571 }
9572
9573 if (decalsystem->numdecals <= 0)
9574 {
9575 // if there are no decals left, reset decalsystem
9576 R_DecalSystem_Reset(decalsystem);
9577 }
9578}
9579
9582{
9583 int i;
9584 decalsystem_t *decalsystem = &ent->decalsystem;
9585 int numdecals;
9586 tridecal_t *decal;
9587 float faderate;
9588 float alpha;
9589 float *v3f;
9590 float *c4f;
9591 float *t2f;
9592 const int *e;
9593 const unsigned char *surfacevisible = ent == r_refdef.scene.worldentity ? r_refdef.viewcache.world_surfacevisible : NULL;
9594 int numtris = 0;
9595
9596 numdecals = decalsystem->numdecals;
9597 if (!numdecals)
9598 return;
9599
9601 return;
9602
9603 if (ent->model != decalsystem->model || ent->alpha < 1 || (ent->flags & RENDER_ADDITIVE))
9604 {
9605 R_DecalSystem_Reset(decalsystem);
9606 return;
9607 }
9608
9609 // if the model is static it doesn't matter what value we give for
9610 // wantnormals and wanttangents, so this logic uses only rules applicable
9611 // to a model, knowing that they are meaningless otherwise
9612 RSurf_ActiveModelEntity(ent, false, false, false);
9613
9614 decalsystem->lastupdatetime = r_refdef.scene.time;
9615
9616 faderate = 1.0f / max(0.001f, cl_decals_fadetime.value);
9617
9618 // update vertex positions for animated models
9619 v3f = decalsystem->vertex3f;
9620 c4f = decalsystem->color4f;
9621 t2f = decalsystem->texcoord2f;
9622 for (i = 0, decal = decalsystem->decals;i < numdecals;i++, decal++)
9623 {
9624 if (!decal->color4f[0][3])
9625 continue;
9626
9627 if (surfacevisible && !surfacevisible[decal->surfaceindex])
9628 continue;
9629
9630 // skip backfaces
9631 if (decal->triangleindex < 0 && DotProduct(r_refdef.view.origin, decal->plane) < decal->plane[3])
9632 continue;
9633
9634 // update color values for fading decals
9635 if (decal->lived >= cl_decals_time.value)
9636 alpha = 1 - faderate * (decal->lived - cl_decals_time.value);
9637 else
9638 alpha = 1.0f;
9639
9640 c4f[ 0] = decal->color4f[0][0] * alpha;
9641 c4f[ 1] = decal->color4f[0][1] * alpha;
9642 c4f[ 2] = decal->color4f[0][2] * alpha;
9643 c4f[ 3] = 1;
9644 c4f[ 4] = decal->color4f[1][0] * alpha;
9645 c4f[ 5] = decal->color4f[1][1] * alpha;
9646 c4f[ 6] = decal->color4f[1][2] * alpha;
9647 c4f[ 7] = 1;
9648 c4f[ 8] = decal->color4f[2][0] * alpha;
9649 c4f[ 9] = decal->color4f[2][1] * alpha;
9650 c4f[10] = decal->color4f[2][2] * alpha;
9651 c4f[11] = 1;
9652
9653 t2f[0] = decal->texcoord2f[0][0];
9654 t2f[1] = decal->texcoord2f[0][1];
9655 t2f[2] = decal->texcoord2f[1][0];
9656 t2f[3] = decal->texcoord2f[1][1];
9657 t2f[4] = decal->texcoord2f[2][0];
9658 t2f[5] = decal->texcoord2f[2][1];
9659
9660 // update vertex positions for animated models
9661 if (decal->triangleindex >= 0 && decal->triangleindex < rsurface.modelnumtriangles)
9662 {
9663 e = rsurface.modelelement3i + 3*decal->triangleindex;
9664 VectorCopy(rsurface.modelvertex3f + 3*e[0], v3f);
9665 VectorCopy(rsurface.modelvertex3f + 3*e[1], v3f + 3);
9666 VectorCopy(rsurface.modelvertex3f + 3*e[2], v3f + 6);
9667 }
9668 else
9669 {
9670 VectorCopy(decal->vertex3f[0], v3f);
9671 VectorCopy(decal->vertex3f[1], v3f + 3);
9672 VectorCopy(decal->vertex3f[2], v3f + 6);
9673 }
9674
9675 if (r_refdef.fogenabled)
9676 {
9677 alpha = RSurf_FogVertex(v3f);
9678 VectorScale(c4f, alpha, c4f);
9679 alpha = RSurf_FogVertex(v3f + 3);
9680 VectorScale(c4f + 4, alpha, c4f + 4);
9681 alpha = RSurf_FogVertex(v3f + 6);
9682 VectorScale(c4f + 8, alpha, c4f + 8);
9683 }
9684
9685 v3f += 9;
9686 c4f += 12;
9687 t2f += 6;
9688 numtris++;
9689 }
9690
9691 if (numtris > 0)
9692 {
9693 r_refdef.stats[r_stat_drawndecals] += numtris;
9694
9695 // now render the decals all at once
9696 // (this assumes they all use one particle font texture!)
9697 RSurf_ActiveCustomEntity(&rsurface.matrix, &rsurface.inversematrix, rsurface.ent_flags, ent->shadertime, 1, 1, 1, 1, numdecals*3, decalsystem->vertex3f, decalsystem->texcoord2f, NULL, NULL, NULL, decalsystem->color4f, numtris, decalsystem->element3i, decalsystem->element3s, false, false);
9698// R_Mesh_ResetTextureState();
9699 R_Mesh_PrepareVertices_Generic_Arrays(numtris * 3, decalsystem->vertex3f, decalsystem->color4f, decalsystem->texcoord2f);
9700 GL_DepthMask(false);
9701 GL_DepthRange(0, 1);
9703 GL_DepthTest(true);
9706 R_SetupShader_Generic(decalskinframe->base, false, false, false);
9707 R_Mesh_Draw(0, numtris * 3, 0, numtris, decalsystem->element3i, NULL, 0, decalsystem->element3s, NULL, 0);
9708 }
9709}
9710
9711static void R_DrawModelDecals(void)
9712{
9713 int i, numdecals;
9714
9715 // fade faster when there are too many decals
9717 for (i = 0;i < r_refdef.scene.numentities;i++)
9719
9721 for (i = 0;i < r_refdef.scene.numentities;i++)
9724
9726
9728 for (i = 0;i < r_refdef.scene.numentities;i++)
9730
9731 r_refdef.stats[r_stat_totaldecals] += numdecals;
9732
9734 return;
9735
9737
9738 for (i = 0;i < r_refdef.scene.numentities;i++)
9739 {
9741 continue;
9744 }
9745}
9746
9747static void R_DrawDebugModel(void)
9748{
9750 int j, flagsmask;
9751 const msurface_t *surface;
9752 model_t *model = ent->model;
9753
9754 if (!sv.active && !cls.demoplayback && ent != r_refdef.scene.worldentity)
9755 return;
9756
9757 if (r_showoverdraw.value > 0)
9758 {
9759 float c = r_refdef.view.colorscale * r_showoverdraw.value * 0.125f;
9760 flagsmask = MATERIALFLAG_SKY | MATERIALFLAG_WALL;
9761 R_SetupShader_Generic_NoTexture(false, false);
9762 GL_DepthTest(false);
9763 GL_DepthMask(false);
9764 GL_DepthRange(0, 1);
9766 for (j = model->submodelsurfaces_start;j < model->submodelsurfaces_end;j++)
9767 {
9769 continue;
9770 surface = model->data_surfaces + j;
9772 if ((rsurface.texture->currentmaterialflags & flagsmask) && surface->num_triangles)
9773 {
9777 GL_Color(c, 0, 0, 1.0f);
9778 else if (ent == r_refdef.scene.worldentity)
9779 GL_Color(c, c, c, 1.0f);
9780 else
9781 GL_Color(0, c, 0, 1.0f);
9784 }
9785 }
9787 }
9788
9789 flagsmask = MATERIALFLAG_SKY | MATERIALFLAG_WALL;
9790
9791// R_Mesh_ResetTextureState();
9792 R_SetupShader_Generic_NoTexture(false, false);
9793 GL_DepthRange(0, 1);
9795 GL_DepthMask(false);
9797
9798 if (r_showcollisionbrushes.value > 0 && model->collision_bih.numleafs)
9799 {
9800 int triangleindex;
9801 int bihleafindex;
9802 qbool cullbox = false;
9803 const q3mbrush_t *brush;
9804 const bih_t *bih = &model->collision_bih;
9805 const bih_leaf_t *bihleaf;
9806 float vertex3f[3][3];
9808 for (bihleafindex = 0, bihleaf = bih->leafs;bihleafindex < bih->numleafs;bihleafindex++, bihleaf++)
9809 {
9810 if (cullbox && R_CullFrustum(bihleaf->mins, bihleaf->maxs))
9811 continue;
9812 switch (bihleaf->type)
9813 {
9814 case BIH_BRUSH:
9815 brush = model->brush.data_brushes + bihleaf->itemindex;
9816 if (brush->colbrushf && brush->colbrushf->numtriangles)
9817 {
9818 GL_Color((bihleafindex & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 5) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 10) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, r_showcollisionbrushes.value);
9819 R_Mesh_PrepareVertices_Generic_Arrays(brush->colbrushf->numpoints, brush->colbrushf->points->v, NULL, NULL);
9820 R_Mesh_Draw(0, brush->colbrushf->numpoints, 0, brush->colbrushf->numtriangles, brush->colbrushf->elements, NULL, 0, NULL, NULL, 0);
9821 }
9822 break;
9824 triangleindex = bihleaf->itemindex;
9825 VectorCopy(model->brush.data_collisionvertex3f + 3*model->brush.data_collisionelement3i[triangleindex*3+0], vertex3f[0]);
9826 VectorCopy(model->brush.data_collisionvertex3f + 3*model->brush.data_collisionelement3i[triangleindex*3+1], vertex3f[1]);
9827 VectorCopy(model->brush.data_collisionvertex3f + 3*model->brush.data_collisionelement3i[triangleindex*3+2], vertex3f[2]);
9828 GL_Color((bihleafindex & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 5) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 10) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, r_showcollisionbrushes.value);
9831 break;
9832 case BIH_RENDERTRIANGLE:
9833 triangleindex = bihleaf->itemindex;
9834 VectorCopy(model->surfmesh.data_vertex3f + 3*model->surfmesh.data_element3i[triangleindex*3+0], vertex3f[0]);
9835 VectorCopy(model->surfmesh.data_vertex3f + 3*model->surfmesh.data_element3i[triangleindex*3+1], vertex3f[1]);
9836 VectorCopy(model->surfmesh.data_vertex3f + 3*model->surfmesh.data_element3i[triangleindex*3+2], vertex3f[2]);
9837 GL_Color((bihleafindex & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 5) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 10) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, r_showcollisionbrushes.value);
9840 break;
9841 }
9842 }
9843 }
9844
9846
9847#ifndef USE_GLES2
9848 if (r_showtris.value > 0 && qglPolygonMode)
9849 {
9851 {
9853 GL_DepthMask(false);
9854 }
9855 else
9856 {
9858 GL_DepthMask(true);
9859 }
9860 qglPolygonMode(GL_FRONT_AND_BACK, GL_LINE);CHECKGLERROR
9861 for (j = model->submodelsurfaces_start; j < model->submodelsurfaces_end; j++)
9862 {
9864 continue;
9865 surface = model->data_surfaces + j;
9867 if ((rsurface.texture->currentmaterialflags & flagsmask) && surface->num_triangles)
9868 {
9872 else if (ent == r_refdef.scene.worldentity)
9874 else
9878 }
9879 }
9880 qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);CHECKGLERROR
9882 }
9883
9884# if 0
9885 // FIXME! implement r_shownormals with just triangles
9886 if (r_shownormals.value != 0 && qglBegin)
9887 {
9888 int l, k;
9889 vec3_t v;
9891 {
9893 GL_DepthMask(false);
9894 }
9895 else
9896 {
9898 GL_DepthMask(true);
9899 }
9900 for (j = model->submodelsurfaces_start; j < model->submodelsurfaces_end; j++)
9901 {
9903 continue;
9904 surface = model->data_surfaces + j;
9906 if ((rsurface.texture->currentmaterialflags & flagsmask) && surface->num_triangles)
9907 {
9909 qglBegin(GL_LINES);
9911 {
9912 for (k = 0, l = rsurface.batchfirstvertex;k < rsurface.batchnumvertices;k++, l++)
9913 {
9915 GL_Color(0, 0, r_refdef.view.colorscale, 1);
9916 qglVertex3f(v[0], v[1], v[2]);
9919 qglVertex3f(v[0], v[1], v[2]);
9920 }
9921 }
9923 {
9924 for (k = 0, l = rsurface.batchfirstvertex;k < rsurface.batchnumvertices;k++, l++)
9925 {
9927 GL_Color(r_refdef.view.colorscale, 0, 0, 1);
9928 qglVertex3f(v[0], v[1], v[2]);
9931 qglVertex3f(v[0], v[1], v[2]);
9932 }
9933 }
9935 {
9936 for (k = 0, l = rsurface.batchfirstvertex;k < rsurface.batchnumvertices;k++, l++)
9937 {
9939 GL_Color(0, r_refdef.view.colorscale, 0, 1);
9940 qglVertex3f(v[0], v[1], v[2]);
9943 qglVertex3f(v[0], v[1], v[2]);
9944 }
9945 }
9947 {
9948 for (k = 0, l = rsurface.batchfirstvertex;k < rsurface.batchnumvertices;k++, l++)
9949 {
9951 GL_Color(0, 0, r_refdef.view.colorscale, 1);
9952 qglVertex3f(v[0], v[1], v[2]);
9955 qglVertex3f(v[0], v[1], v[2]);
9956 }
9957 }
9958 qglEnd();
9960 }
9961 }
9963 }
9964# endif
9965#endif
9966}
9967
9970void R_DrawModelSurfaces(entity_render_t *ent, qbool skysurfaces, qbool writedepth, qbool depthonly, qbool debug, qbool prepass, qbool ui)
9971{
9972 int i, j, flagsmask;
9973 model_t *model = ent->model;
9974 msurface_t *surfaces;
9975 unsigned char *update;
9976 int numsurfacelist = 0;
9977 if (model == NULL)
9978 return;
9979
9980 if (r_maxsurfacelist < model->num_surfaces)
9981 {
9982 r_maxsurfacelist = model->num_surfaces;
9983 if (r_surfacelist)
9986 }
9987
9989 RSurf_ActiveModelEntity(ent, false, false, false);
9990 else if (prepass)
9991 RSurf_ActiveModelEntity(ent, true, true, true);
9992 else if (depthonly)
9993 RSurf_ActiveModelEntity(ent, model->wantnormals, model->wanttangents, false);
9994 else
9995 RSurf_ActiveModelEntity(ent, true, true, false);
9996
9997 surfaces = model->data_surfaces;
9998 update = model->brushq1.lightmapupdateflags;
9999
10000 flagsmask = skysurfaces ? MATERIALFLAG_SKY : MATERIALFLAG_WALL;
10001
10002 if (debug)
10003 {
10005 rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveModelEntity
10006 return;
10007 }
10008
10009 // check if this is an empty model
10010 if (model->submodelsurfaces_start >= model->submodelsurfaces_end)
10011 return;
10012
10018 numsurfacelist = 0;
10019
10020 // add visible surfaces to draw list
10021 if (ent == r_refdef.scene.worldentity)
10022 {
10023 // for the world entity, check surfacevisible
10024 for (i = model->submodelsurfaces_start;i < model->submodelsurfaces_end;i++)
10025 {
10026 j = model->modelsurfaces_sorted[i];
10028 r_surfacelist[numsurfacelist++] = surfaces + j;
10029 }
10030
10031 // don't do anything if there were no surfaces added (none of the world entity is visible)
10032 if (!numsurfacelist)
10033 {
10034 rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveModelEntity
10035 return;
10036 }
10037 }
10038 else if (ui)
10039 {
10040 // for ui we have to preserve the order of surfaces (not using modelsurfaces_sorted)
10041 for (i = model->submodelsurfaces_start; i < model->submodelsurfaces_end; i++)
10042 r_surfacelist[numsurfacelist++] = surfaces + i;
10043 }
10044 else
10045 {
10046 // add all surfaces
10047 for (i = model->submodelsurfaces_start; i < model->submodelsurfaces_end; i++)
10048 r_surfacelist[numsurfacelist++] = surfaces + model->modelsurfaces_sorted[i];
10049 }
10050
10051 /*
10052 * Mark lightmaps as dirty if their lightstyle's value changed. We do this by
10053 * using style chains because most styles do not change on most frames, and most
10054 * surfaces do not have styles on them. Mods like Arcane Dimensions (e.g. ad_necrokeep)
10055 * break this rule and animate most surfaces.
10056 */
10057 if (update && !skysurfaces && !depthonly && !prepass && model->brushq1.num_lightstyles && r_refdef.scene.lightmapintensity > 0 && r_q1bsp_lightmap_updates_enabled.integer)
10058 {
10060
10061 // For each lightstyle, check if its value changed and mark the lightmaps as dirty if so
10062 for (i = 0, style = model->brushq1.data_lightstyleinfo; i < model->brushq1.num_lightstyles; i++, style++)
10063 {
10064 if (style->value != r_refdef.scene.lightstylevalue[style->style])
10065 {
10066 int* list = style->surfacelist;
10067 style->value = r_refdef.scene.lightstylevalue[style->style];
10068 // Value changed - mark the surfaces belonging to this style chain as dirty
10069 for (j = 0; j < style->numsurfaces; j++)
10070 update[list[j]] = true;
10071 }
10072 }
10073 // Now check if update flags are set on any surfaces that are visible
10075 {
10076 /*
10077 * We can do less frequent texture uploads (approximately 10hz for animated
10078 * lightstyles) by rebuilding lightmaps on surfaces that are not currently visible.
10079 * For optimal efficiency, this includes the submodels of the worldmodel, so we
10080 * use model->num_surfaces, not nummodelsurfaces.
10081 */
10082 for (i = 0; i < model->num_surfaces;i++)
10083 if (update[i])
10085 }
10086 else
10087 {
10088 for (i = 0; i < numsurfacelist; i++)
10089 if (update[r_surfacelist[i] - surfaces])
10091 }
10092 }
10093
10094 R_QueueModelSurfaceList(ent, numsurfacelist, r_surfacelist, flagsmask, writedepth, depthonly, prepass, ui);
10095
10096 // add to stats if desired
10097 if (r_speeds.integer && !skysurfaces && !depthonly)
10098 {
10099 r_refdef.stats[r_stat_entities_surfaces] += numsurfacelist;
10100 for (j = 0;j < numsurfacelist;j++)
10102 }
10103
10104 rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveModelEntity
10105}
10106
10107void R_DebugLine(vec3_t start, vec3_t end)
10108{
10109 model_t *mod = CL_Mesh_UI();
10110 msurface_t *surf;
10111 int e0, e1, e2, e3;
10112 float offsetx, offsety, x1, y1, x2, y2, width = 1.0f;
10113 float r1 = 1.0f, g1 = 0.0f, b1 = 0.0f, alpha1 = 0.25f;
10114 float r2 = 1.0f, g2 = 1.0f, b2 = 0.0f, alpha2 = 0.25f;
10115 vec4_t w[2], s[2];
10116
10117 // transform to screen coords first
10118 Vector4Set(w[0], start[0], start[1], start[2], 1);
10119 Vector4Set(w[1], end[0], end[1], end[2], 1);
10122 x1 = s[0][0] * vid_conwidth.value / vid.mode.width;
10123 y1 = (vid.mode.height - s[0][1]) * vid_conheight.value / vid.mode.height;
10124 x2 = s[1][0] * vid_conwidth.value / vid.mode.width;
10125 y2 = (vid.mode.height - s[1][1]) * vid_conheight.value / vid.mode.height;
10126 //Con_DPrintf("R_DebugLine: %.0f,%.0f to %.0f,%.0f\n", x1, y1, x2, y2);
10127
10128 // add the line to the UI mesh for drawing later
10129
10130 // width is measured in real pixels
10131 if (fabs(x2 - x1) > fabs(y2 - y1))
10132 {
10133 offsetx = 0;
10134 offsety = 0.5f * width * vid_conheight.value / vid.mode.height;
10135 }
10136 else
10137 {
10138 offsetx = 0.5f * width * vid_conwidth.value / vid.mode.width;
10139 offsety = 0;
10140 }
10142 e0 = Mod_Mesh_IndexForVertex(mod, surf, x1 - offsetx, y1 - offsety, 10, 0, 0, -1, 0, 0, 0, 0, r1, g1, b1, alpha1);
10143 e1 = Mod_Mesh_IndexForVertex(mod, surf, x2 - offsetx, y2 - offsety, 10, 0, 0, -1, 0, 0, 0, 0, r2, g2, b2, alpha2);
10144 e2 = Mod_Mesh_IndexForVertex(mod, surf, x2 + offsetx, y2 + offsety, 10, 0, 0, -1, 0, 0, 0, 0, r2, g2, b2, alpha2);
10145 e3 = Mod_Mesh_IndexForVertex(mod, surf, x1 + offsetx, y1 + offsety, 10, 0, 0, -1, 0, 0, 0, 0, r1, g1, b1, alpha1);
10146 Mod_Mesh_AddTriangle(mod, surf, e0, e1, e2);
10147 Mod_Mesh_AddTriangle(mod, surf, e0, e2, e3);
10148
10149}
10150
10151
10152void 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)
10153{
10154 static texture_t texture;
10155
10156 // fake enough texture and surface state to render this geometry
10157
10158 texture.update_lastrenderframe = -1; // regenerate this texture
10159 texture.basematerialflags = materialflags | MATERIALFLAG_CUSTOMSURFACE | MATERIALFLAG_WALL;
10160 texture.basealpha = 1.0f;
10161 texture.currentskinframe = skinframe;
10162 texture.currenttexmatrix = *texmatrix; // requires MATERIALFLAG_CUSTOMSURFACE
10163 texture.offsetmapping = OFFSETMAPPING_OFF;
10164 texture.offsetscale = 1;
10165 texture.specularscalemod = 1;
10166 texture.specularpowermod = 1;
10167 texture.transparentsort = TRANSPARENTSORT_DISTANCE;
10168
10169 R_DrawCustomSurface_Texture(&texture, texmatrix, materialflags, firstvertex, numvertices, firsttriangle, numtriangles, writedepth, prepass, ui);
10170}
10171
10172void 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)
10173{
10174 static msurface_t surface;
10175 const msurface_t *surfacelist = &surface;
10176
10177 // fake enough texture and surface state to render this geometry
10178 surface.texture = texture;
10179 surface.num_triangles = numtriangles;
10180 surface.num_firsttriangle = firsttriangle;
10181 surface.num_vertices = numvertices;
10182 surface.num_firstvertex = firstvertex;
10183
10184 // now render it
10189 R_DrawModelTextureSurfaceList(1, &surfacelist, writedepth, prepass, ui);
10190}
int BIH_GetTriangleListForBox(const bih_t *bih, int maxtriangles, int *trianglelist_idx, int *trianglelist_surf, const float *mins, const float *maxs)
Definition bih.c:211
@ BIH_COLLISIONTRIANGLE
Definition bih.h:30
@ BIH_RENDERTRIANGLE
Definition bih.h:31
@ BIH_BRUSH
Definition bih.h:29
#define SUPERCONTENTS_SKY
Definition bspfile.h:200
#define SUPERCONTENTS_SOLID
Definition bspfile.h:196
trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend, qbool hitnetworkbrushmodels, qbool hitnetworkplayers, int *hitnetworkentity, qbool hitcsqcentities, qbool hitsurfaces)
trace_t CL_Cache_TraceLineSurfaces(const vec3_t start, const vec3_t end, int type, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask)
static vec3_t offsets[NUMOFFSETS]
Definition cl_input.c:838
cl_locnode_t * CL_Locs_FindNearest(const vec3_t point)
Definition cl_main.c:2193
client_state_t cl
Definition cl_main.c:117
client_static_t cls
Definition cl_main.c:116
void CL_MeshEntities_Init(void)
Definition cl_main.c:2555
entity_t cl_meshentities[NUM_MESHENTITIES]
Definition cl_main.c:2513
void CL_ParseEntityLump(char *entdata)
Definition cl_parse.c:384
void R_DrawParticles(void)
cvar_t cl_decals_fadetime
void R_Particles_Init(void)
cvar_t cl_decals_time
int r_stereo_side
Definition cl_screen.c:1553
cvar_t r_stereo_angle
Definition cl_screen.c:87
qbool R_Stereo_ColorMasking(void)
Definition cl_screen.c:2072
void R_ClearScreen(qbool fogcolor)
Definition cl_screen.c:1534
qbool R_Stereo_Active(void)
Definition cl_screen.c:2077
cvar_t r_stereo_separation
Definition cl_screen.c:80
cvar_t vid_conheight
Definition cl_screen.c:57
cvar_t vid_conwidth
Definition cl_screen.c:56
int cl_videoplaying
Definition cl_video.c:458
#define CL_Mesh_UI()
Definition client.h:1372
@ MESH_UI
Definition client.h:1365
@ ca_dedicated
Definition client.h:530
#define CSHIFT_DAMAGE
Definition client.h:512
void Cmd_AddCommand(unsigned flags, const char *cmd_name, xcommand_t function, const char *description)
called by the init functions of other parts of the program to register commands and functions to call...
Definition cmd.c:1661
cmd_state_t * cmd_local
command interpreter for local commands injected by SVQC, CSQC, MQC, server or client engine code uses...
Definition cmd.c:25
#define CF_CLIENT
cvar/command that only the client can change/execute
Definition cmd.h:48
#define CF_ARCHIVE
cvar should have its set value saved to config.cfg and persist across sessions
Definition cmd.h:53
void Collision_Cache_Reset(qbool resetlimits)
Definition collision.c:1480
unsigned short CRC_Block(const unsigned char *data, size_t size)
Definition com_crc16.c:75
gamemode_t gamemode
Definition com_game.c:26
@ GAME_NEHAHRA
Definition com_game.h:32
@ GAME_TENEBRAE
full of evil hackery
Definition com_game.h:41
char * va(char *buf, size_t buflen, const char *format,...)
Definition common.c:972
int dpsnprintf(char *buffer, size_t buffersize, const char *format,...)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
Definition common.c:997
@ PROTOCOL_QUAKEWORLD
quakeworld protocol
Definition common.h:145
#define dp_strlcat(dst, src, dsize)
Definition common.h:304
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
Definition console.c:1544
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
#define CON_ERROR
Definition console.h:102
qbool CL_VM_TransformView(int entnum, matrix4x4_t *viewmatrix, mplane_t *clipplane, vec3_t visorigin)
Definition csprogs.c:1196
vector size
float frametime
float mod(float dividend, float divisor)
vector mins
vector maxs
vector angles
vector origin
string model
float solid
void Cvar_SetValueQuick(cvar_t *var, float value)
Definition cvar.c:473
void Cvar_SetQuick(cvar_t *var, const char *value)
Definition cvar.c:436
void Cvar_RegisterVariable(cvar_t *variable)
registers a cvar that already has the name, string, and optionally the archive elements set.
Definition cvar.c:599
float scale
float style
entity viewmodelforclient
entity tag_entity
vector color
float alpha
vector colormod
void DrawQ_Start(void)
Definition gl_draw.c:789
void DrawQ_Finish(void)
Definition gl_draw.c:1456
float noise4f(float x, float y, float z, float w)
#define n(x, y)
unsigned char * FS_LoadFile(const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
Definition fs.c:3540
qfile_t * FS_OpenRealFile(const char *filepath, const char *mode, qbool quiet)
Definition fs.c:2901
static int(ZEXPORT *qz_inflate)(z_stream *strm
int FS_Close(qfile_t *file)
Definition fs.c:2970
int FS_Print(qfile_t *file, const char *msg)
Definition fs.c:3261
int64_t fs_offset_t
Definition fs.h:37
void Font_Init(void)
Definition ft2.c:443
void R_Mesh_PrepareVertices_Vertex3f(int numvertices, const float *vertex3f, const r_meshbuffer_t *vertexbuffer, int bufferoffset)
float gl_modelviewprojection16f[16]
Definition gl_backend.c:30
matrix4x4_t gl_modelmatrix
Definition gl_backend.c:24
void GL_Clear(int mask, const float *colorvalue, float depthvalue, int stencilvalue)
void R_Mesh_VertexPointer(int components, int gltype, size_t stride, const void *pointer, const r_meshbuffer_t *vertexbuffer, size_t bufferoffset)
void R_Mesh_CopyToTexture(rtexture_t *tex, int tx, int ty, int sx, int sy, int width, int height)
cvar_t r_renderview
Definition gl_backend.c:12
void GL_CullFace(int state)
void GL_ColorMask(int r, int g, int b, int a)
unsigned short polygonelement3s[(POLYGONELEMENTS_MAXPOINTS-2) *3]
Definition gl_backend.c:241
void R_Mesh_TexCoordPointer(unsigned int unitnum, int components, int gltype, size_t stride, const void *pointer, const r_meshbuffer_t *vertexbuffer, size_t bufferoffset)
void GL_DepthMask(int state)
void GL_Backend_FreeProgram(unsigned int prog)
matrix4x4_t gl_modelviewprojectionmatrix
Definition gl_backend.c:28
int polygonelement3i[(POLYGONELEMENTS_MAXPOINTS-2) *3]
Definition gl_backend.c:240
void R_Mesh_TexBind(unsigned int unitnum, rtexture_t *tex)
void R_Mesh_ColorPointer(int components, int gltype, size_t stride, const void *pointer, const r_meshbuffer_t *vertexbuffer, size_t bufferoffset)
void GL_DepthFunc(int state)
void R_Mesh_Draw(int firstvertex, int numvertices, int firsttriangle, int numtriangles, const int *element3i, const r_meshbuffer_t *element3i_indexbuffer, int element3i_bufferoffset, const unsigned short *element3s, const r_meshbuffer_t *element3s_indexbuffer, int element3s_bufferoffset)
void R_Viewport_TransformToScreen(const r_viewport_t *v, const vec4_t in, vec4_t out)
Definition gl_backend.c:383
void R_Viewport_InitPerspective(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, float frustumx, float frustumy, float nearclip, float farclip, const float *nearplane)
Definition gl_backend.c:677
void GL_DepthTest(int state)
void GL_DepthRange(float nearfrac, float farfrac)
void R_Viewport_InitOrtho3D(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, float frustumx, float frustumy, float nearclip, float farclip, const float *nearplane)
Definition gl_backend.c:635
void R_Mesh_SetRenderTargets(int fbo)
void GL_PolygonOffset(float planeoffset, float depthoffset)
r_meshbuffer_t * R_Mesh_CreateMeshBuffer(const void *data, size_t size, const char *name, qbool isindexbuffer, qbool isuniformbuffer, qbool isdynamic, qbool isindex16)
int R_Mesh_CreateFramebufferObject(rtexture_t *depthtexture, rtexture_t *colortexture, rtexture_t *colortexture2, rtexture_t *colortexture3, rtexture_t *colortexture4)
Definition gl_backend.c:960
void R_SetViewport(const r_viewport_t *v)
Definition gl_backend.c:897
void R_Viewport_InitOrtho(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, float x1, float y1, float x2, float y2, float nearclip, float farclip, const float *nearplane)
Definition gl_backend.c:587
matrix4x4_t gl_modelviewmatrix
Definition gl_backend.c:26
void R_Mesh_DestroyMeshBuffer(r_meshbuffer_t *buffer)
void R_Mesh_ResetTextureState(void)
matrix4x4_t gl_projectionmatrix
Definition gl_backend.c:27
void GL_Color(float cr, float cg, float cb, float ca)
void R_Mesh_PrepareVertices_Mesh_Arrays(int numvertices, const float *vertex3f, const float *svector3f, const float *tvector3f, const float *normal3f, const float *color4f, const float *texcoordtexture2f, const float *texcoordlightmap2f)
void GL_BlendFunc(int blendfunc1, int blendfunc2)
qbool R_ScissorForBBox(const float *mins, const float *maxs, int *scissor)
Definition gl_backend.c:430
void R_Viewport_InitPerspectiveInfinite(r_viewport_t *v, const matrix4x4_t *cameramatrix, int x, int y, int width, int height, float frustumx, float frustumy, float nearclip, const float *nearplane)
Definition gl_backend.c:719
void GL_AlphaToCoverage(qbool state)
void GL_Scissor(int x, int y, int width, int height)
float gl_modelview16f[16]
Definition gl_backend.c:29
void R_Mesh_PrepareVertices_Generic_Arrays(int numvertices, const float *vertex3f, const float *color4f, const float *texcoord2f)
qbool gl_modelmatrixchanged
Definition gl_backend.c:31
void R_Mesh_UpdateMeshBuffer(r_meshbuffer_t *buffer, const void *data, size_t size, qbool subdata, size_t offset)
matrix4x4_t gl_viewmatrix
Definition gl_backend.c:25
void R_Mesh_DestroyFramebufferObject(int fbo)
void GL_ScissorTest(int state)
void gl_backend_init(void)
Definition gl_backend.c:339
unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **vertexstrings_list, int geometrystrings_count, const char **geometrystrings_list, int fragmentstrings_count, const char **fragmentstrings_list)
void GL_Draw_Init(void)
Definition gl_draw.c:747
static const int nomodelelement3i[24]
Definition gl_rmain.c:6144
rtexture_t * r_texture_whitecube
Definition gl_rmain.c:277
static void R_DecalSystem_ApplySplatEntitiesQueue(void)
Definition gl_rmain.c:9522
void R_FrameData_SetMark(void)
set a marker that allows you to discard the following temporary memory allocations
Definition gl_rmain.c:3581
static int R_DrawBrushModelsSky(void)
only used if skyrendermasked, and normally returns false
Definition gl_rmain.c:4058
void R_Mesh_AddPolygon3f(rmesh_t *mesh, int numvertices, float *vertex3f)
Definition gl_rmain.c:6321
cvar_t r_shadows_castfrombmodels
Definition gl_rmain.c:128
cvar_t r_buffermegs[R_BUFFERDATA_COUNT]
Definition gl_rmain.c:249
cvar_t r_showlighting
Definition gl_rmain.c:88
cvar_t r_shadows_shadowmapbias
Definition gl_rmain.c:131
void R_GLSL_Restart_f(cmd_state_t *cmd)
Definition gl_rmain.c:1394
unsigned short locboxelements[6 *2 *3]
Definition gl_rmain.c:9068
void R_SetupShader_Generic_NoTexture(qbool usegamma, qbool notrippy)
Definition gl_rmain.c:1488
rtexturepool_t * r_main_texturepool
Definition gl_rmain.c:43
static void R_LoadQWSkin(r_qwskincache_t *cache, const char *skinname)
Definition gl_rmain.c:6522
static const float nomodelvertex3f[6 *3]
Definition gl_rmain.c:6168
cvar_t r_motionblur_velocityfactor
Definition gl_rmain.c:65
void R_RenderView(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, int x, int y, int width, int height)
Definition gl_rmain.c:5637
static void R_Main_FreeViewCache(void)
Definition gl_rmain.c:2998
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)
Definition gl_rmain.c:3888
skinframe_t * R_SkinFrame_LoadInternalQuake(const char *name, int textureflags, int loadpantsandshirt, int loadglowtexture, const unsigned char *skindata, int width, int height)
Definition gl_rmain.c:2616
void RSurf_PrepareVerticesForBatch(int batchneed, int texturenumsurfaces, const msurface_t **texturesurfacelist)
Definition gl_rmain.c:7388
int r_decalsystem_numqueued
Definition gl_rmain.c:9503
void R_ResetViewRendering2D(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
Definition gl_rmain.c:4477
static void R_BuildWhiteCube(void)
Definition gl_rmain.c:401
static void R_DrawModelDecals_Entity(entity_render_t *ent)
Definition gl_rmain.c:9581
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)
Definition gl_rmain.c:4564
#define BLENDFUNC_ALLOWS_FOG_HACK0
Definition gl_rmain.c:1519
cvar_t r_motionblur_minblur
Definition gl_rmain.c:63
cvar_t r_shadows_drawafterrtlighting
Definition gl_rmain.c:127
static void R_DrawEntityBBoxes_Callback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
Definition gl_rmain.c:6086
cvar_t r_showspriteedges
Definition gl_rmain.c:93
void R_RenderView_UpdateViewVectors(void)
Definition gl_rmain.c:4512
static void R_BlendView(rtexture_t *viewcolortexture, int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, int x, int y, int width, int height)
Definition gl_rmain.c:5317
void R_EntityMatrix(const matrix4x4_t *matrix)
Definition gl_rmain.c:4417
void R_FrameData_ReturnToMark(void)
discard recent memory allocations (rewind to marker)
Definition gl_rmain.c:3588
cvar_t r_water_hideplayer
Definition gl_rmain.c:200
void R_FrameData_Reset(void)
free all R_FrameData memory
Definition gl_rmain.c:3493
skinframe_t * R_SkinFrame_LoadInternalUsingTexture(const char *name, int textureflags, rtexture_t *tex, int width, int height, qbool sRGB)
Definition gl_rmain.c:2840
int r_shadow_shadowmappcf
Definition r_shadow.c:60
cvar_t r_hdr_irisadaptation_fade_up
Definition gl_rmain.c:225
void Render_Init(void)
Definition gl_rmain.c:3420
cvar_t r_glsl_offsetmapping_reliefmapping_steps
Definition gl_rmain.c:175
cvar_t r_q1bsp_lightmap_updates_enabled
Definition gl_rmain.c:257
static void R_DrawLoc_Callback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
Definition gl_rmain.c:9078
#define R_MESH_PLANE_DIST_EPSILON
Definition gl_rmain.c:6363
void R_DecalSystem_Reset(decalsystem_t *decalsystem)
Definition gl_rmain.c:9134
cvar_t r_batch_dynamicbuffer
Definition gl_rmain.c:240
#define R_BUFFERDATA_CYCLE
Definition gl_rmain.c:3598
cvar_t r_hdr_irisadaptation_value
Definition gl_rmain.c:224
cvar_t r_hdr_irisadaptation_minvalue
Definition gl_rmain.c:222
static void R_SortEntities(void)
Definition gl_rmain.c:5620
unsigned int r_maxqueries
Definition gl_rmain.c:299
cvar_t r_hdr_irisadaptation_fade_down
Definition gl_rmain.c:226
cvar_t r_drawfog
Definition gl_rmain.c:139
float RSurf_FogVertex(const float *v)
Definition gl_rmain.c:7324
rtexture_t * r_texture_grey128
Definition gl_rmain.c:274
memexpandablearray_t r_glsl_permutationarray
storage for permutations linked in the hash table
Definition gl_rmain.c:938
#define R_COMPILESHADER_STATICPARM_ENABLE(p)
Definition gl_rmain.c:857
rtexture_t * r_shadow_prepasslightingdiffusetexture
Definition r_shadow.c:121
void R_SetupShader_DepthOrShadow(qbool notrippy, qbool depthrgb, qbool skeletal)
Definition gl_rmain.c:1493
cvar_t r_motionblur
Definition gl_rmain.c:59
cvar_t r_drawdecals
cvar_t r_bloom_colorsubtract
Definition gl_rmain.c:215
cvar_t r_shadows_focus
Definition gl_rmain.c:129
static qbool r_savedds
Definition gl_rmain.c:51
cvar_t r_fullbrights
Definition gl_rmain.c:122
rtexture_t * r_texture_fogattenuation
Definition gl_rmain.c:279
skinframe_t * decalskinframe
cvar_t r_viewscale_fpsscaling_stepsize
Definition gl_rmain.c:166
static char * R_ShaderStrCat(const char **strings)
Definition gl_rmain.c:965
static qbool r_gpuskeletal
Definition gl_rmain.c:52
cvar_t r_fullbright_directed_pitch_relative
Definition gl_rmain.c:118
cvar_t r_nolerp_list
Definition gl_rmain.c:204
cvar_t r_usedepthtextures
Definition gl_rmain.c:159
cvar_t r_bloom_colorexponent
Definition gl_rmain.c:214
cvar_t r_shadows_darken
Definition gl_rmain.c:124
cvar_t r_glsl_postprocess_uservec1_enable
Definition gl_rmain.c:185
void R_RenderScene(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
Definition gl_rmain.c:5830
cvar_t r_water_clippingplanebias
Definition gl_rmain.c:194
qbool R_AnimCache_GetEntity(entity_render_t *ent, qbool wantnormals, qbool wanttangents)
get the skeletal data or cached animated mesh data for an entity (optionally with normals and tangent...
Definition gl_rmain.c:3789
r_skinframe_t r_skinframe
Definition gl_rmain.c:2166
static void R_DrawModelsDebug(void)
Definition gl_rmain.c:4112
static void R_CalcTexCoordsForView(float x, float y, float w, float h, float tw, float th, float *texcoord2f)
Definition gl_rmain.c:4547
shadermodeinfo_t shadermodeinfo[SHADERLANGUAGE_COUNT][SHADERMODE_COUNT]
Definition gl_rmain.c:662
static rtexture_t * R_LoadCubemap(const char *basename)
Definition gl_rmain.c:2908
cvar_t r_lockvisibility
Definition gl_rsurf.c:30
cvar_t r_q1bsp_skymasking
Definition gl_rmain.c:132
rtexture_t * r_shadow_prepasslightingspeculartexture
Definition r_shadow.c:122
cvar_t r_draw2d
Definition gl_rmain.c:97
cvar_t r_transparent_sortmaxdist
Definition gl_rmain.c:142
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)
Definition gl_rmain.c:10152
cvar_t r_smoothnormals_areaweighting
Definition gl_rmain.c:229
static void R_SkinFrame_GenerateTexturesFromQPixels(skinframe_t *skinframe, qbool colormapped)
Definition gl_rmain.c:2676
#define FOGWIDTH
int r_maxsurfacelist
Definition gl_rmain.c:9968
void R_SkinFrame_PrepareForPurge(void)
Definition gl_rmain.c:2168
cvar_t r_fullbright_directed_diffuse
Definition gl_rmain.c:116
cvar_t r_test
Definition gl_rmain.c:235
void R_SetupShader_Generic(rtexture_t *t, qbool usegamma, qbool notrippy, qbool suppresstexalpha)
Definition gl_rmain.c:1461
cvar_t r_bloom
Definition gl_rmain.c:208
cvar_t r_shadows_throwdirection
Definition gl_rmain.c:126
cvar_t r_transparent_useplanardistance
Definition gl_rmain.c:81
rtexture_t * r_texture_black
Definition gl_rmain.c:275
void RSurf_DrawBatch(void)
Definition gl_rmain.c:8477
static r_qwskincache_t * r_qwskincache
Definition gl_rmain.c:308
cvar_t r_motionblur_velocityfactor_minspeed
Definition gl_rmain.c:66
int r_textureframe
used only by R_GetCurrentTexture, incremented per view and per UI render
Definition gl_rmain.c:45
cvar_t r_celoutlines
Definition gl_rmain.c:145
cvar_t r_glsl_deluxemapping
Definition gl_rmain.c:171
static void gl_main_start(void)
Definition gl_rmain.c:3041
static r_bufferdata_buffer_t * r_bufferdata_buffer[R_BUFFERDATA_CYCLE][R_BUFFERDATA_COUNT]
Definition gl_rmain.c:3610
cvar_t r_q1bsp_lightmap_updates_hidden_surfaces
Definition gl_rmain.c:259
static void R_DecalSystem_SpawnTriangle(decalsystem_t *decalsystem, const float *v0, const float *v1, const float *v2, const float *t0, const float *t1, const float *t2, const float *c0, const float *c1, const float *c2, int triangleindex, int surfaceindex, unsigned int decalsequence)
Definition gl_rmain.c:9141
static void R_DrawModelTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist, qbool writedepth, qbool prepass, qbool ui)
Definition gl_rmain.c:8832
static void R_BuildBlankTextures(void)
Definition gl_rmain.c:371
void R_RenderWaterPlanes(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
Definition gl_rmain.c:5803
static void R_DrawModelsAddWaterPlanes(void)
Definition gl_rmain.c:4127
cvar_t r_showtris
Definition gl_rmain.c:86
r_refdef_scene_t * R_GetScenePointer(r_refdef_scene_type_t scenetype)
Definition gl_rmain.c:5588
#define BLENDFUNC_ALLOWS_FOG_HACKALPHA
Definition gl_rmain.c:1520
qbool r_loadfog
Definition gl_rmain.c:49
r_glsl_permutation_t * r_glsl_permutation
currently selected permutation
Definition gl_rmain.c:936
float viewscalefpsadjusted
Definition gl_rmain.c:4382
int r_texture_numcubemaps
Definition gl_rmain.c:294
void R_FillColors(float *out, int verts, float r, float g, float b, float a)
Definition gl_rmain.c:335
void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *planes)
Definition gl_rmain.c:6364
cvar_t r_viewscale_fpsscaling_stepmax
Definition gl_rmain.c:167
void R_BufferData_NewFrame(void)
begin a new frame (recycle old buffers)
Definition gl_rmain.c:3678
cvar_t r_viewscale
Definition gl_rmain.c:162
static void R_DrawNoModel_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
Definition gl_rmain.c:6188
qbool r_shadow_usingdeferredprepass
Definition r_shadow.c:64
static void R_DrawTextureSurfaceList_GL20(int texturenumsurfaces, const msurface_t **texturesurfacelist, qbool writedepth, qbool prepass, qbool ui)
Definition gl_rmain.c:8686
cvar_t r_shadows
Definition gl_rmain.c:123
void R_ResetViewRendering3D(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
Definition gl_rmain.c:4482
cvar_t r_showcollisionbrushes_polygonfactor
Definition gl_rmain.c:90
static qbool R_BlendView_IsTrivial(int viewwidth, int viewheight, int width, int height)
Definition gl_rmain.c:5224
static void R_DrawLocs(void)
Definition gl_rmain.c:9121
static void R_Bloom_StartFrame(void)
Definition gl_rmain.c:5019
cvar_t r_motionblur_velocityfactor_maxspeed
Definition gl_rmain.c:67
void FOG_clear(void)
Definition gl_rmain.c:349
float RSurf_FogPoint(const float *v)
Definition gl_rmain.c:7308
void R_UpdateFog(void)
Definition gl_rmain.c:5396
cvar_t gl_fogdensity
Definition gl_rmain.c:148
cvar_t r_cullentities_trace
Definition gl_rmain.c:101
cvar_t r_colorfringe
Definition gl_rmain.c:189
static void R_DecalSystem_SplatTriangle(decalsystem_t *decalsystem, float r, float g, float b, float a, float s1, float t1, float s2, float t2, unsigned int decalsequence, qbool dynamic, float(*planes)[4], matrix4x4_t *projection, int triangleindex, int surfaceindex)
Definition gl_rmain.c:9214
cvar_t r_water_scissormode
Definition gl_rmain.c:198
cvar_t r_polygonoffset_decals_factor
Definition gl_rmain.c:135
skinframe_t * R_SkinFrame_LoadExternal(const char *name, int textureflags, qbool complain, qbool fallbacknotexture)
Definition gl_rmain.c:2314
cvar_t gl_fogblue
Definition gl_rmain.c:151
cvar_t r_hdr_irisadaptation_maxvalue
Definition gl_rmain.c:223
cvar_t r_viewscale_fpsscaling_target
Definition gl_rmain.c:168
const float r_screenvertex3f[12]
vertex coordinates for a quad that covers the screen exactly
Definition gl_rmain.c:313
void V_MakeViewIsometric(void)
Definition view.c:968
rtexture_t * r_texture_notexture
Definition gl_rmain.c:276
static void R_BufferData_Resize(r_bufferdata_type_t type, qbool mustgrow, size_t minsize)
Definition gl_rmain.c:3636
cvar_t gl_picmip
Definition gl_textures.c:29
cvar_t r_viewscale_fpsscaling_min
Definition gl_rmain.c:164
static void RSurf_RenumberElements(const int *inelement3i, int *outelement3i, int numelements, int adjust)
Definition gl_rmain.c:7380
cvar_t r_drawparticles
void R_HDR_UpdateIrisAdaptation(const vec3_t point)
Definition gl_rmain.c:4144
r_framebufferstate_t r_fb
Definition gl_rmain.c:265
cvar_t r_water_resolutionmultiplier
Definition gl_rmain.c:195
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)
Definition gl_rmain.c:2546
float locboxvertex3f[6 *4 *3]
Definition gl_rmain.c:9058
matrix4x4_t r_waterscrollmatrix
Definition gl_rmain.c:5394
static void R_FrameData_Resize(qbool mustgrow)
Definition gl_rmain.c:3503
cvar_t r_glsl_offsetmapping_reliefmapping_refinesteps
Definition gl_rmain.c:176
qbool r_shadow_shadowmapsampler
Definition r_shadow.c:58
static void R_BuildNormalizationCube(void)
Definition gl_rmain.c:408
rtexture_t * r_texture_reflectcube
Definition gl_rmain.c:284
cvar_t v_glslgamma_2d
Definition vid_shared.c:186
cvar_t r_water_refractdistort
Definition gl_rmain.c:196
static void R_MotionBlurView(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
Definition gl_rmain.c:5251
static float irisvecs[7][3]
Definition gl_rmain.c:4142
void R_SetupShader_DeferredLight(const rtlight_t *rtlight)
Definition gl_rmain.c:2091
void R_UpdateVariables(void)
Definition gl_rmain.c:5483
cvar_t v_isometric
Definition view.c:97
void * R_FrameData_Alloc(size_t size)
allocate some temporary memory for your purposes
Definition gl_rmain.c:3539
static int RSurf_FindWaterPlaneForSurface(const msurface_t *surface)
Definition gl_rmain.c:8536
rsurfacestate_t rsurface
Definition gl_rmain.c:6919
cvar_t r_glsl_vertextextureblend_usebothalphas
Definition gl_rmain.c:245
cvar_t r_farclip_world
Definition gl_rmain.c:75
skinframe_t * R_SkinFrame_Find(const char *name, int textureflags, int comparewidth, int compareheight, int comparecrc, qbool add)
Definition gl_rmain.c:2240
cvar_t r_drawportals
Definition gl_rmain.c:95
void R_RenderTarget_FreeUnused(qbool force)
Definition gl_rmain.c:4523
static const unsigned short bboxelements[36]
Definition gl_rmain.c:6002
r_decalsystem_splatqueue_t r_decalsystem_queue[MAX_DECALSYSTEM_QUEUE]
Definition gl_rmain.c:9504
cvar_t r_waterscroll
Definition gl_rmain.c:206
cvar_t r_cullentities_trace_eyejitter
Definition gl_rmain.c:109
static void R_SetupShader_SetPermutationGLSL(unsigned int mode, uint64_t permutation)
Definition gl_rmain.c:1346
skinframe_t * R_SkinFrame_LoadNoTexture(void)
Definition gl_rmain.c:2832
cvar_t r_glsl_postprocess_uservec3_enable
Definition gl_rmain.c:187
static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode, uint64_t permutation)
Definition gl_rmain.c:1024
unsigned int r_texture_gammaramps_serial
Definition gl_rmain.c:282
cvar_t r_polygonoffset_decals_offset
Definition gl_rmain.c:136
static void gl_main_newmap(void)
Definition gl_rmain.c:3194
cvar_t r_bloom_scenebrightness
Definition gl_rmain.c:216
static const float bboxedges[BBOXEDGES][6]
Definition gl_rmain.c:6013
void R_Water_AddWaterPlane(msurface_t *surface, int entno)
Definition gl_rmain.c:4640
cvar_t r_celshading
Definition gl_rmain.c:144
static void R_View_Update(const int *myscissor)
Definition gl_rmain.c:4374
void R_SkinFrame_Purge(void)
Definition gl_rmain.c:2203
mempool_t * r_main_mempool
Definition gl_rmain.c:42
void GL_Main_Init(void)
Definition gl_rmain.c:3220
static void R_View_UpdateEntityVisible(void)
Definition gl_rmain.c:3992
cvar_t r_fullbright
Definition gl_rmain.c:112
#define SKINFRAME_HASH
Definition gl_rmain.c:2157
cvar_t r_bloom_colorscale
Definition gl_rmain.c:209
unsigned int r_numqueries
Definition gl_rmain.c:298
#define NORMSIZE
cvar_t r_motionblur_mousefactor
Definition gl_rmain.c:68
rtexture_t * r_texture_blanknormalmap
Definition gl_rmain.c:272
cvar_t r_transparent_sortsurfacesbynearest
Definition gl_rmain.c:80
qbool v_flipped_state
Definition gl_backend.c:21
static char * ShaderModeInfo_GetShaderText(shadermodeinfo_t *modeinfo, qbool printfromdisknotice, qbool builtinonly)
Definition gl_rmain.c:1006
texture_t * R_GetCurrentTexture(texture_t *t)
Definition gl_rmain.c:6549
static const char * shaderstaticparmstrings_list[SHADERSTATICPARMS_COUNT]
Definition gl_rmain.c:853
cvar_t r_showoverdraw
Definition gl_rmain.c:82
cvar_t r_glsl_offsetmapping
Definition gl_rmain.c:172
cvar_t r_batch_multidraw_mintriangles
Definition gl_rmain.c:238
rtexture_t * r_texture_fogheighttexture
Definition gl_rmain.c:280
void R_AnimCache_Free(void)
Animation cache prevents re-generating mesh data for an animated model multiple times in one frame fo...
Definition gl_rmain.c:3758
void R_SelectScene(r_refdef_scene_type_t scenetype)
Definition gl_rmain.c:5573
static void R_ProcessModelTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist, qbool writedepth, qbool depthonly, qbool prepass, qbool ui)
Definition gl_rmain.c:8978
static void R_DrawModels(void)
Definition gl_rmain.c:4078
cvar_t r_water_lowquality
Definition gl_rmain.c:199
static void R_DrawModelDecals_FadeEntity(entity_render_t *ent)
Definition gl_rmain.c:9533
cvar_t r_cullentities_trace_tempentitysamples
Definition gl_rmain.c:104
cvar_t r_cullentities_trace_delay
Definition gl_rmain.c:108
static const unsigned short nomodelelement3s[24]
Definition gl_rmain.c:6156
#define BBOXEDGES
Definition gl_rmain.c:6012
static void R_Bloom_MakeTexture(void)
Definition gl_rmain.c:5113
cvar_t r_bloom_resolution
Definition gl_rmain.c:213
void R_ResetViewRendering2D_Common(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight, float x2, float y2)
Definition gl_rmain.c:4439
cvar_t r_hdr_irisadaptation
Definition gl_rmain.c:220
cvar_t gl_fogenable
Definition gl_rmain.c:147
void RSurf_SetupDepthAndCulling(bool ui)
Definition gl_rmain.c:8576
static void R_View_SetFrustum(const int *scissor)
Definition gl_rmain.c:4189
svbsp_t r_svbsp
shadow volume bsp struct with automatically growing nodes buffer
Definition gl_rmain.c:268
static void R_GetCornerOfBox(vec3_t out, const vec3_t mins, const vec3_t maxs, int signbits)
Definition gl_rmain.c:3438
static void R_tcMod_ApplyToMatrix(matrix4x4_t *texmatrix, q3shaderinfo_layer_tcmod_t *tcmod, int currentmaterialflags)
Definition gl_rmain.c:6445
cvar_t r_fullbright_directed
Definition gl_rmain.c:114
cvar_t r_drawentities
Definition gl_rmain.c:96
cvar_t r_dynamic
Definition gl_rmain.c:121
cvar_t r_useinfinitefarclip
Definition gl_rmain.c:73
cvar_t r_bloom_brighten
Definition gl_rmain.c:211
cvar_t r_shadows_shadowmapscale
Definition gl_rmain.c:130
cvar_t cl_locs_show
Definition cl_main.c:98
cvar_t r_batch_multidraw
Definition gl_rmain.c:237
static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, const msurface_t **texturesurfacelist)
Definition gl_rmain.c:8587
int r_uniformbufferalignment
Definition gl_rmain.c:270
#define SHADERSTATICPARMS_COUNT
Definition gl_rmain.c:851
cvar_t r_hdr_scenebrightness
Definition gl_rmain.c:218
static void R_QueueModelSurfaceList(entity_render_t *ent, int numsurfaces, const msurface_t **surfacelist, int flagsmask, qbool writedepth, qbool depthonly, qbool prepass, qbool ui)
Definition gl_rmain.c:9012
static r_refdef_scene_type_t r_currentscenetype
Definition gl_rmain.c:5566
static void R_ProcessTransparentTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist)
Definition gl_rmain.c:8933
rtexture_t * R_GetCubemap(const char *basename)
Definition gl_rmain.c:2982
qbool R_CullBox(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes)
Definition gl_rmain.c:3470
shaderpermutationinfo_t shaderpermutationinfo[SHADERPERMUTATION_COUNT]
Definition gl_rmain.c:625
cvar_t r_motionblur_maxblur
Definition gl_rmain.c:64
cvar_t r_motionblur_averaging
Definition gl_rmain.c:61
cvar_t r_fxaa
Definition gl_rmain.c:190
cvar_t r_fullbright_directed_ambient
Definition gl_rmain.c:115
cvar_t r_transparent_sortarraysize
Definition gl_rmain.c:143
#define R_COMPILESHADER_STATICPARM_EMIT(p, n)
Definition gl_rmain.c:906
cvar_t r_motionblur_mousefactor_maxspeed
Definition gl_rmain.c:70
qbool R_CompileShader_CheckStaticParms(void)
Definition gl_rmain.c:861
static qbool r_loadnormalmap
Definition gl_rmain.c:47
static void R_DecalSystem_ApplySplatEntities(const vec3_t worldorigin, const vec3_t worldnormal, float r, float g, float b, float a, float s1, float t1, float s2, float t2, float worldsize, unsigned int decalsequence)
Definition gl_rmain.c:9466
cvar_t r_showparticleedges
Definition gl_rmain.c:94
cvar_t r_fullbright_directed_pitch
Definition gl_rmain.c:117
cvar_t r_water_reflectdistort
Definition gl_rmain.c:197
cvar_t r_showsurfaces
Definition gl_rmain.c:85
skinframe_t * R_SkinFrame_FindNextByName(skinframe_t *last, const char *name)
Definition gl_rmain.c:2217
cvar_t r_motionblur_mousefactor_minspeed
Definition gl_rmain.c:69
cvar_t gl_fogstart
Definition gl_rmain.c:152
cvar_t r_hdr_irisadaptation_radius
Definition gl_rmain.c:227
static void R_CompileShader_AddStaticParms(unsigned int mode, uint64_t permutation)
Definition gl_rmain.c:911
cvar_t r_polygonoffset_submodel_factor
Definition gl_rmain.c:133
static void R_Water_ProcessPlanes(int fbo, rtexture_t *depthtexture, rtexture_t *colortexture, int viewx, int viewy, int viewwidth, int viewheight)
Definition gl_rmain.c:4757
void R_AnimCache_ClearCache(void)
clear the animcache pointers on all known render entities
Definition gl_rmain.c:3762
cvar_t r_drawexteriormodel
Definition gl_rmain.c:100
cubemapinfo_t * r_texture_cubemaps[MAX_CUBEMAPS]
Definition gl_rmain.c:295
void R_DebugLine(vec3_t start, vec3_t end)
Definition gl_rmain.c:10107
static int componentorder[4]
Definition gl_rmain.c:2906
static qbool _R_CullBox(const vec3_t mins, const vec3_t maxs, int numplanes, const mplane_t *planes, int ignore)
Definition gl_rmain.c:3445
cvar_t developer_texturelogging
Definition gl_rmain.c:231
void R_CalcBeam_Vertex3f(float *vert, const float *org1, const float *org2, float width)
Definition gl_rmain.c:6253
static const int quadedges[6][2]
Definition gl_rmain.c:7387
cvar_t r_viewscale_fpsscaling_multiply
Definition gl_rmain.c:165
cvar_t r_water
Definition gl_rmain.c:192
const msurface_t ** r_surfacelist
Definition gl_rmain.c:9969
cvar_t r_glsl_offsetmapping_lod
Definition gl_rmain.c:178
void R_BufferData_Reset(void)
frees all dynamic buffers
Definition gl_rmain.c:3613
void R_CalcSprite_Vertex3f(float *vertex3f, const vec3_t origin, const vec3_t left, const vec3_t up, float scalex1, float scalex2, float scaley1, float scaley2)
Definition gl_rmain.c:6283
#define R_SKINFRAME_LOAD_AVERAGE_COLORS(cnt, getpixel)
Definition gl_rmain.c:2279
cvar_t r_glsl_offsetmapping_scale
Definition gl_rmain.c:177
cvar_t r_showbboxes
Definition gl_rmain.c:83
cvar_t r_batch_debugdynamicvertexpath
Definition gl_rmain.c:239
void RSurf_UploadBuffersForBatch(void)
Definition gl_rmain.c:7340
static void R_InitShaderModeInfo(void)
Definition gl_rmain.c:987
void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b)
Definition gl_rmain.c:321
static int r_bufferdata_cycle
Definition gl_rmain.c:3609
cvar_t cl_decals_models
cvar_t r_shadows_throwdistance
Definition gl_rmain.c:125
void R_DrawModelSurfaces(entity_render_t *ent, qbool skysurfaces, qbool writedepth, qbool depthonly, qbool debug, qbool prepass, qbool ui)
Definition gl_rmain.c:9970
cvar_t r_lockpvs
Definition gl_rsurf.c:29
static unsigned int r_compileshader_staticparms[(SHADERSTATICPARMS_COUNT+0x1F) > > 5]
Definition gl_rmain.c:856
void R_SkinFrame_PurgeSkinFrame(skinframe_t *s)
Definition gl_rmain.c:2184
cvar_t gl_lightmaps
Definition gl_rmain.c:233
cvar_t r_transparent_sortmindist
Definition gl_rmain.c:141
cvar_t r_cullentities_trace_samples
Definition gl_rmain.c:103
cvar_t r_showbboxes_client
Definition gl_rmain.c:84
#define RAMPWIDTH
skinframe_t * R_SkinFrame_LoadMissing(void)
Definition gl_rmain.c:2804
cvar_t r_framedatasize
Definition gl_rmain.c:248
cvar_t r_wateralpha
Definition gl_rmain.c:120
cvar_t r_glsl_postprocess_uservec2_enable
Definition gl_rmain.c:186
void R_SetupView(qbool allowwaterclippingplane, int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
Definition gl_rmain.c:4384
cvar_t r_showcollisionbrushes
Definition gl_rmain.c:89
void RSurf_ActiveModelEntity(const entity_render_t *ent, qbool wantnormals, qbool wanttangents, qbool prepass)
Definition gl_rmain.c:6921
cvar_t r_fog_clear
Definition gl_rmain.c:138
cvar_t r_damageblur
Definition gl_rmain.c:60
cvar_t r_fog_exp2
Definition gl_rmain.c:137
static void R_BuildFogTexture(void)
Definition gl_rmain.c:470
cvar_t r_glsl_postprocess_uservec4
Definition gl_rmain.c:184
static r_glsl_permutation_t * R_GLSL_FindPermutation(unsigned int mode, uint64_t permutation)
Definition gl_rmain.c:940
cvar_t gl_fogred
Definition gl_rmain.c:149
@ SHADERSTATICPARM_POSTPROCESS_USERVEC4
postprocess uservec4 is enabled
Definition gl_rmain.c:840
@ SHADERSTATICPARM_SHADOWSAMPLER
sampler
Definition gl_rmain.c:845
@ SHADERSTATICPARM_EXACTSPECULARMATH
(lightsource or deluxemapping) use exact reflection map for specular effects, as opposed to the usual...
Definition gl_rmain.c:836
@ SHADERSTATICPARM_CELOUTLINES
celoutline (depth buffer analysis to produce outlines)
Definition gl_rmain.c:847
@ SHADERSTATICPARM_VERTEXTEXTUREBLEND_USEBOTHALPHAS
Definition gl_rmain.c:841
@ SHADERSTATICPARM_SHADOWMAPPCF_1
PCF 1.
Definition gl_rmain.c:843
@ SHADERSTATICPARM_CELSHADING
celshading (alternative diffuse and specular math)
Definition gl_rmain.c:846
@ SHADERSTATICPARM_COLORFRINGE
colorfringe (chromatic aberration)
Definition gl_rmain.c:849
@ SHADERSTATICPARM_POSTPROCESS_USERVEC2
postprocess uservec2 is enabled
Definition gl_rmain.c:838
@ SHADERSTATICPARM_OFFSETMAPPING_USELOD
LOD for offsetmapping.
Definition gl_rmain.c:842
@ SHADERSTATICPARM_FXAA
fast approximate anti aliasing
Definition gl_rmain.c:848
@ SHADERSTATICPARM_POSTPROCESS_USERVEC1
postprocess uservec1 is enabled
Definition gl_rmain.c:837
@ SHADERSTATICPARM_SATURATION_REDCOMPENSATE
red compensation filter for saturation
Definition gl_rmain.c:835
@ SHADERSTATICPARM_SHADOWMAPPCF_2
PCF 2.
Definition gl_rmain.c:844
@ SHADERSTATICPARM_POSTPROCESS_USERVEC3
postprocess uservec3 is enabled
Definition gl_rmain.c:839
skinframe_t * R_SkinFrame_LoadExternal_SkinFrame(skinframe_t *skinframe, const char *name, int textureflags, qbool complain, qbool fallbacknotexture)
Definition gl_rmain.c:2331
int r_shadow_shadowmapatlas_modelshadows_size
Definition r_shadow.c:69
cvar_t r_cullentities_trace_expand
Definition gl_rmain.c:106
static void R_Mesh_AddPolygon3d(rmesh_t *mesh, int numvertices, double *vertex3d)
Definition gl_rmain.c:6342
static int shaderstaticparms_count
Definition gl_rmain.c:854
r_glsl_permutation_t * r_glsl_permutationhash[SHADERMODE_COUNT][SHADERPERMUTATION_HASHSIZE]
information about each possible shader permutation
Definition gl_rmain.c:934
cvar_t r_shownormals
Definition gl_rmain.c:87
cvar_t r_shadow_bouncegrid
Definition r_shadow.c:198
void R_SkinFrame_MarkUsed(skinframe_t *skinframe)
Definition gl_rmain.c:2176
cvar_t r_transparent
Definition gl_rmain.c:78
void R_DecalSystem_SplatEntities(const vec3_t worldorigin, const vec3_t worldnormal, float r, float g, float b, float a, float s1, float t1, float s2, float t2, float worldsize)
Definition gl_rmain.c:9506
cvar_t r_bloom_blur
Definition gl_rmain.c:212
cvar_t r_sortentities
Definition gl_rmain.c:110
cvar_t r_transparent_alphatocoverage
Definition gl_rmain.c:79
cvar_t cl_decals_bias
void R_FrameData_NewFrame(void)
prepare for a new frame, recycles old buffers if a resize occurred previously
Definition gl_rmain.c:3521
cvar_t r_glsl_saturation_redcompensate
Definition gl_rmain.c:243
cvar_t r_glsl_offsetmapping_reliefmapping
Definition gl_rmain.c:174
cvar_t r_speeds
Definition gl_rmain.c:111
cvar_t r_polygonoffset_submodel_offset
Definition gl_rmain.c:134
static void gl_main_shutdown(void)
Definition gl_rmain.c:3138
#define BLENDFUNC_ALLOWS_FOG
Definition gl_rmain.c:1518
cvar_t r_showcollisionbrushes_polygonoffset
Definition gl_rmain.c:91
static r_refdef_scene_t r_scenes_store[RST_COUNT]
Definition gl_rmain.c:5567
cvar_t r_showdisabledepthtest
Definition gl_rmain.c:92
static void R_DrawDebugModel(void)
Definition gl_rmain.c:9747
cvar_t r_drawworld
Definition gl_rmain.c:98
cvar_t r_motionblur_randomize
Definition gl_rmain.c:62
#define BLENDFUNC_ALLOWS_COLORMOD
Definition gl_rmain.c:1517
void R_SetupShader_Surface(const float rtlightambient[3], const float rtlightdiffuse[3], const float rtlightspecular[3], rsurfacepass_t rsurfacepass, int texturenumsurfaces, const msurface_t **texturesurfacelist, void *surfacewaterplane, qbool notrippy, qbool ui)
Definition gl_rmain.c:1563
cvar_t r_drawviewmodel
Definition gl_rmain.c:99
static r_framedata_mem_t * r_framedata_mem
Definition gl_rmain.c:3491
cvar_t r_nearclip
Definition gl_rmain.c:76
#define SHADERPERMUTATION_HASHSIZE
Definition gl_rmain.c:828
cvar_t r_cullentities_trace_pad
Definition gl_rmain.c:107
cvar_t gl_fogend
Definition gl_rmain.c:153
static int R_Mesh_AddVertex(rmesh_t *mesh, float x, float y, float z)
Definition gl_rmain.c:6299
static void R_DrawSurface_TransparentCallback(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist)
Definition gl_rmain.c:8851
cvar_t r_cullentities_trace_enlarge
Definition gl_rmain.c:105
static void R_BuildNoTexture(void)
Definition gl_rmain.c:396
static const float nomodelcolor4f[6 *4]
Definition gl_rmain.c:6178
cvar_t r_glsl_postprocess_uservec4_enable
Definition gl_rmain.c:188
cvar_t r_hdr_irisadaptation_multiplier
Definition gl_rmain.c:221
cvar_t r_glsl_postprocess_uservec1
Definition gl_rmain.c:181
cvar_t r_lerpsprites
Definition gl_rmain.c:202
static qbool R_TestQ3WaveFunc(q3wavefunc_t func, const float *parms)
Definition gl_rmain.c:6397
cvar_t r_water_cameraentitiesonly
Definition gl_rmain.c:193
static void R_Water_StartFrame(int viewwidth, int viewheight)
Definition gl_rmain.c:4608
qbool R_CullFrustum(const vec3_t mins, const vec3_t maxs)
Definition gl_rmain.c:3464
static float R_EvaluateQ3WaveFunc(q3wavefunc_t func, const float *parms)
Definition gl_rmain.c:6407
cvar_t r_rendertarget_debug
Definition gl_rmain.c:161
rtexture_t * loadingscreentexture
Definition cl_screen.c:1567
cvar_t r_glsl_offsetmapping_steps
Definition gl_rmain.c:173
cvar_t r_q1bsp_lightmap_updates_combine
Definition gl_rmain.c:258
static void R_BuildFogHeightTexture(void)
Definition gl_rmain.c:526
rtexture_t * r_texture_gammaramps
Definition gl_rmain.c:281
static int R_SortEntities_Compare(const void *ap, const void *bp)
Definition gl_rmain.c:5598
static void R_DrawModelDecals(void)
Definition gl_rmain.c:9711
r_refdef_t r_refdef
Definition gl_rmain.c:57
static void R_Main_ResizeViewCache(void)
Definition gl_rmain.c:3011
static suffixinfo_t suffix[3][6]
Definition gl_rmain.c:2878
cvar_t r_texture_dds_load
Definition gl_rmain.c:156
cvar_t r_lerplightstyles
Definition gl_rmain.c:205
cvar_t r_depthfirst
Definition gl_rmain.c:72
cvar_t r_deformvertexes
Definition gl_rmain.c:77
rtexture_t * r_texture_white
Definition gl_rmain.c:273
cvar_t r_glsl_saturation
Definition gl_rmain.c:242
static int r_qwskincache_size
Definition gl_rmain.c:309
cvar_t gl_skyclip
Definition gl_rmain.c:154
cvar_t r_viewfbo
Definition gl_rmain.c:160
rtexture_t * r_texture_normalizationcube
Definition gl_rmain.c:278
cvar_t r_lerpmodels
Definition gl_rmain.c:203
static void R_GLSL_DumpShader_f(cmd_state_t *cmd)
Definition gl_rmain.c:1419
unsigned int r_shadow_occlusion_buf
Definition r_shadow.c:136
static void R_DrawModelsDepth(void)
Definition gl_rmain.c:4097
cvar_t r_farclip_base
Definition gl_rmain.c:74
cvar_t r_glsl_postprocess_uservec2
Definition gl_rmain.c:182
r_meshbuffer_t * R_BufferData_Store(size_t datasize, const void *data, r_bufferdata_type_t type, int *returnbufferoffset)
request space in a vertex/index/uniform buffer for the chosen data, returns the buffer pointer and of...
Definition gl_rmain.c:3707
cvar_t r_glsl_postprocess
Definition gl_rmain.c:180
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)
Definition gl_rmain.c:10172
static void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, float ca)
Definition gl_rmain.c:6034
static void R_DrawTextureSurfaceList_DepthOnly(int texturenumsurfaces, const msurface_t **texturesurfacelist)
Definition gl_rmain.c:8965
cvar_t r_hdr_glowintensity
Definition gl_rmain.c:219
void * R_FrameData_Store(size_t size, void *data)
allocate some temporary memory and copy this data into it
Definition gl_rmain.c:3573
cvar_t r_cullentities_trace_entityocclusion
Definition gl_rmain.c:102
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)
Definition gl_rmain.c:7146
#define BLENDFUNC_ALLOWS_ANYFOG
Definition gl_rmain.c:1521
cvar_t r_transparentdepthmasking
Definition gl_rmain.c:140
static qbool r_loadgloss
Definition gl_rmain.c:48
static void R_DrawNoModel(entity_render_t *ent)
Definition gl_rmain.c:6243
static void R_DecalSystem_SplatEntity(entity_render_t *ent, const vec3_t worldorigin, const vec3_t worldnormal, float r, float g, float b, float a, float s1, float t1, float s2, float t2, float worldsize, unsigned int decalsequence)
Definition gl_rmain.c:9307
static const char * builtinshaderstrings[]
Definition gl_rmain.c:596
static qbool r_loaddds
Definition gl_rmain.c:50
cvar_t r_glsl_postprocess_uservec3
Definition gl_rmain.c:183
static void R_DrawTextureSurfaceList_ShowSurfaces(int texturenumsurfaces, const msurface_t **texturesurfacelist, qbool writedepth)
Definition gl_rmain.c:8746
cvar_t r_glsl_offsetmapping_lod_distance
Definition gl_rmain.c:179
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)
Definition gl_rmain.c:2749
cvar_t r_glsl_skeletal
Definition gl_rmain.c:170
cvar_t gl_foggreen
Definition gl_rmain.c:150
cvar_t cl_decals_newsystem_intensitymultiplier
void R_AnimCache_CacheVisibleEntities(void)
generate animcache data for all entities marked visible
Definition gl_rmain.c:3874
static void R_DrawEntityBBoxes(prvm_prog_t *prog)
Definition gl_rmain.c:6120
cvar_t cl_decals_max
static int R_BlendFuncFlags(int src, int dst)
Definition gl_rmain.c:1522
unsigned int r_queries[MAX_OCCLUSION_QUERIES]
Definition gl_rmain.c:297
cvar_t r_viewscale_fpsscaling
Definition gl_rmain.c:163
cvar_t r_texture_dds_save
Definition gl_rmain.c:157
void GL_Surf_Init(void)
Definition gl_rsurf.c:1564
cvar_t r_ambient
Definition gl_rsurf.c:28
void R_BuildLightMap(const entity_render_t *ent, msurface_t *surface, int combine)
Definition gl_rsurf.c:50
void R_View_WorldVisibility(qbool forcenovis)
Definition gl_rsurf.c:436
void R_DrawPortals(void)
Definition gl_rsurf.c:381
cvar_t r_q3bsp_renderskydepth
Definition gl_rsurf.c:41
void R_PurgeTexture(rtexture_t *rt)
void R_FreeTexturePool(rtexturepool_t **rtexturepool)
int R_TextureFlags(rtexture_t *rt)
cvar_t gl_texturecompression_lightcubemaps
Definition gl_textures.c:46
cvar_t gl_texturecompression
Definition gl_textures.c:37
rtexture_t * R_LoadTextureRenderBuffer(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, textype_t textype)
void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, int z, int width, int height, int depth, int combine)
cvar_t gl_texturecompression_reflectmask
Definition gl_textures.c:47
cvar_t gl_texturecompression_color
Definition gl_textures.c:38
rtexture_t * R_LoadTextureDDSFile(rtexturepool_t *rtexturepool, const char *filename, qbool srgb, int flags, qbool *hasalphaflag, float *avgcolor, int miplevel, qbool optionaltexture)
int R_SaveTextureDDSFile(rtexture_t *rt, const char *filename, qbool skipuncompressed, qbool hasalpha)
cvar_t gl_texturecompression_glow
Definition gl_textures.c:41
rtexture_t * R_LoadTextureCubeMap(rtexturepool_t *rtexturepool, const char *identifier, int width, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette)
rtexturepool_t * R_AllocTexturePool(void)
void R_FreeTexture(rtexture_t *rt)
void R_Textures_Init(void)
void R_Textures_Frame(void)
cvar_t gl_texturecompression_gloss
Definition gl_textures.c:40
int R_PicmipForFlags(int flags)
rtexture_t * R_LoadTexture2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, const unsigned char *data, textype_t textype, int flags, int miplevel, const unsigned int *palette)
cvar_t gl_texturecompression_normal
Definition gl_textures.c:39
GLubyte GLubyte GLubyte z
Definition glquake.h:782
GLenum GLenum GLuint texture
Definition glquake.h:613
#define GL_NONE
Definition glquake.h:127
GLenum GLsizei width
Definition glquake.h:622
GLenum GLsizei GLsizei height
Definition glquake.h:622
#define CHECKGLERROR
Definition glquake.h:1059
GLfloat GLfloat GLfloat v2
Definition glquake.h:747
GLint GLint GLint yoffset
Definition glquake.h:649
GLubyte GLubyte GLubyte GLubyte w
Definition glquake.h:782
#define GL_UNIFORM_BUFFER
Definition glquake.h:413
int GLint
Definition glquake.h:51
GLsizei samples
Definition glquake.h:623
GLenum mode
Definition glquake.h:718
GLsizei const GLfloat * value
Definition glquake.h:740
GLsizei const GLchar ** string
Definition glquake.h:728
#define GL_FRONT_AND_BACK
Definition glquake.h:136
#define GL_POLYGON_OFFSET_FILL
Definition glquake.h:183
#define GL_ONE_MINUS_DST_ALPHA
Definition glquake.h:82
#define GL_ONE_MINUS_DST_COLOR
Definition glquake.h:78
const GLdouble * v
Definition glquake.h:762
#define GL_SRC_ALPHA
Definition glquake.h:79
GLint GLenum GLint GLint y
Definition glquake.h:651
#define GL_BACK
Definition glquake.h:133
#define GL_SRC_COLOR
Definition glquake.h:75
#define GL_FLOAT
Definition glquake.h:124
#define GL_ZERO
Definition glquake.h:73
GLint GLenum GLint x
Definition glquake.h:651
GLint GLint xoffset
Definition glquake.h:649
#define GL_UNSIGNED_BYTE
Definition glquake.h:119
GLsizeiptr const GLvoid * data
Definition glquake.h:639
GLfloat v0
Definition glquake.h:739
#define GL_LEQUAL
Definition glquake.h:162
GLfloat GLfloat v1
Definition glquake.h:743
unsigned int GLenum
Definition glquake.h:45
int GLsizei
Definition glquake.h:55
#define GL_COLOR_BUFFER_BIT
Definition glquake.h:171
#define GL_FILL
Definition glquake.h:108
GLuint GLuint GLintptr offset
Definition glquake.h:632
#define GL_ONE_MINUS_SRC_ALPHA
Definition glquake.h:80
#define GL_ONE
Definition glquake.h:74
GLint GLenum GLenum GLvoid * pixels
Definition glquake.h:706
#define GL_DST_ALPHA
Definition glquake.h:81
#define GL_LINE
Definition glquake.h:107
const GLchar * name
Definition glquake.h:601
#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT
Definition glquake.h:426
#define GL_DST_COLOR
Definition glquake.h:77
#define GL_FRONT
Definition glquake.h:132
#define GL_ACTIVE_UNIFORMS
Definition glquake.h:454
#define GL_DEPTH_BUFFER_BIT
Definition glquake.h:169
GLuint index
Definition glquake.h:629
#define GL_ONE_MINUS_SRC_COLOR
Definition glquake.h:76
GLenum type
Definition glquake.h:656
host_static_t host
Definition host.c:41
cvar_t developer_extra
Definition host.c:49
cvar_t developer_loading
Definition host.c:52
unsigned char * Image_GenerateNoTexture(void)
Definition image.c:1887
int image_height
Definition image.c:10
void Image_HeightmapToNormalmap_BGRA(const unsigned char *inpixels, unsigned char *outpixels, int width, int height, int clamp, float bumpscale)
Definition image.c:1769
void Image_Copy8bitBGRA(const unsigned char *in, unsigned char *out, int pixels, const unsigned int *pal)
Definition image.c:129
void Image_CopyMux(unsigned char *outpixels, const unsigned char *inpixels, int inputwidth, int inputheight, qbool inputflipx, qbool inputflipy, qbool inputflipdiagonal, int numoutputcomponents, int numinputcomponents, int *outputinputcomponentindices)
Definition image.c:24
unsigned char * loadimagepixelsbgra(const char *filename, qbool complain, qbool allowFixtrans, qbool convertsRGB, int *miplevel)
Definition image.c:1043
qbool LoadPCX_QWSkin(const unsigned char *f, int filesize, unsigned char *pixels, int outwidth, int outheight)
Definition image.c:286
int image_width
Definition image.c:9
void Image_StripImageExtension(const char *in, char *out, size_t size_out)
Definition image.c:913
#define Image_sRGBFloatFromLinearFloat(c)
Definition image.h:68
vec3_t vec3_origin
Definition mathlib.c:26
int LoopingFrameNumberFromDouble(double t, int loopframes)
Definition mathlib.c:891
void AnglesFromVectors(vec3_t angles, const vec3_t forward, const vec3_t up, qbool flippitch)
LadyHavoc: calculates pitch/yaw/roll angles from forward and up vectors.
Definition mathlib.c:650
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Definition mathlib.c:444
void PlaneClassify(mplane_t *p)
Definition mathlib.c:310
#define VectorLerp(v1, lerp, v2, out)
Definition mathlib.h:120
#define max(A, B)
Definition mathlib.h:38
#define VectorNegate(a, b)
Definition mathlib.h:95
#define min(A, B)
Definition mathlib.h:37
#define Vector4Multiply(a, b, out)
Definition mathlib.h:91
#define BoxesOverlap(a, b, c, d)
Definition mathlib.h:122
#define VectorReflect(a, r, b, out)
Definition mathlib.h:121
#define VectorNormalize(v)
Definition mathlib.h:104
#define VectorClear(a)
Definition mathlib.h:97
#define bound(min, num, max)
Definition mathlib.h:34
#define VectorLength(a)
Definition mathlib.h:109
#define lhrandom(MIN, MAX)
LadyHavoc: this function never returns exactly MIN or exactly MAX, because of a QuakeC bug in id1 whe...
Definition mathlib.h:48
#define VectorMAMAM(scale1, b1, scale2, b2, scale3, b3, out)
Definition mathlib.h:117
#define Vector4Set(vec, r, g, b, a)
Definition mathlib.h:86
#define VectorLength2(a)
Definition mathlib.h:110
#define Vector4Clear(a)
Definition mathlib.h:82
#define VectorSet(vec, x, y, z)
Definition mathlib.h:96
#define Vector4Copy(in, out)
Definition mathlib.h:84
#define VectorDistance2(a, b)
Definition mathlib.h:107
#define VectorSubtract(a, b, out)
Definition mathlib.h:99
#define Vector4Add(a, b, out)
Definition mathlib.h:89
#define CrossProduct(a, b, out)
Definition mathlib.h:103
#define VectorCompare(a, b)
Definition mathlib.h:113
#define TriangleNormal(a, b, c, n)
Definition mathlib.h:126
#define PlaneDiff(point, plane)
Definition mathlib.h:257
#define VectorDistance(a, b)
Definition mathlib.h:108
#define DotProduct(a, b)
Definition mathlib.h:98
#define VectorCopy(in, out)
Definition mathlib.h:101
#define VectorScale(in, scale, out)
Definition mathlib.h:111
#define VectorMAM(scale1, b1, scale2, b2, out)
Definition mathlib.h:116
#define VectorAdd(a, b, out)
Definition mathlib.h:100
#define M_PI
Definition mathlib.h:28
#define VectorMA(a, scale, b, out)
Definition mathlib.h:114
#define VectorMAMAMAM(scale1, b1, scale2, b2, scale3, b3, scale4, b4, out)
Definition mathlib.h:118
void Matrix4x4_Concat(matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2)
Definition matrixlib.c:83
void Matrix4x4_CreateIdentity(matrix4x4_t *out)
Definition matrixlib.c:564
void Matrix4x4_TransformStandardPlane(const matrix4x4_t *in, float x, float y, float z, float d, float *o)
Definition matrixlib.c:1717
void Matrix4x4_FromArray12FloatGL(matrix4x4_t *out, const float in[12])
Definition matrixlib.c:1352
void Matrix4x4_Transform(const matrix4x4_t *in, const float v[3], float out[3])
Definition matrixlib.c:1657
void Matrix4x4_ToArrayFloatGL(const matrix4x4_t *in, float out[16])
Definition matrixlib.c:1165
void Matrix4x4_CreateTranslate(matrix4x4_t *out, double x, double y, double z)
Definition matrixlib.c:584
void Matrix4x4_Transform3x3(const matrix4x4_t *in, const float v[3], float out[3])
Definition matrixlib.c:1685
void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, double x, double y, double z, double pitch, double yaw, double roll, double scale)
Definition matrixlib.c:715
int Matrix4x4_Invert_Full(matrix4x4_t *out, const matrix4x4_t *in1)
Definition matrixlib.c:145
void Matrix4x4_CreateScale3(matrix4x4_t *out, double x, double y, double z)
Definition matrixlib.c:695
void Matrix4x4_ConcatScale3(matrix4x4_t *out, double x, double y, double z)
Definition matrixlib.c:1784
void Matrix4x4_Normalize3(matrix4x4_t *out, matrix4x4_t *in1)
Definition matrixlib.c:508
void Matrix4x4_Reflect(matrix4x4_t *out, double normalx, double normaly, double normalz, double dist, double axisscale)
Definition matrixlib.c:535
void Matrix4x4_Invert_Simple(matrix4x4_t *out, const matrix4x4_t *in1)
Definition matrixlib.c:422
void Matrix4x4_ConcatTranslate(matrix4x4_t *out, double x, double y, double z)
Definition matrixlib.c:1757
double Matrix4x4_ScaleFromMatrix(const matrix4x4_t *in)
Definition matrixlib.c:1805
void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3])
Definition matrixlib.c:970
void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3])
Definition matrixlib.c:939
const matrix4x4_t identitymatrix
Definition matrixlib.c:9
void Matrix4x4_ConcatRotate(matrix4x4_t *out, double angle, double x, double y, double z)
Definition matrixlib.c:1766
void Matrix4x4_OriginFromMatrix(const matrix4x4_t *in, float *out)
Definition matrixlib.c:1792
cvar_t r_shadow_realtime_dlight
Definition r_shadow.c:159
cvar_t r_shadow_realtime_world_shadows
Definition r_shadow.c:166
cvar_t r_shadow_realtime_world
Definition r_shadow.c:163
cvar_t r_shadow_gloss
Definition r_shadow.c:147
cvar_t r_shadow_realtime_dlight_shadows
Definition r_shadow.c:160
cvar_t r_shadow_realtime_world_lightmaps
Definition r_shadow.c:165
cvar_t gl_flashblend
Definition r_shadow.c:236
float ceil(float f)
float strlen(string s)
void error(string err,...)
float sqrt(float f)
void cmd(string command,...)
float sin(float f)
float fabs(float f)
float floor(float f)
void R_MeshQueue_BeginScene(void)
Definition meshqueue.c:26
void R_MeshQueue_AddTransparent(dptransparentsortcategory_t category, const vec3_t center, void(*callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist), const entity_render_t *ent, int surfacenumber, const rtlight_t *rtlight)
Definition meshqueue.c:33
void R_MeshQueue_RenderTransparent(void)
Definition meshqueue.c:62
#define MESHQUEUE_TRANSPARENT_BATCHSIZE
Definition meshqueue.h:6
void Mod_Skeletal_BuildTransforms(const model_t *RESTRICT model, const frameblend_t *RESTRICT frameblend, const skeleton_t *skeleton, float *RESTRICT bonepose, float *RESTRICT boneposerelative)
Definition model_alias.c:65
cvar_t r_novis
Definition model_brush.c:31
cvar_t r_trippy
Definition model_brush.c:29
#define MATERIALFLAG_ADD
Definition model_brush.h:81
#define MATERIALFLAG_SKY
Definition model_brush.h:92
#define MATERIALFLAG_VERTEXCOLOR
#define MATERIALFLAG_FULLBRIGHT
Definition model_brush.h:87
#define MATERIALFLAG_ALPHA
Definition model_brush.h:79
#define MATERIALFLAG_REFRACTION
#define MATERIALFLAG_NODRAW
Definition model_brush.h:96
#define MATERIALFLAGMASK_DEPTHSORTED
#define MATERIALFLAG_ALPHATEST
#define MATERIALFLAG_CUSTOMSURFACE
#define MATERIALFLAG_BLENDED
#define MATERIALFLAG_TRANSDEPTH
#define MATERIALFLAG_VERTEXTEXTUREBLEND
#define MATERIALFLAG_WATERALPHA
Definition model_brush.h:85
#define MATERIALFLAG_LIGHTGRID
#define MATERIALFLAG_ALPHAGEN_VERTEX
#define MATERIALFLAG_WATERSHADER
#define MATERIALFLAG_MODELLIGHT
#define MATERIALFLAG_CAMERA
#define MATERIALFLAG_OCCLUDE
#define MATERIALFLAG_NODEPTHTEST
Definition model_brush.h:83
#define MATERIALFLAGMASK_TRANSLUCENT
#define MATERIALFLAG_WALL
Definition model_brush.h:89
#define MATERIALFLAG_NOSHADOW
#define MATERIALFLAG_REFLECTION
#define MATERIALFLAG_SHORTDEPTHRANGE
#define MATERIALFLAG_NOCULLFACE
#define MATERIALFLAG_WATERSCROLL
Definition model_brush.h:94
#define MATERIALFLAG_CUSTOMBLEND
#define MATERIALFLAG_NORTLIGHT
#define Q3SURFACEFLAG_NOMARKS
msurface_t * Mod_Mesh_AddSurface(model_t *mod, texture_t *tex, qbool batchwithprevioussurface)
int Mod_Mesh_IndexForVertex(model_t *mod, msurface_t *surf, float x, float y, float z, float nx, float ny, float nz, float s, float t, float u, float v, float r, float g, float b, float a)
void Mod_BuildNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const int *elements, float *normal3f, qbool areaweighting)
cvar_t r_mipnormalmaps
texture_t * Mod_Mesh_GetTexture(model_t *mod, const char *name, int defaultdrawflags, int defaulttexflags, int defaultmaterialflags)
void Mod_Mesh_AddTriangle(model_t *mod, msurface_t *surf, int e0, int e1, int e2)
void Mod_BuildTextureVectorsFromNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const float *texcoord2f, const float *normal3f, const int *elements, float *svector3f, float *tvector3f, qbool areaweighting)
cvar_t r_mipskins
void Mod_RenderInit(void)
@ mod_brushq3
@ mod_sprite
unsigned int palette_bgra_nocolormap[256]
Definition palette.c:16
unsigned int palette_bgra_transparent[256]
Definition palette.c:24
unsigned int palette_bgra_onlyfullbrights_transparent[256]
Definition palette.c:21
unsigned int palette_bgra_nocolormapnofullbrights[256]
Definition palette.c:17
unsigned int palette_bgra_shirtaswhite[256]
Definition palette.c:23
unsigned int palette_bgra_complete[256]
Definition palette.c:13
unsigned int palette_bgra_nofullbrights_transparent[256]
Definition palette.c:19
unsigned char palette_featureflags[256]
Definition palette.c:26
unsigned int palette_bgra_nofullbrights[256]
Definition palette.c:18
unsigned int palette_bgra_onlyfullbrights[256]
Definition palette.c:20
unsigned int palette_bgra_pantsaswhite[256]
Definition palette.c:22
#define PALETTEFEATURE_SHIRT
Definition palette.h:8
#define PALETTEFEATURE_GLOW
Definition palette.h:9
#define PALETTEFEATURE_PANTS
Definition palette.h:7
int PolygonF_Clip(int innumpoints, const float *inpoints, float planenormalx, float planenormaly, float planenormalz, float planedist, float epsilon, int outfrontmaxpoints, float *outfrontpoints)
Definition polygon.c:99
void PolygonD_QuadForPlane(double *outpoints, double planenormalx, double planenormaly, double planenormalz, double planedist, double quadsize)
Definition polygon.c:54
void PolygonD_Divide(int innumpoints, const double *inpoints, double planenormalx, double planenormaly, double planenormalz, double planedist, double epsilon, int outfrontmaxpoints, double *outfrontpoints, int *neededfrontpoints, int outbackmaxpoints, double *outbackpoints, int *neededbackpoints, int *oncountpointer)
Definition polygon.c:245
#define CLVM_prog
Definition progsvm.h:767
#define PRVM_serveredictedict(ed, fieldname)
Definition progsvm.h:175
#define PRVM_gameedictedict(ed, fieldname)
Definition progsvm.h:163
#define PRVM_EDICT_NUM(n)
Definition progsvm.h:867
#define PRVM_serveredictfloat(ed, fieldname)
Definition progsvm.h:172
#define SVVM_prog
Definition progsvm.h:766
#define RENDER_EXTERIORMODEL
Definition protocol.h:359
#define RENDER_VIEWMODEL
Definition protocol.h:358
#define RENDER_DYNAMICMODELLIGHT
Definition protocol.h:373
#define RENDER_WORLDOBJECT
Definition protocol.h:362
#define RENDER_DOUBLESIDED
Definition protocol.h:371
#define RENDER_ADDITIVE
Definition protocol.h:370
#define RENDER_NOSELFSHADOW
Definition protocol.h:367
#define RENDER_LIGHT
Definition protocol.h:366
#define RENDER_CUSTOMIZEDMODELLIGHT
Definition protocol.h:372
#define RENDER_NODEPTHTEST
Definition protocol.h:369
prvm_eval_t * src
int i
#define MAX_WATERPLANES
max number of water planes visible (each one causes additional view renders)
Definition qdefs.h:129
#define MAX_EDICTS
max number of objects in game world at once (32768 protocol limit)
Definition qdefs.h:105
#define MAX_CUBEMAPS
max number of cubemap textures loaded for light filters
Definition qdefs.h:130
#define MAX_QPATH
max length of a quake game pathname
Definition qdefs.h:169
#define MAX_OCCLUSION_QUERIES
max number of query objects that can be used in one frame
Definition qdefs.h:124
#define MAX_DECALSYSTEM_QUEUE
Definition qdefs.h:150
#define NULL
Definition qtypes.h:12
float vec_t
Definition qtypes.h:68
vec_t vec3_t[3]
Definition qtypes.h:71
bool qbool
Definition qtypes.h:9
vec_t vec4_t[4]
Definition qtypes.h:72
cvar_t chase_active
Definition view.c:132
void R_DrawExplosions(void)
void R_Explosion_Init(void)
void R_LightningBeams_Init(void)
Definition r_lightning.c:96
void R_RegisterModule(const char *name, void(*start)(void), void(*shutdown)(void), void(*newmap)(void), void(*devicelost)(void), void(*devicerestored)(void))
Definition r_modules.c:25
int q3wavefunc_t
Definition r_qshader.h:41
#define Q3WAVEFUNC_USER_COUNT
Definition r_qshader.h:42
@ Q3DEFORM_NORMAL
Definition r_qshader.h:61
@ Q3DEFORM_TEXT3
Definition r_qshader.h:54
@ Q3DEFORM_TEXT5
Definition r_qshader.h:56
@ Q3DEFORM_TEXT0
Definition r_qshader.h:51
@ Q3DEFORM_AUTOSPRITE
Definition r_qshader.h:49
@ Q3DEFORM_PROJECTIONSHADOW
Definition r_qshader.h:48
@ Q3DEFORM_WAVE
Definition r_qshader.h:60
@ Q3DEFORM_TEXT1
Definition r_qshader.h:52
@ Q3DEFORM_TEXT2
Definition r_qshader.h:53
@ Q3DEFORM_NONE
Definition r_qshader.h:47
@ Q3DEFORM_AUTOSPRITE2
Definition r_qshader.h:50
@ Q3DEFORM_TEXT7
Definition r_qshader.h:58
@ Q3DEFORM_MOVE
Definition r_qshader.h:62
@ Q3DEFORM_TEXT6
Definition r_qshader.h:57
@ Q3DEFORM_TEXT4
Definition r_qshader.h:55
@ Q3DEFORM_BULGE
Definition r_qshader.h:59
@ TRANSPARENTSORT_DISTANCE
Definition r_qshader.h:194
@ TRANSPARENTSORT_SKY
Definition r_qshader.h:193
@ TRANSPARENTSORT_HUD
Definition r_qshader.h:195
#define Q3WAVEFUNC_USER_SHIFT
Definition r_qshader.h:43
@ Q3TCMOD_SCALE
Definition r_qshader.h:114
@ Q3TCMOD_ROTATE
Definition r_qshader.h:113
@ Q3TCMOD_ENTITYTRANSLATE
Definition r_qshader.h:112
@ Q3TCMOD_TRANSFORM
Definition r_qshader.h:117
@ Q3TCMOD_SCROLL
Definition r_qshader.h:115
@ Q3TCMOD_PAGE
Definition r_qshader.h:119
@ Q3TCMOD_TURBULENT
Definition r_qshader.h:118
@ Q3TCMOD_STRETCH
Definition r_qshader.h:116
@ Q3TCMOD_NONE
Definition r_qshader.h:111
@ Q3TCMOD_COUNT
Definition r_qshader.h:120
@ OFFSETMAPPING_DEFAULT
Definition r_qshader.h:186
@ OFFSETMAPPING_OFF
Definition r_qshader.h:185
@ OFFSETMAPPING_LINEAR
Definition r_qshader.h:187
@ OFFSETMAPPING_RELIEF
Definition r_qshader.h:188
@ Q3TCGEN_VECTOR
Definition r_qshader.h:104
@ Q3TCGEN_ENVIRONMENT
Definition r_qshader.h:102
@ Q3TCGEN_LIGHTMAP
Definition r_qshader.h:103
@ Q3TCGEN_TEXTURE
Definition r_qshader.h:101
@ Q3WAVEFUNC_INVERSESAWTOOTH
Definition r_qshader.h:32
@ Q3WAVEFUNC_SAWTOOTH
Definition r_qshader.h:34
@ Q3WAVEFUNC_TRIANGLE
Definition r_qshader.h:37
@ Q3WAVEFUNC_NOISE
Definition r_qshader.h:33
@ Q3WAVEFUNC_COUNT
Definition r_qshader.h:38
@ Q3WAVEFUNC_NONE
Definition r_qshader.h:31
@ Q3WAVEFUNC_SIN
Definition r_qshader.h:35
@ Q3WAVEFUNC_SQUARE
Definition r_qshader.h:36
cvar_t r_shadow_glossintensity
Definition r_shadow.c:149
int r_shadow_viewx
Definition r_shadow.c:127
cvar_t r_shadow_bumpscale_bumpmap
Definition r_shadow.c:142
float r_shadow_modelshadowmap_parameters[4]
Definition r_shadow.c:43
rtexture_t * r_shadow_prepassgeometrynormalmaptexture
Definition r_shadow.c:120
void R_Shadow_DrawShadowMaps(void)
Definition r_shadow.c:4204
qbool r_shadow_shadowmapvsdct
Definition r_shadow.c:57
rtexture_t * r_shadow_viewdepthtexture
Definition r_shadow.c:125
int r_shadow_viewfbo
Definition r_shadow.c:124
rtexture_t * r_shadow_attenuationgradienttexture
Definition r_shadow.c:108
void R_Shadow_PrepareLights(void)
Definition r_shadow.c:4031
qbool R_Shadow_ShadowMappingEnabled(void)
Definition r_shadow.c:378
float r_shadow_lightshadowmap_parameters[4]
Definition r_shadow.c:41
void R_Shadow_PrepareModelShadows(void)
Definition r_shadow.c:4242
qbool r_shadow_usingshadowmap2d
Definition r_shadow.c:37
cvar_t r_shadow_glossexact
Definition r_shadow.c:152
float r_shadow_lightshadowmap_texturescale[4]
Definition r_shadow.c:40
rtexture_t * r_shadow_viewcolortexture
Definition r_shadow.c:126
int r_shadow_viewy
Definition r_shadow.c:128
qbool r_shadow_usingshadowmaportho
Definition r_shadow.c:38
cvar_t r_shadow_frontsidecasting
Definition r_shadow.c:158
void R_Shadow_UpdateBounceGridTexture(void)
Definition r_shadow.c:2755
rtexture_t * r_shadow_shadowmapvsdcttexture
Definition r_shadow.c:112
rtexture_t * r_shadow_shadowmap2ddepthtexture
Definition r_shadow.c:111
matrix4x4_t r_shadow_shadowmapmatrix
Definition r_shadow.c:62
void R_Shadow_DrawCoronas(void)
Definition r_shadow.c:4528
void R_Shadow_Init(void)
Definition r_shadow.c:601
cvar_t r_shadow_gloss2intensity
Definition r_shadow.c:148
rtexture_t * r_shadow_shadowmap2ddepthbuffer
Definition r_shadow.c:110
void R_Shadow_DrawLights(void)
Definition r_shadow.c:4226
cvar_t r_shadow_glossexponent
Definition r_shadow.c:150
cvar_t r_shadow_gloss2exponent
Definition r_shadow.c:151
void R_Shadow_DrawPrepass(void)
Definition r_shadow.c:3958
void R_Shadow_UpdateWorldLightSelection(void)
Definition r_shadow.c:5289
int r_shadow_viewwidth
Definition r_shadow.c:129
cvar_t r_shadow_bumpscale_basetexture
Definition r_shadow.c:141
int r_shadow_viewheight
Definition r_shadow.c:130
r_shadow_bouncegrid_state_t r_shadow_bouncegrid_state
Definition r_shadow.c:259
void R_CompleteLightPoint(float *ambient, float *diffuse, float *lightdir, const vec3_t p, const int flags, float lightmapintensity, float ambientintensity)
Definition r_shadow.c:6014
float r_shadow_modelshadowmap_texturescale[4]
Definition r_shadow.c:42
#define LP_DYNLIGHT
Definition r_shadow.h:194
#define LP_LIGHTMAP
Definition r_shadow.h:192
#define LP_RTWORLD
Definition r_shadow.h:193
cvar_t r_sky_scissor
Definition r_sky.c:9
int skyrendermasked
Definition r_sky.c:11
void R_Sky_Init(void)
Definition r_sky.c:464
int skyrenderlater
Definition r_sky.c:10
void R_Sky(void)
Definition r_sky.c:403
int skyscissor[4]
Definition r_sky.c:12
void R_SkyStartFrame(void)
Definition r_sky.c:57
int r_timereport_active
Definition r_stats.c:189
void R_TimeReport(const char *desc)
Definition r_stats.c:193
@ r_stat_animcache_shape_count
Definition r_stats.h:67
@ r_stat_batch_fast_vertices
Definition r_stats.h:77
@ r_stat_batch_dynamic_triangles_because_deformvertexes_normal
Definition r_stats.h:110
@ r_stat_batch_entitycustom_surfaces
Definition r_stats.h:164
@ r_stat_batch_dynamic_vertices_because_deformvertexes_move
Definition r_stats.h:121
@ r_stat_batch_dynamic_surfaces_because_deformvertexes_wave
Definition r_stats.h:112
@ r_stat_batch_dynamic_batches_because_deformvertexes_autosprite
Definition r_stats.h:99
@ r_stat_batch_dynamic_surfaces_because_deformvertexes_move
Definition r_stats.h:120
@ r_stat_batch_dynamic_vertices_because_deformvertexes_normal
Definition r_stats.h:109
@ r_stat_batch_entityanimate_count
Definition r_stats.h:151
@ r_stat_framedatacurrent
Definition r_stats.h:51
@ r_stat_batch_dynamic_vertices_because_nogaps
Definition r_stats.h:141
@ r_stat_batch_dynamic_vertices_because_cvar
Definition r_stats.h:93
@ r_stat_batch_entitycache_triangles
Definition r_stats.h:150
@ r_stat_batch_dynamic_batches_because_deformvertexes_bulge
Definition r_stats.h:115
@ r_stat_batch_dynamic_batches_because_tcmod_turbulent
Definition r_stats.h:135
@ r_stat_batch_entityskeletal_vertices
Definition r_stats.h:157
@ r_stat_batch_dynamic_batches
Definition r_stats.h:83
@ r_stat_batch_dynamic_vertices_because_tcgen_lightmap
Definition r_stats.h:125
@ r_stat_batch_dynamic_surfaces_because_tcgen_environment
Definition r_stats.h:132
@ r_stat_batch_entitycustom_triangles
Definition r_stats.h:166
@ r_stat_drawndecals
Definition r_stats.h:22
@ r_stat_animcache_skeletal_bones
Definition r_stats.h:62
@ r_stat_batch_vertices
Definition r_stats.h:73
@ r_stat_batch_dynamic_batches_because_deformvertexes_move
Definition r_stats.h:119
@ r_stat_rendertargets_used
Definition r_stats.h:45
@ r_stat_batch_entitystatic_surfaces
Definition r_stats.h:160
@ r_stat_batch_copytriangles_vertices
Definition r_stats.h:81
@ r_stat_bloom
Definition r_stats.h:42
@ r_stat_batch_dynamic_vertices_because_deformvertexes_wave
Definition r_stats.h:113
@ r_stat_rendertargets_pixels
Definition r_stats.h:46
@ r_stat_renders
Definition r_stats.h:11
@ r_stat_batch_dynamic_triangles_because_cvar
Definition r_stats.h:94
@ r_stat_batch_dynamic_vertices_because_tcgen_environment
Definition r_stats.h:133
@ r_stat_batch_dynamic_batches_because_cvar
Definition r_stats.h:91
@ r_stat_batch_dynamic_batches_because_deformvertexes_wave
Definition r_stats.h:111
@ r_stat_batch_dynamic_triangles_because_deformvertexes_wave
Definition r_stats.h:114
@ r_stat_batch_dynamic_batches_because_lightmapvertex
Definition r_stats.h:95
@ r_stat_batch_dynamic_surfaces_because_deformvertexes_normal
Definition r_stats.h:108
@ r_stat_batch_copytriangles_batches
Definition r_stats.h:79
@ r_stat_entities_triangles
Definition r_stats.h:14
@ r_stat_animcache_shape_maxvertices
Definition r_stats.h:69
@ r_stat_bufferdatasize_vertex
Definition r_stats.h:57
@ r_stat_batch_dynamic_surfaces_because_tcgen_vector
Definition r_stats.h:128
@ r_stat_bloom_drawpixels
Definition r_stats.h:44
@ r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite2
Definition r_stats.h:104
@ r_stat_batch_dynamic_vertices
Definition r_stats.h:85
@ r_stat_batch_dynamic_triangles_because_deformvertexes_bulge
Definition r_stats.h:118
@ r_stat_batch_dynamic_triangles
Definition r_stats.h:86
@ r_stat_batch_entitycache_vertices
Definition r_stats.h:149
@ r_stat_batch_dynamic_surfaces_because_nogaps
Definition r_stats.h:140
@ r_stat_batch_entitycustom_vertices
Definition r_stats.h:165
@ r_stat_batch_dynamic_vertices_because_tcgen_vector
Definition r_stats.h:129
@ r_stat_batch_entitycache_surfaces
Definition r_stats.h:148
@ r_stat_batch_triangles
Definition r_stats.h:74
@ r_stat_batch_entityanimate_surfaces
Definition r_stats.h:152
@ r_stat_batch_dynamic_surfaces_because_deformvertexes_autosprite
Definition r_stats.h:100
@ r_stat_batch_dynamicskeletal_triangles
Definition r_stats.h:90
@ r_stat_batch_dynamicskeletal_batches
Definition r_stats.h:87
@ r_stat_batch_entitycustom_count
Definition r_stats.h:163
@ r_stat_batch_dynamic_surfaces_because_tcgen_lightmap
Definition r_stats.h:124
@ r_stat_batch_surfaces
Definition r_stats.h:72
@ r_stat_batch_dynamicskeletal_vertices
Definition r_stats.h:89
@ r_stat_animcache_skeletal_maxbones
Definition r_stats.h:63
@ r_stat_batch_dynamic_batches_because_nogaps
Definition r_stats.h:139
@ r_stat_entities_surfaces
Definition r_stats.h:13
@ r_stat_batch_copytriangles_surfaces
Definition r_stats.h:80
@ r_stat_batch_fast_surfaces
Definition r_stats.h:76
@ r_stat_batch_dynamic_batches_because_tcgen_environment
Definition r_stats.h:131
@ r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite2
Definition r_stats.h:106
@ r_stat_batch_dynamic_surfaces_because_tcmod_turbulent
Definition r_stats.h:136
@ r_stat_animcache_skeletal_count
Definition r_stats.h:61
@ r_stat_batch_dynamic_batches_because_deformvertexes_normal
Definition r_stats.h:107
@ r_stat_batch_dynamic_surfaces_because_cvar
Definition r_stats.h:92
@ r_stat_batch_entitystatic_triangles
Definition r_stats.h:162
@ r_stat_batch_dynamic_batches_because_deformvertexes_autosprite2
Definition r_stats.h:103
@ r_stat_framedatasize
Definition r_stats.h:52
@ r_stat_batch_dynamic_vertices_because_deformvertexes_bulge
Definition r_stats.h:117
@ r_stat_batch_dynamic_triangles_because_tcgen_environment
Definition r_stats.h:134
@ r_stat_batch_fast_triangles
Definition r_stats.h:78
@ r_stat_animcache_shade_count
Definition r_stats.h:64
@ r_stat_batch_entitystatic_count
Definition r_stats.h:159
@ r_stat_batch_dynamic_batches_because_tcgen_vector
Definition r_stats.h:127
@ r_stat_batch_dynamic_triangles_because_lightmapvertex
Definition r_stats.h:98
@ r_stat_batch_dynamic_triangles_because_nogaps
Definition r_stats.h:142
@ r_stat_batch_dynamic_triangles_because_deformvertexes_autosprite
Definition r_stats.h:102
@ r_stat_batch_dynamic_surfaces_because_deformvertexes_bulge
Definition r_stats.h:116
@ r_stat_batch_entityskeletal_surfaces
Definition r_stats.h:156
@ r_stat_batch_copytriangles_triangles
Definition r_stats.h:82
@ r_stat_batch_fast_batches
Definition r_stats.h:75
@ r_stat_batch_dynamicskeletal_surfaces
Definition r_stats.h:88
@ r_stat_totaldecals
Definition r_stats.h:23
@ r_stat_batch_dynamic_vertices_because_lightmapvertex
Definition r_stats.h:97
@ r_stat_bloom_copypixels
Definition r_stats.h:43
@ r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite2
Definition r_stats.h:105
@ r_stat_batch_dynamic_batches_because_tcgen_lightmap
Definition r_stats.h:123
@ r_stat_batch_dynamic_surfaces_because_lightmapvertex
Definition r_stats.h:96
@ r_stat_batch_entitystatic_vertices
Definition r_stats.h:161
@ r_stat_batch_dynamic_vertices_because_deformvertexes_autosprite
Definition r_stats.h:101
@ r_stat_batch_withgaps
Definition r_stats.h:71
@ r_stat_batch_entityanimate_vertices
Definition r_stats.h:153
@ r_stat_animcache_shape_vertices
Definition r_stats.h:68
@ r_stat_batch_dynamic_vertices_because_tcmod_turbulent
Definition r_stats.h:137
@ r_stat_entities
Definition r_stats.h:12
@ r_stat_batch_entitycache_count
Definition r_stats.h:147
@ r_stat_animcache_shade_vertices
Definition r_stats.h:65
@ r_stat_batch_entityskeletal_triangles
Definition r_stats.h:158
@ r_stat_batch_dynamic_triangles_because_tcgen_vector
Definition r_stats.h:130
@ r_stat_animcache_shade_maxvertices
Definition r_stats.h:66
@ r_stat_batch_dynamic_triangles_because_tcmod_turbulent
Definition r_stats.h:138
@ r_stat_batch_batches
Definition r_stats.h:70
@ r_stat_bufferdatacurrent_vertex
Definition r_stats.h:53
@ r_stat_batch_entityskeletal_count
Definition r_stats.h:155
@ r_stat_batch_entityanimate_triangles
Definition r_stats.h:154
@ r_stat_batch_dynamic_surfaces
Definition r_stats.h:84
@ r_stat_batch_dynamic_triangles_because_deformvertexes_move
Definition r_stats.h:122
@ r_stat_batch_dynamic_triangles_because_tcgen_lightmap
Definition r_stats.h:126
#define TEXF_PICMIP
Definition r_textures.h:21
#define TEXF_IMPORTANTBITS
Definition r_textures.h:39
#define TEXF_ALPHA
Definition r_textures.h:9
#define TEXF_FORCELINEAR
Definition r_textures.h:19
#define TEXF_MIPMAP
Definition r_textures.h:11
#define TEXF_FORCENEAREST
Definition r_textures.h:17
#define TEXF_COMPRESS
Definition r_textures.h:23
textype_t
Definition r_textures.h:44
@ TEXTYPE_PALETTE
Definition r_textures.h:49
@ TEXTYPE_SRGB_BGRA
Definition r_textures.h:73
@ TEXTYPE_COLORBUFFER
Definition r_textures.h:84
@ TEXTYPE_SRGB_PALETTE
Definition r_textures.h:69
@ TEXTYPE_COLORBUFFER32F
Definition r_textures.h:88
@ TEXTYPE_UNUSED
Definition r_textures.h:46
@ TEXTYPE_BGRA
Definition r_textures.h:53
@ TEXTYPE_DEPTHBUFFER24STENCIL8
Definition r_textures.h:94
@ TEXTYPE_COLORBUFFER16F
Definition r_textures.h:86
#define TEXF_CLAMP
Definition r_textures.h:15
#define TEXF_FORCE_RELOAD
Definition r_textures.h:41
#define TEXF_PERSISTENT
Definition r_textures.h:25
#define TEXF_RENDERTARGET
Definition r_textures.h:37
r_bufferdata_type_t
enum of the various types of hardware buffer object used in rendering note that the r_buffermegs[] ar...
Definition render.h:524
@ R_BUFFERDATA_VERTEX
Definition render.h:525
@ R_BUFFERDATA_COUNT
uniform buffer
Definition render.h:529
@ R_BUFFERDATA_UNIFORM
index buffer - 32bit (because D3D cares)
Definition render.h:528
@ R_BUFFERDATA_INDEX32
index buffer - 16bit (because D3D cares)
Definition render.h:527
@ R_BUFFERDATA_INDEX16
vertex buffer
Definition render.h:526
#define SHADERPERMUTATION_FOGALPHAHACK
fog color and density determined by texture mapped on vertical axis
Definition render.h:81
#define SHADERPERMUTATION_SKELETAL
(skeletal models) use skeletal matrices to deform vertices (gpu-skinning)
Definition render.h:103
#define SHADERPERMUTATION_SPECULAR
(lightsource or deluxemapping) render specular effects
Definition render.h:86
#define SHADERPERMUTATION_POSTPROCESSING
user defined postprocessing (postprocessing only)
Definition render.h:87
#define SHADERPERMUTATION_COUNT
size of shaderpermutationinfo array
Definition render.h:105
#define SHADERPERMUTATION_BLOOM
bloom (postprocessing only)
Definition render.h:85
@ SHADERMODE_DEFERREDGEOMETRY
(deferred) render material properties to screenspace geometry buffers
Definition render.h:67
@ SHADERMODE_FLATCOLOR
(lightmap) modulate texture by uniform color (q1bsp, q3bsp)
Definition render.h:55
@ SHADERMODE_LIGHTDIRECTION
(lightmap) use directional pixel shading from fixed light direction (q3bsp)
Definition render.h:63
@ SHADERMODE_VERTEXCOLOR
(lightmap) modulate texture by vertex colors (q3bsp)
Definition render.h:56
@ SHADERMODE_LIGHTDIRECTIONMAP_MODELSPACE
(lightmap) use directional pixel shading from texture containing modelspace light directions (q3bsp d...
Definition render.h:58
@ SHADERMODE_COUNT
Definition render.h:69
@ SHADERMODE_LIGHTMAP
(lightmap) modulate texture by lightmap texture (q1bsp, q3bsp)
Definition render.h:57
@ SHADERMODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP
Definition render.h:60
@ SHADERMODE_GENERIC
(particles/HUD/etc) vertex color, optionally multiplied by one texture
Definition render.h:52
@ SHADERMODE_POSTPROCESS
postprocessing shader (r_glsl_postprocess)
Definition render.h:53
@ SHADERMODE_LIGHTDIRECTIONMAP_TANGENTSPACE
(lightmap) use directional pixel shading from texture containing tangentspace light directions (q1bsp...
Definition render.h:59
@ SHADERMODE_DEFERREDLIGHTSOURCE
(deferred) use directional pixel shading from light source (rtlight) on screenspace geometry buffers
Definition render.h:68
@ SHADERMODE_WATER
refract background and reflection (the material is rendered normally after this pass)
Definition render.h:66
@ SHADERMODE_DEPTH_OR_SHADOW
(depthfirst/shadows) vertex shader only
Definition render.h:54
@ SHADERMODE_LIGHTSOURCE
(lightsource) use directional pixel shading from light source (rtlight)
Definition render.h:64
@ SHADERMODE_LIGHTGRID
(lightmap) use directional pixel shading from lightgrid data (q3bsp)
Definition render.h:62
@ SHADERMODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR
Definition render.h:61
@ SHADERMODE_REFRACTION
refract background (the material is rendered normally after this pass)
Definition render.h:65
#define SHADERPERMUTATION_ALPHAKILL
(deferredgeometry) discard pixel if diffuse texture alpha below 0.5, (generic) apply global alpha
Definition render.h:95
#define SHADERPERMUTATION_ALPHAGEN_VERTEX
alphaGen vertex
Definition render.h:102
#define FOGMASKTABLEWIDTH
Definition render.h:428
#define SHADERPERMUTATION_DEPTHRGB
read/write depth values in RGB color coded format for older hardware without depth samplers
Definition render.h:101
#define SHADERPERMUTATION_GLOW
(lightmap) blend in an additive glow texture
Definition render.h:84
#define SHADERPERMUTATION_FOGHEIGHTTEXTURE
fog color and density determined by texture mapped on vertical axis
Definition render.h:80
#define SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL
(lightmap) use 16-component pixels in bouncegrid texture for directional lighting rather than standar...
Definition render.h:99
#define SHADERPERMUTATION_FOGOUTSIDE
tint the color by fog color or black if using additive blend mode
Definition render.h:79
#define BATCHNEED_ALLOWMULTIDRAW
Definition render.h:795
#define SHADERPERMUTATION_SHADOWMAPVSDCT
(lightsource) use virtual shadow depth cube texture for shadowmap indexing
Definition render.h:92
void Sbar_Init(void)
Definition sbar.c:359
#define BATCHNEED_NOGAPS
Definition render.h:793
#define SHADERPERMUTATION_VIEWTINT
view tint (postprocessing only), use vertex colors (generic only)
Definition render.h:75
#define BATCHNEED_ARRAY_VERTEXCOLOR
Definition render.h:789
#define BATCHNEED_ARRAY_NORMAL
Definition render.h:786
#define BATCHNEED_ALWAYSCOPY
Definition render.h:794
#define SHADERPERMUTATION_OCCLUDE
use occlusion buffer for corona
Definition render.h:104
#define BATCHNEED_ARRAY_SKELETAL
Definition render.h:792
#define BATCHNEED_ARRAY_LIGHTMAP
Definition render.h:791
#define SHADERPERMUTATION_OFFSETMAPPING
adjust texcoords to roughly simulate a displacement mapped surface
Definition render.h:89
@ SHADERLANGUAGE_COUNT
Definition render.h:45
@ SHADERLANGUAGE_GLSL
Definition render.h:44
#define SHADERPERMUTATION_SHADOWMAP2D
(lightsource) use shadowmap texture as light filter
Definition render.h:91
#define SHADERPERMUTATION_BOUNCEGRID
(lightmap) use Texture_BounceGrid as an additional source of ambient light
Definition render.h:98
#define SHADERPERMUTATION_VERTEXTEXTUREBLEND
indicates this is a two-layer material blend based on vertex alpha (q3bsp)
Definition render.h:74
#define BATCHNEED_ARRAY_VECTOR
Definition render.h:787
#define SHADERPERMUTATION_FOGINSIDE
tint the color by fog color or black if using additive blend mode
Definition render.h:78
#define SHADERPERMUTATION_NORMALMAPSCROLLBLEND
(water) counter-direction normalmaps scrolling
Definition render.h:97
#define SHADERPERMUTATION_SHADOWMAPORTHO
(lightsource) use orthographic shadowmap projection
Definition render.h:93
#define BATCHNEED_ARRAY_VERTEX
Definition render.h:785
#define SHADERPERMUTATION_CUBEFILTER
(lightsource) use cubemap light filter
Definition render.h:83
#define SHADERPERMUTATION_REFLECTION
normalmap-perturbed reflection of the scene infront of the surface, preformed as an overlay on the su...
Definition render.h:88
r_refdef_scene_type_t
Definition render.h:222
@ RST_CLIENT
Definition render.h:223
@ RST_COUNT
Definition render.h:225
rsurfacepass_t
Definition render.h:803
@ RSURFPASS_BACKGROUND
Definition render.h:805
@ RSURFPASS_BASE
Definition render.h:804
@ RSURFPASS_DEFERREDGEOMETRY
Definition render.h:807
@ RSURFPASS_RTLIGHT
Definition render.h:806
#define SHADERPERMUTATION_REFLECTCUBE
fake reflections using global cubemap (not HDRI light probe)
Definition render.h:96
#define SHADERPERMUTATION_SATURATION
saturation (postprocessing only)
Definition render.h:77
#define SHADERPERMUTATION_DEFERREDLIGHTMAP
(lightmap) read Texture_ScreenDiffuse/Specular textures and add them on top of lightmapping
Definition render.h:94
#define SHADERPERMUTATION_COLORMAPPING
indicates this is a colormapped skin
Definition render.h:76
#define SHADERPERMUTATION_GAMMARAMPS
gamma (postprocessing only)
Definition render.h:82
#define SHADERPERMUTATION_TRIPPY
use trippy vertex shader effect
Definition render.h:100
#define BATCHNEED_ARRAY_TEXCOORD
Definition render.h:790
#define SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING
adjust texcoords to accurately simulate a displacement mapped surface (requires OFFSETMAPPING to also...
Definition render.h:90
#define SHADERPERMUTATION_DIFFUSE
(lightsource) whether to use directional shading
Definition render.h:73
server_t sv
local server
Definition sv_main.c:223
#define SOLID_BBOX
touch on edge, block
Definition server.h:334
#define SOLID_SLIDEBOX
touch on edge, but not an onground
Definition server.h:335
#define SOLID_CORPSE
same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters)
Definition server.h:338
#define SOLID_NOT
no interaction with other objects
Definition server.h:332
#define SOLID_TRIGGER
touch on edge, but not blocking
Definition server.h:333
#define SOLID_BSP
bsp clip, touch on edge, block
Definition server.h:336
dp_FragColor r
uniform highp float FogHeightFade
vec2 dir
dp_FragColor g
precision highp float
Definition shader_glsl.h:53
float f
vec3 y2
vec3 x2
vec3 normal
float fogfrac
dp_FragColor b
vec3 x1
vec4 sw
vec3 float FogPlaneVertexDist
void vec2 tc
ret a
uniform highp float FogPlaneViewDist
float intensity
Definition snd_mix.c:314
#define SPR_LABEL
Definition spritegn.h:101
#define SPR_LABEL_SCALE
Definition spritegn.h:102
float maxs[3]
Definition bih.h:61
bih_leaftype_t type
Definition bih.h:59
int itemindex
Definition bih.h:65
float mins[3]
Definition bih.h:60
Definition bih.h:70
bih_leaf_t * leafs
Definition bih.h:74
vec3_t mins
Definition client.h:725
struct cl_locnode_s * next
Definition client.h:723
vec3_t maxs
Definition client.h:725
vec3_t movement_origin
Definition client.h:809
double oldtime
Definition client.h:868
vec3_t movement_velocity
Definition client.h:810
cl_locnode_t * locnodes
Definition client.h:1125
unsigned int decalsequence
Definition client.h:978
scoreboard_t * scores
Definition client.h:945
cshift_t cshifts[NUM_CSHIFTS]
Definition client.h:775
vec3_t viewangles
Definition client.h:786
struct model_s * worldmodel
Definition client.h:934
double realframetime
Definition client.h:871
double time
Definition client.h:868
float motionbluralpha
Definition client.h:882
csqc_vidvars_t csqc_vidvars
Definition client.h:834
char worldnamenoextension[MAX_QPATH]
Definition client.h:900
qbool demoplayback
Definition client.h:587
cactive_t state
Definition client.h:568
mempool_t * levelmempool
Definition client.h:571
protocolversion_t protocol
Definition client.h:617
command interpreter state - the tokenizing and execution of commands, as well as pointers to which cv...
Definition cmd.h:127
float percent
Definition client.h:507
qbool drawworld
Definition client.h:706
rtexture_t * texture
Definition gl_rmain.c:290
Definition cvar.h:66
float value
Definition cvar.h:74
int integer
Definition cvar.h:73
const char * string
Definition cvar.h:71
model_t * model
Definition client.h:57
int maxdecals
Definition client.h:59
int * element3i
Definition client.h:65
tridecal_t * decals
Definition client.h:61
double lastupdatetime
Definition client.h:58
int numdecals
Definition client.h:60
unsigned short * element3s
Definition client.h:66
float * color4f
Definition client.h:64
float * texcoord2f
Definition client.h:63
float * vertex3f
Definition client.h:62
frameblend_t frameblend[MAX_FRAMEBLENDS]
Definition client.h:373
float render_fullbright[3]
Definition client.h:412
vec_t userwavefunc_param[Q3WAVEFUNC_USER_COUNT]
Definition client.h:445
float * animcache_skeletaltransform3x4
Definition client.h:395
float render_rtlight_diffuse[3]
Definition client.h:426
matrix4x4_t inversematrix
Definition client.h:334
float render_glowmod[3]
Definition client.h:414
r_meshbuffer_t * animcache_vertex3f_vertexbuffer
Definition client.h:380
matrix4x4_t matrix
Definition client.h:332
float render_modellight_specular[3]
Definition client.h:420
float * animcache_normal3f
Definition client.h:382
float colormod[3]
Definition client.h:359
vec3_t mins
Definition client.h:371
int animcache_skeletaltransform3x4size
Definition client.h:398
qbool render_rtlight_disabled
Definition client.h:431
int animcache_vertex3f_bufferoffset
Definition client.h:381
r_meshbuffer_t * animcache_svector3f_vertexbuffer
Definition client.h:386
float render_modellight_lightdir_world[3]
Definition client.h:418
model_t * model
Definition client.h:343
float render_lightmap_ambient[3]
Definition client.h:422
decalsystem_t decalsystem
Definition client.h:438
float render_modellight_lightdir_local[3]
Definition client.h:419
vec3_t colormap_shirtcolor
Definition client.h:348
r_meshbuffer_t * animcache_tvector3f_vertexbuffer
Definition client.h:389
qbool render_modellight_forced
Definition client.h:429
float transparent_offset
Definition client.h:340
framegroupblend_t framegroupblend[MAX_FRAMEGROUPBLENDS]
Definition client.h:363
double last_trace_visibility
Definition client.h:442
double shadertime
Definition client.h:366
float * animcache_vertex3f
Definition client.h:379
float render_lightmap_diffuse[3]
Definition client.h:423
int animcache_svector3f_bufferoffset
Definition client.h:387
float render_modellight_ambient[3]
Definition client.h:416
float render_rtlight_specular[3]
Definition client.h:427
float render_lightmap_specular[3]
Definition client.h:424
r_meshbuffer_t * animcache_skeletaltransform3x4buffer
Definition client.h:396
r_meshbuffer_t * animcache_normal3f_vertexbuffer
Definition client.h:383
qbool render_lightgrid
Definition client.h:433
float render_modellight_diffuse[3]
Definition client.h:417
float glowmod[3]
Definition client.h:360
float * animcache_svector3f
Definition client.h:385
int animcache_tvector3f_bufferoffset
Definition client.h:390
float * animcache_tvector3f
Definition client.h:388
vec3_t colormap_pantscolor
Definition client.h:347
int animcache_skeletaltransform3x4offset
Definition client.h:397
vec3_t maxs
Definition client.h:371
skeleton_t * skeleton
Definition client.h:375
int animcache_normal3f_bufferoffset
Definition client.h:384
entity_render_t render
Definition client.h:477
float lerp
Definition client.h:313
double realtime
the accumulated mainloop time since application started (with filtering), without any slowmo or clamp...
Definition host.h:46
int clusterindex
int(* BoxTouchingVisibleLeafs)(struct model_s *model, const unsigned char *visibleleafs, const vec3_t mins, const vec3_t maxs)
size_t(* FatPVS)(struct model_s *model, const vec3_t org, vec_t radius, unsigned char **pvsbuffer, mempool_t *pool, qbool merge)
mleaf_t *(* PointInLeaf)(struct model_s *model, const vec3_t p)
int num_pvsclusterbytes
matrix4x4_t lightgridworldtotexturematrix
qbool deluxemapping_modelspace
rtexture_t * lightgridtexture
model_brush_t brush
void(* DrawDepth)(struct entity_render_s *ent)
model_sprite_t sprite
modtype_t type
surfmesh_t surfmesh
void(* Draw)(struct entity_render_s *ent)
float radius
model_brushq3_t brushq3
void(* DrawSky)(struct entity_render_s *ent)
void(* DrawAddWaterPlanes)(struct entity_render_s *ent)
float lightmapscale
void(* DrawDebug)(struct entity_render_s *ent)
char name[MAX_QPATH]
int num_surfaces
vec3_t normal
Definition model_brush.h:59
vec_t dist
Definition model_brush.h:60
int signbits
Definition model_brush.h:66
unsigned char styles[MAXLIGHTMAPS]
unsigned char * samples
describes the textures to use on a range of triangles in the model, and mins/maxs (AABB) for culling.
msurface_lightmapinfo_t * lightmapinfo
lightmaptexture rebuild information not used in q3bsp
int num_firsttriangle
int num_triangles
range of triangles and vertices in model->surfmesh
texture_t * texture
the texture to use on the surface
int num_firstvertex
vec3_t mins
bounding box for onscreen checks
struct rtexture_s * deluxemaptexture
the lighting direction texture fragment to use on the rendering mesh
struct rtexture_s * lightmaptexture
the lightmap texture fragment to use on the rendering mesh
qbool free
true if this edict is unused
Definition progsvm.h:93
union prvm_edict_t::@29 priv
struct edict_engineprivate_s * server
FIXME: this server pointer really means world, not server (it is used by both server qc and client qc...
Definition progsvm.h:106
int num_edicts
copies of some vars that were former read from sv
Definition progsvm.h:671
struct colbrushf_s * colbrushf
q3wavefunc_t wavefunc
Definition r_qshader.h:178
float parms[Q3DEFORM_MAXPARMS]
Definition r_qshader.h:177
float waveparms[Q3WAVEPARMS]
Definition r_qshader.h:179
float parms[Q3TCGEN_MAXPARMS]
Definition r_qshader.h:145
float parms[Q3TCMOD_MAXPARMS]
Definition r_qshader.h:152
float waveparms[Q3WAVEPARMS]
Definition r_qshader.h:154
struct r_bufferdata_buffer_s * purge
Definition gl_rmain.c:3602
r_meshbuffer_t * buffer
Definition gl_rmain.c:3605
qbool ghosttexture_valid
Definition render.h:900
memexpandablearray_t rendertargets
Definition render.h:904
r_rendertarget_t * rt_bloom
Definition render.h:888
float offsettexcoord2f[8]
Definition render.h:896
rtexture_t * ghosttexture
Definition render.h:890
r_waterstate_t water
Definition render.h:898
r_rendertarget_t * rt_screen
Definition render.h:887
textype_t textype
Definition render.h:883
float ghosttexcoord2f[8]
Definition render.h:891
unsigned char * data
Definition gl_rmain.c:3487
struct r_framedata_mem_s * purge
Definition gl_rmain.c:3482
int loc_Texture_FogHeightTexture
Definition gl_rmain.c:743
int tex_Texture_SecondaryNormal
Definition gl_rmain.c:706
int loc_Texture_First
locations of detected uniforms in program object, or -1 if not found
Definition gl_rmain.c:730
int tex_Texture_FogHeightTexture
Definition gl_rmain.c:712
int loc_ScreenCenterRefractReflect
Definition gl_rmain.c:795
int loc_Texture_SecondaryNormal
Definition gl_rmain.c:737
int loc_Texture_ScreenNormalMap
Definition gl_rmain.c:754
int program
0 if compilation failed
Definition gl_rmain.c:697
struct r_glsl_permutation_s * hashnext
hash lookup data
Definition gl_rmain.c:690
int ubibind_Skeletal_Transform12_UniformBlock
uniform block bindings
Definition gl_rmain.c:822
qbool compiled
indicates if we have tried compiling this permutation already
Definition gl_rmain.c:695
int ubiloc_Skeletal_Transform12_UniformBlock
uniform block indices
Definition gl_rmain.c:824
int loc_ScreenScaleRefractReflect
Definition gl_rmain.c:796
unsigned int mode
Definition gl_rmain.c:691
int loc_OffsetMapping_ScaleSteps
Definition gl_rmain.c:786
int loc_DistortScaleRefractReflect
Definition gl_rmain.c:774
int loc_OffsetMapping_LodDistance
Definition gl_rmain.c:787
int tex_Texture_ScreenNormalMap
Definition gl_rmain.c:723
int loc_ModelViewProjectionMatrix
Definition gl_rmain.c:812
skinframe_t * skinframe
Definition gl_rmain.c:304
char name[MAX_QPATH]
Definition gl_rmain.c:303
float ambientintensity
Definition render.h:384
float lightmapintensity
Definition render.h:387
float rtlightstylevalue[MAX_LIGHTSTYLES]
float fraction of base light value
Definition render.h:377
entity_render_t ** entities
renderable entities (excluding world)
Definition render.h:361
model_t * worldmodel
same as worldentity->model
Definition render.h:358
qbool rtworldshadows
Definition render.h:390
qbool rtdlightshadows
Definition render.h:392
unsigned short lightstylevalue[MAX_LIGHTSTYLES]
8.8 fraction of base light value
Definition render.h:380
entity_render_t * worldentity
the world
Definition render.h:355
double time
(client gameworld) time for rendering time based effects
Definition render.h:352
float viewblend[4]
Definition render.h:416
float fogplaneviewdist
Definition render.h:421
float fogmasktable[FOGMASKTABLEWIDTH]
Definition render.h:429
float fog_height_texcoordscale
Definition render.h:449
qbool oldgl_fogenable
Definition render.h:441
r_refdef_viewcache_t viewcache
Definition render.h:407
char fog_height_texturename[64]
Definition render.h:444
qbool fogenabled
Definition render.h:440
float fog_start
Definition render.h:436
float fog_height_tablescale
Definition render.h:448
float fogheightfade
Definition render.h:423
float polygonoffset
Definition render.h:459
double lastdrawscreentime
Definition render.h:462
float fogmasktable_start
Definition render.h:430
r_refdef_view_t view
Definition render.h:406
float fogmasktabledistmultiplier
Definition render.h:427
float fogcolor[3]
Definition render.h:424
unsigned char * fog_height_table1d
Definition render.h:445
float fog_density
Definition render.h:431
qbool fogplaneviewabove
Definition render.h:422
unsigned char * fog_height_table2d
Definition render.h:446
double farclip
Definition render.h:413
float fog_height
Definition render.h:438
float fogrange
Definition render.h:425
int stats[r_stat_count]
Definition render.h:466
float fog_green
Definition render.h:433
char fogheighttexturename[64]
Definition render.h:450
float fog_alpha
Definition render.h:435
float fog_fadedepth
Definition render.h:439
r_refdef_scene_t scene
Definition render.h:418
double nearclip
Definition render.h:410
qbool envmap
Definition render.h:455
float polygonfactor
Definition render.h:458
float fograngerecip
Definition render.h:426
float fogmasktable_density
Definition render.h:430
float fog_end
Definition render.h:437
float fogplane[4]
Definition render.h:420
int fog_height_tablesize
Definition render.h:447
float fog_blue
Definition render.h:434
float fogmasktable_alpha
Definition render.h:430
float fogmasktable_range
Definition render.h:430
float fog_red
Definition render.h:432
float frustum_y
Definition render.h:277
vec3_t left
Definition render.h:269
qbool useclipplane
Definition render.h:274
qbool clear
whether to call R_ClearScreen before rendering stuff
Definition render.h:305
qbool usecustompvs
uses r_refdef.viewcache.pvsbits as-is rather than computing it
Definition render.h:275
float colorscale
global RGB color multiplier for rendering
Definition render.h:302
qbool showdebug
Definition render.h:314
vec3_t right
Definition render.h:270
int numfrustumplanes
Definition render.h:272
float quality
render quality (0 to 1) - affects r_drawparticles_drawdistance and others
Definition render.h:321
int cullface_back
Definition render.h:318
float frustum_x
Definition render.h:277
vec3_t origin
Definition render.h:267
int useperspective
if turned off it renders an ortho view
Definition render.h:280
mplane_t frustum[6]
Definition render.h:273
qbool isoverlay
if true, don't clear or do any post process effects (bloom, etc)
Definition render.h:307
float ortho_x
Definition render.h:287
r_viewport_t viewport
note: if r_viewscale is used, the viewport.width and viewport.height may be less than width and heigh...
Definition render.h:296
qbool ismain
if true, this is the MAIN view (which is, after CSQC, copied into the scene for use e....
Definition render.h:309
int colormask[4]
which color components to allow (for anaglyph glasses)
Definition render.h:299
matrix4x4_t matrix
Definition render.h:266
int cullface_front
Definition render.h:317
vec3_t frustumcorner[4]
Definition render.h:278
float ortho_y
Definition render.h:287
matrix4x4_t inverse_matrix
Definition render.h:266
vec3_t forward
Definition render.h:268
mplane_t clipplane
Definition render.h:276
int usevieworiginculling
allows visibility culling based on the view origin (e.g.
Definition render.h:286
unsigned char * world_leafvisible
Definition render.h:341
unsigned char * world_pvsbits
Definition render.h:340
qbool world_novis
if true, the view is currently in a leaf without pvs data
Definition render.h:344
unsigned char * world_surfacevisible
Definition render.h:342
unsigned char * entityvisible
which entities are currently visible for this viewpoint (the used range is 0...r_refdef....
Definition render.h:336
rtexture_t * depthtexture
Definition render.h:835
float texcoord2f[8]
Definition render.h:819
textype_t colortextype[4]
Definition render.h:824
rtexture_t * colortexture[4]
Definition render.h:834
struct rtexture_s * texture
Definition r_shadow.h:100
unsigned int loadsequence
Definition gl_rmain.c:2161
skinframe_t * hash[SKINFRAME_HASH]
Definition gl_rmain.c:2163
memexpandablearray_t array
Definition gl_rmain.c:2162
float screentodepth[2]
used by deferred renderer to calculate linear depth from device depth coordinates
Definition render.h:250
matrix4x4_t viewmatrix
actual matrix for rendering (transforms to viewspace)
Definition render.h:241
qbool renderingscene
Definition render.h:876
int maxwaterplanes
Definition render.h:867
float screencenter[2]
Definition render.h:872
int texturewidth
Definition render.h:864
float screenscale[2]
Definition render.h:871
int numwaterplanes
Definition render.h:868
int textureheight
Definition render.h:864
int cameraheight
Definition render.h:865
r_waterstate_waterplane_t waterplanes[MAX_WATERPLANES]
Definition render.h:869
qbool hideplayer
Definition render.h:877
int camerawidth
Definition render.h:865
int waterheight
Definition render.h:863
qbool enabled
Definition render.h:874
unsigned char * pvsbits
Definition render.h:854
r_rendertarget_t * rt_refraction
Definition render.h:849
r_rendertarget_t * rt_camera
Definition render.h:851
r_rendertarget_t * rt_reflection
Definition render.h:850
int numtriangles
Definition render.h:169
float epsilon2
Definition render.h:172
int * element3i
Definition render.h:170
float * vertex3f
Definition render.h:160
int maxvertices
Definition render.h:158
int maxtriangles
Definition render.h:168
int numvertices
Definition render.h:159
int batchskeletalindex4ub_bufferoffset
Definition render.h:696
int batchvertex3f_bufferoffset
Definition render.h:675
int modelskeletalweight4ub_bufferoffset
Definition render.h:648
qbool uselightmaptexture
Definition render.h:738
vec3_t localvieworigin
Definition render.h:728
int * modelelement3i
Definition render.h:649
float * modellightmapcolor4f
Definition render.h:634
int * batchelement3i
Definition render.h:700
unsigned short * batchelement3s
Definition render.h:703
const msurface_t * modelsurfaces
Definition render.h:658
float * entityskeletaltransform3x4
Definition render.h:618
unsigned char * modelskeletalindex4ub
Definition render.h:643
const rtlight_t * rtlight
Definition render.h:748
const msurface_t ** batchmultidrawsurfacelist
Definition render.h:668
int modeltvector3f_bufferoffset
Definition render.h:630
int batchskeletalweight4ub_bufferoffset
Definition render.h:699
int batchelement3s_bufferoffset
Definition render.h:705
float * batchtexcoordlightmap2f
Definition render.h:691
float * batchtexcoordtexture2f
Definition render.h:688
int batchnumtriangles
Definition render.h:672
int batchelement3i_bufferoffset
Definition render.h:702
float inversematrixscale
Definition render.h:723
int modelelement3i_bufferoffset
Definition render.h:651
const r_meshbuffer_t * batchtexcoordlightmap2f_vertexbuffer
Definition render.h:692
float * batchsvector3f
Definition render.h:676
int modelsvector3f_bufferoffset
Definition render.h:627
unsigned short * modelelement3s
Definition render.h:652
matrix4x4_t entitytolight
Definition render.h:754
float fogplaneviewdist
Definition render.h:744
rtexture_t * lightmaptexture
Definition render.h:734
int batchtexcoordlightmap2f_bufferoffset
Definition render.h:693
int modeltexcoordlightmap2f_bufferoffset
Definition render.h:642
int * modellightmapoffsets
Definition render.h:655
const r_meshbuffer_t * modellightmapcolor4f_vertexbuffer
Definition render.h:635
int modelelement3s_bufferoffset
Definition render.h:654
int batchnormal3f_bufferoffset
Definition render.h:684
unsigned char * batchskeletalindex4ub
Definition render.h:694
const r_meshbuffer_t * batchlightmapcolor4f_vertexbuffer
Definition render.h:686
float * modeltvector3f
Definition render.h:628
float basepolygonfactor
Definition render.h:730
float fogheightfade
Definition render.h:743
int batchnumvertices
Definition render.h:670
const r_meshbuffer_t * modeltexcoordlightmap2f_vertexbuffer
Definition render.h:641
const r_meshbuffer_t * batchsvector3f_vertexbuffer
Definition render.h:677
qbool modelgeneratedvertex
Definition render.h:611
float fogmasktabledistmultiplier
Definition render.h:741
float * modeltexcoordtexture2f
Definition render.h:637
int modellightmapcolor4f_bufferoffset
Definition render.h:636
const r_meshbuffer_t * batchtvector3f_vertexbuffer
Definition render.h:680
rtexture_t * deluxemaptexture
Definition render.h:735
int batchlightmapcolor4f_bufferoffset
Definition render.h:687
const r_meshbuffer_t * entityskeletaltransform3x4buffer
Definition render.h:619
float fograngerecip
Definition render.h:740
unsigned char * modelskeletalweight4ub
Definition render.h:646
const r_meshbuffer_t * modelvertex3f_vertexbuffer
Definition render.h:623
const r_meshbuffer_t * batchvertex3f_vertexbuffer
Definition render.h:674
matrix4x4_t matrix
Definition render.h:719
int modelnumtriangles
Definition render.h:657
texture_t * texture
Definition render.h:733
const r_meshbuffer_t * modelnormal3f_vertexbuffer
Definition render.h:632
float * modelsvector3f
Definition render.h:625
int modelnormal3f_bufferoffset
Definition render.h:633
int entityskeletaltransform3x4size
Definition render.h:621
entity_render_t * entity
Definition render.h:767
const r_meshbuffer_t * modelelement3s_indexbuffer
Definition render.h:653
float * modelvertex3f
Definition render.h:622
int batchtvector3f_bufferoffset
Definition render.h:681
int batchfirsttriangle
Definition render.h:671
int entityskeletaltransform3x4offset
Definition render.h:620
const r_meshbuffer_t * modeltvector3f_vertexbuffer
Definition render.h:629
const r_meshbuffer_t * batchtexcoordtexture2f_vertexbuffer
Definition render.h:689
float * batchtvector3f
Definition render.h:679
vec3_t entitylightorigin
Definition render.h:751
int modelskeletalindex4ub_bufferoffset
Definition render.h:645
const r_meshbuffer_t * batchskeletalweight4ub_vertexbuffer
Definition render.h:698
int ent_alttextures
Definition render.h:716
int modelnumvertices
Definition render.h:656
int entityskeletalnumtransforms
Definition render.h:617
const r_meshbuffer_t * batchskeletaltransform3x4buffer
Definition render.h:708
int batchskeletalnumtransforms
Definition render.h:706
int batchfirstvertex
Definition render.h:669
const r_meshbuffer_t * batchelement3i_indexbuffer
Definition render.h:701
float * modeltexcoordlightmap2f
Definition render.h:640
float matrixscale
Definition render.h:722
int modelvertex3f_bufferoffset
Definition render.h:624
int batchskeletaltransform3x4size
Definition render.h:710
frameblend_t frameblend[MAX_FRAMEBLENDS]
Definition render.h:725
float basepolygonoffset
Definition render.h:731
float * modelnormal3f
Definition render.h:631
const r_meshbuffer_t * batchnormal3f_vertexbuffer
Definition render.h:683
int modeltexcoordtexture2f_bufferoffset
Definition render.h:639
const r_meshbuffer_t * modelskeletalindex4ub_vertexbuffer
Definition render.h:644
float userwavefunc_param[Q3WAVEFUNC_USER_COUNT]
Definition render.h:762
int batchskeletaltransform3x4offset
Definition render.h:709
int batchmultidrawnumsurfaces
Definition render.h:667
double shadertime
Definition render.h:717
float * batchvertex3f
Definition render.h:673
unsigned char * batchskeletalweight4ub
Definition render.h:697
float * batchnormal3f
Definition render.h:682
const r_meshbuffer_t * modelelement3i_indexbuffer
Definition render.h:650
const r_meshbuffer_t * modelsvector3f_vertexbuffer
Definition render.h:626
qbool forcecurrenttextureupdate
Definition render.h:610
const r_meshbuffer_t * modelskeletalweight4ub_vertexbuffer
Definition render.h:647
float * batchskeletaltransform3x4
Definition render.h:707
int batchsvector3f_bufferoffset
Definition render.h:678
skeleton_t * skeleton
Definition render.h:726
int batchtexcoordtexture2f_bufferoffset
Definition render.h:690
float fogplane[4]
Definition render.h:742
matrix4x4_t inversematrix
Definition render.h:720
const r_meshbuffer_t * batchelement3s_indexbuffer
Definition render.h:704
const r_meshbuffer_t * batchskeletalindex4ub_vertexbuffer
Definition render.h:695
qbool batchgeneratedvertex
Definition render.h:665
float * batchlightmapcolor4f
Definition render.h:685
qbool batchmultidraw
Definition render.h:666
const r_meshbuffer_t * modeltexcoordtexture2f_vertexbuffer
Definition render.h:638
vec_t ambientscale
ambient intensity to render
Definition client.h:128
rtexture_t * currentcubemap
this is R_GetCubemap(rtlight->cubemapname)
Definition client.h:153
vec3_t currentcolor
Definition client.h:147
vec_t specularscale
specular intensity to render
Definition client.h:132
vec3_t shadoworigin
used only for casting shadows
Definition client.h:138
matrix4x4_t matrix_lighttoworld
matrix for transforming light filter coordinates to world coordinates
Definition client.h:110
vec_t diffusescale
diffuse intensity to render
Definition client.h:130
char qw_skin[MAX_QPATH]
Definition client.h:501
qbool active
false if only a net client
Definition server.h:66
char * builtinstring
Definition gl_rmain.c:619
const char * name
Definition gl_rmain.c:617
const char ** builtinshaderstrings
Definition gl_rmain.c:615
const char * extension
Definition gl_rmain.c:614
const char * sourcebasename
Definition gl_rmain.c:613
const char * pretext
Definition gl_rmain.c:616
const char * pretext
Definition gl_rmain.c:606
struct matrix4x4_s * relativetransforms
Definition protocol.h:426
struct rtexture_s * pants
Definition r_textures.h:130
struct rtexture_s * stain
Definition r_textures.h:127
qbool qgeneratebase
Definition r_textures.h:161
struct rtexture_s * merged
Definition r_textures.h:128
struct rtexture_s * shirt
Definition r_textures.h:131
struct skinframe_s * next
Definition r_textures.h:142
struct rtexture_s * reflect
Definition r_textures.h:136
struct rtexture_s * base
Definition r_textures.h:129
struct rtexture_s * gloss
Definition r_textures.h:133
qbool qhascolormapping
Definition r_textures.h:160
struct rtexture_s * fog
Definition r_textures.h:135
float avgcolor[4]
Definition r_textures.h:155
struct rtexture_s * nmap
Definition r_textures.h:132
qbool qgenerateglow
Definition r_textures.h:164
unsigned int loadsequence
Definition r_textures.h:151
unsigned char * qpixels
Definition r_textures.h:157
int compareheight
Definition r_textures.h:146
struct rtexture_s * glow
Definition r_textures.h:134
qbool qgeneratenmap
Definition r_textures.h:163
char basename[MAX_QPATH]
Definition r_textures.h:143
qbool qgeneratemerged
Definition r_textures.h:162
qbool hasalpha
Definition r_textures.h:153
const char * suffix
Definition gl_rmain.c:2874
qbool flipdiagonal
Definition gl_rmain.c:2875
float * data_vertex3f
svbsp_node_t * nodes
Definition svbsp.h:30
q3shaderinfo_layer_tcmod_t tcmods[Q3MAXTCMODS]
Definition r_qshader.h:270
struct skinframe_s * skinframes[TEXTURE_MAXFRAMES]
Definition r_qshader.h:265
q3shaderinfo_layer_tcgen_t tcgen
Definition r_qshader.h:269
float specularpower
struct skinframe_s * backgroundcurrentskinframe
struct rtexture_s * basetexture
int currentblendfunc[2]
float render_rtlight_specular[3]
matrix4x4_t currenttexmatrix
qbool colormapping
struct rtexture_s * glosstexture
float refractfactor
float render_modellight_lightdir_world[3]
float render_glowmod[3]
dptransparentsortcategory_t transparentsort
float render_colormap_pants[3]
struct rtexture_s * nmaptexture
int anim_total[2]
dpoffsetmapping_technique_t offsetmapping
struct rtexture_s * backgroundglosstexture
struct rtexture_s * backgroundbasetexture
int currentmaterialflags
texture_shaderpass_t * backgroundshaderpass
int camera_entity
void * update_lastrenderentity
float render_colormap_shirt[3]
float r_water_waterscroll[2]
float biaspolygonoffset
float basealpha
float render_modellight_diffuse[3]
float render_rtlight_diffuse[3]
float render_modellight_ambient[3]
struct rtexture_s * shirttexture
struct rtexture_s * pantstexture
float specularpowermod
int basematerialflags
struct texture_s * currentframe
float reflectmin
struct rtexture_s * glowtexture
int update_lastrenderframe
vec4_t refractcolor4f
float render_modellight_lightdir_local[3]
struct rtexture_s * backgroundglowtexture
q3shaderinfo_deform_t deforms[Q3MAXDEFORMS]
float render_lightmap_specular[3]
struct rtexture_s * reflectmasktexture
matrix4x4_t currentbackgroundtexmatrix
char name[64]
struct rtexture_s * fogtexture
struct rtexture_s * reflectcubetexture
float render_lightmap_diffuse[3]
float reflectmax
float offsetscale
texture_shaderpass_t * materialshaderpass
float render_lightmap_ambient[3]
float r_water_wateralpha
float specularscalemod
float reflectfactor
struct rtexture_s * backgroundnmaptexture
float offsetbias
float currentalpha
float biaspolygonfactor
float render_modellight_specular[3]
struct skinframe_s * currentskinframe
struct texture_s * anim_frames[2][10]
vec4_t reflectcolor4f
int customblendfunc[2]
double endpos[3]
Definition collision.h:42
float vertex3f[3][3]
Definition client.h:41
int surfaceindex
Definition client.h:49
float lived
Definition client.h:45
float color4f[3][4]
Definition client.h:42
int triangleindex
Definition client.h:47
float texcoord2f[3][2]
Definition client.h:40
unsigned int decalsequence
Definition client.h:51
float plane[4]
Definition client.h:43
int samples
Definition vid.h:65
int width
Definition vid.h:60
int height
Definition vid.h:61
qbool ext_texture_compression_s3tc
Definition vid.h:48
int glshaderversion
this is at least 150 (GL 3.2)
Definition vid.h:45
unsigned int maxtexturesize_2d
Definition vid.h:83
qbool sRGB3D
whether 3D rendering is sRGB corrected (based on sRGBcapable3D)
Definition vid.h:76
qbool sRGB2D
whether 2D rendering is sRGB corrected (based on sRGBcapable2D)
Definition vid.h:75
renderpath_t renderpath
Definition vid.h:80
qbool stencil
Definition vid.h:74
viddef_support_t support
Definition vid.h:89
viddef_mode_t mode
currently active video mode
Definition vid.h:73
qbool allowalphatocoverage
indicates the GL_AlphaToCoverage function works on this renderpath and framebuffer
Definition vid.h:81
static vec3_t forward
Definition sv_user.c:305
static vec3_t right
Definition sv_user.c:305
static vec3_t up
Definition sv_user.c:305
void Sys_Error(const char *error,...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN
Causes the entire program to exit ASAP.
Definition sys_shared.c:724
cvar_t vid_sRGB_fallback
Definition vid_shared.c:158
qbool vid_gammatables_trivial
this is set to true if all color control values are at default setting, and it therefore would make n...
unsigned int vid_gammatables_serial
so other subsystems can poll if gamma parameters have changed; this starts with 0 and gets increased ...
@ RENDERPATH_GLES2
Definition vid.h:38
@ RENDERPATH_GL32
Definition vid.h:37
cvar_t vid_sRGB
Definition vid_shared.c:157
viddef_t vid
global video state
Definition vid_shared.c:64
void VID_BuildGammaTables(unsigned short *ramps, int rampsize)
builds the current gamma tables into an array (needs 3*rampsize items)
#define MOVE_NORMAL
Definition world.h:28
size_t Mem_ExpandableArray_IndexRange(const memexpandablearray_t *l)
Definition zone.c:763
void Mem_ExpandableArray_NewArray(memexpandablearray_t *l, mempool_t *mempool, size_t recordsize, int numrecordsperarray)
Definition zone.c:675
void Mem_ExpandableArray_FreeRecord(memexpandablearray_t *l, void *record)
Definition zone.c:743
void * Mem_ExpandableArray_AllocRecord(memexpandablearray_t *l)
Definition zone.c:695
void * Mem_ExpandableArray_RecordAtIndex(const memexpandablearray_t *l, size_t index)
Definition zone.c:780
mempool_t * tempmempool
Definition zone.c:794
void Mem_ExpandableArray_FreeArray(memexpandablearray_t *l)
Definition zone.c:683
#define Mem_Free(mem)
Definition zone.h:96
#define Mem_Alloc(pool, size)
Definition zone.h:92
#define Mem_strdup(pool, s)
Definition zone.h:97
#define Mem_AllocPool(name, flags, parent)
Definition zone.h:104