summaryrefslogtreecommitdiff
path: root/Source/Core/Common/GL/GLContext.cpp
diff options
context:
space:
mode:
authorStenzek <stenzek@users.noreply.github.com>2018-10-24 14:51:21 +1100
committerGitHub <noreply@github.com>2018-10-24 14:51:21 +1100
commitc4d1e4adffcd380cc87b841069ce2fe8b62d7b60 (patch)
treec61a0a07c14ccc3c1f7247bdcc82927a82c145bb /Source/Core/Common/GL/GLContext.cpp
parent9c9d598ec006527bc47aea306e5171d03c12c5f5 (diff)
parent2c6d96433c322b50470705d43005fd6308506d49 (diff)
Merge pull request #7450 from stenzek/glcontext
GLInterface refactoring/cleanup and runtime platform selection
Diffstat (limited to 'Source/Core/Common/GL/GLContext.cpp')
-rw-r--r--Source/Core/Common/GL/GLContext.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/Source/Core/Common/GL/GLContext.cpp b/Source/Core/Common/GL/GLContext.cpp
new file mode 100644
index 0000000000..b02e27778f
--- /dev/null
+++ b/Source/Core/Common/GL/GLContext.cpp
@@ -0,0 +1,126 @@
+// Copyright 2014 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include <memory>
+
+#include "Common/GL/GLContext.h"
+
+#if defined(__APPLE__)
+#include "Common/GL/GLInterface/AGL.h"
+#endif
+#if defined(WIN32)
+#include "Common/GL/GLInterface/WGL.h"
+#endif
+#if HAVE_X11
+#include "Common/GL/GLInterface/GLX.h"
+#endif
+#if HAVE_EGL
+#include "Common/GL/GLInterface/EGL.h"
+#if HAVE_X11
+#include "Common/GL/GLInterface/EGLX11.h"
+#endif
+#if defined(ANDROID)
+#include "Common/GL/GLInterface/EGLAndroid.h"
+#endif
+#endif
+
+const std::array<std::pair<int, int>, 9> GLContext::s_desktop_opengl_versions = {
+ {{4, 6}, {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2}}};
+
+GLContext::~GLContext() = default;
+
+bool GLContext::Initialize(void* display_handle, void* window_handle, bool stereo, bool core)
+{
+ return false;
+}
+
+bool GLContext::IsHeadless() const
+{
+ return true;
+}
+
+std::unique_ptr<GLContext> GLContext::CreateSharedContext()
+{
+ return nullptr;
+}
+
+bool GLContext::MakeCurrent()
+{
+ return false;
+}
+
+bool GLContext::ClearCurrent()
+{
+ return false;
+}
+
+void GLContext::Update()
+{
+}
+
+void GLContext::UpdateSurface(void* window_handle)
+{
+}
+
+void GLContext::Swap()
+{
+}
+
+void GLContext::SwapInterval(int interval)
+{
+}
+
+void* GLContext::GetFuncAddress(const std::string& name)
+{
+ return nullptr;
+}
+
+std::unique_ptr<GLContext> GLContext::Create(const WindowSystemInfo& wsi, bool stereo, bool core,
+ bool prefer_egl, bool prefer_gles)
+{
+ std::unique_ptr<GLContext> context;
+#if defined(__APPLE__)
+ if (wsi.type == WindowSystemType::MacOS || wsi.type == WindowSystemType::Headless)
+ context = std::make_unique<GLContextAGL>();
+#endif
+#if defined(_WIN32)
+ if (wsi.type == WindowSystemType::Windows)
+ context = std::make_unique<GLContextWGL>();
+#endif
+#if defined(ANDROID)
+ if (wsi.type == WindowSystemType::Android)
+ context = std::make_unique<GLContextEGLAndroid>();
+#endif
+#if HAVE_X11
+ if (wsi.type == WindowSystemType::X11)
+ {
+ // GLES 3 is not supported via GLX.
+ const bool use_egl = prefer_egl || prefer_gles;
+#if defined(HAVE_EGL)
+ if (use_egl)
+ context = std::make_unique<GLContextEGLX11>();
+ else
+ context = std::make_unique<GLContextGLX>();
+#else
+ context = std::make_unique<GLContextGLX>();
+#endif
+ }
+#endif
+#if HAVE_EGL
+ if (wsi.type == WindowSystemType::Headless)
+ context = std::make_unique<GLContextEGL>();
+#endif
+
+ if (!context)
+ return nullptr;
+
+ // Option to prefer GLES on desktop platforms, useful for testing.
+ if (prefer_gles)
+ context->m_opengl_mode = Mode::OpenGLES;
+
+ if (!context->Initialize(wsi.display_connection, wsi.render_surface, stereo, core))
+ return nullptr;
+
+ return context;
+}