Refactoring and cleanup of GLInterface (now GLContext)

This commit is contained in:
Stenzek
2018-10-03 23:02:45 +10:00
parent 74b82bab3b
commit 134d967be2
39 changed files with 741 additions and 690 deletions

View File

@ -9,7 +9,7 @@
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/GL/GLInterfaceBase.h"
#include "Common/GL/GLContext.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
@ -414,7 +414,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 (!g_main_gl_context->IsGLES())
glEnable(GL_PROGRAM_POINT_SIZE);
}

View File

@ -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"

View File

@ -6,7 +6,7 @@
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/GL/GLInterfaceBase.h"
#include "Common/GL/GLContext.h"
#include "Common/GL/GLUtil.h"
#include "VideoBackends/OGL/PerfQuery.h"
@ -17,11 +17,10 @@ namespace OGL
{
std::unique_ptr<PerfQueryBase> GetPerfQuery()
{
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3 &&
GLExtensions::Supports("GL_NV_occlusion_query_samples"))
if (g_main_gl_context->IsGLES() && GLExtensions::Supports("GL_NV_occlusion_query_samples"))
return std::make_unique<PerfQueryGLESNV>();
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
if (g_main_gl_context->IsGLES())
return std::make_unique<PerfQueryGL>(GL_ANY_SAMPLES_PASSED);
return std::make_unique<PerfQueryGL>(GL_SAMPLES_PASSED);
@ -266,4 +265,4 @@ void PerfQueryGLESNV::FlushResults()
FlushOne();
}
} // namespace
} // namespace OGL

View File

@ -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,7 @@ void ProgramShaderCache::CreateHeader()
bool SharedContextAsyncShaderCompiler::WorkerThreadInitMainThread(void** param)
{
std::unique_ptr<cInterfaceBase> context = GLInterface->CreateSharedContext();
std::unique_ptr<GLContext> context = g_main_gl_context->CreateSharedContext();
if (!context)
{
PanicAlert("Failed to create shared context for shader compiling.");
@ -818,7 +818,7 @@ 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;
@ -831,7 +831,7 @@ bool SharedContextAsyncShaderCompiler::WorkerThreadInitWorkerThread(void* param)
void SharedContextAsyncShaderCompiler::WorkerThreadExit(void* param)
{
cInterfaceBase* context = static_cast<cInterfaceBase*>(param);
GLContext* context = static_cast<GLContext*>(param);
context->ClearCurrent();
delete context;
}

View File

@ -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"
@ -354,8 +354,8 @@ 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(static_cast<int>(std::max(g_main_gl_context->GetBackBufferWidth(), 1u)),
static_cast<int>(std::max(g_main_gl_context->GetBackBufferHeight(), 1u)))
{
bool bSuccess = true;
@ -365,7 +365,7 @@ Renderer::Renderer()
InitDriverInfo();
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
if (!g_main_gl_context->IsGLES())
{
if (!GLExtensions::Supports("GL_ARB_framebuffer_object"))
{
@ -500,7 +500,7 @@ Renderer::Renderer()
g_Config.backend_info.bSupportsBPTCTextures =
GLExtensions::Supports("GL_ARB_texture_compression_bptc");
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
if (g_main_gl_context->IsGLES())
{
g_ogl_config.SupportedESPointSize =
GLExtensions::Supports("GL_OES_geometry_point_size") ?
@ -730,10 +730,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.",
g_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 +760,7 @@ Renderer::Renderer()
// Handle VSync on/off
s_vsync = g_ActiveConfig.IsVSync();
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC))
GLInterface->SwapInterval(s_vsync);
g_main_gl_context->SwapInterval(s_vsync);
// Because of the fixed framebuffer size we need to disable the resolution
// options while running
@ -1044,7 +1043,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 (g_main_gl_context->IsGLES())
// XXX: Swap colours
glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth,
targetPixelRcHeight, GL_RGBA, GL_UNSIGNED_BYTE, colorMap.get());
@ -1351,7 +1350,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 (g_main_gl_context->IsGLES())
{
// Logic ops aren't available in GLES3
}
@ -1421,7 +1420,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
OSD::DrawMessages();
// Swap the back and front buffers, presenting the image.
GLInterface->Swap();
g_main_gl_context->Swap();
}
else
{
@ -1466,7 +1465,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);
g_main_gl_context->SwapInterval(s_vsync);
}
// Clean out old stuff from caches. It's not worth it to clean out the shader caches.
@ -1502,12 +1501,11 @@ void Renderer::CheckForSurfaceChange()
m_surface_handle = m_new_surface_handle;
m_new_surface_handle = nullptr;
GLInterface->UpdateHandle(m_surface_handle);
GLInterface->UpdateSurface();
g_main_gl_context->UpdateSurface(m_surface_handle);
// With a surface change, the window likely has new dimensions.
m_backbuffer_width = GLInterface->GetBackBufferWidth();
m_backbuffer_height = GLInterface->GetBackBufferHeight();
m_backbuffer_width = g_main_gl_context->GetBackBufferWidth();
m_backbuffer_height = g_main_gl_context->GetBackBufferHeight();
}
void Renderer::CheckForSurfaceResize()
@ -1515,7 +1513,7 @@ void Renderer::CheckForSurfaceResize()
if (!m_surface_resized.TestAndClear())
return;
GLInterface->Update();
g_main_gl_context->Update();
m_backbuffer_width = m_new_backbuffer_width;
m_backbuffer_height = m_new_backbuffer_height;
}
@ -1538,7 +1536,7 @@ void Renderer::ResetAPIState()
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
if (!g_main_gl_context->IsGLES())
glDisable(GL_COLOR_LOGIC_OP);
if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
{
@ -1717,4 +1715,4 @@ std::unique_ptr<VideoCommon::AsyncShaderCompiler> Renderer::CreateAsyncShaderCom
{
return std::make_unique<SharedContextAsyncShaderCompiler>();
}
}
} // namespace OGL

View File

@ -7,7 +7,7 @@
#include <memory>
#include "Common/CommonTypes.h"
#include "Common/GL/GLInterfaceBase.h"
#include "Common/GL/GLContext.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 (!g_main_gl_context->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

View File

@ -10,7 +10,6 @@
#include <vector>
#include "Common/Assert.h"
#include "Common/GL/GLInterfaceBase.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"

View File

@ -39,7 +39,7 @@ 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"
@ -66,7 +66,7 @@ std::string VideoBackend::GetName() const
std::string VideoBackend::GetDisplayName() const
{
if (GLInterface != nullptr && GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
if (g_main_gl_context && g_main_gl_context->GetMode() == GLContext::Mode::OpenGLES)
return _trans("OpenGL ES");
else
return _trans("OpenGL");
@ -161,12 +161,12 @@ bool VideoBackend::Initialize(void* window_handle)
{
InitializeShared();
GLUtil::InitInterface();
GLInterface->SetMode(GLInterfaceMode::MODE_DETECT);
if (!GLInterface->Create(window_handle, g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer))
g_main_gl_context =
GLContext::Create(window_handle, g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer);
if (!g_main_gl_context)
return false;
GLInterface->MakeCurrent();
g_main_gl_context->MakeCurrent();
if (!InitializeGLExtensions() || !FillBackendInfo())
return false;
@ -196,9 +196,9 @@ void VideoBackend::Shutdown()
g_perf_query.reset();
g_vertex_manager.reset();
g_renderer.reset();
GLInterface->ClearCurrent();
GLInterface->Shutdown();
GLInterface.reset();
g_main_gl_context->ClearCurrent();
g_main_gl_context->Shutdown();
g_main_gl_context.reset();
ShutdownShared();
}
}
} // namespace OGL