2018-10-03 13:02:45 +00:00
|
|
|
// 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"
|
2018-10-14 13:17:31 +00:00
|
|
|
#endif
|
|
|
|
#if defined(WIN32)
|
2018-10-03 13:02:45 +00:00
|
|
|
#include "Common/GL/GLInterface/WGL.h"
|
2018-10-14 13:17:31 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_X11
|
2018-10-03 13:02:45 +00:00
|
|
|
#include "Common/GL/GLInterface/GLX.h"
|
2018-10-14 13:17:31 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_EGL
|
2018-10-03 13:02:45 +00:00
|
|
|
#include "Common/GL/GLInterface/EGL.h"
|
2018-10-14 13:17:31 +00:00
|
|
|
#if HAVE_X11
|
|
|
|
#include "Common/GL/GLInterface/EGLX11.h"
|
|
|
|
#endif
|
|
|
|
#if defined(ANDROID)
|
|
|
|
#include "Common/GL/GLInterface/EGLAndroid.h"
|
|
|
|
#endif
|
2018-10-03 13:02:45 +00:00
|
|
|
#endif
|
|
|
|
|
2018-10-14 13:32:50 +00:00
|
|
|
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}}};
|
|
|
|
|
2018-10-03 13:02:45 +00:00
|
|
|
GLContext::~GLContext() = default;
|
|
|
|
|
2019-04-10 14:40:19 +00:00
|
|
|
bool GLContext::Initialize(const WindowSystemInfo& wsi, bool stereo, bool core)
|
2018-10-03 13:02:45 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:03:36 +00:00
|
|
|
std::unique_ptr<GLContext> GLContext::Create(const WindowSystemInfo& wsi, bool stereo, bool core,
|
|
|
|
bool prefer_egl, bool prefer_gles)
|
2018-10-03 13:02:45 +00:00
|
|
|
{
|
|
|
|
std::unique_ptr<GLContext> context;
|
|
|
|
#if defined(__APPLE__)
|
2018-10-14 13:17:31 +00:00
|
|
|
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)
|
|
|
|
{
|
2020-03-23 06:24:27 +00:00
|
|
|
#if defined(HAVE_EGL)
|
2018-10-14 13:17:31 +00:00
|
|
|
// GLES 3 is not supported via GLX.
|
|
|
|
const bool use_egl = prefer_egl || prefer_gles;
|
|
|
|
if (use_egl)
|
|
|
|
context = std::make_unique<GLContextEGLX11>();
|
|
|
|
else
|
|
|
|
context = std::make_unique<GLContextGLX>();
|
2018-10-03 13:02:45 +00:00
|
|
|
#else
|
2018-10-14 13:17:31 +00:00
|
|
|
context = std::make_unique<GLContextGLX>();
|
2018-10-03 13:02:45 +00:00
|
|
|
#endif
|
2018-10-14 13:17:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if HAVE_EGL
|
2019-04-10 14:44:21 +00:00
|
|
|
if (wsi.type == WindowSystemType::Headless || wsi.type == WindowSystemType::FBDev)
|
2018-10-14 13:17:31 +00:00
|
|
|
context = std::make_unique<GLContextEGL>();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return nullptr;
|
2018-10-03 13:03:36 +00:00
|
|
|
|
|
|
|
// Option to prefer GLES on desktop platforms, useful for testing.
|
|
|
|
if (prefer_gles)
|
|
|
|
context->m_opengl_mode = Mode::OpenGLES;
|
|
|
|
|
2019-04-10 14:40:19 +00:00
|
|
|
if (!context->Initialize(wsi, stereo, core))
|
2018-10-03 13:02:45 +00:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|