From d4fadf4b6f9c4acdf12b3cfa81b37df93797cdf1 Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 25 Mar 2013 15:45:10 +0100 Subject: [PATCH] implement 4xSSAA for OGL I don't think it's needed, but its requested often --- Source/Core/VideoCommon/Src/VideoConfig.h | 11 ----- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 40 +++++++++++++++++-- Source/Plugins/Plugin_VideoOGL/Src/Render.h | 1 + Source/Plugins/Plugin_VideoOGL/Src/main.cpp | 2 +- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h index ee5e662a62..442e95f9bf 100644 --- a/Source/Core/VideoCommon/Src/VideoConfig.h +++ b/Source/Core/VideoCommon/Src/VideoConfig.h @@ -37,17 +37,6 @@ #define CONF_SAVETARGETS 8 #define CONF_SAVESHADERS 16 -enum MultisampleMode { - MULTISAMPLE_OFF, - MULTISAMPLE_2X, - MULTISAMPLE_4X, - MULTISAMPLE_8X, - MULTISAMPLE_CSAA_8X, - MULTISAMPLE_CSAA_8XQ, - MULTISAMPLE_CSAA_16X, - MULTISAMPLE_CSAA_16XQ, -}; - enum AspectMode { ASPECT_AUTO = 0, ASPECT_FORCE_16_9 = 1, diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 8ecee1b234..d4b2d2051b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -104,6 +104,20 @@ int OSDInternalW, OSDInternalH; namespace OGL { + +enum MultisampleMode { + MULTISAMPLE_OFF, + MULTISAMPLE_2X, + MULTISAMPLE_4X, + MULTISAMPLE_8X, + MULTISAMPLE_CSAA_8X, + MULTISAMPLE_CSAA_8XQ, + MULTISAMPLE_CSAA_16X, + MULTISAMPLE_CSAA_16XQ, + MULTISAMPLE_SSAA_4X, +}; + + VideoConfig g_ogl_config; // Declarations and definitions @@ -149,6 +163,7 @@ int GetNumMSAASamples(int MSAAMode) case MULTISAMPLE_4X: case MULTISAMPLE_CSAA_8X: case MULTISAMPLE_CSAA_16X: + case MULTISAMPLE_SSAA_4X: samples = 4; break; @@ -192,6 +207,19 @@ int GetNumMSAACoverageSamples(int MSAAMode) return 0; } +void ApplySSAASettings() { + if(g_ActiveConfig.iMultisampleMode == MULTISAMPLE_SSAA_4X) { + if(g_ogl_config.bSupportSampleShading) { + glEnable(GL_SAMPLE_SHADING_ARB); + glMinSampleShadingARB(s_MSAASamples); + } else { + ERROR_LOG(VIDEO, "MSAA Bug: SSAA selected, but not supported by gpu."); + } + } else if(g_ogl_config.bSupportSampleShading) { + glDisable(GL_SAMPLE_SHADING_ARB); + } +} + // Init functions Renderer::Renderer() { @@ -271,6 +299,7 @@ Renderer::Renderer() g_ogl_config.bSupportsGLSync = GLEW_ARB_sync; g_ogl_config.bSupportsGLBaseVertex = GLEW_ARB_draw_elements_base_vertex; g_ogl_config.bSupportCoverageMSAA = GLEW_NV_framebuffer_multisample_coverage; + g_ogl_config.bSupportSampleShading = GLEW_ARB_sample_shading; g_ogl_config.gl_vendor = (const char*)glGetString(GL_VENDOR); g_ogl_config.gl_renderer = (const char*)glGetString(GL_RENDERER); @@ -299,20 +328,22 @@ Renderer::Renderer() g_ogl_config.gl_renderer, g_ogl_config.gl_version).c_str(), 5000); - OSD::AddMessage(StringFromFormat("Missing Extensions: %s%s%s%s%s%s%s", + OSD::AddMessage(StringFromFormat("Missing Extensions: %s%s%s%s%s%s%s%s", g_ActiveConfig.backend_info.bSupportsDualSourceBlend ? "" : "DualSourceBlend ", g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "UniformBuffer ", g_ogl_config.bSupportsGLPinnedMemory ? "" : "PinnedMemory ", g_ogl_config.bSupportsGLSLCache ? "" : "ShaderCache ", g_ogl_config.bSupportsGLBaseVertex ? "" : "BaseVertex ", g_ogl_config.bSupportsGLSync ? "" : "Sync ", - g_ogl_config.bSupportCoverageMSAA ? "" : "CSAA " + g_ogl_config.bSupportCoverageMSAA ? "" : "CSAA ", + g_ogl_config.bSupportSampleShading ? "" : "SSAA " ).c_str(), 5000); s_LastMultisampleMode = g_ActiveConfig.iMultisampleMode; s_MSAASamples = GetNumMSAASamples(s_LastMultisampleMode); s_MSAACoverageSamples = GetNumMSAACoverageSamples(s_LastMultisampleMode); - + ApplySSAASettings(); + // Decide frambuffer size s_backbuffer_width = (int)GLInterface->GetBackBufferWidth(); s_backbuffer_height = (int)GLInterface->GetBackBufferHeight(); @@ -1270,7 +1301,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons s_LastMultisampleMode = g_ActiveConfig.iMultisampleMode; s_MSAASamples = GetNumMSAASamples(s_LastMultisampleMode); s_MSAACoverageSamples = GetNumMSAACoverageSamples(s_LastMultisampleMode); - + ApplySSAASettings(); + delete g_framebuffer_manager; g_framebuffer_manager = new FramebufferManager(s_target_width, s_target_height, s_MSAASamples, s_MSAACoverageSamples); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.h b/Source/Plugins/Plugin_VideoOGL/Src/Render.h index cf039b5c0b..d5510753c2 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.h @@ -16,6 +16,7 @@ extern struct VideoConfig { bool bSupportsGLSync; bool bSupportsGLBaseVertex; bool bSupportCoverageMSAA; + bool bSupportSampleShading; const char *gl_vendor; const char *gl_renderer; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index 56a56418b1..ddce3bb01f 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -141,7 +141,7 @@ void InitBackendInfo() g_Config.backend_info.bSupportsPixelLighting = true; // aamodes - const char* caamodes[] = {"None", "2x", "4x", "8x", "8x CSAA", "8xQ CSAA", "16x CSAA", "16xQ CSAA"}; + const char* caamodes[] = {"None", "2x", "4x", "8x", "8x CSAA", "8xQ CSAA", "16x CSAA", "16xQ CSAA", "4x SSAA"}; g_Config.backend_info.AAModes.assign(caamodes, caamodes + sizeof(caamodes)/sizeof(*caamodes)); // pp shaders