diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index 53c351a14..84d775af4 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -312,10 +312,8 @@ elseif(UNIX) externals/duckstation/gl/context_egl_x11.cpp externals/duckstation/gl/context_glx.cpp externals/duckstation/gl/x11_window.cpp - - ../../externals/glad/src/glad_egl.c - ../../externals/glad/src/glad_glx.c ) + target_link_libraries(citra PRIVATE "${X11_LIBRARIES}" "${EGL_LIBRARIES}") target_include_directories(citra PRIVATE "${X11_INCLUDE_DIR}") add_compile_definitions(QAPPLICATION_CLASS=QApplication) diff --git a/src/citra_qt/externals/duckstation/gl/context.cpp b/src/citra_qt/externals/duckstation/gl/context.cpp index 56f03466b..f7578064f 100644 --- a/src/citra_qt/externals/duckstation/gl/context.cpp +++ b/src/citra_qt/externals/duckstation/gl/context.cpp @@ -1,7 +1,7 @@ #include #include #include -#include "../log.h" +#include "citra_qt/wayland/log.h" #include "context.h" #include "loader.h" Log_SetChannel(GL::Context); diff --git a/src/citra_qt/externals/duckstation/gl/context.h b/src/citra_qt/externals/duckstation/gl/context.h index a77c99e3b..e7d2bc571 100644 --- a/src/citra_qt/externals/duckstation/gl/context.h +++ b/src/citra_qt/externals/duckstation/gl/context.h @@ -2,8 +2,9 @@ #include #include #include -#include "../duckstation_compat.h" -#include "../window_info.h" + +#include "citra_qt/wayland/duckstation_compat.h" +#include "citra_qt/wayland/window_info.h" namespace GL { using namespace citra; diff --git a/src/citra_qt/externals/duckstation/gl/context_agl.mm b/src/citra_qt/externals/duckstation/gl/context_agl.mm index f83351834..a0fa4cbde 100644 --- a/src/citra_qt/externals/duckstation/gl/context_agl.mm +++ b/src/citra_qt/externals/duckstation/gl/context_agl.mm @@ -1,214 +1,195 @@ -#include "context_agl.h" -#include "../duckstation_compat.h" -#include "../log.h" -#include "loader.h" #include +#include "citra_qt/wayland/duckstation_compat.h" +#include "citra_qt/wayland/log.h" +#include "context_agl.h" +#include "loader.h" Log_SetChannel(GL::ContextAGL); namespace GL { -ContextAGL::ContextAGL(const WindowInfo& wi) : Context(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(const WindowInfo& wi) : Context(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() -{ - if ([NSOpenGLContext currentContext] == m_context) - [NSOpenGLContext clearCurrentContext]; +ContextAGL::~ContextAGL() { + if ([NSOpenGLContext currentContext] == m_context) + [NSOpenGLContext clearCurrentContext]; - if (m_context) - [m_context release]; + if (m_context) + [m_context release]; - if (m_pixel_format) - [m_pixel_format release]; + if (m_pixel_format) + [m_pixel_format release]; - if (m_opengl_module_handle) - dlclose(m_opengl_module_handle); + if (m_opengl_module_handle) + dlclose(m_opengl_module_handle); } std::unique_ptr ContextAGL::Create(const WindowInfo& wi, const Version* versions_to_try, - size_t num_versions_to_try) -{ - std::unique_ptr context = std::make_unique(wi); - if (!context->Initialize(versions_to_try, num_versions_to_try)) - return nullptr; + size_t num_versions_to_try) { + std::unique_ptr context = std::make_unique(wi); + if (!context->Initialize(versions_to_try, num_versions_to_try)) + return nullptr; - return context; + return context; } -bool ContextAGL::Initialize(const Version* versions_to_try, size_t num_versions_to_try) -{ - for (size_t i = 0; i < num_versions_to_try; i++) - { - const Version& cv = versions_to_try[i]; - if (cv.profile == Profile::NoProfile && CreateContext(nullptr, NSOpenGLProfileVersionLegacy, true)) - { - // we already have the dummy context, so just use that - m_version = cv; - return true; +bool ContextAGL::Initialize(const Version* versions_to_try, size_t num_versions_to_try) { + for (size_t i = 0; i < num_versions_to_try; i++) { + const Version& cv = versions_to_try[i]; + if (cv.profile == Profile::NoProfile && + CreateContext(nullptr, NSOpenGLProfileVersionLegacy, true)) { + // we already have the dummy context, so just use that + m_version = cv; + return true; + } else if (cv.profile == Profile::Core) { + if (cv.major_version > 4 && cv.minor_version > 1) + continue; + + const NSOpenGLPixelFormatAttribute profile = + (cv.major_version > 3 || cv.minor_version > 2) ? NSOpenGLProfileVersion4_1Core + : NSOpenGLProfileVersion3_2Core; + if (CreateContext(nullptr, static_cast(profile), true)) { + m_version = cv; + return true; + } + } } - else if (cv.profile == Profile::Core) - { - if (cv.major_version > 4 && cv.minor_version > 1) - continue; - - const NSOpenGLPixelFormatAttribute profile = (cv.major_version > 3 || cv.minor_version > 2) ? NSOpenGLProfileVersion4_1Core : NSOpenGLProfileVersion3_2Core; - if (CreateContext(nullptr, static_cast(profile), true)) - { - m_version = cv; - return true; - } - } - } - return false; -} - -void* ContextAGL::GetProcAddress(const char* name) -{ - void* addr = m_opengl_module_handle ? dlsym(m_opengl_module_handle, name) : nullptr; - if (addr) - return addr; - - return dlsym(RTLD_NEXT, name); -} - -bool ContextAGL::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*/) -{ - UpdateDimensions(); -} - -bool ContextAGL::UpdateDimensions() -{ - const NSSize window_size = [GetView() frame].size; - const CGFloat window_scale = [[GetView() window] backingScaleFactor]; - const u32 new_width = static_cast(static_cast(window_size.width) * window_scale); - const u32 new_height = static_cast(static_cast(window_size.height) * window_scale); - - if (m_wi.surface_width == new_width && m_wi.surface_height == new_height) return false; - - m_wi.surface_width = new_width; - m_wi.surface_height = new_height; - - dispatch_block_t block = ^{ - [m_context update]; - }; - - if ([NSThread isMainThread]) - block(); - else - dispatch_sync(dispatch_get_main_queue(), block); - - return true; } -bool ContextAGL::SwapBuffers() -{ - [m_context flushBuffer]; - return true; +void* ContextAGL::GetProcAddress(const char* name) { + void* addr = m_opengl_module_handle ? dlsym(m_opengl_module_handle, name) : nullptr; + if (addr) + return addr; + + return dlsym(RTLD_NEXT, name); } -bool ContextAGL::MakeCurrent() -{ - [m_context makeCurrentContext]; - return true; -} - -bool ContextAGL::DoneCurrent() -{ - [NSOpenGLContext clearCurrentContext]; - return true; -} - -bool ContextAGL::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) -{ - 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) - return nullptr; - - context->m_version = m_version; - context->m_pixel_format = m_pixel_format; - [context->m_pixel_format retain]; - - if (wi.type == WindowInfo::Type::MacOS) - context->BindContextToView(); - - return context; -} - -bool ContextAGL::CreateContext(NSOpenGLContext* share_context, int profile, bool make_current) -{ - if (m_context) - { - [m_context release]; - m_context = nullptr; - } - - if (m_pixel_format) - [m_pixel_format release]; - - const std::array attribs = {{ - NSOpenGLPFADoubleBuffer, - NSOpenGLPFAOpenGLProfile, - static_cast(profile), - NSOpenGLPFAAccelerated, - 0}}; - m_pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs.data()]; - if (m_pixel_format == nil) - { - Log_ErrorPrintf("Failed to initialize pixel format"); - return false; - } - - m_context = [[NSOpenGLContext alloc] initWithFormat:m_pixel_format shareContext:nil]; - if (m_context == nil) - return false; - - if (m_wi.type == WindowInfo::Type::MacOS) +bool ContextAGL::ChangeSurface(const WindowInfo& new_wi) { + m_wi = new_wi; BindContextToView(); - - if (make_current) - [m_context makeCurrentContext]; - - return true; + return true; } -void ContextAGL::BindContextToView() -{ - NSView* const view = GetView(); - NSWindow* const window = [view window]; - [view setWantsBestResolutionOpenGLSurface:YES]; +void ContextAGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/) { + UpdateDimensions(); +} - UpdateDimensions(); +bool ContextAGL::UpdateDimensions() { + const NSSize window_size = [GetView() frame].size; + const CGFloat window_scale = [[GetView() window] backingScaleFactor]; + const u32 new_width = static_cast(static_cast(window_size.width) * window_scale); + const u32 new_height = + static_cast(static_cast(window_size.height) * window_scale); - dispatch_block_t block = ^{ - [window makeFirstResponder:view]; - [m_context setView:view]; - [window makeKeyAndOrderFront:nil]; - }; + if (m_wi.surface_width == new_width && m_wi.surface_height == new_height) + return false; - if ([NSThread isMainThread]) - block(); - else - dispatch_sync(dispatch_get_main_queue(), block); + m_wi.surface_width = new_width; + m_wi.surface_height = new_height; + + dispatch_block_t block = ^{ + [m_context update]; + }; + + if ([NSThread isMainThread]) + block(); + else + dispatch_sync(dispatch_get_main_queue(), block); + + return true; +} + +bool ContextAGL::SwapBuffers() { + [m_context flushBuffer]; + return true; +} + +bool ContextAGL::MakeCurrent() { + [m_context makeCurrentContext]; + return true; +} + +bool ContextAGL::DoneCurrent() { + [NSOpenGLContext clearCurrentContext]; + return true; +} + +bool ContextAGL::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) { + 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) + return nullptr; + + context->m_version = m_version; + context->m_pixel_format = m_pixel_format; + [context->m_pixel_format retain]; + + if (wi.type == WindowInfo::Type::MacOS) + context->BindContextToView(); + + return context; +} + +bool ContextAGL::CreateContext(NSOpenGLContext* share_context, int profile, bool make_current) { + if (m_context) { + [m_context release]; + m_context = nullptr; + } + + if (m_pixel_format) + [m_pixel_format release]; + + const std::array attribs = { + {NSOpenGLPFADoubleBuffer, NSOpenGLPFAOpenGLProfile, + static_cast(profile), NSOpenGLPFAAccelerated, 0}}; + m_pixel_format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs.data()]; + if (m_pixel_format == nil) { + Log_ErrorPrintf("Failed to initialize pixel format"); + return false; + } + + m_context = [[NSOpenGLContext alloc] initWithFormat:m_pixel_format shareContext:nil]; + if (m_context == nil) + return false; + + if (m_wi.type == WindowInfo::Type::MacOS) + BindContextToView(); + + if (make_current) + [m_context makeCurrentContext]; + + return true; +} + +void ContextAGL::BindContextToView() { + NSView* const view = GetView(); + NSWindow* const window = [view window]; + [view setWantsBestResolutionOpenGLSurface:YES]; + + UpdateDimensions(); + + dispatch_block_t block = ^{ + [window makeFirstResponder:view]; + [m_context setView:view]; + [window makeKeyAndOrderFront:nil]; + }; + + if ([NSThread isMainThread]) + block(); + else + dispatch_sync(dispatch_get_main_queue(), block); } } // namespace GL diff --git a/src/citra_qt/externals/duckstation/gl/context_egl.cpp b/src/citra_qt/externals/duckstation/gl/context_egl.cpp index 4d0a9cb3a..d8aaf6f2e 100644 --- a/src/citra_qt/externals/duckstation/gl/context_egl.cpp +++ b/src/citra_qt/externals/duckstation/gl/context_egl.cpp @@ -1,8 +1,8 @@ #include #include #include -#include "../duckstation_compat.h" -#include "../log.h" +#include "citra_qt/wayland/duckstation_compat.h" +#include "citra_qt/wayland/log.h" #include "context_egl.h" Log_SetChannel(GL::ContextEGL); diff --git a/src/citra_qt/externals/duckstation/gl/context_egl.h b/src/citra_qt/externals/duckstation/gl/context_egl.h index cf19a8991..0c02e043e 100644 --- a/src/citra_qt/externals/duckstation/gl/context_egl.h +++ b/src/citra_qt/externals/duckstation/gl/context_egl.h @@ -1,7 +1,9 @@ #pragma once -#include "../../../../../externals/glad/src/glad_egl.h" + #include "context.h" +#include + namespace GL { class ContextEGL : public Context { diff --git a/src/citra_qt/externals/duckstation/gl/context_egl_wayland.cpp b/src/citra_qt/externals/duckstation/gl/context_egl_wayland.cpp index 9f6929aa8..ac320fe89 100644 --- a/src/citra_qt/externals/duckstation/gl/context_egl_wayland.cpp +++ b/src/citra_qt/externals/duckstation/gl/context_egl_wayland.cpp @@ -1,5 +1,5 @@ #include -#include "../log.h" +#include "citra_qt/wayland/log.h" #include "context_egl_wayland.h" Log_SetChannel(ContextEGLWayland); diff --git a/src/citra_qt/externals/duckstation/gl/context_egl_x11.cpp b/src/citra_qt/externals/duckstation/gl/context_egl_x11.cpp index 1cf6f5882..3ed3187e7 100644 --- a/src/citra_qt/externals/duckstation/gl/context_egl_x11.cpp +++ b/src/citra_qt/externals/duckstation/gl/context_egl_x11.cpp @@ -1,4 +1,4 @@ -#include "../log.h" +#include "citra_qt/wayland/log.h" #include "context_egl_x11.h" Log_SetChannel(GL::ContextEGLX11); diff --git a/src/citra_qt/externals/duckstation/gl/context_glx.cpp b/src/citra_qt/externals/duckstation/gl/context_glx.cpp index 34eb16431..b818425a0 100644 --- a/src/citra_qt/externals/duckstation/gl/context_glx.cpp +++ b/src/citra_qt/externals/duckstation/gl/context_glx.cpp @@ -1,6 +1,6 @@ #include -#include "../duckstation_compat.h" -#include "../log.h" +#include "citra_qt/wayland/duckstation_compat.h" +#include "citra_qt/wayland/log.h" #include "context_glx.h" Log_SetChannel(GL::ContextGLX); diff --git a/src/citra_qt/externals/duckstation/gl/context_glx.h b/src/citra_qt/externals/duckstation/gl/context_glx.h index f8f2fafab..c03ecb278 100644 --- a/src/citra_qt/externals/duckstation/gl/context_glx.h +++ b/src/citra_qt/externals/duckstation/gl/context_glx.h @@ -1,8 +1,10 @@ #pragma once -#include "../../../../../externals/glad/src/glad_glx.h" + #include "context.h" #include "x11_window.h" +#include + namespace GL { class ContextGLX final : public Context { diff --git a/src/citra_qt/externals/duckstation/gl/context_wgl.cpp b/src/citra_qt/externals/duckstation/gl/context_wgl.cpp index 2d79ca71d..7db4dac31 100644 --- a/src/citra_qt/externals/duckstation/gl/context_wgl.cpp +++ b/src/citra_qt/externals/duckstation/gl/context_wgl.cpp @@ -1,6 +1,6 @@ -#include "../duckstation_compat.h" -#include "../log.h" -#include "../scoped_guard.h" +#include "citra_qt/wayland/duckstation_compat.h" +#include "citra_qt/wayland/log.h" +#include "citra_qt/wayland/scoped_guard.h" #include "context_wgl.h" #include "loader.h" using namespace melonDS; diff --git a/src/citra_qt/externals/duckstation/gl/context_wgl.h b/src/citra_qt/externals/duckstation/gl/context_wgl.h index 1f869e005..28a133815 100644 --- a/src/citra_qt/externals/duckstation/gl/context_wgl.h +++ b/src/citra_qt/externals/duckstation/gl/context_wgl.h @@ -1,8 +1,10 @@ #pragma once -#include "../windows_headers.h" + +#include "citra+qt/wayland/windows_headers.h" #include -#include "../../../../../externals/glad/src/glad_wgl.h" +#include + #include "context.h" #include "loader.h" diff --git a/src/citra_qt/externals/duckstation/gl/loader.h b/src/citra_qt/externals/duckstation/gl/loader.h index 4aefd97f4..7e457a6b9 100644 --- a/src/citra_qt/externals/duckstation/gl/loader.h +++ b/src/citra_qt/externals/duckstation/gl/loader.h @@ -2,7 +2,7 @@ // Fix glad.h including windows.h #ifdef _WIN32 -#include "../windows_headers.h" +#include "citra_qt/wayland/windows_headers.h" #endif -#include "../../../../../externals/glad/src/glad.h" +#include diff --git a/src/citra_qt/externals/duckstation/gl/x11_window.cpp b/src/citra_qt/externals/duckstation/gl/x11_window.cpp index 6ae766b92..c71dd1780 100644 --- a/src/citra_qt/externals/duckstation/gl/x11_window.cpp +++ b/src/citra_qt/externals/duckstation/gl/x11_window.cpp @@ -1,6 +1,6 @@ #include -#include "../duckstation_compat.h" -#include "../log.h" +#include "citra_qt/wayland/duckstation_compat.h" +#include "citra_qt/wayland/log.h" #include "x11_window.h" Log_SetChannel(X11Window); diff --git a/src/citra_qt/externals/duckstation/gl/x11_window.h b/src/citra_qt/externals/duckstation/gl/x11_window.h index a8fa2f6cb..9d2e529d8 100644 --- a/src/citra_qt/externals/duckstation/gl/x11_window.h +++ b/src/citra_qt/externals/duckstation/gl/x11_window.h @@ -1,7 +1,7 @@ #pragma once #include #include -#include "../duckstation_compat.h" +#include "citra_qt/wayland/duckstation_compat.h" namespace GL { using namespace citra; diff --git a/src/citra_qt/externals/types.h b/src/citra_qt/externals/types.h deleted file mode 100644 index 8d0c3edb9..000000000 --- a/src/citra_qt/externals/types.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright 2016-2023 melonDS team - - This file is part of melonDS. - - melonDS is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - melonDS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef TYPES_H -#define TYPES_H - -#include -#include - -namespace citra { -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -typedef int8_t s8; -typedef int16_t s16; -typedef int32_t s32; -typedef int64_t s64; - -template -using array2d = std::array, A>; -} // namespace citra -#endif // TYPES_H diff --git a/src/citra_qt/externals/duckstation/duckstation_compat.h b/src/citra_qt/wayland/duckstation_compat.h similarity index 88% rename from src/citra_qt/externals/duckstation/duckstation_compat.h rename to src/citra_qt/wayland/duckstation_compat.h index 9c2caf778..d2c297842 100644 --- a/src/citra_qt/externals/duckstation/duckstation_compat.h +++ b/src/citra_qt/wayland/duckstation_compat.h @@ -1,7 +1,7 @@ #ifndef DUCKSTATION_COMPAT_H #define DUCKSTATION_COMPAT_H -#include "../types.h" +#include "common/common_types.h" #include @@ -14,4 +14,4 @@ #define UnreachableCode() __builtin_unreachable() -#endif \ No newline at end of file +#endif diff --git a/src/citra_qt/externals/duckstation/log.h b/src/citra_qt/wayland/log.h similarity index 100% rename from src/citra_qt/externals/duckstation/log.h rename to src/citra_qt/wayland/log.h diff --git a/src/citra_qt/externals/duckstation/scoped_guard.h b/src/citra_qt/wayland/scoped_guard.h similarity index 100% rename from src/citra_qt/externals/duckstation/scoped_guard.h rename to src/citra_qt/wayland/scoped_guard.h diff --git a/src/citra_qt/externals/duckstation/window_info.cpp b/src/citra_qt/wayland/window_info.cpp similarity index 99% rename from src/citra_qt/externals/duckstation/window_info.cpp rename to src/citra_qt/wayland/window_info.cpp index 615cd4baf..ab8d3e8b2 100644 --- a/src/citra_qt/externals/duckstation/window_info.cpp +++ b/src/citra_qt/wayland/window_info.cpp @@ -86,7 +86,7 @@ bool WindowInfo::QueryRefreshRateForWindow(const WindowInfo& wi, float* refresh_ #include #include "common/scoped_guard.h" -#include "gl/x11_window.h" +#include "x11_window.h" static bool GetRefreshRateFromXRandR(const WindowInfo& wi, float* refresh_rate) { Display* display = static_cast(wi.display_connection); @@ -172,4 +172,4 @@ bool WindowInfo::QueryRefreshRateForWindow(const WindowInfo& wi, float* refresh_ return false; } -#endif \ No newline at end of file +#endif diff --git a/src/citra_qt/externals/duckstation/window_info.h b/src/citra_qt/wayland/window_info.h similarity index 96% rename from src/citra_qt/externals/duckstation/window_info.h rename to src/citra_qt/wayland/window_info.h index 848cc3703..9a019b95e 100644 --- a/src/citra_qt/externals/duckstation/window_info.h +++ b/src/citra_qt/wayland/window_info.h @@ -1,5 +1,5 @@ #pragma once -#include "../types.h" +#include "common/common_types.h" // Contains the information required to create a graphics context in a window. struct WindowInfo { diff --git a/src/citra_qt/externals/duckstation/windows_headers.h b/src/citra_qt/wayland/windows_headers.h similarity index 100% rename from src/citra_qt/externals/duckstation/windows_headers.h rename to src/citra_qt/wayland/windows_headers.h diff --git a/src/common/common_types.h b/src/common/common_types.h index 808d2c5a7..c5f079fda 100644 --- a/src/common/common_types.h +++ b/src/common/common_types.h @@ -54,6 +54,9 @@ typedef u32 PAddr; ///< Represents a pointer in the ARM11 physical address space using u128 = std::array; static_assert(sizeof(u128) == 16, "u128 must be 128 bits wide"); +template +using array2d = std::array, A>; + // An inheritable class to disallow the copy constructor and operator= functions class NonCopyable { protected: