diff --git a/source/src/protos.h b/source/src/protos.h index ecfeb21f..d8c773bc 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -391,6 +391,7 @@ extern int isoccluded(float vx, float vy, float cx, float cy, float csize); // main extern SDL_Surface *screen; +extern int colorbits, depthbits, stencilbits; extern time_t now_utc; extern struct tm *systemtime(); diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 18ff3f26..74a1295e 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -873,7 +873,8 @@ void gl_drawframe(int w, int h, float changelod, float curfps) } } - glClear((outsidemap(camera1) ? GL_COLOR_BUFFER_BIT : 0) | GL_DEPTH_BUFFER_BIT | (hasstencil && stencilshadow ? GL_STENCIL_BUFFER_BIT : 0)); + if(stencilshadow && hasstencil && stencilbits >= 8) glClearStencil((hasSTS || hasST2) && !hasSTW ? 128 : 0); + glClear((outsidemap(camera1) ? GL_COLOR_BUFFER_BIT : 0) | GL_DEPTH_BUFFER_BIT | (stencilshadow && hasstencil && stencilbits >= 8 ? GL_STENCIL_BUFFER_BIT : 0)); glEnable(GL_TEXTURE_2D); @@ -922,7 +923,7 @@ void gl_drawframe(int w, int h, float changelod, float curfps) renderbounceents(); endmodelbatches(); - if(stencilshadow && hasstencil) drawstencilshadows(); + if(stencilshadow && hasstencil && stencilbits >= 8) drawstencilshadows(); // Added by Rick: Need todo here because of drawing the waypoints glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index c9ab3dd5..596307a0 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -282,7 +282,7 @@ void endmodelbatches(bool flush) } renderbatchedmodel(b.m, bm); } - if(dynshadow && b.m->hasshadows() && (!reflecting || refracting) && (!stencilshadow || !hasstencil)) + if(dynshadow && b.m->hasshadows() && (!reflecting || refracting) && (!stencilshadow || !hasstencil || stencilbits < 8)) { glColor4f(0, 0, 0, dynshadow/100.0f); loopvj(b.batched) @@ -377,7 +377,7 @@ void rendermodel(const char *mdl, int anim, int tex, float rad, const vec &o, fl if(!OUTBORD(x, y)) { sqr *s = S(x, y); - if(!(anim&ANIM_TRANSLUCENT) && dynshadow && m->hasshadows() && (!reflecting || refracting) && (!stencilshadow || !hasstencil)) + if(!(anim&ANIM_TRANSLUCENT) && dynshadow && m->hasshadows() && (!reflecting || refracting) && (!stencilshadow || !hasstencil || stencilbits < 8)) { vec center(o.x, o.y, s->floor); if(s->type==FHF) center.z -= s->vdelta/4.0f; diff --git a/source/src/shadow.cpp b/source/src/shadow.cpp index a36ebd94..470a3926 100644 --- a/source/src/shadow.cpp +++ b/source/src/shadow.cpp @@ -330,7 +330,7 @@ void drawstencilshadows() shadowx1 = shadowy1 = 1; memset(shadowtiles, 0, sizeof(shadowtiles)); - if((hasST2 || hasSTS) && hasSTW) + if(hasST2 || hasSTS) { glDisable(GL_CULL_FACE); @@ -340,17 +340,17 @@ void drawstencilshadows() glActiveStencilFace_(GL_BACK); glStencilFunc(GL_ALWAYS, 0, ~0U); - glStencilOp(GL_KEEP, GL_KEEP, GL_INCR_WRAP_EXT); + glStencilOp(GL_KEEP, GL_KEEP, hasSTW ? GL_INCR_WRAP_EXT : GL_INCR); glActiveStencilFace_(GL_FRONT); glStencilFunc(GL_ALWAYS, 0, ~0U); - glStencilOp(GL_KEEP, GL_KEEP, GL_DECR_WRAP_EXT); + glStencilOp(GL_KEEP, GL_KEEP, hasSTW ? GL_DECR_WRAP_EXT : GL_DECR); } else { glStencilFuncSeparate_(GL_ALWAYS, GL_ALWAYS, 0, ~0U); - glStencilOpSeparate_(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP_EXT); - glStencilOpSeparate_(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR_WRAP_EXT); + glStencilOpSeparate_(GL_BACK, GL_KEEP, GL_KEEP, hasSTW ? GL_INCR_WRAP_EXT : GL_INCR); + glStencilOpSeparate_(GL_FRONT, GL_KEEP, GL_KEEP, hasSTW ? GL_DECR_WRAP_EXT : GL_DECR); } startmodelbatches(); @@ -393,8 +393,16 @@ void drawstencilshadows() { glDisable(GL_DEPTH_TEST); - glStencilFunc(GL_NOTEQUAL, 0, ~0U); - glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); + if((hasST2 || hasSTS) && !hasSTW) + { + glStencilFunc(GL_NOTEQUAL, 128, ~0U); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + } + else + { + glStencilFunc(GL_NOTEQUAL, 0, ~0U); + glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); + } glEnable(GL_BLEND); glBlendFunc(GL_ZERO, GL_SRC_COLOR);