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://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1209 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Eric Wasylishen 2015-05-18 06:11:56 +00:00
parent 93a442003a
commit 2e2b110ecb
2 changed files with 32 additions and 2 deletions

View File

@ -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<cl_numvisedicts ; i++)
{
currententity = cl_visedicts[i];
@ -864,6 +873,11 @@ void R_DrawShadows (void)
GL_DrawAliasShadow (currententity);
}
if (gl_stencilbits)
{
glDisable(GL_STENCIL_TEST);
}
}
/*

View File

@ -536,7 +536,7 @@ static qboolean VID_SetMode (int width, int height, int bpp, qboolean fullscreen
int temp;
Uint32 flags;
char caption[50];
int depthbits;
int depthbits, stencilbits;
int fsaa_obtained;
// so Con_Printfs don't mess us up by forcing vid and snd updates
@ -548,9 +548,17 @@ static qboolean VID_SetMode (int width, int height, int bpp, qboolean fullscreen
/* z-buffer depth */
if (bpp == 16)
{
depthbits = 16;
else depthbits = 24;
stencilbits = 0;
}
else
{
depthbits = 24;
stencilbits = 8;
}
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depthbits);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencilbits);
/* fsaa */
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, fsaa > 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");
}