mirror of https://github.com/PCSX2/pcsx2.git
Common: Make GL::Context::Create use gsl::span
This commit is contained in:
parent
074e90d046
commit
1ac081ef4c
|
@ -79,42 +79,41 @@ namespace GL
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<GL::Context> Context::Create(const WindowInfo& wi, const Version* versions_to_try,
|
std::unique_ptr<GL::Context> Context::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
|
||||||
size_t num_versions_to_try)
|
|
||||||
{
|
{
|
||||||
if (ShouldPreferESContext())
|
if (ShouldPreferESContext())
|
||||||
{
|
{
|
||||||
// move ES versions to the front
|
// move ES versions to the front
|
||||||
Version* new_versions_to_try = static_cast<Version*>(alloca(sizeof(Version) * num_versions_to_try));
|
Version* new_versions_to_try = static_cast<Version*>(alloca(sizeof(Version) * versions_to_try.size()));
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
for (size_t i = 0; i < num_versions_to_try; i++)
|
for (size_t i = 0; i < versions_to_try.size(); i++)
|
||||||
{
|
{
|
||||||
if (versions_to_try[i].profile == Profile::ES)
|
if (versions_to_try[i].profile == Profile::ES)
|
||||||
new_versions_to_try[count++] = versions_to_try[i];
|
new_versions_to_try[count++] = versions_to_try[i];
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < num_versions_to_try; i++)
|
for (size_t i = 0; i < versions_to_try.size(); i++)
|
||||||
{
|
{
|
||||||
if (versions_to_try[i].profile != Profile::ES)
|
if (versions_to_try[i].profile != Profile::ES)
|
||||||
new_versions_to_try[count++] = versions_to_try[i];
|
new_versions_to_try[count++] = versions_to_try[i];
|
||||||
}
|
}
|
||||||
versions_to_try = new_versions_to_try;
|
versions_to_try = gsl::span<const Version>(new_versions_to_try, versions_to_try.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Context> context;
|
std::unique_ptr<Context> context;
|
||||||
#if defined(_WIN32) && !defined(_M_ARM64)
|
#if defined(_WIN32) && !defined(_M_ARM64)
|
||||||
context = ContextWGL::Create(wi, versions_to_try, num_versions_to_try);
|
context = ContextWGL::Create(wi, versions_to_try);
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
context = ContextAGL::Create(wi, versions_to_try, num_versions_to_try);
|
context = ContextAGL::Create(wi, versions_to_try);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(X11_API)
|
#if defined(X11_API)
|
||||||
if (wi.type == WindowInfo::Type::X11)
|
if (wi.type == WindowInfo::Type::X11)
|
||||||
context = ContextEGLX11::Create(wi, versions_to_try, num_versions_to_try);
|
context = ContextEGLX11::Create(wi, versions_to_try);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WAYLAND_API)
|
#if defined(WAYLAND_API)
|
||||||
if (wi.type == WindowInfo::Type::Wayland)
|
if (wi.type == WindowInfo::Type::Wayland)
|
||||||
context = ContextEGLWayland::Create(wi, versions_to_try, num_versions_to_try);
|
context = ContextEGLWayland::Create(wi, versions_to_try);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!context)
|
if (!context)
|
||||||
|
@ -160,9 +159,10 @@ namespace GL
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::array<Context::Version, 16>& Context::GetAllVersionsList()
|
gsl::span<const Context::Version> Context::GetAllVersionsList()
|
||||||
{
|
{
|
||||||
static constexpr std::array<Version, 16> vlist = {{{Profile::Core, 4, 6},
|
static constexpr Version vlist[] = {
|
||||||
|
{Profile::Core, 4, 6},
|
||||||
{Profile::Core, 4, 5},
|
{Profile::Core, 4, 5},
|
||||||
{Profile::Core, 4, 4},
|
{Profile::Core, 4, 4},
|
||||||
{Profile::Core, 4, 3},
|
{Profile::Core, 4, 3},
|
||||||
|
@ -177,7 +177,8 @@ namespace GL
|
||||||
{Profile::ES, 3, 1},
|
{Profile::ES, 3, 1},
|
||||||
{Profile::ES, 3, 0},
|
{Profile::ES, 3, 0},
|
||||||
{Profile::ES, 2, 0},
|
{Profile::ES, 2, 0},
|
||||||
{Profile::NoProfile, 0, 0}}};
|
{Profile::NoProfile, 0, 0}
|
||||||
|
};
|
||||||
return vlist;
|
return vlist;
|
||||||
}
|
}
|
||||||
} // namespace GL
|
} // namespace GL
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "common/Pcsx2Defs.h"
|
#include "common/Pcsx2Defs.h"
|
||||||
#include "common/WindowInfo.h"
|
#include "common/WindowInfo.h"
|
||||||
|
|
||||||
|
#include <gsl/span>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -66,18 +67,11 @@ namespace GL {
|
||||||
|
|
||||||
virtual std::vector<FullscreenModeInfo> EnumerateFullscreenModes();
|
virtual std::vector<FullscreenModeInfo> EnumerateFullscreenModes();
|
||||||
|
|
||||||
static std::unique_ptr<Context> Create(const WindowInfo& wi, const Version* versions_to_try,
|
static std::unique_ptr<Context> Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try);
|
||||||
size_t num_versions_to_try);
|
|
||||||
|
|
||||||
template<size_t N>
|
|
||||||
static std::unique_ptr<Context> Create(const WindowInfo& wi, const std::array<Version, N>& versions_to_try)
|
|
||||||
{
|
|
||||||
return Create(wi, versions_to_try.data(), versions_to_try.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::unique_ptr<Context> Create(const WindowInfo& wi) { return Create(wi, GetAllVersionsList()); }
|
static std::unique_ptr<Context> Create(const WindowInfo& wi) { return Create(wi, GetAllVersionsList()); }
|
||||||
|
|
||||||
static const std::array<Version, 16>& GetAllVersionsList();
|
static gsl::span<const Version> GetAllVersionsList();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
WindowInfo m_wi;
|
WindowInfo m_wi;
|
||||||
|
|
|
@ -33,8 +33,7 @@ namespace GL
|
||||||
ContextAGL(const WindowInfo& wi);
|
ContextAGL(const WindowInfo& wi);
|
||||||
~ContextAGL() override;
|
~ContextAGL() override;
|
||||||
|
|
||||||
static std::unique_ptr<Context> Create(const WindowInfo& wi, const Version* versions_to_try,
|
static std::unique_ptr<Context> Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try);
|
||||||
size_t num_versions_to_try);
|
|
||||||
|
|
||||||
void* GetProcAddress(const char* name) override;
|
void* GetProcAddress(const char* name) override;
|
||||||
bool ChangeSurface(const WindowInfo& new_wi) override;
|
bool ChangeSurface(const WindowInfo& new_wi) override;
|
||||||
|
@ -46,7 +45,7 @@ namespace GL
|
||||||
std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
|
std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Initialize(const Version* versions_to_try, size_t num_versions_to_try);
|
bool Initialize(gsl::span<const Version> versions_to_try);
|
||||||
bool CreateContext(NSOpenGLContext* share_context, int profile, bool make_current);
|
bool CreateContext(NSOpenGLContext* share_context, int profile, bool make_current);
|
||||||
void BindContextToView();
|
void BindContextToView();
|
||||||
void CleanupView();
|
void CleanupView();
|
||||||
|
|
|
@ -44,21 +44,19 @@ namespace GL
|
||||||
dlclose(m_opengl_module_handle);
|
dlclose(m_opengl_module_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Context> ContextAGL::Create(const WindowInfo& wi, const Version* versions_to_try,
|
std::unique_ptr<Context> ContextAGL::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
|
||||||
size_t num_versions_to_try)
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<ContextAGL> context = std::make_unique<ContextAGL>(wi);
|
std::unique_ptr<ContextAGL> context = std::make_unique<ContextAGL>(wi);
|
||||||
if (!context->Initialize(versions_to_try, num_versions_to_try))
|
if (!context->Initialize(versions_to_try))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContextAGL::Initialize(const Version* versions_to_try, size_t num_versions_to_try)
|
bool ContextAGL::Initialize(gsl::span<const Version> versions_to_try)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < num_versions_to_try; i++)
|
for (const Version& cv : versions_to_try)
|
||||||
{
|
{
|
||||||
const Version& cv = versions_to_try[i];
|
|
||||||
if (cv.profile == Profile::NoProfile && CreateContext(nullptr, NSOpenGLProfileVersionLegacy, true))
|
if (cv.profile == Profile::NoProfile && CreateContext(nullptr, NSOpenGLProfileVersionLegacy, true))
|
||||||
{
|
{
|
||||||
// we already have the dummy context, so just use that
|
// we already have the dummy context, so just use that
|
||||||
|
|
|
@ -35,17 +35,16 @@ namespace GL
|
||||||
DestroyContext();
|
DestroyContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Context> ContextEGL::Create(const WindowInfo& wi, const Version* versions_to_try,
|
std::unique_ptr<Context> ContextEGL::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
|
||||||
size_t num_versions_to_try)
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<ContextEGL> context = std::make_unique<ContextEGL>(wi);
|
std::unique_ptr<ContextEGL> context = std::make_unique<ContextEGL>(wi);
|
||||||
if (!context->Initialize(versions_to_try, num_versions_to_try))
|
if (!context->Initialize(versions_to_try))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContextEGL::Initialize(const Version* versions_to_try, size_t num_versions_to_try)
|
bool ContextEGL::Initialize(gsl::span<const Version> versions_to_try)
|
||||||
{
|
{
|
||||||
if (!gladLoadEGL())
|
if (!gladLoadEGL())
|
||||||
{
|
{
|
||||||
|
@ -73,9 +72,9 @@ namespace GL
|
||||||
if (!m_supports_surfaceless)
|
if (!m_supports_surfaceless)
|
||||||
Console.Warning("EGL implementation does not support surfaceless contexts, emulating with pbuffers");
|
Console.Warning("EGL implementation does not support surfaceless contexts, emulating with pbuffers");
|
||||||
|
|
||||||
for (size_t i = 0; i < num_versions_to_try; i++)
|
for (const Version& version : versions_to_try)
|
||||||
{
|
{
|
||||||
if (CreateContextAndSurface(versions_to_try[i], nullptr, true))
|
if (CreateContextAndSurface(version, nullptr, true))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,7 @@ namespace GL
|
||||||
ContextEGL(const WindowInfo& wi);
|
ContextEGL(const WindowInfo& wi);
|
||||||
~ContextEGL() override;
|
~ContextEGL() override;
|
||||||
|
|
||||||
static std::unique_ptr<Context> Create(const WindowInfo& wi, const Version* versions_to_try,
|
static std::unique_ptr<Context> Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try);
|
||||||
size_t num_versions_to_try);
|
|
||||||
|
|
||||||
void* GetProcAddress(const char* name) override;
|
void* GetProcAddress(const char* name) override;
|
||||||
virtual bool ChangeSurface(const WindowInfo& new_wi) override;
|
virtual bool ChangeSurface(const WindowInfo& new_wi) override;
|
||||||
|
@ -42,7 +41,7 @@ namespace GL
|
||||||
virtual bool SetDisplay();
|
virtual bool SetDisplay();
|
||||||
virtual EGLNativeWindowType GetNativeWindow(EGLConfig config);
|
virtual EGLNativeWindowType GetNativeWindow(EGLConfig config);
|
||||||
|
|
||||||
bool Initialize(const Version* versions_to_try, size_t num_versions_to_try);
|
bool Initialize(gsl::span<const Version> versions_to_try);
|
||||||
bool CreateDisplay();
|
bool CreateDisplay();
|
||||||
bool CreateContext(const Version& version, EGLContext share_context);
|
bool CreateContext(const Version& version, EGLContext share_context);
|
||||||
bool CreateContextAndSurface(const Version& version, EGLContext share_context, bool make_current);
|
bool CreateContextAndSurface(const Version& version, EGLContext share_context, bool make_current);
|
||||||
|
|
|
@ -37,11 +37,10 @@ namespace GL
|
||||||
dlclose(m_wl_module);
|
dlclose(m_wl_module);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Context> ContextEGLWayland::Create(const WindowInfo& wi, const Version* versions_to_try,
|
std::unique_ptr<Context> ContextEGLWayland::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
|
||||||
size_t num_versions_to_try)
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<ContextEGLWayland> context = std::make_unique<ContextEGLWayland>(wi);
|
std::unique_ptr<ContextEGLWayland> context = std::make_unique<ContextEGLWayland>(wi);
|
||||||
if (!context->LoadModule() || !context->Initialize(versions_to_try, num_versions_to_try))
|
if (!context->LoadModule() || !context->Initialize(versions_to_try))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
|
|
@ -28,8 +28,7 @@ namespace GL
|
||||||
ContextEGLWayland(const WindowInfo& wi);
|
ContextEGLWayland(const WindowInfo& wi);
|
||||||
~ContextEGLWayland() override;
|
~ContextEGLWayland() override;
|
||||||
|
|
||||||
static std::unique_ptr<Context> Create(const WindowInfo& wi, const Version* versions_to_try,
|
static std::unique_ptr<Context> Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try);
|
||||||
size_t num_versions_to_try);
|
|
||||||
|
|
||||||
std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
|
std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
|
||||||
void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
|
void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
|
||||||
|
|
|
@ -27,11 +27,10 @@ namespace GL
|
||||||
}
|
}
|
||||||
ContextEGLX11::~ContextEGLX11() = default;
|
ContextEGLX11::~ContextEGLX11() = default;
|
||||||
|
|
||||||
std::unique_ptr<Context> ContextEGLX11::Create(const WindowInfo& wi, const Version* versions_to_try,
|
std::unique_ptr<Context> ContextEGLX11::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
|
||||||
size_t num_versions_to_try)
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<ContextEGLX11> context = std::make_unique<ContextEGLX11>(wi);
|
std::unique_ptr<ContextEGLX11> context = std::make_unique<ContextEGLX11>(wi);
|
||||||
if (!context->Initialize(versions_to_try, num_versions_to_try))
|
if (!context->Initialize(versions_to_try))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
|
|
@ -25,8 +25,7 @@ namespace GL
|
||||||
ContextEGLX11(const WindowInfo& wi);
|
ContextEGLX11(const WindowInfo& wi);
|
||||||
~ContextEGLX11() override;
|
~ContextEGLX11() override;
|
||||||
|
|
||||||
static std::unique_ptr<Context> Create(const WindowInfo& wi, const Version* versions_to_try,
|
static std::unique_ptr<Context> Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try);
|
||||||
size_t num_versions_to_try);
|
|
||||||
|
|
||||||
std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
|
std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
|
||||||
void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
|
void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
|
||||||
|
|
|
@ -46,17 +46,16 @@ namespace GL
|
||||||
ReleaseDC();
|
ReleaseDC();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Context> ContextWGL::Create(const WindowInfo& wi, const Version* versions_to_try,
|
std::unique_ptr<Context> ContextWGL::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
|
||||||
size_t num_versions_to_try)
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<ContextWGL> context = std::make_unique<ContextWGL>(wi);
|
std::unique_ptr<ContextWGL> context = std::make_unique<ContextWGL>(wi);
|
||||||
if (!context->Initialize(versions_to_try, num_versions_to_try))
|
if (!context->Initialize(versions_to_try))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContextWGL::Initialize(const Version* versions_to_try, size_t num_versions_to_try)
|
bool ContextWGL::Initialize(gsl::span<const Version> versions_to_try)
|
||||||
{
|
{
|
||||||
if (m_wi.type == WindowInfo::Type::Win32)
|
if (m_wi.type == WindowInfo::Type::Win32)
|
||||||
{
|
{
|
||||||
|
@ -73,9 +72,8 @@ namespace GL
|
||||||
if (!CreateAnyContext(nullptr, true))
|
if (!CreateAnyContext(nullptr, true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (size_t i = 0; i < num_versions_to_try; i++)
|
for (const Version& cv : versions_to_try)
|
||||||
{
|
{
|
||||||
const Version& cv = versions_to_try[i];
|
|
||||||
if (cv.profile == Profile::NoProfile)
|
if (cv.profile == Profile::NoProfile)
|
||||||
{
|
{
|
||||||
// we already have the dummy context, so just use that
|
// we already have the dummy context, so just use that
|
||||||
|
|
|
@ -34,8 +34,7 @@ namespace GL
|
||||||
ContextWGL(const WindowInfo& wi);
|
ContextWGL(const WindowInfo& wi);
|
||||||
~ContextWGL() override;
|
~ContextWGL() override;
|
||||||
|
|
||||||
static std::unique_ptr<Context> Create(const WindowInfo& wi, const Version* versions_to_try,
|
static std::unique_ptr<Context> Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try);
|
||||||
size_t num_versions_to_try);
|
|
||||||
|
|
||||||
void* GetProcAddress(const char* name) override;
|
void* GetProcAddress(const char* name) override;
|
||||||
bool ChangeSurface(const WindowInfo& new_wi) override;
|
bool ChangeSurface(const WindowInfo& new_wi) override;
|
||||||
|
@ -51,7 +50,7 @@ namespace GL
|
||||||
|
|
||||||
HDC GetDCAndSetPixelFormat(HWND hwnd);
|
HDC GetDCAndSetPixelFormat(HWND hwnd);
|
||||||
|
|
||||||
bool Initialize(const Version* versions_to_try, size_t num_versions_to_try);
|
bool Initialize(gsl::span<const Version> versions_to_try);
|
||||||
bool InitializeDC();
|
bool InitializeDC();
|
||||||
void ReleaseDC();
|
void ReleaseDC();
|
||||||
bool CreatePBuffer();
|
bool CreatePBuffer();
|
||||||
|
|
Loading…
Reference in New Issue