From 5717f1f15b2069230be331a8efc876505b08418b Mon Sep 17 00:00:00 2001 From: Nolan Check Date: Mon, 29 Jun 2009 00:52:54 +0000 Subject: [PATCH] Grok EFB pixel format to determine whether render target has alpha, thus fixing the "Stage Clear" screen in SSBM. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3588 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/VideoCommon/Src/BPStructs.cpp | 2 +- Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp | 7 ++++++- .../Plugin_VideoOGL/Src/FramebufferManager.cpp | 11 +++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/Src/BPStructs.cpp b/Source/Core/VideoCommon/Src/BPStructs.cpp index 7773773439..e0b0c9bca2 100644 --- a/Source/Core/VideoCommon/Src/BPStructs.cpp +++ b/Source/Core/VideoCommon/Src/BPStructs.cpp @@ -358,7 +358,7 @@ void BPWritten(const Bypass& bp) #endif break; } - case BPMEM_ZCOMPARE: // Set the Z-Compare + case BPMEM_ZCOMPARE: // Set the Z-Compare and EFB pixel format case BPMEM_TEXINVALIDATE: // Used, if game has manual control the Texture Cache, which we don't allow case BPMEM_MIPMAP_STRIDE: // MipMap Stride Channel case BPMEM_COPYYSCALE: // Display Copy Y Scale diff --git a/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp b/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp index 3c5992f0b1..51f4121954 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/BPFunctions.cpp @@ -156,10 +156,15 @@ void ClearScreen(const Bypass &bp, const TRectangle &multirc) if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate) { u32 clearColor = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB; + + // Alpha may or may not be present depending on the EFB pixel format. + GLclampf clearAlpha = (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24) ? + ((clearColor>>24) & 0xff)*(1/255.0f) : 1.0f; + glClearColor(((clearColor>>16) & 0xff)*(1/255.0f), ((clearColor>>8 ) & 0xff)*(1/255.0f), ((clearColor>>0 ) & 0xff)*(1/255.0f), - ((clearColor>>24) & 0xff)*(1/255.0f)); + clearAlpha); bits |= GL_COLOR_BUFFER_BIT; } if (bpmem.zmode.updateenable) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp index 49f804b91a..1c531db68d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/FramebufferManager.cpp @@ -25,6 +25,17 @@ void FramebufferManager::Init(int targetWidth, int targetHeight, int msaaSamples m_msaaSamples = msaaSamples; m_msaaCoverageSamples = msaaCoverageSamples; + // The EFB can be set to different pixel formats by the game through the + // BPMEM_ZCOMPARE register (which should probably have a different name). + // They are: + // - 24-bit RGB (8-bit components) with 24-bit Z + // - 24-bit RGBA (6-bit components) with 24-bit Z + // - Multisampled 16-bit RGB (5-6-5 format) with 16-bit Z + // We only use one EFB format here: 32-bit ARGB with 24-bit Z. + // Multisampling depends on user settings. + // The distinction becomes important for certain operations, i.e. the + // alpha channel should be ignored if the EFB does not have one. + // Create EFB target. glGenFramebuffersEXT(1, &m_efbFramebuffer);