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/Software/SWOGLWindow.cpp | |
| 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/Software/SWOGLWindow.cpp')
| -rw-r--r-- | Source/Core/VideoBackends/Software/SWOGLWindow.cpp | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/Source/Core/VideoBackends/Software/SWOGLWindow.cpp b/Source/Core/VideoBackends/Software/SWOGLWindow.cpp index 695f58cc1d..81216ff7ef 100644 --- a/Source/Core/VideoBackends/Software/SWOGLWindow.cpp +++ b/Source/Core/VideoBackends/Software/SWOGLWindow.cpp @@ -4,52 +4,51 @@ #include <memory> -#include "Common/GL/GLInterfaceBase.h" +#include "Common/GL/GLContext.h" #include "Common/GL/GLUtil.h" #include "Common/Logging/Log.h" +#include "Common/MsgHandler.h" #include "VideoBackends/Software/SWOGLWindow.h" #include "VideoBackends/Software/SWTexture.h" -std::unique_ptr<SWOGLWindow> SWOGLWindow::s_instance; +SWOGLWindow::SWOGLWindow() = default; +SWOGLWindow::~SWOGLWindow() = default; -void SWOGLWindow::Init(void* window_handle) +std::unique_ptr<SWOGLWindow> SWOGLWindow::Create(const WindowSystemInfo& wsi) { - GLUtil::InitInterface(); - GLInterface->SetMode(GLInterfaceMode::MODE_DETECT); - if (!GLInterface->Create(window_handle)) + std::unique_ptr<SWOGLWindow> window = std::unique_ptr<SWOGLWindow>(new SWOGLWindow()); + if (!window->Initialize(wsi)) { - ERROR_LOG(VIDEO, "GLInterface::Create failed."); + PanicAlert("Failed to create OpenGL window"); + return nullptr; } - s_instance.reset(new SWOGLWindow()); + return window; } -void SWOGLWindow::Shutdown() +bool SWOGLWindow::IsHeadless() const { - GLInterface->Shutdown(); - GLInterface.reset(); - - s_instance.reset(); + return m_gl_context->IsHeadless(); } -void SWOGLWindow::Prepare() +bool SWOGLWindow::Initialize(const WindowSystemInfo& wsi) { - if (m_init) - return; - m_init = true; + m_gl_context = GLContext::Create(wsi); + if (!m_gl_context) + return false; // Init extension support. - if (!GLExtensions::Init()) + if (!GLExtensions::Init(m_gl_context.get())) { ERROR_LOG(VIDEO, "GLExtensions::Init failed!Does your video card support OpenGL 2.0?"); - return; + return false; } else if (GLExtensions::Version() < 310) { ERROR_LOG(VIDEO, "OpenGL Version %d detected, but at least 3.1 is required.", GLExtensions::Version()); - return; + return false; } std::string frag_shader = "in vec2 TexCoord;\n" @@ -66,10 +65,9 @@ void SWOGLWindow::Prepare() " TexCoord = vec2(rawpos.x, -rawpos.y);\n" "}\n"; - std::string header = GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL ? - "#version 140\n" : - "#version 300 es\n" - "precision highp float;\n"; + std::string header = m_gl_context->IsGLES() ? "#version 300 es\n" + "precision highp float;\n" : + "#version 140\n"; m_image_program = GLUtil::CompileProgram(header + vertex_shader, header + frag_shader); @@ -83,6 +81,7 @@ void SWOGLWindow::Prepare() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glGenVertexArrays(1, &m_image_vao); + return true; } void SWOGLWindow::PrintText(const std::string& text, int x, int y, u32 color) @@ -93,10 +92,10 @@ void SWOGLWindow::PrintText(const std::string& text, int x, int y, u32 color) void SWOGLWindow::ShowImage(AbstractTexture* image, const EFBRectangle& xfb_region) { SW::SWTexture* sw_image = static_cast<SW::SWTexture*>(image); - GLInterface->Update(); // just updates the render window position and the backbuffer size + m_gl_context->Update(); // just updates the render window position and the backbuffer size - GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth(); - GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight(); + GLsizei glWidth = (GLsizei)m_gl_context->GetBackBufferWidth(); + GLsizei glHeight = (GLsizei)m_gl_context->GetBackBufferHeight(); glViewport(0, 0, glWidth, glHeight); @@ -123,10 +122,5 @@ void SWOGLWindow::ShowImage(AbstractTexture* image, const EFBRectangle& xfb_regi // } m_text.clear(); - GLInterface->Swap(); -} - -int SWOGLWindow::PeekMessages() -{ - return GLInterface->PeekMessages(); + m_gl_context->Swap(); } |
