diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index 5909c7ab1..93ef5cd54 100644 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -1871,7 +1871,7 @@ Render3DError OpenGLRenderer_1_2::UploadClearImage(const u16 *__restrict colorBu { for (size_t i = 0; i < GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT; i++) { - OGLRef.workingCIDepthStencilBuffer[i] = depthBuffer[i] << 8; + OGLRef.workingCIDepthStencilBuffer[i] = (depthBuffer[i] << 8) | polyIDBuffer[i]; OGLRef.workingCIDepthBuffer[i] = depthBuffer[i] | 0xFF000000; OGLRef.workingCIFogAttributesBuffer[i] = (fogBuffer[i]) ? 0xFF0000FF : 0xFF000000; OGLRef.workingCIPolyIDBuffer[i] = (GLuint)polyIDBuffer[i] | 0xFF000000; @@ -1881,7 +1881,7 @@ Render3DError OpenGLRenderer_1_2::UploadClearImage(const u16 *__restrict colorBu { for (size_t i = 0; i < GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT; i++) { - OGLRef.workingCIDepthStencilBuffer[i] = depthBuffer[i] << 8; + OGLRef.workingCIDepthStencilBuffer[i] = (depthBuffer[i] << 8) | polyIDBuffer[i]; } } @@ -2363,7 +2363,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf // We do this because glBlitFramebufferEXT() for GL_STENCIL_BUFFER_BIT has been tested // to be unsupported on ATI/AMD GPUs running in compatibility mode. So we do the separate // glClear() for GL_STENCIL_BUFFER_BIT to keep these GPUs working. - glClearStencil(0); + glClearStencil(polyIDBuffer[0]); glClear(GL_STENCIL_BUFFER_BIT); // Blit the working depth buffer @@ -2397,7 +2397,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingImage(const u16 *__restrict colorBuf glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, OGLRef.fboRenderID); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, OGLRef.selectedRenderingFBO); - glClearStencil(0); + glClearStencil(polyIDBuffer[0]); glClear(GL_STENCIL_BUFFER_BIT); // Blit the working depth buffer @@ -2445,7 +2445,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingValues(const FragmentColor &clearCol glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); // texGColorID glClearColor(divide5bitBy31_LUT[clearColor.r], divide5bitBy31_LUT[clearColor.g], divide5bitBy31_LUT[clearColor.b], divide5bitBy31_LUT[clearColor.a]); glClearDepth((GLclampd)clearAttributes.depth / (GLclampd)0x00FFFFFF); - glClearStencil(0); + glClearStencil(clearAttributes.opaquePolyID); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); // texGDepthID @@ -2466,7 +2466,7 @@ Render3DError OpenGLRenderer_1_2::ClearUsingValues(const FragmentColor &clearCol { glClearColor(divide5bitBy31_LUT[clearColor.r], divide5bitBy31_LUT[clearColor.g], divide5bitBy31_LUT[clearColor.b], divide5bitBy31_LUT[clearColor.a]); glClearDepth((GLclampd)clearAttributes.depth / (GLclampd)0x00FFFFFF); - glClearStencil(0); + glClearStencil(clearAttributes.opaquePolyID); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } @@ -2868,7 +2868,7 @@ Render3DError OpenGLRenderer_1_3::UploadClearImage(const u16 *__restrict colorBu { for (size_t i = 0; i < GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT; i++) { - OGLRef.workingCIDepthStencilBuffer[i] = depthBuffer[i] << 8; + OGLRef.workingCIDepthStencilBuffer[i] = (depthBuffer[i] << 8) | polyIDBuffer[i]; OGLRef.workingCIDepthBuffer[i] = depthBuffer[i] | 0xFF000000; OGLRef.workingCIFogAttributesBuffer[i] = (fogBuffer[i]) ? 0xFF0000FF : 0xFF000000; OGLRef.workingCIPolyIDBuffer[i] = (GLuint)polyIDBuffer[i] | 0xFF000000; @@ -2878,7 +2878,7 @@ Render3DError OpenGLRenderer_1_3::UploadClearImage(const u16 *__restrict colorBu { for (size_t i = 0; i < GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT; i++) { - OGLRef.workingCIDepthStencilBuffer[i] = depthBuffer[i] << 8; + OGLRef.workingCIDepthStencilBuffer[i] = (depthBuffer[i] << 8) | polyIDBuffer[i]; } } diff --git a/desmume/src/OGLRender_3_2.cpp b/desmume/src/OGLRender_3_2.cpp index b42884526..f172e6efa 100644 --- a/desmume/src/OGLRender_3_2.cpp +++ b/desmume/src/OGLRender_3_2.cpp @@ -1411,7 +1411,7 @@ Render3DError OpenGLRenderer_3_2::ClearUsingValues(const FragmentColor &clearCol const GLfloat oglPolyID[4] = {(GLfloat)clearAttributes.opaquePolyID/63.0f, 0.0, 0.0, 1.0}; const GLfloat oglFogAttr[4] = {clearAttributes.isFogged, 0.0, 0.0, 1.0}; - glClearBufferfi(GL_DEPTH_STENCIL, 0, (GLfloat)clearAttributes.depth / (GLfloat)0x00FFFFFF, 0); + glClearBufferfi(GL_DEPTH_STENCIL, 0, (GLfloat)clearAttributes.depth / (GLfloat)0x00FFFFFF, clearAttributes.opaquePolyID); glClearBufferfv(GL_COLOR, 0, oglColor); // texGColorID glClearBufferfv(GL_COLOR, 1, oglDepth); // texGDepthID glClearBufferfv(GL_COLOR, 2, oglPolyID); // texGPolyID