| 1 | // Copyright 2014 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "Common/GL/GLContext.h" |
| 7 | |
| 8 | #if defined(__APPLE__) |
| 9 | #include "Common/GL/GLInterface/AGL.h" |
| 10 | #endif |
| 11 | #if defined(_WIN32) |
| 12 | #include "Common/GL/GLInterface/WGL.h" |
| 13 | #endif |
| 14 | #if defined(__HAIKU__) |
| 15 | #include "Common/GL/GLInterface/BGL.h" |
| 16 | #endif |
| 17 | #if HAVE_EGL |
| 18 | #include "Common/GL/GLInterface/EGL.h" |
| 19 | #if HAVE_X11 |
| 20 | #include "Common/GL/GLInterface/EGLX11.h" |
| 21 | #endif |
| 22 | #if defined(ANDROID) |
| 23 | #include "Common/GL/GLInterface/EGLAndroid.h" |
| 24 | #endif |
| 25 | #endif |
| 26 | |
| 27 | const std::array<std::pair<int, int>, 9> GLContext::s_desktop_opengl_versions = { |
| 28 | {{4, 6}, {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, {3, 3}, {3, 2}}}; |
| 29 | |
| 30 | GLContext::~GLContext() = default; |
| 31 | |
| 32 | bool GLContext::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core) |
| 33 | { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | bool GLContext::IsHeadless() const |
| 38 | { |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | std::unique_ptr<GLContext> GLContext::CreateSharedContext() |
| 43 | { |
| 44 | return nullptr; |
| 45 | } |
| 46 | |
| 47 | bool GLContext::MakeCurrent() |
| 48 | { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | bool GLContext::ClearCurrent() |
| 53 | { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | void GLContext::Update() |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | void GLContext::UpdateSurface(void* window_handle) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | void GLContext::Swap() |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | void GLContext::SwapInterval(int interval) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | void* GLContext::GetFuncAddress(const std::string& name) |
| 74 | { |
| 75 | return nullptr; |
| 76 | } |
| 77 | |
| 78 | std::unique_ptr<GLContext> GLContext::Create(const WindowSystemInfo& wsi, bool stereo, bool core, |
| 79 | bool prefer_gles) |
| 80 | { |
| 81 | std::unique_ptr<GLContext> context; |
| 82 | #if defined(__APPLE__) |
| 83 | if (wsi.type == WindowSystemType::MacOS || wsi.type == WindowSystemType::Headless) |
| 84 | context = std::make_unique<GLContextAGL>(); |
| 85 | #endif |
| 86 | #if defined(_WIN32) |
| 87 | if (wsi.type == WindowSystemType::Windows) |
| 88 | context = std::make_unique<GLContextWGL>(); |
| 89 | #endif |
| 90 | #if defined(ANDROID) |
| 91 | if (wsi.type == WindowSystemType::Android) |
| 92 | context = std::make_unique<GLContextEGLAndroid>(); |
| 93 | #endif |
| 94 | #if defined(__HAIKU__) |
| 95 | if (wsi.type == WindowSystemType::Haiku) |
| 96 | context = std::make_unique<GLContextBGL>(); |
| 97 | #endif |
| 98 | #if HAVE_EGL |
| 99 | #if HAVE_X11 |
| 100 | if (wsi.type == WindowSystemType::X11) |
| 101 | context = std::make_unique<GLContextEGLX11>(); |
| 102 | #endif |
| 103 | if (wsi.type == WindowSystemType::Headless || wsi.type == WindowSystemType::FBDev) |
| 104 | context = std::make_unique<GLContextEGL>(); |
| 105 | #endif |
| 106 | |
| 107 | if (!context) |
| 108 | return nullptr; |
| 109 | |
| 110 | // Option to prefer GLES on desktop platforms, useful for testing. |
| 111 | if (prefer_gles) |
| 112 | context->m_opengl_mode = Mode::OpenGLES; |
| 113 | |
| 114 | if (!context->Initialize(wsi, stereo, core)) |
| 115 | return nullptr; |
| 116 | |
| 117 | return context; |
| 118 | } |