diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 60a087cd2..e34d7838c 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -1755,7 +1755,7 @@ static const char* s_log_filters[] = { #endif #ifdef ENABLE_OPENGL - "GL::Context", + "OpenGLContext", "OpenGLDevice", #endif @@ -1778,7 +1778,6 @@ static const char* s_log_filters[] = { "CocoaProgressCallback", "MetalDevice", #else - "ContextEGLWayland", "X11NoGUIPlatform", "WaylandNoGUIPlatform", #endif diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 814aecd01..f26239133 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -95,8 +95,8 @@ endif() if(ENABLE_OPENGL) target_sources(util PRIVATE - gl/context.cpp - gl/context.h + opengl_context.cpp + opengl_context.h opengl_device.cpp opengl_device.h opengl_loader.h @@ -112,29 +112,29 @@ if(ENABLE_OPENGL) if(WIN32) target_sources(util PRIVATE - gl/context_wgl.cpp - gl/context_wgl.h + opengl_context_wgl.cpp + opengl_context_wgl.h ) target_link_libraries(util PRIVATE "opengl32.lib") endif() if(LINUX OR FREEBSD OR ANDROID) target_sources(util PRIVATE - gl/context_egl.cpp - gl/context_egl.h + opengl_context_egl.cpp + opengl_context_egl.h ) target_compile_definitions(util PRIVATE "-DENABLE_EGL=1") if(ENABLE_X11) target_sources(util PRIVATE - gl/context_egl_x11.cpp - gl/context_egl_x11.h + opengl_context_egl_x11.cpp + opengl_context_egl_x11.h ) endif() if(ENABLE_WAYLAND) target_sources(util PRIVATE - gl/context_egl_wayland.cpp - gl/context_egl_wayland.h + opengl_context_egl_wayland.cpp + opengl_context_egl_wayland.h ) endif() if(ANDROID) @@ -144,10 +144,10 @@ if(ENABLE_OPENGL) if(APPLE) target_sources(util PRIVATE - gl/context_agl.mm - gl/context_agl.h + opengl_context_agl.mm + opengl_context_agl.h ) - set_source_files_properties(gl/context_agl.mm PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE) + set_source_files_properties(opengl_context_agl.mm PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE) endif() endif() diff --git a/src/util/gl/context_egl_x11.cpp b/src/util/gl/context_egl_x11.cpp deleted file mode 100644 index c3b467a0b..000000000 --- a/src/util/gl/context_egl_x11.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin -// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) - -#include "context_egl_x11.h" - -#include "common/error.h" - -namespace GL { -ContextEGLX11::ContextEGLX11(const WindowInfo& wi) : ContextEGL(wi) -{ -} -ContextEGLX11::~ContextEGLX11() = default; - -std::unique_ptr ContextEGLX11::Create(const WindowInfo& wi, std::span versions_to_try, - Error* error) -{ - std::unique_ptr context = std::make_unique(wi); - if (!context->Initialize(versions_to_try, error)) - return nullptr; - - return context; -} - -std::unique_ptr ContextEGLX11::CreateSharedContext(const WindowInfo& wi, Error* error) -{ - std::unique_ptr context = std::make_unique(wi); - context->m_display = m_display; - - if (!context->CreateContextAndSurface(m_version, m_context, false)) - return nullptr; - - return context; -} - -EGLDisplay ContextEGLX11::GetPlatformDisplay(const EGLAttrib* attribs, Error* error) -{ - EGLDisplay dpy = TryGetPlatformDisplay(EGL_PLATFORM_X11_KHR, attribs); - if (dpy == EGL_NO_DISPLAY) - dpy = GetFallbackDisplay(error); - - return dpy; -} - -} // namespace GL diff --git a/src/util/gl/context_egl_x11.h b/src/util/gl/context_egl_x11.h deleted file mode 100644 index 7734d6281..000000000 --- a/src/util/gl/context_egl_x11.h +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin -// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) - -#pragma once -#include "context_egl.h" - -namespace GL { - -class ContextEGLX11 final : public ContextEGL -{ -public: - ContextEGLX11(const WindowInfo& wi); - ~ContextEGLX11() override; - - static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try, Error* error); - - std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; - -protected: - EGLDisplay GetPlatformDisplay(const EGLAttrib* attribs, Error* error) override; -}; - -} // namespace GL diff --git a/src/util/gl/context.cpp b/src/util/opengl_context.cpp similarity index 86% rename from src/util/gl/context.cpp rename to src/util/opengl_context.cpp index b84abde61..543f2fa44 100644 --- a/src/util/gl/context.cpp +++ b/src/util/opengl_context.cpp @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) -#include "context.h" -#include "../opengl_loader.h" +#include "opengl_context.h" +#include "opengl_loader.h" #include "common/error.h" #include "common/log.h" @@ -16,25 +16,23 @@ #endif #if defined(_WIN32) && !defined(_M_ARM64) -#include "context_wgl.h" +#include "opengl_context_wgl.h" #elif defined(__APPLE__) -#include "context_agl.h" +#include "opengl_context_agl.h" #elif defined(__ANDROID__) -#include "context_egl_android.h" +#include "opengl_context_egl_android.h" #else #ifdef ENABLE_EGL #ifdef ENABLE_WAYLAND -#include "context_egl_wayland.h" +#include "opengl_context_egl_wayland.h" #endif #ifdef ENABLE_X11 -#include "context_egl_x11.h" +#include "opengl_context_egl_x11.h" #endif #endif #endif -Log_SetChannel(GL::Context); - -namespace GL { +Log_SetChannel(OpenGLContext); static bool ShouldPreferESContext() { @@ -107,18 +105,18 @@ static void DisableBrokenExtensions(const char* gl_vendor, const char* gl_render } } -Context::Context(const WindowInfo& wi) : m_wi(wi) +OpenGLContext::OpenGLContext(const WindowInfo& wi) : m_wi(wi) { } -Context::~Context() = default; +OpenGLContext::~OpenGLContext() = default; -std::vector Context::EnumerateFullscreenModes() +std::vector OpenGLContext::EnumerateFullscreenModes() { return {}; } -std::unique_ptr Context::Create(const WindowInfo& wi, Error* error) +std::unique_ptr OpenGLContext::Create(const WindowInfo& wi, Error* error) { static constexpr std::array vlist = {{{Profile::Core, 4, 6}, {Profile::Core, 4, 5}, @@ -154,37 +152,33 @@ std::unique_ptr Context::Create(const WindowInfo& wi, Error* error) versions_to_try = std::span(new_versions_to_try, versions_to_try.size()); } - std::unique_ptr context; - Error local_error; + std::unique_ptr context; #if defined(_WIN32) && !defined(_M_ARM64) - context = ContextWGL::Create(wi, versions_to_try, error ? error : &local_error); + context = OpenGLContextWGL::Create(wi, versions_to_try, error); #elif defined(__APPLE__) - context = ContextAGL::Create(wi, versions_to_try); + context = OpenGLContextAGL::Create(wi, versions_to_try, error); #elif defined(__ANDROID__) - context = ContextEGLAndroid::Create(wi, versions_to_try, error ? error : &local_error); + context = ContextEGLAndroid::Create(wi, versions_to_try, error); #else #if defined(ENABLE_X11) if (wi.type == WindowInfo::Type::X11) - context = ContextEGLX11::Create(wi, versions_to_try, error ? error : &local_error); + context = OpenGLContextEGLX11::Create(wi, versions_to_try, error); #endif #if defined(ENABLE_WAYLAND) if (wi.type == WindowInfo::Type::Wayland) - context = ContextEGLWayland::Create(wi, versions_to_try, error ? error : &local_error); + context = OpenGLContextEGLWayland::Create(wi, versions_to_try, error); #endif if (wi.type == WindowInfo::Type::Surfaceless) - context = ContextEGL::Create(wi, versions_to_try, error ? error : &local_error); + context = OpenGLContextEGL::Create(wi, versions_to_try, error); #endif if (!context) - { - Log_ErrorFmt("Failed to create GL context: {}", (error ? error : &local_error)->GetDescription()); return nullptr; - } Log_InfoPrint(context->IsGLES() ? "Created an OpenGL ES context" : "Created an OpenGL context"); // TODO: Not thread-safe. - static Context* context_being_created; + static OpenGLContext* context_being_created; context_being_created = context.get(); // load up glad @@ -218,5 +212,3 @@ std::unique_ptr Context::Create(const WindowInfo& wi, Error* error) return context; } - -} // namespace GL diff --git a/src/util/gl/context.h b/src/util/opengl_context.h similarity index 82% rename from src/util/gl/context.h rename to src/util/opengl_context.h index 2ab720464..1a2219617 100644 --- a/src/util/gl/context.h +++ b/src/util/opengl_context.h @@ -3,7 +3,7 @@ #pragma once -#include "../window_info.h" +#include "window_info.h" #include "common/types.h" @@ -13,12 +13,11 @@ class Error; -namespace GL { -class Context +class OpenGLContext { public: - Context(const WindowInfo& wi); - virtual ~Context(); + OpenGLContext(const WindowInfo& wi); + virtual ~OpenGLContext(); enum class Profile { @@ -55,14 +54,13 @@ public: virtual bool MakeCurrent() = 0; virtual bool DoneCurrent() = 0; virtual bool SetSwapInterval(s32 interval) = 0; - virtual std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) = 0; + virtual std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) = 0; virtual std::vector EnumerateFullscreenModes(); - static std::unique_ptr Create(const WindowInfo& wi, Error* error); + static std::unique_ptr Create(const WindowInfo& wi, Error* error); protected: WindowInfo m_wi; Version m_version = {}; }; -} // namespace GL diff --git a/src/util/gl/context_agl.h b/src/util/opengl_context_agl.h similarity index 62% rename from src/util/gl/context_agl.h rename to src/util/opengl_context_agl.h index 679238964..94639fadd 100644 --- a/src/util/gl/context_agl.h +++ b/src/util/opengl_context_agl.h @@ -1,9 +1,10 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once -#include "../opengl_loader.h" -#include "context.h" + +#include "opengl_context.h" +#include "opengl_loader.h" #if defined(__APPLE__) && defined(__OBJC__) #import @@ -14,15 +15,14 @@ struct NSView; #define __bridge #endif -namespace GL { - -class ContextAGL final : public Context +class OpenGLContextAGL final : public OpenGLContext { public: - ContextAGL(const WindowInfo& wi); - ~ContextAGL() override; + OpenGLContextAGL(const WindowInfo& wi); + ~OpenGLContextAGL() override; - static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try); + static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try, + Error* error); void* GetProcAddress(const char* name) override; bool ChangeSurface(const WindowInfo& new_wi) override; @@ -32,13 +32,13 @@ public: bool MakeCurrent() override; bool DoneCurrent() override; bool SetSwapInterval(s32 interval) override; - std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; + std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; private: ALWAYS_INLINE NSView* GetView() const { return static_cast((__bridge NSView*)m_wi.window_handle); } - bool Initialize(std::span versions_to_try); - bool CreateContext(NSOpenGLContext* share_context, int profile, bool make_current); + bool Initialize(std::span versions_to_try, Error* error); + bool CreateContext(NSOpenGLContext* share_context, int profile, bool make_current, Error* error); void BindContextToView(); // returns true if dimensions have changed @@ -48,5 +48,3 @@ private: NSOpenGLPixelFormat* m_pixel_format = nullptr; void* m_opengl_module_handle = nullptr; }; - -} // namespace GL diff --git a/src/util/gl/context_agl.mm b/src/util/opengl_context_agl.mm similarity index 72% rename from src/util/gl/context_agl.mm rename to src/util/opengl_context_agl.mm index f4a98e52d..35408d3de 100644 --- a/src/util/gl/context_agl.mm +++ b/src/util/opengl_context_agl.mm @@ -1,22 +1,24 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) -#include "context_agl.h" +#include "opengl_context_agl.h" + #include "common/assert.h" #include "common/error.h" #include "common/log.h" -#include -Log_SetChannel(GL::Context); -namespace GL { -ContextAGL::ContextAGL(const WindowInfo& wi) : Context(wi) +#include + +Log_SetChannel(OpenGLContext); + +OpenGLContextAGL::OpenGLContextAGL(const WindowInfo& wi) : OpenGLContext(wi) { m_opengl_module_handle = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_NOW); if (!m_opengl_module_handle) Log_ErrorPrint("Could not open OpenGL.framework, function lookups will probably fail"); } -ContextAGL::~ContextAGL() +OpenGLContextAGL::~OpenGLContextAGL() { if ([NSOpenGLContext currentContext] == m_context) [NSOpenGLContext clearCurrentContext]; @@ -31,20 +33,20 @@ ContextAGL::~ContextAGL() dlclose(m_opengl_module_handle); } -std::unique_ptr ContextAGL::Create(const WindowInfo& wi, std::span versions_to_try) +std::unique_ptr OpenGLContextAGL::Create(const WindowInfo& wi, std::span versions_to_try, Error* error) { - std::unique_ptr context = std::make_unique(wi); - if (!context->Initialize(versions_to_try)) + std::unique_ptr context = std::make_unique(wi); + if (!context->Initialize(versions_to_try, error)) return nullptr; return context; } -bool ContextAGL::Initialize(const std::span versions_to_try) +bool OpenGLContextAGL::Initialize(const std::span versions_to_try, Error* error) { for (const Version& cv : versions_to_try) { - if (cv.profile == Profile::NoProfile && CreateContext(nullptr, NSOpenGLProfileVersionLegacy, true)) + if (cv.profile == Profile::NoProfile && CreateContext(nullptr, NSOpenGLProfileVersionLegacy, true, error)) { // we already have the dummy context, so just use that m_version = cv; @@ -57,7 +59,7 @@ bool ContextAGL::Initialize(const std::span versions_to_try) const NSOpenGLPixelFormatAttribute profile = (cv.major_version > 3 || cv.minor_version > 2) ? NSOpenGLProfileVersion4_1Core : NSOpenGLProfileVersion3_2Core; - if (CreateContext(nullptr, static_cast(profile), true)) + if (CreateContext(nullptr, static_cast(profile), true, error)) { m_version = cv; return true; @@ -65,10 +67,11 @@ bool ContextAGL::Initialize(const std::span versions_to_try) } } + Error::SetStringView(error, "Failed to create any context versions."); return false; } -void* ContextAGL::GetProcAddress(const char* name) +void* OpenGLContextAGL::GetProcAddress(const char* name) { void* addr = m_opengl_module_handle ? dlsym(m_opengl_module_handle, name) : nullptr; if (addr) @@ -77,19 +80,19 @@ void* ContextAGL::GetProcAddress(const char* name) return dlsym(RTLD_NEXT, name); } -bool ContextAGL::ChangeSurface(const WindowInfo& new_wi) +bool OpenGLContextAGL::ChangeSurface(const WindowInfo& new_wi) { m_wi = new_wi; BindContextToView(); return true; } -void ContextAGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/) +void OpenGLContextAGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/) { UpdateDimensions(); } -bool ContextAGL::UpdateDimensions() +bool OpenGLContextAGL::UpdateDimensions() { const NSSize window_size = [GetView() frame].size; const CGFloat window_scale = [[GetView() window] backingScaleFactor]; @@ -114,39 +117,39 @@ bool ContextAGL::UpdateDimensions() return true; } -bool ContextAGL::SwapBuffers() +bool OpenGLContextAGL::SwapBuffers() { [m_context flushBuffer]; return true; } -bool ContextAGL::IsCurrent() +bool OpenGLContextAGL::IsCurrent() { return (m_context != nil && [NSOpenGLContext currentContext] == m_context); } -bool ContextAGL::MakeCurrent() +bool OpenGLContextAGL::MakeCurrent() { [m_context makeCurrentContext]; return true; } -bool ContextAGL::DoneCurrent() +bool OpenGLContextAGL::DoneCurrent() { [NSOpenGLContext clearCurrentContext]; return true; } -bool ContextAGL::SetSwapInterval(s32 interval) +bool OpenGLContextAGL::SetSwapInterval(s32 interval) { GLint gl_interval = static_cast(interval); [m_context setValues:&gl_interval forParameter:NSOpenGLCPSwapInterval]; return true; } -std::unique_ptr ContextAGL::CreateSharedContext(const WindowInfo& wi, Error* error) +std::unique_ptr OpenGLContextAGL::CreateSharedContext(const WindowInfo& wi, Error* error) { - std::unique_ptr context = std::make_unique(wi); + std::unique_ptr context = std::make_unique(wi); context->m_context = [[NSOpenGLContext alloc] initWithFormat:m_pixel_format shareContext:m_context]; if (context->m_context == nil) @@ -165,7 +168,7 @@ std::unique_ptr ContextAGL::CreateSharedContext(const WindowInfo& wi, E return context; } -bool ContextAGL::CreateContext(NSOpenGLContext* share_context, int profile, bool make_current) +bool OpenGLContextAGL::CreateContext(NSOpenGLContext* share_context, int profile, bool make_current, Error* error) { if (m_context) { @@ -182,13 +185,16 @@ bool ContextAGL::CreateContext(NSOpenGLContext* share_context, int profile, bool m_pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs.data()]; if (m_pixel_format == nil) { - Log_ErrorPrintf("Failed to initialize pixel format"); + Error::SetStringView(error, "Failed to initialize pixel format"); return false; } m_context = [[NSOpenGLContext alloc] initWithFormat:m_pixel_format shareContext:nil]; if (m_context == nil) + { + Error::SetStringView(error, "NSOpenGLContext initWithFormat failed"); return false; + } if (m_wi.type == WindowInfo::Type::MacOS) BindContextToView(); @@ -199,7 +205,7 @@ bool ContextAGL::CreateContext(NSOpenGLContext* share_context, int profile, bool return true; } -void ContextAGL::BindContextToView() +void OpenGLContextAGL::BindContextToView() { NSView* const view = GetView(); NSWindow* const window = [view window]; @@ -218,4 +224,3 @@ void ContextAGL::BindContextToView() else dispatch_sync(dispatch_get_main_queue(), block); } -} // namespace GL diff --git a/src/util/gl/context_egl.cpp b/src/util/opengl_context_egl.cpp similarity index 85% rename from src/util/gl/context_egl.cpp rename to src/util/opengl_context_egl.cpp index b86bff904..1ead62391 100644 --- a/src/util/gl/context_egl.cpp +++ b/src/util/opengl_context_egl.cpp @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) -#include "context_egl.h" +#include "opengl_context_egl.h" #include "common/assert.h" #include "common/dynamic_library.h" @@ -13,7 +13,7 @@ #include #include -Log_SetChannel(GL::Context); +Log_SetChannel(OpenGLContext); static DynamicLibrary s_egl_library; static std::atomic_uint32_t s_egl_refcount = 0; @@ -77,30 +77,29 @@ static std::vector EGLAttribToInt(const EGLAttrib* attribs) return int_attribs; } -namespace GL { -ContextEGL::ContextEGL(const WindowInfo& wi) : Context(wi) +OpenGLContextEGL::OpenGLContextEGL(const WindowInfo& wi) : OpenGLContext(wi) { LoadEGL(); } -ContextEGL::~ContextEGL() +OpenGLContextEGL::~OpenGLContextEGL() { DestroySurface(); DestroyContext(); UnloadEGL(); } -std::unique_ptr ContextEGL::Create(const WindowInfo& wi, std::span versions_to_try, - Error* error) +std::unique_ptr OpenGLContextEGL::Create(const WindowInfo& wi, std::span versions_to_try, + Error* error) { - std::unique_ptr context = std::make_unique(wi); + std::unique_ptr context = std::make_unique(wi); if (!context->Initialize(versions_to_try, error)) return nullptr; return context; } -bool ContextEGL::Initialize(std::span versions_to_try, Error* error) +bool OpenGLContextEGL::Initialize(std::span versions_to_try, Error* error) { if (!LoadGLADEGL(EGL_NO_DISPLAY, error)) return false; @@ -136,7 +135,7 @@ bool ContextEGL::Initialize(std::span versions_to_try, Error* err return false; } -EGLDisplay ContextEGL::GetPlatformDisplay(const EGLAttrib* attribs, Error* error) +EGLDisplay OpenGLContextEGL::GetPlatformDisplay(const EGLAttrib* attribs, Error* error) { EGLDisplay dpy = TryGetPlatformDisplay(EGL_PLATFORM_SURFACELESS_MESA, attribs); if (dpy == EGL_NO_DISPLAY) @@ -145,7 +144,7 @@ EGLDisplay ContextEGL::GetPlatformDisplay(const EGLAttrib* attribs, Error* error return dpy; } -EGLDisplay ContextEGL::TryGetPlatformDisplay(EGLenum platform, const EGLAttrib* attribs) +EGLDisplay OpenGLContextEGL::TryGetPlatformDisplay(EGLenum platform, const EGLAttrib* attribs) { const char* extensions_str = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); if (!extensions_str) @@ -203,7 +202,7 @@ EGLDisplay ContextEGL::TryGetPlatformDisplay(EGLenum platform, const EGLAttrib* return dpy; } -EGLDisplay ContextEGL::GetFallbackDisplay(Error* error) +EGLDisplay OpenGLContextEGL::GetFallbackDisplay(Error* error) { Log_WarningPrint("Using fallback eglGetDisplay() path."); EGLDisplay dpy = eglGetDisplay(m_wi.display_connection); @@ -216,7 +215,7 @@ EGLDisplay ContextEGL::GetFallbackDisplay(Error* error) return dpy; } -EGLSurface ContextEGL::CreatePlatformSurface(EGLConfig config, const EGLAttrib* attribs, Error* error) +EGLSurface OpenGLContextEGL::CreatePlatformSurface(EGLConfig config, const EGLAttrib* attribs, Error* error) { EGLSurface surface = EGL_NO_SURFACE; if (GLAD_EGL_VERSION_1_5) @@ -234,7 +233,7 @@ EGLSurface ContextEGL::CreatePlatformSurface(EGLConfig config, const EGLAttrib* return surface; } -EGLSurface ContextEGL::CreateFallbackSurface(EGLConfig config, const EGLAttrib* attribs, void* win, Error* error) +EGLSurface OpenGLContextEGL::CreateFallbackSurface(EGLConfig config, const EGLAttrib* attribs, void* win, Error* error) { Log_WarningPrint("Using fallback eglCreateWindowSurface() path."); @@ -251,12 +250,12 @@ EGLSurface ContextEGL::CreateFallbackSurface(EGLConfig config, const EGLAttrib* return surface; } -void* ContextEGL::GetProcAddress(const char* name) +void* OpenGLContextEGL::GetProcAddress(const char* name) { return reinterpret_cast(eglGetProcAddress(name)); } -bool ContextEGL::ChangeSurface(const WindowInfo& new_wi) +bool OpenGLContextEGL::ChangeSurface(const WindowInfo& new_wi) { const bool was_current = (eglGetCurrentContext() == m_context); if (was_current) @@ -281,7 +280,7 @@ bool ContextEGL::ChangeSurface(const WindowInfo& new_wi) return true; } -void ContextEGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/) +void OpenGLContextEGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/) { if (new_surface_width == 0 && new_surface_height == 0) { @@ -303,17 +302,17 @@ void ContextEGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_he m_wi.surface_height = new_surface_height; } -bool ContextEGL::SwapBuffers() +bool OpenGLContextEGL::SwapBuffers() { return eglSwapBuffers(m_display, m_surface); } -bool ContextEGL::IsCurrent() +bool OpenGLContextEGL::IsCurrent() { return m_context && eglGetCurrentContext() == m_context; } -bool ContextEGL::MakeCurrent() +bool OpenGLContextEGL::MakeCurrent() { if (!eglMakeCurrent(m_display, m_surface, m_surface, m_context)) { @@ -324,19 +323,19 @@ bool ContextEGL::MakeCurrent() return true; } -bool ContextEGL::DoneCurrent() +bool OpenGLContextEGL::DoneCurrent() { return eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } -bool ContextEGL::SetSwapInterval(s32 interval) +bool OpenGLContextEGL::SetSwapInterval(s32 interval) { return eglSwapInterval(m_display, interval); } -std::unique_ptr ContextEGL::CreateSharedContext(const WindowInfo& wi, Error* error) +std::unique_ptr OpenGLContextEGL::CreateSharedContext(const WindowInfo& wi, Error* error) { - std::unique_ptr context = std::make_unique(wi); + std::unique_ptr context = std::make_unique(wi); context->m_display = m_display; if (!context->CreateContextAndSurface(m_version, m_context, false)) @@ -348,7 +347,7 @@ std::unique_ptr ContextEGL::CreateSharedContext(const WindowInfo& wi, E return context; } -bool ContextEGL::CreateSurface() +bool OpenGLContextEGL::CreateSurface() { if (m_wi.type == WindowInfo::Type::Surfaceless) { @@ -384,7 +383,7 @@ bool ContextEGL::CreateSurface() return true; } -bool ContextEGL::CreatePBufferSurface() +bool OpenGLContextEGL::CreatePBufferSurface() { const u32 width = std::max(m_wi.surface_width, 1); const u32 height = std::max(m_wi.surface_height, 1); @@ -407,7 +406,7 @@ bool ContextEGL::CreatePBufferSurface() return true; } -bool ContextEGL::CheckConfigSurfaceFormat(EGLConfig config, GPUTexture::Format format) +bool OpenGLContextEGL::CheckConfigSurfaceFormat(EGLConfig config, GPUTexture::Format format) { int red_size, green_size, blue_size, alpha_size; if (!eglGetConfigAttrib(m_display, config, EGL_RED_SIZE, &red_size) || @@ -437,7 +436,7 @@ bool ContextEGL::CheckConfigSurfaceFormat(EGLConfig config, GPUTexture::Format f } } -GPUTexture::Format ContextEGL::GetSurfaceTextureFormat() const +GPUTexture::Format OpenGLContextEGL::GetSurfaceTextureFormat() const { int red_size = 0, green_size = 0, blue_size = 0, alpha_size = 0; eglGetConfigAttrib(m_display, m_config, EGL_RED_SIZE, &red_size); @@ -464,7 +463,7 @@ GPUTexture::Format ContextEGL::GetSurfaceTextureFormat() const } } -void ContextEGL::DestroyContext() +void OpenGLContextEGL::DestroyContext() { if (eglGetCurrentContext() == m_context) eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); @@ -476,7 +475,7 @@ void ContextEGL::DestroyContext() } } -void ContextEGL::DestroySurface() +void OpenGLContextEGL::DestroySurface() { if (eglGetCurrentSurface(EGL_DRAW) == m_surface) eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); @@ -488,11 +487,12 @@ void ContextEGL::DestroySurface() } } -bool ContextEGL::CreateContext(const Version& version, EGLContext share_context) +bool OpenGLContextEGL::CreateContext(const Version& version, EGLContext share_context) { - Log_DevPrintf( - "Trying version %u.%u (%s)", version.major_version, version.minor_version, - version.profile == Context::Profile::ES ? "ES" : (version.profile == Context::Profile::Core ? "Core" : "None")); + Log_DevPrintf("Trying version %u.%u (%s)", version.major_version, version.minor_version, + version.profile == OpenGLContext::Profile::ES ? + "ES" : + (version.profile == OpenGLContext::Profile::Core ? "Core" : "None")); int surface_attribs[16] = { EGL_RENDERABLE_TYPE, (version.profile == Profile::ES) ? @@ -600,16 +600,17 @@ bool ContextEGL::CreateContext(const Version& version, EGLContext share_context) return false; } - Log_InfoPrintf( - "Got version %u.%u (%s)", version.major_version, version.minor_version, - version.profile == Context::Profile::ES ? "ES" : (version.profile == Context::Profile::Core ? "Core" : "None")); + Log_InfoPrintf("Got version %u.%u (%s)", version.major_version, version.minor_version, + version.profile == OpenGLContext::Profile::ES ? + "ES" : + (version.profile == OpenGLContext::Profile::Core ? "Core" : "None")); m_config = config.value(); m_version = version; return true; } -bool ContextEGL::CreateContextAndSurface(const Version& version, EGLContext share_context, bool make_current) +bool OpenGLContextEGL::CreateContextAndSurface(const Version& version, EGLContext share_context, bool make_current) { if (!CreateContext(version, share_context)) return false; @@ -637,4 +638,3 @@ bool ContextEGL::CreateContextAndSurface(const Version& version, EGLContext shar return true; } -} // namespace GL diff --git a/src/util/gl/context_egl.h b/src/util/opengl_context_egl.h similarity index 79% rename from src/util/gl/context_egl.h rename to src/util/opengl_context_egl.h index 41f9b75d4..c7b148fe9 100644 --- a/src/util/gl/context_egl.h +++ b/src/util/opengl_context_egl.h @@ -3,19 +3,18 @@ #pragma once -#include "context.h" +#include "opengl_context.h" #include "glad/egl.h" -namespace GL { - -class ContextEGL : public Context +class OpenGLContextEGL : public OpenGLContext { public: - ContextEGL(const WindowInfo& wi); - ~ContextEGL() override; + OpenGLContextEGL(const WindowInfo& wi); + ~OpenGLContextEGL() override; - static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try, Error* error); + static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try, + Error* error); void* GetProcAddress(const char* name) override; virtual bool ChangeSurface(const WindowInfo& new_wi) override; @@ -25,7 +24,7 @@ public: bool MakeCurrent() override; bool DoneCurrent() override; bool SetSwapInterval(s32 interval) override; - virtual std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; + virtual std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; protected: virtual EGLDisplay GetPlatformDisplay(const EGLAttrib* attribs, Error* error); @@ -36,7 +35,6 @@ protected: EGLSurface CreateFallbackSurface(EGLConfig config, const EGLAttrib* attribs, void* window, Error* error); bool Initialize(std::span versions_to_try, Error* error); - bool CreateDisplay(); bool CreateContext(const Version& version, EGLContext share_context); bool CreateContextAndSurface(const Version& version, EGLContext share_context, bool make_current); bool CreateSurface(); @@ -52,5 +50,3 @@ protected: EGLConfig m_config = {}; }; - -} // namespace GL diff --git a/src/util/gl/context_egl_wayland.cpp b/src/util/opengl_context_egl_wayland.cpp similarity index 60% rename from src/util/gl/context_egl_wayland.cpp rename to src/util/opengl_context_egl_wayland.cpp index 9f70ef77f..54d71038e 100644 --- a/src/util/gl/context_egl_wayland.cpp +++ b/src/util/opengl_context_egl_wayland.cpp @@ -1,22 +1,19 @@ // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) -#include "context_egl_wayland.h" +#include "opengl_context_egl_wayland.h" #include "common/error.h" -#include "common/log.h" #include -Log_SetChannel(ContextEGL); - -namespace GL { static const char* WAYLAND_EGL_MODNAME = "libwayland-egl.so.1"; -ContextEGLWayland::ContextEGLWayland(const WindowInfo& wi) : ContextEGL(wi) +OpenGLContextEGLWayland::OpenGLContextEGLWayland(const WindowInfo& wi) : OpenGLContextEGL(wi) { } -ContextEGLWayland::~ContextEGLWayland() + +OpenGLContextEGLWayland::~OpenGLContextEGLWayland() { if (m_wl_window) m_wl_egl_window_destroy(m_wl_window); @@ -24,36 +21,36 @@ ContextEGLWayland::~ContextEGLWayland() dlclose(m_wl_module); } -std::unique_ptr ContextEGLWayland::Create(const WindowInfo& wi, std::span versions_to_try, - Error* error) +std::unique_ptr OpenGLContextEGLWayland::Create(const WindowInfo& wi, + std::span versions_to_try, Error* error) { - std::unique_ptr context = std::make_unique(wi); - if (!context->LoadModule() || !context->Initialize(versions_to_try, error)) + std::unique_ptr context = std::make_unique(wi); + if (!context->LoadModule(error) || !context->Initialize(versions_to_try, error)) return nullptr; return context; } -std::unique_ptr ContextEGLWayland::CreateSharedContext(const WindowInfo& wi, Error* error) +std::unique_ptr OpenGLContextEGLWayland::CreateSharedContext(const WindowInfo& wi, Error* error) { - std::unique_ptr context = std::make_unique(wi); + std::unique_ptr context = std::make_unique(wi); context->m_display = m_display; - if (!context->LoadModule() || !context->CreateContextAndSurface(m_version, m_context, false)) + if (!context->LoadModule(error) || !context->CreateContextAndSurface(m_version, m_context, false)) return nullptr; return context; } -void ContextEGLWayland::ResizeSurface(u32 new_surface_width, u32 new_surface_height) +void OpenGLContextEGLWayland::ResizeSurface(u32 new_surface_width, u32 new_surface_height) { if (m_wl_window) m_wl_egl_window_resize(m_wl_window, new_surface_width, new_surface_height, 0, 0); - ContextEGL::ResizeSurface(new_surface_width, new_surface_height); + OpenGLContextEGL::ResizeSurface(new_surface_width, new_surface_height); } -EGLDisplay ContextEGLWayland::GetPlatformDisplay(const EGLAttrib* attribs, Error* error) +EGLDisplay OpenGLContextEGLWayland::GetPlatformDisplay(const EGLAttrib* attribs, Error* error) { EGLDisplay dpy = TryGetPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, attribs); if (dpy == EGL_NO_DISPLAY) @@ -62,7 +59,7 @@ EGLDisplay ContextEGLWayland::GetPlatformDisplay(const EGLAttrib* attribs, Error return dpy; } -EGLSurface ContextEGLWayland::CreatePlatformSurface(EGLConfig config, const EGLAttrib* attribs, Error* error) +EGLSurface OpenGLContextEGLWayland::CreatePlatformSurface(EGLConfig config, const EGLAttrib* attribs, Error* error) { if (m_wl_window) { @@ -100,12 +97,13 @@ EGLSurface ContextEGLWayland::CreatePlatformSurface(EGLConfig config, const EGLA return surface; } -bool ContextEGLWayland::LoadModule() +bool OpenGLContextEGLWayland::LoadModule(Error* error) { m_wl_module = dlopen(WAYLAND_EGL_MODNAME, RTLD_NOW | RTLD_GLOBAL); if (!m_wl_module) { - Log_ErrorPrintf("Failed to load %s.", WAYLAND_EGL_MODNAME); + const char* err = dlerror(); + Error::SetStringFmt(error, "Loading {} failed: {}", WAYLAND_EGL_MODNAME, err ? err : ""); return false; } @@ -117,10 +115,9 @@ bool ContextEGLWayland::LoadModule() reinterpret_cast(dlsym(m_wl_module, "wl_egl_window_resize")); if (!m_wl_egl_window_create || !m_wl_egl_window_destroy || !m_wl_egl_window_resize) { - Log_ErrorPrintf("Failed to load one or more functions from %s.", WAYLAND_EGL_MODNAME); + Error::SetStringFmt(error, "Failed to load one or more functions from {}.", WAYLAND_EGL_MODNAME); return false; } return true; } -} // namespace GL diff --git a/src/util/gl/context_egl_wayland.h b/src/util/opengl_context_egl_wayland.h similarity index 62% rename from src/util/gl/context_egl_wayland.h rename to src/util/opengl_context_egl_wayland.h index 5180f23ca..822cff494 100644 --- a/src/util/gl/context_egl_wayland.h +++ b/src/util/opengl_context_egl_wayland.h @@ -2,20 +2,21 @@ // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once -#include "context_egl.h" + +#include "opengl_context_egl.h" + #include -namespace GL { - -class ContextEGLWayland final : public ContextEGL +class OpenGLContextEGLWayland final : public OpenGLContextEGL { public: - ContextEGLWayland(const WindowInfo& wi); - ~ContextEGLWayland() override; + OpenGLContextEGLWayland(const WindowInfo& wi); + ~OpenGLContextEGLWayland() override; - static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try, Error* error); + static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try, + Error* error); - std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; + std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override; protected: @@ -23,7 +24,7 @@ protected: EGLSurface CreatePlatformSurface(EGLConfig config, const EGLAttrib* attribs, Error* error) override; private: - bool LoadModule(); + bool LoadModule(Error* error); wl_egl_window* m_wl_window = nullptr; @@ -32,5 +33,3 @@ private: void (*m_wl_egl_window_destroy)(struct wl_egl_window* egl_window); void (*m_wl_egl_window_resize)(struct wl_egl_window* egl_window, int width, int height, int dx, int dy); }; - -} // namespace GL diff --git a/src/util/opengl_context_egl_x11.cpp b/src/util/opengl_context_egl_x11.cpp new file mode 100644 index 000000000..9ea15401d --- /dev/null +++ b/src/util/opengl_context_egl_x11.cpp @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin +// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) + +#include "opengl_context_egl_x11.h" + +#include "common/error.h" + +OpenGLContextEGLX11::OpenGLContextEGLX11(const WindowInfo& wi) : OpenGLContextEGL(wi) +{ +} + +OpenGLContextEGLX11::~OpenGLContextEGLX11() = default; + +std::unique_ptr OpenGLContextEGLX11::Create(const WindowInfo& wi, + std::span versions_to_try, Error* error) +{ + std::unique_ptr context = std::make_unique(wi); + if (!context->Initialize(versions_to_try, error)) + return nullptr; + + return context; +} + +std::unique_ptr OpenGLContextEGLX11::CreateSharedContext(const WindowInfo& wi, Error* error) +{ + std::unique_ptr context = std::make_unique(wi); + context->m_display = m_display; + + if (!context->CreateContextAndSurface(m_version, m_context, false)) + return nullptr; + + return context; +} + +EGLDisplay OpenGLContextEGLX11::GetPlatformDisplay(const EGLAttrib* attribs, Error* error) +{ + EGLDisplay dpy = TryGetPlatformDisplay(EGL_PLATFORM_X11_KHR, attribs); + if (dpy == EGL_NO_DISPLAY) + dpy = GetFallbackDisplay(error); + + return dpy; +} diff --git a/src/util/opengl_context_egl_x11.h b/src/util/opengl_context_egl_x11.h new file mode 100644 index 000000000..e0af7e081 --- /dev/null +++ b/src/util/opengl_context_egl_x11.h @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin +// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) + +#pragma once + +#include "opengl_context_egl.h" + +class OpenGLContextEGLX11 final : public OpenGLContextEGL +{ +public: + OpenGLContextEGLX11(const WindowInfo& wi); + ~OpenGLContextEGLX11() override; + + static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try, + Error* error); + + std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; + +protected: + EGLDisplay GetPlatformDisplay(const EGLAttrib* attribs, Error* error) override; +}; diff --git a/src/util/gl/context_wgl.cpp b/src/util/opengl_context_wgl.cpp similarity index 87% rename from src/util/gl/context_wgl.cpp rename to src/util/opengl_context_wgl.cpp index 20612da5f..2949ae184 100644 --- a/src/util/gl/context_wgl.cpp +++ b/src/util/opengl_context_wgl.cpp @@ -1,15 +1,15 @@ // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) -#include "context_wgl.h" -#include "../opengl_loader.h" +#include "opengl_context_wgl.h" +#include "opengl_loader.h" #include "common/assert.h" #include "common/error.h" #include "common/log.h" #include "common/scoped_guard.h" -Log_SetChannel(GL::Context); +Log_SetChannel(GL::OpenGLContext); #ifdef __clang__ #pragma clang diagnostic ignored "-Wmicrosoft-cast" @@ -36,12 +36,11 @@ static bool ReloadWGL(HDC dc) return true; } -namespace GL { -ContextWGL::ContextWGL(const WindowInfo& wi) : Context(wi) +OpenGLContextWGL::OpenGLContextWGL(const WindowInfo& wi) : OpenGLContext(wi) { } -ContextWGL::~ContextWGL() +OpenGLContextWGL::~OpenGLContextWGL() { if (wglGetCurrentContext() == m_rc) wglMakeCurrent(m_dc, nullptr); @@ -52,17 +51,17 @@ ContextWGL::~ContextWGL() ReleaseDC(); } -std::unique_ptr ContextWGL::Create(const WindowInfo& wi, std::span versions_to_try, - Error* error) +std::unique_ptr OpenGLContextWGL::Create(const WindowInfo& wi, std::span versions_to_try, + Error* error) { - std::unique_ptr context = std::make_unique(wi); + std::unique_ptr context = std::make_unique(wi); if (!context->Initialize(versions_to_try, error)) return nullptr; return context; } -bool ContextWGL::Initialize(std::span versions_to_try, Error* error) +bool OpenGLContextWGL::Initialize(std::span versions_to_try, Error* error) { if (m_wi.type == WindowInfo::Type::Win32) { @@ -98,12 +97,12 @@ bool ContextWGL::Initialize(std::span versions_to_try, Error* err return false; } -void* ContextWGL::GetProcAddress(const char* name) +void* OpenGLContextWGL::GetProcAddress(const char* name) { return GetProcAddressCallback(name); } -bool ContextWGL::ChangeSurface(const WindowInfo& new_wi) +bool OpenGLContextWGL::ChangeSurface(const WindowInfo& new_wi) { const bool was_current = (wglGetCurrentContext() == m_rc); Error error; @@ -127,7 +126,7 @@ bool ContextWGL::ChangeSurface(const WindowInfo& new_wi) return true; } -void ContextWGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/) +void OpenGLContextWGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/) { RECT client_rc = {}; GetClientRect(GetHWND(), &client_rc); @@ -135,17 +134,17 @@ void ContextWGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_he m_wi.surface_height = static_cast(client_rc.bottom - client_rc.top); } -bool ContextWGL::SwapBuffers() +bool OpenGLContextWGL::SwapBuffers() { return ::SwapBuffers(m_dc); } -bool ContextWGL::IsCurrent() +bool OpenGLContextWGL::IsCurrent() { return (m_rc && wglGetCurrentContext() == m_rc); } -bool ContextWGL::MakeCurrent() +bool OpenGLContextWGL::MakeCurrent() { if (!wglMakeCurrent(m_dc, m_rc)) { @@ -156,12 +155,12 @@ bool ContextWGL::MakeCurrent() return true; } -bool ContextWGL::DoneCurrent() +bool OpenGLContextWGL::DoneCurrent() { return wglMakeCurrent(m_dc, nullptr); } -bool ContextWGL::SetSwapInterval(s32 interval) +bool OpenGLContextWGL::SetSwapInterval(s32 interval) { if (!GLAD_WGL_EXT_swap_control) return false; @@ -169,9 +168,9 @@ bool ContextWGL::SetSwapInterval(s32 interval) return wglSwapIntervalEXT(interval); } -std::unique_ptr ContextWGL::CreateSharedContext(const WindowInfo& wi, Error* error) +std::unique_ptr OpenGLContextWGL::CreateSharedContext(const WindowInfo& wi, Error* error) { - std::unique_ptr context = std::make_unique(wi); + std::unique_ptr context = std::make_unique(wi); if (wi.type == WindowInfo::Type::Win32) { if (!context->InitializeDC(error)) @@ -198,7 +197,7 @@ std::unique_ptr ContextWGL::CreateSharedContext(const WindowInfo& wi, E return context; } -HDC ContextWGL::GetDCAndSetPixelFormat(HWND hwnd, Error* error) +HDC OpenGLContextWGL::GetDCAndSetPixelFormat(HWND hwnd, Error* error) { PIXELFORMATDESCRIPTOR pfd = {}; pfd.nSize = sizeof(pfd); @@ -242,7 +241,7 @@ HDC ContextWGL::GetDCAndSetPixelFormat(HWND hwnd, Error* error) return hDC; } -bool ContextWGL::InitializeDC(Error* error) +bool OpenGLContextWGL::InitializeDC(Error* error) { if (m_wi.type == WindowInfo::Type::Win32) { @@ -263,7 +262,7 @@ bool ContextWGL::InitializeDC(Error* error) } } -void ContextWGL::ReleaseDC() +void OpenGLContextWGL::ReleaseDC() { if (m_pbuffer) { @@ -286,7 +285,7 @@ void ContextWGL::ReleaseDC() } } -bool ContextWGL::CreatePBuffer(Error* error) +bool OpenGLContextWGL::CreatePBuffer(Error* error) { static bool window_class_registered = false; static const wchar_t* window_class_name = L"ContextWGLPBuffer"; @@ -387,7 +386,7 @@ bool ContextWGL::CreatePBuffer(Error* error) return true; } -bool ContextWGL::CreateAnyContext(HGLRC share_context, bool make_current, Error* error) +bool OpenGLContextWGL::CreateAnyContext(HGLRC share_context, bool make_current, Error* error) { m_rc = wglCreateContext(m_dc); if (!m_rc) @@ -421,7 +420,8 @@ bool ContextWGL::CreateAnyContext(HGLRC share_context, bool make_current, Error* return true; } -bool ContextWGL::CreateVersionContext(const Version& version, HGLRC share_context, bool make_current, Error* error) +bool OpenGLContextWGL::CreateVersionContext(const Version& version, HGLRC share_context, bool make_current, + Error* error) { // we need create context attribs if (!GLAD_WGL_ARB_create_context) @@ -501,4 +501,3 @@ bool ContextWGL::CreateVersionContext(const Version& version, HGLRC share_contex m_rc = new_rc; return true; } -} // namespace GL \ No newline at end of file diff --git a/src/util/gl/context_wgl.h b/src/util/opengl_context_wgl.h similarity index 75% rename from src/util/gl/context_wgl.h rename to src/util/opengl_context_wgl.h index eb3f0b7ec..644efddb0 100644 --- a/src/util/gl/context_wgl.h +++ b/src/util/opengl_context_wgl.h @@ -2,9 +2,9 @@ // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once -#include "context.h" -#include "../opengl_loader.h" +#include "opengl_context.h" +#include "opengl_loader.h" #include "common/windows_headers.h" @@ -12,15 +12,14 @@ #include -namespace GL { - -class ContextWGL final : public Context +class OpenGLContextWGL final : public OpenGLContext { public: - ContextWGL(const WindowInfo& wi); - ~ContextWGL() override; + OpenGLContextWGL(const WindowInfo& wi); + ~OpenGLContextWGL() override; - static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try, Error* error); + static std::unique_ptr Create(const WindowInfo& wi, std::span versions_to_try, + Error* error); void* GetProcAddress(const char* name) override; bool ChangeSurface(const WindowInfo& new_wi) override; @@ -30,7 +29,7 @@ public: bool MakeCurrent() override; bool DoneCurrent() override; bool SetSwapInterval(s32 interval) override; - std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; + std::unique_ptr CreateSharedContext(const WindowInfo& wi, Error* error) override; private: ALWAYS_INLINE HWND GetHWND() const { return static_cast(m_wi.window_handle); } @@ -55,5 +54,3 @@ private: HDC m_dummy_dc = {}; HPBUFFERARB m_pbuffer = {}; }; - -} // namespace GL \ No newline at end of file diff --git a/src/util/opengl_device.cpp b/src/util/opengl_device.cpp index ec5a3324d..61ffddb85 100644 --- a/src/util/opengl_device.cpp +++ b/src/util/opengl_device.cpp @@ -316,7 +316,7 @@ bool OpenGLDevice::CreateDevice(const std::string_view& adapter, bool threaded_p std::optional exclusive_fullscreen_control, FeatureMask disabled_features, Error* error) { - m_gl_context = GL::Context::Create(m_window_info, error); + m_gl_context = OpenGLContext::Create(m_window_info, error); if (!m_gl_context) { Log_ErrorPrintf("Failed to create any GL context"); @@ -692,7 +692,7 @@ GPUDevice::AdapterAndModeList OpenGLDevice::GetAdapterAndModeList() if (m_gl_context) { - for (const GL::Context::FullscreenModeInfo& fmi : m_gl_context->EnumerateFullscreenModes()) + for (const OpenGLContext::FullscreenModeInfo& fmi : m_gl_context->EnumerateFullscreenModes()) { aml.fullscreen_modes.push_back(GetFullscreenModeString(fmi.width, fmi.height, fmi.refresh_rate)); } diff --git a/src/util/opengl_device.h b/src/util/opengl_device.h index a020823dc..8e22b8284 100644 --- a/src/util/opengl_device.h +++ b/src/util/opengl_device.h @@ -1,12 +1,12 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once -#include "gl/context.h" #include "gpu_device.h" #include "gpu_framebuffer_manager.h" #include "gpu_shader_cache.h" +#include "opengl_context.h" #include "opengl_loader.h" #include "opengl_pipeline.h" #include "opengl_texture.h" @@ -168,7 +168,7 @@ private: void SetVertexBufferOffsets(u32 base_vertex); - std::unique_ptr m_gl_context; + std::unique_ptr m_gl_context; std::unique_ptr m_vertex_buffer; std::unique_ptr m_index_buffer; diff --git a/src/util/util.vcxproj b/src/util/util.vcxproj index db2983f77..a4d8b1f19 100644 --- a/src/util/util.vcxproj +++ b/src/util/util.vcxproj @@ -19,12 +19,6 @@ - - true - - - true - @@ -48,6 +42,24 @@ true + + true + + + true + + + true + + + true + + + true + + + true + true @@ -136,12 +148,6 @@ - - true - - - true - @@ -159,6 +165,21 @@ + + true + + + true + + + true + + + true + + + true + true @@ -260,6 +281,9 @@ true Document + + true + {57F6206D-F264-4B07-BAF8-11B9BBE1F455} diff --git a/src/util/util.vcxproj.filters b/src/util/util.vcxproj.filters index 724e927c0..29f0ea8aa 100644 --- a/src/util/util.vcxproj.filters +++ b/src/util/util.vcxproj.filters @@ -54,12 +54,6 @@ - - gl - - - gl - @@ -72,6 +66,12 @@ + + + + + + @@ -135,12 +135,6 @@ - - gl - - - gl - @@ -154,6 +148,11 @@ + + + + + @@ -162,5 +161,6 @@ + \ No newline at end of file