]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_shadow.c
Fix setinfo.
[xonotic/darkplaces.git] / r_shadow.c
index 303322c47afa36efa092b60b8f2528896290bec5..1553ac675d77c024cb9f11a9f9d1659256c3541c 100644 (file)
@@ -24,7 +24,6 @@ r_shadow_rendermode_t;
 
 typedef enum r_shadow_shadowmode_e
 {
-       R_SHADOW_SHADOWMODE_STENCIL,
        R_SHADOW_SHADOWMODE_SHADOWMAP2D
 }
 r_shadow_shadowmode_t;
@@ -104,8 +103,6 @@ unsigned char *r_shadow_buffer_lighttrispvs;
 
 rtexturepool_t *r_shadow_texturepool;
 rtexture_t *r_shadow_attenuationgradienttexture;
-rtexture_t *r_shadow_attenuation2dtexture;
-rtexture_t *r_shadow_attenuation3dtexture;
 skinframe_t *r_shadow_lightcorona;
 rtexture_t *r_shadow_shadowmap2ddepthbuffer;
 rtexture_t *r_shadow_shadowmap2ddepthtexture;
@@ -186,7 +183,6 @@ cvar_t r_shadow_shadowmapping_bias = {CVAR_SAVE, "r_shadow_shadowmapping_bias",
 cvar_t r_shadow_shadowmapping_polygonfactor = {CVAR_SAVE, "r_shadow_shadowmapping_polygonfactor", "2", "slope-dependent shadowmapping bias"};
 cvar_t r_shadow_shadowmapping_polygonoffset = {CVAR_SAVE, "r_shadow_shadowmapping_polygonoffset", "0", "constant shadowmapping bias"};
 cvar_t r_shadow_sortsurfaces = {0, "r_shadow_sortsurfaces", "1", "improve performance by sorting illuminated surfaces by texture"};
-cvar_t r_shadow_texture3d = {0, "r_shadow_texture3d", "1", "use 3D voxel textures for spherical attenuation rather than cylindrical (does not affect OpenGL 2.0 render path)"};
 cvar_t r_shadow_culllights_pvs = {CVAR_SAVE, "r_shadow_culllights_pvs", "1", "check if light overlaps any visible bsp leafs when determining if the light is visible"};
 cvar_t r_shadow_culllights_trace = {CVAR_SAVE, "r_shadow_culllights_trace", "1", "use raytraces from the eye to random places within light bounds to determine if the light is visible"};
 cvar_t r_shadow_culllights_trace_eyejitter = {CVAR_SAVE, "r_shadow_culllights_trace_eyejitter", "16", "offset eye location randomly by this much"};
@@ -234,7 +230,7 @@ cvar_t r_shadow_bouncegrid_static_quality = { CVAR_SAVE, "r_shadow_bouncegrid_st
 cvar_t r_shadow_bouncegrid_static_spacing = {CVAR_SAVE, "r_shadow_bouncegrid_static_spacing", "64", "unit size of bouncegrid pixel when in static mode"};
 cvar_t r_coronas = {CVAR_SAVE, "r_coronas", "0", "brightness of corona flare effects around certain lights, 0 disables corona effects"};
 cvar_t r_coronas_occlusionsizescale = {CVAR_SAVE, "r_coronas_occlusionsizescale", "0.1", "size of light source for corona occlusion checksum the proportion of hidden pixels controls corona intensity"};
-cvar_t r_coronas_occlusionquery = {CVAR_SAVE, "r_coronas_occlusionquery", "0", "use GL_ARB_occlusion_query extension if supported (fades coronas according to visibility) - bad performance (synchronous rendering) - worse on multi-gpu!"};
+cvar_t r_coronas_occlusionquery = {CVAR_SAVE, "r_coronas_occlusionquery", "0", "fades coronas according to visibility"};
 cvar_t gl_flashblend = {CVAR_SAVE, "gl_flashblend", "0", "render bright coronas for dynamic lights instead of actual lighting, fast but ugly"};
 cvar_t r_editlights = {0, "r_editlights", "0", "enables .rtlights file editing mode"};
 cvar_t r_editlights_cursordistance = {0, "r_editlights_cursordistance", "1024", "maximum distance of cursor from eye"};
@@ -287,7 +283,6 @@ void R_Shadow_LoadWorldLights(void);
 void R_Shadow_LoadLightsFile(void);
 void R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(void);
 void R_Shadow_EditLights_Reload_f(void);
-void R_Shadow_ValidateCvars(void);
 static void R_Shadow_MakeTextures(void);
 
 #define EDLIGHTSPRSIZE                 8
@@ -306,25 +301,25 @@ static void R_Shadow_SetShadowMode(void)
        r_shadow_shadowmapborder = bound(1, r_shadow_shadowmapping_bordersize.integer, 16);
        r_shadow_shadowmaptexturesize = bound(256, r_shadow_shadowmapping_texturesize.integer, (int)vid.maxtexturesize_2d);
        r_shadow_shadowmapmaxsize = bound(r_shadow_shadowmapborder+2, r_shadow_shadowmapping_maxsize.integer, r_shadow_shadowmaptexturesize / 8);
-       r_shadow_shadowmapvsdct = r_shadow_shadowmapping_vsdct.integer != 0 && vid.renderpath == RENDERPATH_GL20;
+       r_shadow_shadowmapvsdct = r_shadow_shadowmapping_vsdct.integer != 0 && vid.renderpath == RENDERPATH_GL32;
        r_shadow_shadowmapfilterquality = r_shadow_shadowmapping_filterquality.integer;
        r_shadow_shadowmapshadowsampler = r_shadow_shadowmapping_useshadowsampler.integer != 0;
        r_shadow_shadowmapdepthbits = r_shadow_shadowmapping_depthbits.integer;
        r_shadow_shadowmapsampler = false;
        r_shadow_shadowmappcf = 0;
        r_shadow_shadowmapdepthtexture = r_fb.usedepthtextures;
-       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_STENCIL;
+       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
        Mod_AllocLightmap_Init(&r_shadow_shadowmapatlas_state, r_main_mempool, r_shadow_shadowmaptexturesize, r_shadow_shadowmaptexturesize);
-       if ((r_shadow_shadowmapping.integer || r_shadow_deferred.integer) && vid.support.ext_framebuffer_object)
+       if (r_shadow_shadowmapping.integer || r_shadow_deferred.integer)
        {
                switch(vid.renderpath)
                {
-               case RENDERPATH_GL20:
+               case RENDERPATH_GL32:
                        if(r_shadow_shadowmapfilterquality < 0)
                        {
                                if (!r_fb.usedepthtextures)
                                        r_shadow_shadowmappcf = 1;
-                               else if((strstr(gl_vendor, "NVIDIA") || strstr(gl_renderer, "Radeon HD")) && vid.support.arb_shadow && r_shadow_shadowmapshadowsampler)
+                               else if((strstr(gl_vendor, "NVIDIA") || strstr(gl_renderer, "Radeon HD")) && r_shadow_shadowmapshadowsampler)
                                {
                                        r_shadow_shadowmapsampler = true;
                                        r_shadow_shadowmappcf = 1;
@@ -334,11 +329,11 @@ static void R_Shadow_SetShadowMode(void)
                                else if((strstr(gl_vendor, "ATI") || strstr(gl_vendor, "Advanced Micro Devices")) && !strstr(gl_renderer, "Mesa") && !strstr(gl_version, "Mesa"))
                                        r_shadow_shadowmappcf = 1;
                                else
-                                       r_shadow_shadowmapsampler = vid.support.arb_shadow && r_shadow_shadowmapshadowsampler;
+                                       r_shadow_shadowmapsampler = r_shadow_shadowmapshadowsampler;
                        }
                        else
                        {
-                r_shadow_shadowmapsampler = vid.support.arb_shadow && r_shadow_shadowmapshadowsampler;
+                r_shadow_shadowmapsampler = r_shadow_shadowmapshadowsampler;
                                switch (r_shadow_shadowmapfilterquality)
                                {
                                case 1:
@@ -406,9 +401,7 @@ static void r_shadow_start(void)
        // allocate vertex processing arrays
        memset(&r_shadow_bouncegrid_state, 0, sizeof(r_shadow_bouncegrid_state));
        r_shadow_attenuationgradienttexture = NULL;
-       r_shadow_attenuation2dtexture = NULL;
-       r_shadow_attenuation3dtexture = NULL;
-       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_STENCIL;
+       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
        r_shadow_shadowmap2ddepthtexture = NULL;
        r_shadow_shadowmap2ddepthbuffer = NULL;
        r_shadow_shadowmapvsdcttexture = NULL;
@@ -425,7 +418,6 @@ static void r_shadow_start(void)
 
        r_shadow_texturepool = NULL;
        r_shadow_filters_texturepool = NULL;
-       R_Shadow_ValidateCvars();
        R_Shadow_MakeTextures();
        r_shadow_scenemaxlights = 0;
        r_shadow_scenenumlights = 0;
@@ -467,13 +459,13 @@ static void r_shadow_start(void)
        // these out per frame...
        switch(vid.renderpath)
        {
-       case RENDERPATH_GL20:
+       case RENDERPATH_GL32:
                r_shadow_bouncegrid_state.allowdirectionalshading = true;
-               r_shadow_bouncegrid_state.capable = vid.support.ext_texture_3d;
+               r_shadow_bouncegrid_state.capable = true;
                break;
        case RENDERPATH_GLES2:
                // for performance reasons, do not use directional shading on GLES devices
-               r_shadow_bouncegrid_state.capable = vid.support.ext_texture_3d;
+               r_shadow_bouncegrid_state.capable = true;
                break;
        }
 }
@@ -506,8 +498,6 @@ static void r_shadow_shutdown(void)
        r_shadow_bouncegrid_state.maxsplatpaths = 0;
        memset(&r_shadow_bouncegrid_state, 0, sizeof(r_shadow_bouncegrid_state));
        r_shadow_attenuationgradienttexture = NULL;
-       r_shadow_attenuation2dtexture = NULL;
-       r_shadow_attenuation3dtexture = NULL;
        R_FreeTexturePool(&r_shadow_texturepool);
        R_FreeTexturePool(&r_shadow_filters_texturepool);
        maxshadowtriangles = 0;
@@ -641,7 +631,6 @@ void R_Shadow_Init(void)
        Cvar_RegisterVariable(&r_shadow_shadowmapping_polygonfactor);
        Cvar_RegisterVariable(&r_shadow_shadowmapping_polygonoffset);
        Cvar_RegisterVariable(&r_shadow_sortsurfaces);
-       Cvar_RegisterVariable(&r_shadow_texture3d);
        Cvar_RegisterVariable(&r_shadow_culllights_pvs);
        Cvar_RegisterVariable(&r_shadow_culllights_trace);
        Cvar_RegisterVariable(&r_shadow_culllights_trace_eyejitter);
@@ -1190,8 +1179,8 @@ void R_Shadow_ShadowMapFromList(int numverts, int numtris, const float *vertex3f
                        }
                }
        }
-                       
-       Mod_ShadowMesh_AddMesh(r_main_mempool, r_shadow_compilingrtlight->static_meshchain_shadow_shadowmap, NULL, NULL, NULL, vertex3f, NULL, NULL, NULL, NULL, outtriangles, shadowelements);
+
+       Mod_ShadowMesh_AddMesh(r_shadow_compilingrtlight->static_meshchain_shadow_shadowmap, vertex3f, outtriangles, shadowelements);
 }
 
 static void R_Shadow_MakeTextures_MakeCorona(void)
@@ -1213,7 +1202,7 @@ static void R_Shadow_MakeTextures_MakeCorona(void)
                        pixels[y][x][3] = 255;
                }
        }
-       r_shadow_lightcorona = R_SkinFrame_LoadInternalBGRA("lightcorona", TEXF_FORCELINEAR, &pixels[0][0][0], 32, 32, false);
+       r_shadow_lightcorona = R_SkinFrame_LoadInternalBGRA("lightcorona", TEXF_FORCELINEAR, &pixels[0][0][0], 32, 32, 0, 0, 0, false);
 }
 
 static unsigned int R_Shadow_MakeTextures_SamplePoint(float x, float y, float z)
@@ -1226,7 +1215,7 @@ static unsigned int R_Shadow_MakeTextures_SamplePoint(float x, float y, float z)
 
 static void R_Shadow_MakeTextures(void)
 {
-       int x, y, z;
+       int x;
        float intensity, dist;
        unsigned int *data;
        R_Shadow_FreeShadowMaps();
@@ -1246,22 +1235,6 @@ static void R_Shadow_MakeTextures(void)
        for (x = 0;x < ATTEN1DSIZE;x++)
                data[x] = R_Shadow_MakeTextures_SamplePoint((x + 0.5f) * (1.0f / ATTEN1DSIZE) * (1.0f / 0.9375), 0, 0);
        r_shadow_attenuationgradienttexture = R_LoadTexture2D(r_shadow_texturepool, "attenuation1d", ATTEN1DSIZE, 1, (unsigned char *)data, TEXTYPE_BGRA, TEXF_CLAMP | TEXF_ALPHA | TEXF_FORCELINEAR, -1, NULL);
-       // 2D circle texture
-       for (y = 0;y < ATTEN2DSIZE;y++)
-               for (x = 0;x < ATTEN2DSIZE;x++)
-                       data[y*ATTEN2DSIZE+x] = R_Shadow_MakeTextures_SamplePoint(((x + 0.5f) * (2.0f / ATTEN2DSIZE) - 1.0f) * (1.0f / 0.9375), ((y + 0.5f) * (2.0f / ATTEN2DSIZE) - 1.0f) * (1.0f / 0.9375), 0);
-       r_shadow_attenuation2dtexture = R_LoadTexture2D(r_shadow_texturepool, "attenuation2d", ATTEN2DSIZE, ATTEN2DSIZE, (unsigned char *)data, TEXTYPE_BGRA, TEXF_CLAMP | TEXF_ALPHA | TEXF_FORCELINEAR, -1, NULL);
-       // 3D sphere texture
-       if (r_shadow_texture3d.integer && vid.support.ext_texture_3d)
-       {
-               for (z = 0;z < ATTEN3DSIZE;z++)
-                       for (y = 0;y < ATTEN3DSIZE;y++)
-                               for (x = 0;x < ATTEN3DSIZE;x++)
-                                       data[(z*ATTEN3DSIZE+y)*ATTEN3DSIZE+x] = R_Shadow_MakeTextures_SamplePoint(((x + 0.5f) * (2.0f / ATTEN3DSIZE) - 1.0f) * (1.0f / 0.9375), ((y + 0.5f) * (2.0f / ATTEN3DSIZE) - 1.0f) * (1.0f / 0.9375), ((z + 0.5f) * (2.0f / ATTEN3DSIZE) - 1.0f) * (1.0f / 0.9375));
-               r_shadow_attenuation3dtexture = R_LoadTexture3D(r_shadow_texturepool, "attenuation3d", ATTEN3DSIZE, ATTEN3DSIZE, ATTEN3DSIZE, (unsigned char *)data, TEXTYPE_BGRA, TEXF_CLAMP | TEXF_ALPHA | TEXF_FORCELINEAR, -1, NULL);
-       }
-       else
-               r_shadow_attenuation3dtexture = NULL;
        Mem_Free(data);
 
        R_Shadow_MakeTextures_MakeCorona();
@@ -1377,23 +1350,14 @@ static void R_Shadow_MakeTextures(void)
        , 16, 16, palette_bgra_embeddedpic, palette_bgra_embeddedpic);
 }
 
-void R_Shadow_ValidateCvars(void)
-{
-       if (r_shadow_texture3d.integer && !vid.support.ext_texture_3d)
-               Cvar_SetValueQuick(&r_shadow_texture3d, 0);
-}
-
 void R_Shadow_RenderMode_Begin(void)
 {
 #if 0
        GLint drawbuffer;
        GLint readbuffer;
 #endif
-       R_Shadow_ValidateCvars();
 
-       if (!r_shadow_attenuation2dtexture
-        || (!r_shadow_attenuation3dtexture && r_shadow_texture3d.integer)
-        || r_shadow_lightattenuationdividebias.value != r_shadow_attendividebias
+       if (r_shadow_lightattenuationdividebias.value != r_shadow_attendividebias
         || r_shadow_lightattenuationlinearscale.value != r_shadow_attenlinearscale)
                R_Shadow_MakeTextures();
 
@@ -1532,7 +1496,7 @@ void R_Shadow_ClearShadowMapTexture(void)
                GL_ColorMask(0, 0, 0, 0);
        switch (vid.renderpath)
        {
-       case RENDERPATH_GL20:
+       case RENDERPATH_GL32:
        case RENDERPATH_GLES2:
                GL_CullFace(r_refdef.view.cullface_back);
                break;
@@ -1607,7 +1571,7 @@ static void R_Shadow_RenderMode_ShadowMap(int side, int size, int x, int y)
                GL_ColorMask(0,0,0,0);
        switch(vid.renderpath)
        {
-       case RENDERPATH_GL20:
+       case RENDERPATH_GL32:
        case RENDERPATH_GLES2:
                GL_CullFace(r_refdef.view.cullface_back);
                break;
@@ -1961,21 +1925,9 @@ static void R_Shadow_BounceGrid_UpdateSpacing(void)
        c[1] = (int)floor(size[1] / spacing[1] + 0.5f);
        c[2] = (int)floor(size[2] / spacing[2] + 0.5f);
        // figure out the exact texture size (honoring power of 2 if required)
-       c[0] = bound(4, c[0], (int)vid.maxtexturesize_3d);
-       c[1] = bound(4, c[1], (int)vid.maxtexturesize_3d);
-       c[2] = bound(4, c[2], (int)vid.maxtexturesize_3d);
-       if (vid.support.arb_texture_non_power_of_two)
-       {
-               resolution[0] = c[0];
-               resolution[1] = c[1];
-               resolution[2] = c[2];
-       }
-       else
-       {
-               for (resolution[0] = 4;resolution[0] < c[0];resolution[0]*=2) ;
-               for (resolution[1] = 4;resolution[1] < c[1];resolution[1]*=2) ;
-               for (resolution[2] = 4;resolution[2] < c[2];resolution[2]*=2) ;
-       }
+       resolution[0] = bound(4, c[0], (int)vid.maxtexturesize_3d);
+       resolution[1] = bound(4, c[1], (int)vid.maxtexturesize_3d);
+       resolution[2] = bound(4, c[2], (int)vid.maxtexturesize_3d);
        size[0] = spacing[0] * resolution[0];
        size[1] = spacing[1] * resolution[1];
        size[2] = spacing[2] * resolution[2];
@@ -1988,22 +1940,10 @@ static void R_Shadow_BounceGrid_UpdateSpacing(void)
                c[0] = r_shadow_bouncegrid_dynamic_x.integer;
                c[1] = r_shadow_bouncegrid_dynamic_y.integer;
                c[2] = r_shadow_bouncegrid_dynamic_z.integer;
-               // now we can calculate the texture size (power of 2 if required)
-               c[0] = bound(4, c[0], (int)vid.maxtexturesize_3d);
-               c[1] = bound(4, c[1], (int)vid.maxtexturesize_3d);
-               c[2] = bound(4, c[2], (int)vid.maxtexturesize_3d);
-               if (vid.support.arb_texture_non_power_of_two)
-               {
-                       resolution[0] = c[0];
-                       resolution[1] = c[1];
-                       resolution[2] = c[2];
-               }
-               else
-               {
-                       for (resolution[0] = 4;resolution[0] < c[0];resolution[0]*=2) ;
-                       for (resolution[1] = 4;resolution[1] < c[1];resolution[1]*=2) ;
-                       for (resolution[2] = 4;resolution[2] < c[2];resolution[2]*=2) ;
-               }
+               // now we can calculate the texture size
+               resolution[0] = bound(4, c[0], (int)vid.maxtexturesize_3d);
+               resolution[1] = bound(4, c[1], (int)vid.maxtexturesize_3d);
+               resolution[2] = bound(4, c[2], (int)vid.maxtexturesize_3d);
                size[0] = spacing[0] * resolution[0];
                size[1] = spacing[1] * resolution[1];
                size[2] = spacing[2] * resolution[2];
@@ -2983,7 +2923,7 @@ void R_Shadow_RenderLighting(int texturenumsurfaces, const msurface_t **textures
        VectorMultiply(specularcolor, rsurface.rtlight->currentcolor, specularcolor);
        if (VectorLength2(ambientcolor) + VectorLength2(diffusecolor) + VectorLength2(specularcolor) < (1.0f / 1048576.0f))
                return;
-       negated = (rsurface.rtlight->currentcolor[0] + rsurface.rtlight->currentcolor[1] + rsurface.rtlight->currentcolor[2] < 0) && vid.support.ext_blend_subtract;
+       negated = (rsurface.rtlight->currentcolor[0] + rsurface.rtlight->currentcolor[1] + rsurface.rtlight->currentcolor[2] < 0);
        if(negated)
        {
                VectorNegate(ambientcolor, ambientcolor);
@@ -3087,7 +3027,7 @@ void R_RTLight_Compile(rtlight_t *rtlight)
                model->GetLightInfo(ent, rtlight->shadoworigin, rtlight->radius, rtlight->cullmins, rtlight->cullmaxs, r_shadow_buffer_leaflist, r_shadow_buffer_leafpvs, &numleafs, r_shadow_buffer_surfacelist, r_shadow_buffer_surfacepvs, &numsurfaces, r_shadow_buffer_shadowtrispvs, r_shadow_buffer_lighttrispvs, r_shadow_buffer_visitingleafpvs, 0, NULL, rtlight->shadow == 0);
                R_FrameData_ReturnToMark();
                numleafpvsbytes = (model->brush.num_leafs + 7) >> 3;
-               numshadowtrispvsbytes = ((model->brush.shadowmesh ? model->brush.shadowmesh->numtriangles : model->surfmesh.num_triangles) + 7) >> 3;
+               numshadowtrispvsbytes = (model->surfmesh.num_triangles + 7) >> 3;
                numlighttrispvsbytes = (model->surfmesh.num_triangles + 7) >> 3;
                data = (unsigned char *)Mem_Alloc(r_main_mempool, sizeof(int) * numsurfaces + sizeof(int) * numleafs + numleafpvsbytes + numshadowtrispvsbytes + numlighttrispvsbytes);
                rtlight->static_numsurfaces = numsurfaces;
@@ -3348,24 +3288,20 @@ static void R_Shadow_ComputeShadowCasterCullingPlanes(rtlight_t *rtlight)
 
 static void R_Shadow_DrawWorldShadow_ShadowMap(int numsurfaces, int *surfacelist, const unsigned char *trispvs, const unsigned char *surfacesides)
 {
-       shadowmesh_t *mesh;
-
        RSurf_ActiveModelEntity(r_refdef.scene.worldentity, false, false, false);
 
        if (rsurface.rtlight->compiled && r_shadow_realtime_world_compile.integer && r_shadow_realtime_world_compileshadow.integer)
        {
-               CHECKGLERROR
-               GL_CullFace(GL_NONE);
-               mesh = rsurface.rtlight->static_meshchain_shadow_shadowmap;
-               for (;mesh;mesh = mesh->next)
+               shadowmesh_t *mesh = rsurface.rtlight->static_meshchain_shadow_shadowmap;
+               if (mesh->sidetotals[r_shadow_shadowmapside])
                {
-                       if (!mesh->sidetotals[r_shadow_shadowmapside])
-                               continue;
+                       CHECKGLERROR
+                       GL_CullFace(GL_NONE);
                        r_refdef.stats[r_stat_lights_shadowtriangles] += mesh->sidetotals[r_shadow_shadowmapside];
                        R_Mesh_PrepareVertices_Vertex3f(mesh->numverts, mesh->vertex3f, mesh->vbo_vertexbuffer, mesh->vbooffset_vertex3f);
                        R_Mesh_Draw(0, mesh->numverts, mesh->sideoffsets[r_shadow_shadowmapside], mesh->sidetotals[r_shadow_shadowmapside], mesh->element3i, mesh->element3i_indexbuffer, mesh->element3i_bufferoffset, mesh->element3s, mesh->element3s_indexbuffer, mesh->element3s_bufferoffset);
+                       CHECKGLERROR
                }
-               CHECKGLERROR
        }
        else if (r_refdef.scene.worldentity->model)
                r_refdef.scene.worldmodel->DrawShadowMap(r_shadow_shadowmapside, r_refdef.scene.worldentity, rsurface.rtlight->shadoworigin, NULL, rsurface.rtlight->radius, numsurfaces, surfacelist, surfacesides, rsurface.rtlight->cached_cullmins, rsurface.rtlight->cached_cullmaxs);
@@ -3706,7 +3642,7 @@ static void R_Shadow_PrepareLight(rtlight_t *rtlight)
        rtlight->cached_shadowentities_noselfshadow    = (entity_render_t**)R_FrameData_Store(numshadowentities_noselfshadow*sizeof(entity_render_t *), (void*)shadowentities_noselfshadow);
        if (shadowtrispvs == r_shadow_buffer_shadowtrispvs)
        {
-               int numshadowtrispvsbytes = (((r_refdef.scene.worldmodel->brush.shadowmesh ? r_refdef.scene.worldmodel->brush.shadowmesh->numtriangles : r_refdef.scene.worldmodel->surfmesh.num_triangles) + 7) >> 3);
+               int numshadowtrispvsbytes = ((r_refdef.scene.worldmodel->surfmesh.num_triangles + 7) >> 3);
                int numlighttrispvsbytes = ((r_refdef.scene.worldmodel->surfmesh.num_triangles + 7) >> 3);
                rtlight->cached_shadowtrispvs                  =   (unsigned char *)R_FrameData_Store(numshadowtrispvsbytes, shadowtrispvs);
                rtlight->cached_lighttrispvs                   =   (unsigned char *)R_FrameData_Store(numlighttrispvsbytes, lighttrispvs);
@@ -4110,10 +4046,10 @@ void R_Shadow_PrepareLights(void)
        int shadowmapmaxsize = bound(shadowmapborder+2, r_shadow_shadowmapping_maxsize.integer, shadowmaptexturesize / 8);
 
        if (r_shadow_shadowmaptexturesize != shadowmaptexturesize ||
-               (r_shadow_shadowmode != R_SHADOW_SHADOWMODE_STENCIL) != (r_shadow_shadowmapping.integer || r_shadow_deferred.integer) ||
-               r_shadow_shadowmapvsdct != (r_shadow_shadowmapping_vsdct.integer != 0 && vid.renderpath == RENDERPATH_GL20) ||
+               !(r_shadow_shadowmapping.integer || r_shadow_deferred.integer) ||
+               r_shadow_shadowmapvsdct != (r_shadow_shadowmapping_vsdct.integer != 0 && vid.renderpath == RENDERPATH_GL32) ||
                r_shadow_shadowmapfilterquality != r_shadow_shadowmapping_filterquality.integer ||
-               r_shadow_shadowmapshadowsampler != (vid.support.arb_shadow && r_shadow_shadowmapping_useshadowsampler.integer) ||
+               r_shadow_shadowmapshadowsampler != r_shadow_shadowmapping_useshadowsampler.integer ||
                r_shadow_shadowmapdepthbits != r_shadow_shadowmapping_depthbits.integer ||
                r_shadow_shadowmapborder != shadowmapborder ||
                r_shadow_shadowmapmaxsize != shadowmapmaxsize ||
@@ -4124,9 +4060,9 @@ void R_Shadow_PrepareLights(void)
 
        switch (vid.renderpath)
        {
-       case RENDERPATH_GL20:
+       case RENDERPATH_GL32:
 #ifndef USE_GLES2
-               if (!r_shadow_deferred.integer || r_shadow_shadowmode == R_SHADOW_SHADOWMODE_STENCIL || !vid.support.ext_framebuffer_object || vid.maxdrawbuffers < 2)
+               if (!r_shadow_deferred.integer || vid.maxdrawbuffers < 2)
                {
                        r_shadow_usingdeferredprepass = false;
                        if (r_shadow_prepass_width)
@@ -4173,7 +4109,7 @@ void R_Shadow_PrepareLights(void)
                break;
        }
 
-       R_Shadow_EnlargeLeafSurfaceTrisBuffer(r_refdef.scene.worldmodel->brush.num_leafs, r_refdef.scene.worldmodel->num_surfaces, r_refdef.scene.worldmodel->brush.shadowmesh ? r_refdef.scene.worldmodel->brush.shadowmesh->numtriangles : r_refdef.scene.worldmodel->surfmesh.num_triangles, r_refdef.scene.worldmodel->surfmesh.num_triangles);
+       R_Shadow_EnlargeLeafSurfaceTrisBuffer(r_refdef.scene.worldmodel->brush.num_leafs, r_refdef.scene.worldmodel->num_surfaces, r_refdef.scene.worldmodel->surfmesh.num_triangles, r_refdef.scene.worldmodel->surfmesh.num_triangles);
 
        r_shadow_scenenumlights = 0;
        flag = r_refdef.scene.rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE;
@@ -4493,7 +4429,7 @@ static void R_BeginCoronaQuery(rtlight_t *rtlight, float scale, qboolean usequer
 {
        float zdist;
        vec3_t centerorigin;
-#if defined(GL_SAMPLES_PASSED_ARB) && !defined(USE_GLES2)
+#ifndef USE_GLES2
        float vertex3f[12];
 #endif
        // if it's too close, skip it
@@ -4511,23 +4447,23 @@ static void R_BeginCoronaQuery(rtlight_t *rtlight, float scale, qboolean usequer
 
                switch(vid.renderpath)
                {
-               case RENDERPATH_GL20:
+               case RENDERPATH_GL32:
                case RENDERPATH_GLES2:
-#if defined(GL_SAMPLES_PASSED_ARB) && !defined(USE_GLES2)
+#ifndef USE_GLES2
                        CHECKGLERROR
                        // NOTE: GL_DEPTH_TEST must be enabled or ATI won't count samples, so use GL_DepthFunc instead
-                       qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, rtlight->corona_queryindex_allpixels);
+                       qglBeginQuery(GL_SAMPLES_PASSED, rtlight->corona_queryindex_allpixels);
                        GL_DepthFunc(GL_ALWAYS);
                        R_CalcSprite_Vertex3f(vertex3f, centerorigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale);
                        R_Mesh_PrepareVertices_Vertex3f(4, vertex3f, NULL, 0);
                        R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
-                       qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
+                       qglEndQuery(GL_SAMPLES_PASSED);
                        GL_DepthFunc(GL_LEQUAL);
-                       qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, rtlight->corona_queryindex_visiblepixels);
+                       qglBeginQuery(GL_SAMPLES_PASSED, rtlight->corona_queryindex_visiblepixels);
                        R_CalcSprite_Vertex3f(vertex3f, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale);
                        R_Mesh_PrepareVertices_Vertex3f(4, vertex3f, NULL, 0);
                        R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
-                       qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
+                       qglEndQuery(GL_SAMPLES_PASSED);
                        CHECKGLERROR
 #endif
                        break;
@@ -4542,40 +4478,30 @@ static void R_DrawCorona(rtlight_t *rtlight, float cscale, float scale)
 {
        vec3_t color;
        unsigned int occlude = 0;
-       GLint allpixels = 0, visiblepixels = 0;
 
        // now we have to check the query result
        if (rtlight->corona_queryindex_visiblepixels)
        {
                switch(vid.renderpath)
                {
-               case RENDERPATH_GL20:
+               case RENDERPATH_GL32:
                case RENDERPATH_GLES2:
-#if defined(GL_SAMPLES_PASSED_ARB) && !defined(USE_GLES2)
-                       // See if we can use the GPU-side method to prevent implicit sync
-                       if (vid.support.arb_query_buffer_object) {
+#ifndef USE_GLES2
+                       // store the pixel counts into a uniform buffer for the shader to
+                       // use - we'll never know the results on the cpu without
+                       // synchronizing and we don't want that
 #define BUFFER_OFFSET(i)    ((GLint *)((unsigned char*)NULL + (i)))
-                               if (!r_shadow_occlusion_buf) {
-                                       qglGenBuffersARB(1, &r_shadow_occlusion_buf);
-                                       qglBindBufferARB(GL_QUERY_BUFFER_ARB, r_shadow_occlusion_buf);
-                                       qglBufferDataARB(GL_QUERY_BUFFER_ARB, 8, NULL, GL_DYNAMIC_COPY);
-                               } else {
-                                       qglBindBufferARB(GL_QUERY_BUFFER_ARB, r_shadow_occlusion_buf);
-                               }
-                               qglGetQueryObjectivARB(rtlight->corona_queryindex_visiblepixels, GL_QUERY_RESULT_ARB, BUFFER_OFFSET(0));
-                               qglGetQueryObjectivARB(rtlight->corona_queryindex_allpixels, GL_QUERY_RESULT_ARB, BUFFER_OFFSET(4));
-                               qglBindBufferBase(GL_UNIFORM_BUFFER, 0, r_shadow_occlusion_buf);
-                               occlude = MATERIALFLAG_OCCLUDE;
-                               cscale *= rtlight->corona_visibility;
-                               CHECKGLERROR
-                               break;
+                       if (!r_shadow_occlusion_buf) {
+                               qglGenBuffers(1, &r_shadow_occlusion_buf);
+                               qglBindBuffer(GL_QUERY_BUFFER, r_shadow_occlusion_buf);
+                               qglBufferData(GL_QUERY_BUFFER, 8, NULL, GL_DYNAMIC_COPY);
+                       } else {
+                               qglBindBuffer(GL_QUERY_BUFFER, r_shadow_occlusion_buf);
                        }
-                       CHECKGLERROR
-                       qglGetQueryObjectivARB(rtlight->corona_queryindex_visiblepixels, GL_QUERY_RESULT_ARB, &visiblepixels);
-                       qglGetQueryObjectivARB(rtlight->corona_queryindex_allpixels, GL_QUERY_RESULT_ARB, &allpixels);
-                       if (visiblepixels < 1 || allpixels < 1)
-                               return;
-                       rtlight->corona_visibility *= bound(0, (float)visiblepixels / (float)allpixels, 1);
+                       qglGetQueryObjectiv(rtlight->corona_queryindex_visiblepixels, GL_QUERY_RESULT, BUFFER_OFFSET(0));
+                       qglGetQueryObjectiv(rtlight->corona_queryindex_allpixels, GL_QUERY_RESULT, BUFFER_OFFSET(4));
+                       qglBindBufferBase(GL_UNIFORM_BUFFER, 0, r_shadow_occlusion_buf);
+                       occlude = MATERIALFLAG_OCCLUDE;
                        cscale *= rtlight->corona_visibility;
                        CHECKGLERROR
                        break;
@@ -4593,7 +4519,7 @@ static void R_DrawCorona(rtlight_t *rtlight, float cscale, float scale)
        if (VectorLength(color) > (1.0f / 256.0f))
        {
                float vertex3f[12];
-               qboolean negated = (color[0] + color[1] + color[2] < 0) && vid.support.ext_blend_subtract;
+               qboolean negated = (color[0] + color[1] + color[2] < 0);
                if(negated)
                {
                        VectorNegate(color, color);
@@ -4624,16 +4550,14 @@ void R_Shadow_DrawCoronas(void)
 
        range = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); // checked
 
-       // check occlusion of coronas
-       // use GL_ARB_occlusion_query if available
-       // otherwise use raytraces
+       // check occlusion of coronas, using occlusion queries or raytraces
        r_numqueries = 0;
        switch (vid.renderpath)
        {
-       case RENDERPATH_GL20:
+       case RENDERPATH_GL32:
        case RENDERPATH_GLES2:
-               usequery = vid.support.arb_occlusion_query && r_coronas_occlusionquery.integer;
-#if defined(GL_SAMPLES_PASSED_ARB) && !defined(USE_GLES2)
+               usequery = r_coronas_occlusionquery.integer;
+#ifndef USE_GLES2
                if (usequery)
                {
                        GL_ColorMask(0,0,0,0);
@@ -4644,7 +4568,7 @@ void R_Shadow_DrawCoronas(void)
                                r_maxqueries = ((unsigned int)range + r_refdef.scene.numlights) * 4;
                                r_maxqueries = min(r_maxqueries, MAX_OCCLUSION_QUERIES);
                                CHECKGLERROR
-                               qglGenQueriesARB(r_maxqueries - i, r_queries + i);
+                               qglGenQueries(r_maxqueries - i, r_queries + i);
                                CHECKGLERROR
                        }
                        RSurf_ActiveModelEntity(r_refdef.scene.worldentity, false, false, false);