diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index fa9cb9881..5a23d56cc 100644 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -2749,7 +2749,7 @@ Render3DError OpenGLRenderer_1_2::BeginRender(const GFX3D &engine) } else { - const GLfloat thePolyAlpha = (!thePoly->isWireframe() && thePoly->isTranslucent()) ? divide5bitBy31_LUT[thePoly->getAttributeAlpha()] : 1.0f; + const GLfloat thePolyAlpha = (thePoly->isWireframe()) ? 1.0f : divide5bitBy31_LUT[thePoly->getAttributeAlpha()]; for (size_t j = 0; j < polyType; j++) { @@ -3086,7 +3086,6 @@ void OpenGLRenderer_1_2::SetPolygonIndex(const size_t index) Render3DError OpenGLRenderer_1_2::SetupPolygon(const POLY &thePoly) { const PolygonAttributes attr = thePoly.getAttributes(); - const bool isOpaqueDecal = ((attr.polygonMode == POLYGON_MODE_DECAL) && attr.isOpaque); // Set up depth test mode static const GLenum oglDepthFunc[2] = {GL_LESS, GL_EQUAL}; @@ -3137,11 +3136,11 @@ Render3DError OpenGLRenderer_1_2::SetupPolygon(const POLY &thePoly) else { glStencilFunc(GL_ALWAYS, attr.polygonID, 0x3F); - glStencilOp(GL_KEEP, GL_KEEP, (attr.isTranslucent && !isOpaqueDecal) ? GL_KEEP : GL_REPLACE); + glStencilOp(GL_KEEP, GL_KEEP, (attr.isTranslucent) ? GL_KEEP : GL_REPLACE); glStencilMask(0xFF); // Drawing non-shadow polygons will implicitly reset the stencil buffer bits glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glDepthMask((!attr.isTranslucent || isOpaqueDecal || attr.enableAlphaDepthWrite) ? GL_TRUE : GL_FALSE); + glDepthMask((!attr.isTranslucent || attr.enableAlphaDepthWrite) ? GL_TRUE : GL_FALSE); } // Set up polygon attributes diff --git a/desmume/src/OGLRender_3_2.cpp b/desmume/src/OGLRender_3_2.cpp index 77fd6aba2..19895316d 100644 --- a/desmume/src/OGLRender_3_2.cpp +++ b/desmume/src/OGLRender_3_2.cpp @@ -1817,14 +1817,12 @@ Render3DError OpenGLRenderer_3_2::SetupPolygon(const POLY &thePoly) } else { - const bool isOpaqueDecal = ((attr.polygonMode == POLYGON_MODE_DECAL) && attr.isOpaque); - glStencilFunc(GL_ALWAYS, attr.polygonID, 0x3F); - glStencilOp(GL_KEEP, GL_KEEP, (attr.isTranslucent && !isOpaqueDecal) ? GL_KEEP : GL_REPLACE); + glStencilOp(GL_KEEP, GL_KEEP, (attr.isTranslucent) ? GL_KEEP : GL_REPLACE); glStencilMask(0xFF); // Drawing non-shadow polygons will implicitly reset the stencil buffer bits glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glDepthMask((!attr.isTranslucent || isOpaqueDecal || attr.enableAlphaDepthWrite) ? GL_TRUE : GL_FALSE); + glDepthMask((!attr.isTranslucent || attr.enableAlphaDepthWrite) ? GL_TRUE : GL_FALSE); } return OGLERROR_NOERR; diff --git a/desmume/src/gfx3d.h b/desmume/src/gfx3d.h index 83ac2b891..e2e7e9bc9 100644 --- a/desmume/src/gfx3d.h +++ b/desmume/src/gfx3d.h @@ -452,19 +452,24 @@ struct POLY { bool isTranslucent() const { + const bool isOpaque = this->isOpaque(); + // First, check if the polygon is wireframe or opaque. // If neither, then it must be translucent. - if (!this->isWireframe() && !this->isOpaque()) + if (!this->isWireframe() && !isOpaque) { return true; } // Also check for translucent texture format. - u8 texFormat = this->getTexParamTexFormat(); + const u8 texFormat = this->getTexParamTexFormat(); + const PolygonMode mode = this->getAttributePolygonMode(); //a5i3 or a3i5 -> translucent - if(texFormat == TEXMODE_A3I5 || texFormat == TEXMODE_A5I3) + if ( (texFormat == TEXMODE_A3I5 || texFormat == TEXMODE_A5I3) && !(isOpaque && (mode == POLYGON_MODE_DECAL || mode == POLYGON_MODE_SHADOW)) ) + { return true; + } return false; }