From 0ef7b2be15c06139863169bf45cc256956070390 Mon Sep 17 00:00:00 2001 From: ewasylishen Date: Mon, 18 May 2015 06:11:56 +0000 Subject: [PATCH] r_shadows: Better stencil shadow rendering from MarkV. Now an 8-bit stencil buffer is requested when using a 24-bit depth buffer (the default). git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@1209 af15c1b1-3010-417e-b628-4374ebc0bcbd --- quakespasm/Quake/gl_rmain.c | 14 ++++++++++++++ quakespasm/Quake/gl_vidsdl.c | 20 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/quakespasm/Quake/gl_rmain.c b/quakespasm/Quake/gl_rmain.c index d05ad286..3c029958 100644 --- a/quakespasm/Quake/gl_rmain.c +++ b/quakespasm/Quake/gl_rmain.c @@ -852,6 +852,15 @@ void R_DrawShadows (void) if (!r_shadows.value || !r_drawentities.value || r_drawflat_cheatsafe || r_lightmap_cheatsafe) return; + // Use stencil buffer to prevent self-intersecting shadows, from Baker (MarkV) + if (gl_stencilbits) + { + glClear(GL_STENCIL_BUFFER_BIT); + glStencilFunc(GL_EQUAL, 0, ~0); + glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); + glEnable(GL_STENCIL_TEST); + } + for (i=0 ; i 0 ? 1 : 0); @@ -574,6 +582,10 @@ static qboolean VID_SetMode (int width, int height, int bpp, qboolean fullscreen SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); draw_context = SDL_CreateWindow (caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); } + if (!draw_context) { // scale back SDL_GL_STENCIL_SIZE + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0); + draw_context = SDL_CreateWindow (caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); + } if (!draw_context) Sys_Error ("Couldn't create window"); @@ -631,6 +643,10 @@ static qboolean VID_SetMode (int width, int height, int bpp, qboolean fullscreen if (!draw_context) { // scale back SDL_GL_DEPTH_SIZE SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); draw_context = SDL_SetVideoMode(width, height, bpp, flags); + } + if (!draw_context) { // scale back SDL_GL_STENCIL_SIZE + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0); + draw_context = SDL_SetVideoMode(width, height, bpp, flags); if (!draw_context) Sys_Error ("Couldn't set video mode"); }