GLContext: Remove global context pointer

This commit is contained in:
Stenzek
2018-10-03 23:03:26 +10:00
parent eb284b5d66
commit dcdd02d646
19 changed files with 183 additions and 150 deletions

View File

@ -353,9 +353,10 @@ static void InitDriverInfo()
}
// Init functions
Renderer::Renderer()
: ::Renderer(static_cast<int>(std::max(g_main_gl_context->GetBackBufferWidth(), 1u)),
static_cast<int>(std::max(g_main_gl_context->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 (!g_main_gl_context->IsGLES())
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 (g_main_gl_context->IsGLES())
if (m_main_gl_context->IsGLES())
{
g_ogl_config.SupportedESPointSize =
GLExtensions::Supports("GL_OES_geometry_point_size") ?
@ -731,7 +732,7 @@ Renderer::Renderer()
if (!g_ogl_config.bSupportsGLBufferStorage && !g_ogl_config.bSupportsGLPinnedMemory)
{
OSD::AddMessage(StringFromFormat("Your OpenGL driver does not support %s_buffer_storage.",
g_main_gl_context->IsGLES() ? "EXT" : "ARB"),
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);
@ -760,7 +761,7 @@ Renderer::Renderer()
// Handle VSync on/off
s_vsync = g_ActiveConfig.IsVSync();
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC))
g_main_gl_context->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
@ -795,18 +796,22 @@ Renderer::Renderer()
glClearDepthf(1.0f);
if (g_ActiveConfig.backend_info.bSupportsPrimitiveRestart)
GLUtil::EnablePrimitiveRestart();
GLUtil::EnablePrimitiveRestart(m_main_gl_context.get());
IndexGenerator::Init();
UpdateActiveConfig();
ClearEFBCache();
}
Renderer::~Renderer() = default;
Renderer::~Renderer()
{
m_main_gl_context->ClearCurrent();
m_main_gl_context->Shutdown();
}
bool Renderer::IsHeadless() const
{
return g_main_gl_context->IsHeadless();
return m_main_gl_context->IsHeadless();
}
void Renderer::Shutdown()
@ -1048,7 +1053,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
std::unique_ptr<u32[]> colorMap(new u32[targetPixelRcWidth * targetPixelRcHeight]);
if (g_main_gl_context->IsGLES())
if (IsGLES())
// XXX: Swap colours
glReadPixels(targetPixelRc.left, targetPixelRc.bottom, targetPixelRcWidth,
targetPixelRcHeight, GL_RGBA, GL_UNSIGNED_BYTE, colorMap.get());
@ -1355,7 +1360,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 (g_main_gl_context->IsGLES())
if (IsGLES())
{
// Logic ops aren't available in GLES3
}
@ -1425,7 +1430,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
OSD::DrawMessages();
// Swap the back and front buffers, presenting the image.
g_main_gl_context->Swap();
m_main_gl_context->Swap();
}
else
{
@ -1470,7 +1475,7 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
{
s_vsync = g_ActiveConfig.IsVSync();
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC))
g_main_gl_context->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.
@ -1504,12 +1509,12 @@ void Renderer::CheckForSurfaceChange()
if (!m_surface_changed.TestAndClear())
return;
g_main_gl_context->UpdateSurface(m_new_surface_handle);
m_main_gl_context->UpdateSurface(m_new_surface_handle);
m_new_surface_handle = nullptr;
// With a surface change, the window likely has new dimensions.
m_backbuffer_width = g_main_gl_context->GetBackBufferWidth();
m_backbuffer_height = g_main_gl_context->GetBackBufferHeight();
m_backbuffer_width = m_main_gl_context->GetBackBufferWidth();
m_backbuffer_height = m_main_gl_context->GetBackBufferHeight();
}
void Renderer::CheckForSurfaceResize()
@ -1517,9 +1522,9 @@ void Renderer::CheckForSurfaceResize()
if (!m_surface_resized.TestAndClear())
return;
g_main_gl_context->Update();
m_backbuffer_width = g_main_gl_context->GetBackBufferWidth();
m_backbuffer_height = g_main_gl_context->GetBackBufferHeight();
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,
@ -1540,7 +1545,7 @@ void Renderer::ResetAPIState()
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
if (!g_main_gl_context->IsGLES())
if (!IsGLES())
glDisable(GL_COLOR_LOGIC_OP);
if (g_ActiveConfig.backend_info.bSupportsDepthClamp)
{