From 414e08ab14df747e51896a7e437401741470205a Mon Sep 17 00:00:00 2001 From: vortex Date: Wed, 11 May 2011 22:59:39 +0000 Subject: [PATCH] OpenGL 2.0 path: Make handling of Alpha-To-Coverage same as AlphaTest (enabling before surface render and disabling after), instead of hacky R_ShadowMode_Begin force-to-disable, this also fixes shadowmap bug with ATI hardware. Also made vid_multisampling (if enabled) to force minimal vid_samples 2. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11146 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_backend.c | 6 +++--- gl_rmain.c | 10 ++++------ r_shadow.c | 7 ++++++- vid_sdl.c | 8 +++++++- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/gl_backend.c b/gl_backend.c index e8d2e640..5fbf7979 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -1437,7 +1437,7 @@ static void GL_Backend_ResetState(void) qglColorMask(1, 1, 1, 1);CHECKGLERROR qglAlphaFunc(gl_state.alphafunc, gl_state.alphafuncvalue);CHECKGLERROR - qglDisable((vid_multisampling.integer && r_transparent_alphatocoverage.integer) ? GL_SAMPLE_ALPHA_TO_COVERAGE_ARB : GL_ALPHA_TEST);CHECKGLERROR + qglDisable((r_transparent_alphatocoverage.integer) ? GL_SAMPLE_ALPHA_TO_COVERAGE_ARB : GL_ALPHA_TEST);CHECKGLERROR qglBlendFunc(gl_state.blendfunc1, gl_state.blendfunc2);CHECKGLERROR qglDisable(GL_BLEND);CHECKGLERROR qglCullFace(gl_state.cullface);CHECKGLERROR @@ -2134,11 +2134,11 @@ void GL_AlphaTest(int state) CHECKGLERROR if (gl_state.alphatest) { - qglEnable((vid_multisampling.integer && r_transparent_alphatocoverage.integer) ? GL_SAMPLE_ALPHA_TO_COVERAGE_ARB : GL_ALPHA_TEST);CHECKGLERROR + qglEnable((r_transparent_alphatocoverage.integer) ? GL_SAMPLE_ALPHA_TO_COVERAGE_ARB : GL_ALPHA_TEST);CHECKGLERROR } else { - qglDisable((vid_multisampling.integer && r_transparent_alphatocoverage.integer) ? GL_SAMPLE_ALPHA_TO_COVERAGE_ARB : GL_ALPHA_TEST);CHECKGLERROR + qglDisable((r_transparent_alphatocoverage.integer) ? GL_SAMPLE_ALPHA_TO_COVERAGE_ARB : GL_ALPHA_TEST);CHECKGLERROR } break; case RENDERPATH_D3D9: diff --git a/gl_rmain.c b/gl_rmain.c index 020fa1e8..354160da 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -2092,12 +2092,7 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, matrix4x4_t tempmatrix; r_waterstate_waterplane_t *waterplane = (r_waterstate_waterplane_t *)surfacewaterplane; if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST) - { permutation |= SHADERPERMUTATION_ALPHAKILL; - GL_AlphaTest(true); - } - else - GL_AlphaTest(false); if (rsurface.texture->r_water_waterscroll[0] && rsurface.texture->r_water_waterscroll[1]) permutation |= SHADERPERMUTATION_NORMALMAPSCROLLBLEND; // todo: make generic if (rsurfacepass == RSURFPASS_BACKGROUND) @@ -9461,7 +9456,6 @@ static void R_DrawTextureSurfaceList_GL20(int texturenumsurfaces, const msurface GL_DepthMask(true); R_SetupShader_Surface(vec3_origin, (rsurface.texture->currentmaterialflags & MATERIALFLAG_MODELLIGHT) != 0, 1, 1, rsurface.texture->specularscale, RSURFPASS_DEFERREDGEOMETRY, texturenumsurfaces, texturesurfacelist, NULL); RSurf_DrawBatch(); - return; } // bind lightmap texture @@ -9508,7 +9502,11 @@ static void R_DrawTextureSurfaceList_GL20(int texturenumsurfaces, const msurface // render surface batch normally GL_DepthMask(writedepth && !(rsurface.texture->currentmaterialflags & MATERIALFLAG_BLENDED)); R_SetupShader_Surface(vec3_origin, (rsurface.texture->currentmaterialflags & MATERIALFLAG_MODELLIGHT) != 0, 1, 1, rsurface.texture->specularscale, RSURFPASS_BASE, texturenumsurfaces, texturesurfacelist, NULL); + if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST) + GL_AlphaTest(true); RSurf_DrawBatch(); + if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST) + GL_AlphaTest(false); } static void R_DrawTextureSurfaceList_GL13(int texturenumsurfaces, const msurface_t **texturesurfacelist, qboolean writedepth) diff --git a/r_shadow.c b/r_shadow.c index 47507cf9..909015eb 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -1952,7 +1952,6 @@ void R_Shadow_RenderMode_Begin(void) CHECKGLERROR R_Mesh_ResetTextureState(); GL_BlendFunc(GL_ONE, GL_ZERO); - GL_AlphaTest(false); GL_DepthRange(0, 1); GL_PolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset); GL_DepthTest(true); @@ -3170,10 +3169,16 @@ static void R_Shadow_RenderLighting_Light_GLSL(int texturenumsurfaces, const msu // ARB2 GLSL shader path (GFFX5200, Radeon 9500) R_SetupShader_Surface(lightcolor, false, ambientscale, diffusescale, specularscale, RSURFPASS_RTLIGHT, texturenumsurfaces, texturesurfacelist, NULL); if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST) + { GL_DepthFunc(GL_EQUAL); + GL_AlphaTest(true); + } RSurf_DrawBatch(); if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST) + { GL_DepthFunc(GL_LEQUAL); + GL_AlphaTest(false); + } } static void R_Shadow_RenderLighting_Light_Vertex_Pass(int firstvertex, int numvertices, int numtriangles, const int *element3i, vec3_t diffusecolor2, vec3_t ambientcolor2) diff --git a/vid_sdl.c b/vid_sdl.c index f7f95bb4..fdd70caa 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -2294,10 +2294,16 @@ qboolean VID_InitModeGL(viddef_mode_t *mode) vid_usinghidecursor = false; // enable multisampling - if (mode->samples > 1 && vid_multisampling.integer) + if (vid_multisampling.integer) { if (vid.support.arb_multisample) + { qglEnable(GL_MULTISAMPLE_ARB); + // it seems that enabling GL_MULTISAMPLE_ARB forces antialiasing to always work, fix the cvar as well + // make sure vid_sample is at least 2 to make things correct + if (vid_samples.integer < 2) + Cvar_SetValueQuick(&vid_samples, 0); + } else { Cvar_SetValueQuick(&vid_multisampling, 0); -- 2.39.2