diff options
| author | Stenzek <stenzek@users.noreply.github.com> | 2018-10-24 14:51:21 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-24 14:51:21 +1100 |
| commit | c4d1e4adffcd380cc87b841069ce2fe8b62d7b60 (patch) | |
| tree | c61a0a07c14ccc3c1f7247bdcc82927a82c145bb /Source/Core/VideoBackends/OGL | |
| parent | 9c9d598ec006527bc47aea306e5171d03c12c5f5 (diff) | |
| parent | 2c6d96433c322b50470705d43005fd6308506d49 (diff) | |
Merge pull request #7450 from stenzek/glcontext
GLInterface refactoring/cleanup and runtime platform selection
Diffstat (limited to 'Source/Core/VideoBackends/OGL')
| -rw-r--r-- | Source/Core/VideoBackends/OGL/FramebufferManager.cpp | 3 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/OGLTexture.cpp | 1 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/PerfQuery.cpp | 18 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp | 11 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/Render.cpp | 55 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/Render.h | 14 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/SamplerCache.cpp | 6 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/TextureCache.cpp | 1 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/VideoBackend.h | 8 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/OGL/main.cpp | 29 |
10 files changed, 77 insertions, 69 deletions
diff --git a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp index a6cccdaaa2..12de898ff5 100644 --- a/Source/Core/VideoBackends/OGL/FramebufferManager.cpp +++ b/Source/Core/VideoBackends/OGL/FramebufferManager.cpp @@ -9,7 +9,6 @@ #include "Common/Common.h" #include "Common/CommonTypes.h" -#include "Common/GL/GLInterfaceBase.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" @@ -414,7 +413,7 @@ FramebufferManager::FramebufferManager(int targetWidth, int targetHeight, int ms glBindBuffer(GL_ARRAY_BUFFER, static_cast<VertexManager*>(g_vertex_manager.get())->GetVertexBufferHandle()); - if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL) + if (!static_cast<Renderer*>(g_renderer.get())->IsGLES()) glEnable(GL_PROGRAM_POINT_SIZE); } diff --git a/Source/Core/VideoBackends/OGL/OGLTexture.cpp b/Source/Core/VideoBackends/OGL/OGLTexture.cpp index 1efb650eeb..fbe7f576c7 100644 --- a/Source/Core/VideoBackends/OGL/OGLTexture.cpp +++ b/Source/Core/VideoBackends/OGL/OGLTexture.cpp @@ -4,7 +4,6 @@ #include "Common/Assert.h" #include "Common/CommonTypes.h" -#include "Common/GL/GLInterfaceBase.h" #include "Common/MsgHandler.h" #include "VideoBackends/OGL/FramebufferManager.h" diff --git a/Source/Core/VideoBackends/OGL/PerfQuery.cpp b/Source/Core/VideoBackends/OGL/PerfQuery.cpp index b3b5df2265..77471cee19 100644 --- a/Source/Core/VideoBackends/OGL/PerfQuery.cpp +++ b/Source/Core/VideoBackends/OGL/PerfQuery.cpp @@ -6,25 +6,23 @@ #include "Common/CommonFuncs.h" #include "Common/CommonTypes.h" -#include "Common/GL/GLInterfaceBase.h" -#include "Common/GL/GLUtil.h" +#include "Common/GL/GLExtensions/GLExtensions.h" #include "VideoBackends/OGL/PerfQuery.h" -#include "VideoCommon/RenderBase.h" +#include "VideoBackends/OGL/Render.h" #include "VideoCommon/VideoConfig.h" namespace OGL { std::unique_ptr<PerfQueryBase> GetPerfQuery() { - if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3 && - GLExtensions::Supports("GL_NV_occlusion_query_samples")) + const bool is_gles = static_cast<Renderer*>(g_renderer.get())->IsGLES(); + if (is_gles && GLExtensions::Supports("GL_NV_occlusion_query_samples")) return std::make_unique<PerfQueryGLESNV>(); - - if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3) + else if (is_gles) return std::make_unique<PerfQueryGL>(GL_ANY_SAMPLES_PASSED); - - return std::make_unique<PerfQueryGL>(GL_SAMPLES_PASSED); + else + return std::make_unique<PerfQueryGL>(GL_SAMPLES_PASSED); } PerfQuery::PerfQuery() : m_query_read_pos() @@ -266,4 +264,4 @@ void PerfQueryGLESNV::FlushResults() FlushOne(); } -} // namespace +} // namespace OGL diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 2d284ae4ef..78458aa3fe 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -12,7 +12,7 @@ #include "Common/Assert.h" #include "Common/CommonTypes.h" #include "Common/FileUtil.h" -#include "Common/GL/GLInterfaceBase.h" +#include "Common/GL/GLContext.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" #include "Common/StringUtil.h" @@ -805,7 +805,8 @@ void ProgramShaderCache::CreateHeader() bool SharedContextAsyncShaderCompiler::WorkerThreadInitMainThread(void** param) { - std::unique_ptr<cInterfaceBase> context = GLInterface->CreateSharedContext(); + std::unique_ptr<GLContext> context = + static_cast<Renderer*>(g_renderer.get())->GetMainGLContext()->CreateSharedContext(); if (!context) { PanicAlert("Failed to create shared context for shader compiling."); @@ -818,20 +819,20 @@ bool SharedContextAsyncShaderCompiler::WorkerThreadInitMainThread(void** param) bool SharedContextAsyncShaderCompiler::WorkerThreadInitWorkerThread(void* param) { - cInterfaceBase* context = static_cast<cInterfaceBase*>(param); + GLContext* context = static_cast<GLContext*>(param); if (!context->MakeCurrent()) return false; s_is_shared_context = true; if (g_ActiveConfig.backend_info.bSupportsPrimitiveRestart) - GLUtil::EnablePrimitiveRestart(); + GLUtil::EnablePrimitiveRestart(context); return true; } void SharedContextAsyncShaderCompiler::WorkerThreadExit(void* param) { - cInterfaceBase* context = static_cast<cInterfaceBase*>(param); + GLContext* context = static_cast<GLContext*>(param); context->ClearCurrent(); delete context; } diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 27113a6b8b..360d4c2dcc 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -16,7 +16,7 @@ #include "Common/Assert.h" #include "Common/Atomic.h" #include "Common/CommonTypes.h" -#include "Common/GL/GLInterfaceBase.h" +#include "Common/GL/GLContext.h" #include "Common/GL/GLUtil.h" #include "Common/Logging/LogManager.h" #include "Common/MathUtil.h" @@ -353,9 +353,10 @@ static void InitDriverInfo() } // Init functions -Renderer::Renderer() - : ::Renderer(static_cast<int>(std::max(GLInterface->GetBackBufferWidth(), 1u)), - static_cast<int>(std::max(GLInterface->GetBackBufferHeight(), 1u))) +Renderer::Renderer(std::unique_ptr<GLContext> main_gl_context) + : ::Renderer(static_cast<int>(std::max(main_gl_context->GetBackBufferWidth(), 1u)), + static_cast<int>(std::max(main_gl_context->GetBackBufferHeight(), 1u))), + m_main_gl_context(std::move(main_gl_context)) { bool bSuccess = true; @@ -365,7 +366,7 @@ Renderer::Renderer() InitDriverInfo(); - if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL) + if (!m_main_gl_context->IsGLES()) { if (!GLExtensions::Supports("GL_ARB_framebuffer_object")) { @@ -500,7 +501,7 @@ Renderer::Renderer() g_Config.backend_info.bSupportsBPTCTextures = GLExtensions::Supports("GL_ARB_texture_compression_bptc"); - if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3) + if (m_main_gl_context->IsGLES()) { g_ogl_config.SupportedESPointSize = GLExtensions::Supports("GL_OES_geometry_point_size") ? @@ -730,10 +731,9 @@ Renderer::Renderer() if (!g_ogl_config.bSupportsGLBufferStorage && !g_ogl_config.bSupportsGLPinnedMemory) { - OSD::AddMessage( - StringFromFormat("Your OpenGL driver does not support %s_buffer_storage.", - GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3 ? "EXT" : "ARB"), - 60000); + OSD::AddMessage(StringFromFormat("Your OpenGL driver does not support %s_buffer_storage.", + m_main_gl_context->IsGLES() ? "EXT" : "ARB"), + 60000); OSD::AddMessage("This device's performance will be terrible.", 60000); OSD::AddMessage("Please ask your device vendor for an updated OpenGL driver.", 60000); } @@ -761,7 +761,7 @@ Renderer::Renderer() // Handle VSync on/off s_vsync = g_ActiveConfig.IsVSync(); if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC)) - GLInterface->SwapInterval(s_vsync); + m_main_gl_context->SwapInterval(s_vsync); // Because of the fixed framebuffer size we need to disable the resolution // options while running @@ -796,7 +796,7 @@ Renderer::Renderer() glClearDepthf(1.0f); if (g_ActiveConfig.backend_info.bSupportsPrimitiveRestart) - GLUtil::EnablePrimitiveRestart(); + GLUtil::EnablePrimitiveRestart(m_main_gl_context.get()); IndexGenerator::Init(); UpdateActiveConfig(); @@ -805,6 +805,11 @@ Renderer::Renderer() Renderer::~Renderer() = default; +bool Renderer::IsHeadless() const +{ + return m_main_gl_context->IsHeadless(); +} + void Renderer::Shutdown() { ::Renderer::Shutdown(); @@ -1044,7 +1049,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) std::unique_ptr<u32[]> colorMap(new u32[targetPixelRcWidth * targetPixelRcHeight]); - if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3) + if (IsGLES()) // XXX: Swap colours glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth, targetPixelRcHeight, GL_RGBA, GL_UNSIGNED_BYTE, colorMap.get()); @@ -1351,7 +1356,7 @@ void Renderer::ApplyBlendingState(const BlendingState state, bool force) GL_XOR, GL_OR, GL_NOR, GL_EQUIV, GL_INVERT, GL_OR_REVERSE, GL_COPY_INVERTED, GL_OR_INVERTED, GL_NAND, GL_SET}; - if (GLInterface->GetMode() != GLInterfaceMode::MODE_OPENGL) + if (IsGLES()) { // Logic ops aren't available in GLES3 } @@ -1421,7 +1426,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region OSD::DrawMessages(); // Swap the back and front buffers, presenting the image. - GLInterface->Swap(); + m_main_gl_context->Swap(); } else { @@ -1466,7 +1471,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region { s_vsync = g_ActiveConfig.IsVSync(); if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC)) - GLInterface->SwapInterval(s_vsync); + m_main_gl_context->SwapInterval(s_vsync); } // Clean out old stuff from caches. It's not worth it to clean out the shader caches. @@ -1500,14 +1505,12 @@ void Renderer::CheckForSurfaceChange() if (!m_surface_changed.TestAndClear()) return; - m_surface_handle = m_new_surface_handle; + m_main_gl_context->UpdateSurface(m_new_surface_handle); m_new_surface_handle = nullptr; - GLInterface->UpdateHandle(m_surface_handle); - GLInterface->UpdateSurface(); // With a surface change, the window likely has new dimensions. - m_backbuffer_width = GLInterface->GetBackBufferWidth(); - m_backbuffer_height = GLInterface->GetBackBufferHeight(); + m_backbuffer_width = m_main_gl_context->GetBackBufferWidth(); + m_backbuffer_height = m_main_gl_context->GetBackBufferHeight(); } void Renderer::CheckForSurfaceResize() @@ -1515,9 +1518,9 @@ void Renderer::CheckForSurfaceResize() if (!m_surface_resized.TestAndClear()) return; - GLInterface->Update(); - m_backbuffer_width = m_new_backbuffer_width; - m_backbuffer_height = m_new_backbuffer_height; + m_main_gl_context->Update(); + m_backbuffer_width = m_main_gl_context->GetBackBufferWidth(); + m_backbuffer_height = m_main_gl_context->GetBackBufferHeight(); } void Renderer::DrawEFB(GLuint framebuffer, const TargetRectangle& target_rc, @@ -1538,7 +1541,7 @@ void Renderer::ResetAPIState() glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_BLEND); - if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL) + if (!IsGLES()) glDisable(GL_COLOR_LOGIC_OP); if (g_ActiveConfig.backend_info.bSupportsDepthClamp) { @@ -1717,4 +1720,4 @@ std::unique_ptr<VideoCommon::AsyncShaderCompiler> Renderer::CreateAsyncShaderCom { return std::make_unique<SharedContextAsyncShaderCompiler>(); } -} +} // namespace OGL diff --git a/Source/Core/VideoBackends/OGL/Render.h b/Source/Core/VideoBackends/OGL/Render.h index c27c06308c..5beb4ecd75 100644 --- a/Source/Core/VideoBackends/OGL/Render.h +++ b/Source/Core/VideoBackends/OGL/Render.h @@ -7,7 +7,8 @@ #include <array> #include <string> -#include "Common/GL/GLUtil.h" +#include "Common/GL/GLContext.h" +#include "Common/GL/GLExtensions/GLExtensions.h" #include "VideoCommon/RenderBase.h" struct XFBSourceBase; @@ -81,9 +82,11 @@ extern VideoConfig g_ogl_config; class Renderer : public ::Renderer { public: - Renderer(); + Renderer(std::unique_ptr<GLContext> main_gl_context); ~Renderer() override; + bool IsHeadless() const override; + void Init(); void Shutdown() override; @@ -141,6 +144,10 @@ public: std::unique_ptr<VideoCommon::AsyncShaderCompiler> CreateAsyncShaderCompiler() override; + // Only call methods from this on the GPU thread. + GLContext* GetMainGLContext() const { return m_main_gl_context.get(); } + bool IsGLES() const { return m_main_gl_context->IsGLES(); } + private: void UpdateEFBCache(EFBAccessType type, u32 cacheRectIdx, const EFBRectangle& efbPixelRc, const TargetRectangle& targetPixelRc, const void* data); @@ -159,10 +166,11 @@ private: void ApplyDepthState(const DepthState state, bool force = false); void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size); + std::unique_ptr<GLContext> m_main_gl_context; std::array<const AbstractTexture*, 8> m_bound_textures{}; const OGLPipeline* m_graphics_pipeline = nullptr; RasterizationState m_current_rasterization_state = {}; DepthState m_current_depth_state = {}; BlendingState m_current_blend_state = {}; }; -} +} // namespace OGL diff --git a/Source/Core/VideoBackends/OGL/SamplerCache.cpp b/Source/Core/VideoBackends/OGL/SamplerCache.cpp index 32be0ac4d9..364ec51c99 100644 --- a/Source/Core/VideoBackends/OGL/SamplerCache.cpp +++ b/Source/Core/VideoBackends/OGL/SamplerCache.cpp @@ -3,11 +3,11 @@ // Refer to the license.txt file included. #include "VideoBackends/OGL/SamplerCache.h" +#include "VideoBackends/OGL/Render.h" #include <memory> #include "Common/CommonTypes.h" -#include "Common/GL/GLInterfaceBase.h" #include "VideoCommon/SamplerCommon.h" #include "VideoCommon/VideoConfig.h" @@ -99,7 +99,7 @@ void SamplerCache::SetParameters(GLuint sampler_id, const SamplerState& params) glSamplerParameterf(sampler_id, GL_TEXTURE_MIN_LOD, params.min_lod / 16.f); glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_LOD, params.max_lod / 16.f); - if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL) + if (!static_cast<Renderer*>(g_renderer.get())->IsGLES()) glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, params.lod_bias / 256.f); if (params.anisotropic_filtering && g_ogl_config.bSupportsAniso) @@ -117,4 +117,4 @@ void SamplerCache::Clear() p.second = 0; m_cache.clear(); } -} +} // namespace OGL diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 95a3d30e1a..10f191448e 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -10,7 +10,6 @@ #include <vector> #include "Common/Assert.h" -#include "Common/GL/GLInterfaceBase.h" #include "Common/MsgHandler.h" #include "Common/StringUtil.h" diff --git a/Source/Core/VideoBackends/OGL/VideoBackend.h b/Source/Core/VideoBackends/OGL/VideoBackend.h index 1bb4cb3af1..74bc929e85 100644 --- a/Source/Core/VideoBackends/OGL/VideoBackend.h +++ b/Source/Core/VideoBackends/OGL/VideoBackend.h @@ -7,11 +7,13 @@ #include <string> #include "VideoCommon/VideoBackendBase.h" +class GLContext; + namespace OGL { class VideoBackend : public VideoBackendBase { - bool Initialize(void*) override; + bool Initialize(const WindowSystemInfo& wsi) override; void Shutdown() override; std::string GetName() const override; @@ -20,7 +22,7 @@ class VideoBackend : public VideoBackendBase void InitBackendInfo() override; private: - bool InitializeGLExtensions(); + bool InitializeGLExtensions(GLContext* context); bool FillBackendInfo(); }; -} +} // namespace OGL diff --git a/Source/Core/VideoBackends/OGL/main.cpp b/Source/Core/VideoBackends/OGL/main.cpp index d2e37f07a9..bc67b716cc 100644 --- a/Source/Core/VideoBackends/OGL/main.cpp +++ b/Source/Core/VideoBackends/OGL/main.cpp @@ -39,10 +39,12 @@ Make AA apply instantly during gameplay if possible #include <vector> #include "Common/Common.h" -#include "Common/GL/GLInterfaceBase.h" +#include "Common/GL/GLContext.h" #include "Common/GL/GLUtil.h" #include "Common/MsgHandler.h" +#include "Core/Config/GraphicsSettings.h" + #include "VideoBackends/OGL/BoundingBox.h" #include "VideoBackends/OGL/PerfQuery.h" #include "VideoBackends/OGL/ProgramShaderCache.h" @@ -66,7 +68,7 @@ std::string VideoBackend::GetName() const std::string VideoBackend::GetDisplayName() const { - if (GLInterface != nullptr && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3) + if (g_renderer && static_cast<Renderer*>(g_renderer.get())->IsGLES()) return _trans("OpenGL ES"); else return _trans("OpenGL"); @@ -108,10 +110,10 @@ void VideoBackend::InitBackendInfo() g_Config.backend_info.AAModes = {1, 2, 4, 8}; } -bool VideoBackend::InitializeGLExtensions() +bool VideoBackend::InitializeGLExtensions(GLContext* context) { // Init extension support. - if (!GLExtensions::Init()) + if (!GLExtensions::Init(context)) { // OpenGL 2.0 is required for all shader based drawings. There is no way to get this by // extensions @@ -157,20 +159,20 @@ bool VideoBackend::FillBackendInfo() return true; } -bool VideoBackend::Initialize(void* window_handle) +bool VideoBackend::Initialize(const WindowSystemInfo& wsi) { InitializeShared(); - GLUtil::InitInterface(); - GLInterface->SetMode(GLInterfaceMode::MODE_DETECT); - if (!GLInterface->Create(window_handle, g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer)) + std::unique_ptr<GLContext> main_gl_context = + GLContext::Create(wsi, g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer, true, false, + Config::Get(Config::GFX_PREFER_GLES)); + if (!main_gl_context) return false; - GLInterface->MakeCurrent(); - if (!InitializeGLExtensions() || !FillBackendInfo()) + if (!InitializeGLExtensions(main_gl_context.get()) || !FillBackendInfo()) return false; - g_renderer = std::make_unique<Renderer>(); + g_renderer = std::make_unique<Renderer>(std::move(main_gl_context)); g_vertex_manager = std::make_unique<VertexManager>(); g_perf_query = GetPerfQuery(); ProgramShaderCache::Init(); @@ -196,9 +198,6 @@ void VideoBackend::Shutdown() g_perf_query.reset(); g_vertex_manager.reset(); g_renderer.reset(); - GLInterface->ClearCurrent(); - GLInterface->Shutdown(); - GLInterface.reset(); ShutdownShared(); } -} +} // namespace OGL |
