Gtk: Use glad instead of epoxy.

This commit is contained in:
BearOso 2023-05-31 18:11:01 -05:00
parent 7f41685cf7
commit fa20cd2d19
18 changed files with 61 additions and 159 deletions

View File

@ -4,12 +4,12 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#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
}

View File

@ -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 <epoxy/glx.h>
#include <glad/glx.h>
class GTKGLXContext : public OpenGLContext
{

View File

@ -7,8 +7,7 @@
#include <stdio.h>
#include <string.h>
#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);

View File

@ -6,11 +6,11 @@
#include <stdio.h>
#include <string.h>
#include <tuple>
#include <wayland-util.h>
#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);

View File

@ -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()

View File

@ -5,6 +5,7 @@
\*****************************************************************************/
#include <dlfcn.h>
#include <cstdio>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
@ -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

View File

@ -10,16 +10,16 @@
#include "gtk_s9x.h"
#include "gtk_display_driver.h"
#include <epoxy/gl.h>
#include <glad/gl.h>
#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"

View File

@ -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

View File

@ -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

View File

@ -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 <epoxy/egl.h>
#include <memory>
#include <wayland-egl.h>
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<WaylandSurface> wayland_surface;
};
#endif

View File

@ -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<int, int> 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;
};

View File

@ -10,8 +10,8 @@
#include "port.h"
#ifdef SNES9X_GTK
#include <epoxy/gl.h>
#include <epoxy/glx.h>
#include <glad/gl.h>
#include <glad/glx.h>
#endif
#ifdef _WIN32