diff --git a/gtk/src/fractional-scale-v1.c b/frontend-common/fractional-scale-v1.c similarity index 100% rename from gtk/src/fractional-scale-v1.c rename to frontend-common/fractional-scale-v1.c diff --git a/gtk/src/fractional-scale-v1.h b/frontend-common/fractional-scale-v1.h similarity index 100% rename from gtk/src/fractional-scale-v1.h rename to frontend-common/fractional-scale-v1.h diff --git a/gtk/src/gtk_glx_context.cpp b/frontend-common/glx_context.cpp similarity index 91% rename from gtk/src/gtk_glx_context.cpp rename to frontend-common/glx_context.cpp index fcb3cd5a..2367905b 100644 --- a/gtk/src/gtk_glx_context.cpp +++ b/frontend-common/glx_context.cpp @@ -4,12 +4,12 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ +#include #include #include #include -#include "gtk_s9x.h" -#include "gtk_glx_context.h" +#include "glx_context.hpp" GTKGLXContext::GTKGLXContext() { @@ -18,6 +18,8 @@ GTKGLXContext::GTKGLXContext() version_major = -1; version_minor = -1; + + gladLoaderLoadGLX(nullptr, 0); } GTKGLXContext::~GTKGLXContext() @@ -127,12 +129,12 @@ void GTKGLXContext::make_current() void GTKGLXContext::swap_interval(int frames) { - if (epoxy_has_glx_extension(display, screen, "GLX_EXT_swap_control")) + if (GLAD_GLX_EXT_swap_control) glXSwapIntervalEXT(display, xid, frames); - else if (epoxy_has_glx_extension(display, screen, "GLX_SGI_swap_control")) + else if (GLAD_GLX_SGI_swap_control) glXSwapIntervalSGI(frames); #ifdef GLX_MESA_swap_control - else if (epoxy_has_glx_extension(display, screen, "GLX_MESA_swap_control")) + else if (GLAD_GLX_MESA_swap_control) glXSwapIntervalMESA(frames); #endif } diff --git a/gtk/src/gtk_glx_context.h b/frontend-common/glx_context.hpp similarity index 88% rename from gtk/src/gtk_glx_context.h rename to frontend-common/glx_context.hpp index 272d7b61..7d4f07de 100644 --- a/gtk/src/gtk_glx_context.h +++ b/frontend-common/glx_context.hpp @@ -4,12 +4,12 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#ifndef __GTK_GLX_CONTEXT_H -#define __GTK_GLX_CONTEXT_H +#ifndef __GLX_CONTEXT_HPP +#define __GLX_CONTEXT_HPP -#include "gtk_opengl_context.h" +#include "opengl_context.hpp" -#include +#include class GTKGLXContext : public OpenGLContext { diff --git a/gtk/src/viewporter-client-protocol.c b/frontend-common/viewporter-client-protocol.c similarity index 100% rename from gtk/src/viewporter-client-protocol.c rename to frontend-common/viewporter-client-protocol.c diff --git a/gtk/src/viewporter-client-protocol.h b/frontend-common/viewporter-client-protocol.h similarity index 100% rename from gtk/src/viewporter-client-protocol.h rename to frontend-common/viewporter-client-protocol.h diff --git a/gtk/src/wayland-idle-inhibit-unstable-v1.c b/frontend-common/wayland-idle-inhibit-unstable-v1.c similarity index 100% rename from gtk/src/wayland-idle-inhibit-unstable-v1.c rename to frontend-common/wayland-idle-inhibit-unstable-v1.c diff --git a/gtk/src/wayland-idle-inhibit-unstable-v1.h b/frontend-common/wayland-idle-inhibit-unstable-v1.h similarity index 100% rename from gtk/src/wayland-idle-inhibit-unstable-v1.h rename to frontend-common/wayland-idle-inhibit-unstable-v1.h diff --git a/gtk/src/gtk_wayland_egl_context.cpp b/frontend-common/wayland_egl_context.cpp similarity index 89% rename from gtk/src/gtk_wayland_egl_context.cpp rename to frontend-common/wayland_egl_context.cpp index 99c8be9d..d13ae40f 100644 --- a/gtk/src/gtk_wayland_egl_context.cpp +++ b/frontend-common/wayland_egl_context.cpp @@ -7,8 +7,7 @@ #include #include -#include "gtk_s9x.h" -#include "gtk_wayland_egl_context.h" +#include "wayland_egl_context.hpp" WaylandEGLContext::WaylandEGLContext() { @@ -65,15 +64,27 @@ bool WaylandEGLContext::create_context() EGLint num_configs = 0; + if (!gladLoaderLoadEGL(nullptr)) + { + printf("Couldn't load EGL.\n"); + return false; + } + egl_display = eglGetDisplay((EGLNativeDisplayType)wayland_surface->display); - eglInitialize(egl_display, NULL, NULL); + int major, minor; + eglInitialize(egl_display, &major, &minor); + + // Load the rest of the functions only after calling eglInitialize. + if (!gladLoaderLoadEGL(egl_display)) + { + printf("Couldn't load EGL functions.\n"); + } if (!eglChooseConfig(egl_display, surface_attribs, &egl_config, 1, &num_configs)) { printf("Couldn't find matching config.\n"); return false; } - eglBindAPI(EGL_OPENGL_API); std::tie(width, height) = wayland_surface->get_size(); egl_window = wl_egl_window_create(wayland_surface->child, width, height); @@ -90,6 +101,7 @@ bool WaylandEGLContext::create_context() return false; } + eglBindAPI(EGL_OPENGL_API); egl_context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, core_context_attribs); if (!egl_context) { @@ -107,7 +119,7 @@ bool WaylandEGLContext::create_context() void WaylandEGLContext::resize(WaylandSurface::Metrics m) { wayland_surface->resize(m); - + std::tie(width, height) = wayland_surface->get_size(); wl_egl_window_resize(egl_window, width, height, 0, 0); diff --git a/gtk/src/gtk_wayland_surface.cpp b/frontend-common/wayland_surface.cpp similarity index 97% rename from gtk/src/gtk_wayland_surface.cpp rename to frontend-common/wayland_surface.cpp index 933ee0d6..fe21d3fc 100644 --- a/gtk/src/gtk_wayland_surface.cpp +++ b/frontend-common/wayland_surface.cpp @@ -6,11 +6,11 @@ #include #include +#include #include #include "fractional-scale-v1.h" -#include "gtk_s9x.h" -#include "gtk_wayland_surface.h" +#include "wayland_surface.hpp" #include "wayland-idle-inhibit-unstable-v1.h" #include "viewporter-client-protocol.h" @@ -133,7 +133,7 @@ bool WaylandSurface::attach(wl_display *display, wl_surface *surface, Metrics m) wp_fractional_scale_v1_add_listener(fractional_scale, &fractional_scale_v1_listener, this); } - if (idle_inhibit_manager && gui_config->prevent_screensaver) + if (idle_inhibit_manager) { printf("Inhibiting screensaver.\n"); zwp_idle_inhibit_manager_v1_create_inhibitor(idle_inhibit_manager, child); diff --git a/gtk/CMakeLists.txt b/gtk/CMakeLists.txt index 3f5d1cbe..c7491190 100644 --- a/gtk/CMakeLists.txt +++ b/gtk/CMakeLists.txt @@ -67,18 +67,19 @@ find_library(DL dl REQUIRED) list(APPEND ARGS ${SDL2_CFLAGS} ${GTK_CFLAGS} ${XRANDR_CFLAGS}) list(APPEND LIBS ${X11} ${XEXT} ${DL} ${SDL2_LIBRARIES} ${GTK_LIBRARIES} ${XRANDR_LIBRARIES}) -pkg_check_modules(EPOXY REQUIRED epoxy) -list(APPEND ARGS ${EPOXY_CFLAGS}) -list(APPEND LIBS ${EPOXY_LIBRARIES}) list(APPEND SOURCES src/gtk_display_driver_opengl.cpp - src/gtk_glx_context.cpp + ../frontend-common/glx_context.cpp ../shaders/glsl.cpp ../shaders/shader_helpers.cpp ../vulkan/slang_helpers.cpp ../vulkan/slang_helpers.hpp ../vulkan/slang_preset_ini.cpp ../vulkan/slang_preset_ini.hpp + ../external/glad/src/glx.c + ../external/glad/src/egl.c + ../external/glad/src/gl.c src/gtk_shader_parameters.cpp) +list(APPEND INCLUDES ../external/glad/include) if(USE_SLANG) list(APPEND SOURCES ../shaders/slang.cpp) @@ -151,13 +152,13 @@ list(APPEND INCLUDES ../external/imgui) if(USE_WAYLAND) pkg_check_modules(WAYLAND REQUIRED wayland-client wayland-egl) list(APPEND DEFINES "USE_WAYLAND") - list(APPEND SOURCES src/gtk_wayland_egl_context.cpp - src/gtk_wayland_egl_context.h - src/gtk_wayland_surface.cpp - src/gtk_wayland_surface.h - src/wayland-idle-inhibit-unstable-v1.c - src/viewporter-client-protocol.c - src/fractional-scale-v1.c) + list(APPEND SOURCES ../frontend-common/wayland_egl_context.cpp + ../frontend-common/wayland_egl_context.hpp + ../frontend-common/wayland_surface.cpp + ../frontend-common/wayland_surface.hpp + ../frontend-common/wayland-idle-inhibit-unstable-v1.c + ../frontend-common/viewporter-client-protocol.c + ../frontend-common/fractional-scale-v1.c) list(APPEND ARGS ${WAYLAND_CFLAGS}) list(APPEND LIBS ${WAYLAND_LIBRARIES}) endif() diff --git a/gtk/src/gtk_display_driver_opengl.cpp b/gtk/src/gtk_display_driver_opengl.cpp index 53f324d6..b085a0b1 100644 --- a/gtk/src/gtk_display_driver_opengl.cpp +++ b/gtk/src/gtk_display_driver_opengl.cpp @@ -5,6 +5,7 @@ \*****************************************************************************/ #include +#include #include #include #include @@ -391,9 +392,16 @@ bool S9xOpenGLDisplayDriver::create_context() return false; context->make_current(); + gladLoaderLoadGL(); legacy = false; - version = epoxy_gl_version(); + + auto version_string = (const char *)glGetString(GL_VERSION); + int major_version = 1; + int minor_version = 0; + std::sscanf(version_string, "%d.%d", &major_version, &minor_version); + version = major_version * 10 + minor_version; + if (version < 20) { printf("OpenGL version is only %d.%d. Recommended version is 2.0.\n", @@ -479,6 +487,8 @@ void S9xOpenGLDisplayDriver::deinit() ImGui_ImplOpenGL3_Shutdown(); S9xImGuiDeinit(); } + + gladLoaderUnloadGL(); } int S9xOpenGLDisplayDriver::query_availability() @@ -495,12 +505,7 @@ int S9xOpenGLDisplayDriver::query_availability() #ifdef GDK_WINDOWING_X11 if (GDK_IS_X11_DISPLAY(gdk_display)) { - Display *dpy = GDK_DISPLAY_XDISPLAY(gdk_display); - - if (glXQueryExtension(dpy, NULL, NULL) == True) - { return 1; - } } #endif diff --git a/gtk/src/gtk_display_driver_opengl.h b/gtk/src/gtk_display_driver_opengl.h index 100ff0b7..3374b157 100644 --- a/gtk/src/gtk_display_driver_opengl.h +++ b/gtk/src/gtk_display_driver_opengl.h @@ -10,16 +10,16 @@ #include "gtk_s9x.h" #include "gtk_display_driver.h" -#include +#include -#include "gtk_opengl_context.h" +#include "../../frontend-common/opengl_context.hpp" #include "gtk_compat.h" #ifdef GDK_WINDOWING_X11 -#include "gtk_glx_context.h" +#include "../../frontend-common/glx_context.hpp" #endif #ifdef GDK_WINDOWING_WAYLAND -#include "gtk_wayland_egl_context.h" +#include "../../frontend-common/wayland_egl_context.hpp" #endif #include "shaders/glsl.h" diff --git a/gtk/src/gtk_display_driver_vulkan.h b/gtk/src/gtk_display_driver_vulkan.h index 3fe1a34b..3da9ceb6 100644 --- a/gtk/src/gtk_display_driver_vulkan.h +++ b/gtk/src/gtk_display_driver_vulkan.h @@ -13,7 +13,7 @@ #include "../../vulkan/std_chrono_throttle.hpp" #ifdef VK_USE_PLATFORM_WAYLAND_KHR -#include "gtk_wayland_surface.h" +#include "../../frontend-common/wayland_surface.hpp" #endif class S9xVulkanDisplayDriver : public S9xDisplayDriver diff --git a/gtk/src/gtk_opengl_context.h b/gtk/src/gtk_opengl_context.h deleted file mode 100644 index 62b1c10e..00000000 --- a/gtk/src/gtk_opengl_context.h +++ /dev/null @@ -1,30 +0,0 @@ -/*****************************************************************************\ - Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - This file is licensed under the Snes9x License. - For further information, consult the LICENSE file in the root directory. -\*****************************************************************************/ - -#ifndef __GTK_OPENGL_CONTEXT_H -#define __GTK_OPENGL_CONTEXT_H - -class OpenGLContext -{ - public: - virtual ~OpenGLContext(){}; - virtual bool create_context() = 0; - virtual void resize() = 0; - virtual void swap_buffers() = 0; - virtual void swap_interval(int frames) = 0; - virtual void make_current() = 0; - virtual bool ready() - { - return true; - }; - - int x; - int y; - int width; - int height; -}; - -#endif diff --git a/gtk/src/gtk_wayland_egl_context.h b/gtk/src/gtk_wayland_egl_context.h deleted file mode 100644 index c9513ffa..00000000 --- a/gtk/src/gtk_wayland_egl_context.h +++ /dev/null @@ -1,41 +0,0 @@ -/*****************************************************************************\ - Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - This file is licensed under the Snes9x License. - For further information, consult the LICENSE file in the root directory. -\*****************************************************************************/ - -#ifndef __GTK_WAYLAND_EGL_CONTEXT_H -#define __GTK_WAYLAND_EGL_CONTEXT_H - -#include "gtk_opengl_context.h" -#include "gtk_wayland_surface.h" - -#include -#include -#include - -class WaylandEGLContext : public OpenGLContext -{ - public: - WaylandEGLContext(); - ~WaylandEGLContext(); - bool attach(wl_display *display, wl_surface *surface, WaylandSurface::Metrics m); - bool create_context(); - void resize() {}; - void resize(WaylandSurface::Metrics m); - void swap_buffers(); - void swap_interval(int frames); - void make_current(); - bool ready(); - - EGLDisplay egl_display; - EGLSurface egl_surface; - EGLContext egl_context; - EGLConfig egl_config; - - wl_egl_window *egl_window; - - std::unique_ptr wayland_surface; -}; - -#endif diff --git a/gtk/src/gtk_wayland_surface.h b/gtk/src/gtk_wayland_surface.h deleted file mode 100644 index cead1baf..00000000 --- a/gtk/src/gtk_wayland_surface.h +++ /dev/null @@ -1,47 +0,0 @@ -/*****************************************************************************\ - Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - This file is licensed under the Snes9x License. - For further information, consult the LICENSE file in the root directory. -\*****************************************************************************/ - -#pragma once - -#include "viewporter-client-protocol.h" -#include "fractional-scale-v1.h" - -class WaylandSurface -{ - public: - WaylandSurface(); - ~WaylandSurface(); - - struct Metrics { - int x, y, width, height, scale; - }; - - bool attach(wl_display *display, wl_surface *surface, Metrics source_metrics); - void resize(Metrics new_metrics); - std::tuple get_size(); - - struct wl_display *display; - struct wl_registry *registry; - struct wl_compositor *compositor; - struct wl_subcompositor *subcompositor; - - struct wl_surface *parent; - struct wl_surface *child; - struct wl_subsurface *subsurface; - struct wl_region *region; - - Metrics metrics; - double actual_scale; - - struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager; - struct zwp_idle_inhibitor_v1 *idle_inhibitor; - - struct wp_viewporter *viewporter; - struct wp_viewport *viewport; - - struct wp_fractional_scale_manager_v1 *fractional_scale_manager; - struct wp_fractional_scale_v1 *fractional_scale; -}; diff --git a/shaders/shader_platform.h b/shaders/shader_platform.h index 99ff58da..e3e08194 100644 --- a/shaders/shader_platform.h +++ b/shaders/shader_platform.h @@ -10,8 +10,8 @@ #include "port.h" #ifdef SNES9X_GTK -#include -#include +#include +#include #endif #ifdef _WIN32