From daec5ccc57d6ab5a71f946e07ec8fba0bba4c9df Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Sun, 21 Oct 2018 17:05:37 -0500 Subject: [PATCH] Better Wayland OpenGL. Still breaks with scale factors. --- gtk/Makefile.am | 5 +++ gtk/configure.ac | 3 ++ gtk/src/gtk_display_driver_opengl.cpp | 56 +++++++++++++++++++++++++++ gtk/src/gtk_display_driver_opengl.h | 8 ++++ 4 files changed, 72 insertions(+) diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 053c0b6d..8e090ec6 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -125,6 +125,11 @@ snes9x_gtk_SOURCES += \ ../c4emu.cpp endif +if WAYLAND +snes9x_gtk_SOURCES += \ + src/gtk_wayland_helpers.cpp +endif + # APU snes9x_gtk_SOURCES += \ ../apu/apu.cpp diff --git a/gtk/configure.ac b/gtk/configure.ac index 0ac8e514..ef13cde6 100644 --- a/gtk/configure.ac +++ b/gtk/configure.ac @@ -223,9 +223,11 @@ if test yes = "$with_opengl" ; then LIBS="$LIBS $EPOXY_LIBS" fi +WAYLAND=0 PKG_CHECK_MODULES([WAYLAND_EGL],[wayland-egl],[ CFLAGS="$CFLAGS $WAYLAND_EGL_CFLAGS" LIBS="$LIBS $WAYLAND_EGL_LIBS" + WAYLAND=yes ],[ echo "Not using Wayland-EGL." ]) @@ -499,6 +501,7 @@ AM_CONDITIONAL(PULSEAUDIO, [test yes = "$PULSEAUDIO"]) AM_CONDITIONAL(HQ2X, [test yes = "$HQ2X"]) AM_CONDITIONAL(XBRZ, [test yes = "$XBRZ"]) AM_CONDITIONAL(SYSTEM_ZIP, [test yes = "$SYSTEM_ZIP"]) +AM_CONDITIONAL(WAYLAND, [test yes = "$WAYLAND"]) AC_SUBST(NASM) AC_SUBST(NASM_FLAGS) diff --git a/gtk/src/gtk_display_driver_opengl.cpp b/gtk/src/gtk_display_driver_opengl.cpp index a9e1b2e7..3cfe56bb 100644 --- a/gtk/src/gtk_display_driver_opengl.cpp +++ b/gtk/src/gtk_display_driver_opengl.cpp @@ -16,6 +16,14 @@ #include "shaders/shader_helpers.h" +#ifdef GDK_WINDOWING_WAYLAND +#define ON_WAYLAND(BLOCK) if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default())) \ + { \ + BLOCK \ + } +#else +#define ON_WAYLAND(BLOCK) do {} while (0); +#endif static void S9xViewportCallback (int src_width, int src_height, int viewport_x, int viewport_y, @@ -662,6 +670,12 @@ S9xOpenGLDisplayDriver::refresh (int width, int height) void S9xOpenGLDisplayDriver::resize_window (int width, int height) { + ON_WAYLAND + ( + wl.resize (width, height); + wl.swap_interval (config->sync_to_vblank); + return; + ) gdk_window_destroy (gdk_window); create_window (width, height); @@ -706,6 +720,20 @@ S9xOpenGLDisplayDriver::create_window (int width, int height) int S9xOpenGLDisplayDriver::init_gl (void) { + ON_WAYLAND + ( + gdk_window = gtk_widget_get_window (drawing_area); + if (!wl.attach (gdk_window)) + return 0; + + if (!wl.create_egl_context (256, 224)) + return 0; + + wl.make_current (); + + return 1; + ) + int glx_attribs[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None }; display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); @@ -788,6 +816,11 @@ S9xOpenGLDisplayDriver::swap_control (int enable) { enable = enable ? 1 : 0; + ON_WAYLAND + ( + wl.swap_interval (enable); + ) + #ifdef GDK_WINDOWING_X11 const char *extensions = (const char *) glGetString (GL_EXTENSIONS); @@ -827,6 +860,19 @@ S9xOpenGLDisplayDriver::get_current_buffer (void) void S9xOpenGLDisplayDriver::gl_swap (void) { + ON_WAYLAND + ( + wl.swap_buffers (); + + if (config->sync_every_frame) + { + usleep (0); + glFinish (); + } + + return; + ) + #ifdef GDK_WINDOWING_X11 glXSwapBuffers (display, xwindow); #endif @@ -880,6 +926,11 @@ S9xOpenGLDisplayDriver::deinit (void) glDeleteTextures (1, &texmap); + ON_WAYLAND + ( + return; + ) + glXDestroyContext (display, glx_context); gdk_window_destroy (gdk_window); XFree (vi); @@ -899,6 +950,11 @@ S9xOpenGLDisplayDriver::query_availability (void) { GdkDisplay *gdk_display = gdk_display_get_default (); + ON_WAYLAND + ( + return 1; + ) + #ifdef GDK_WINDOWING_X11 if (GDK_IS_X11_DISPLAY (gdk_display)) { diff --git a/gtk/src/gtk_display_driver_opengl.h b/gtk/src/gtk_display_driver_opengl.h index c2c6624d..ee72c1f0 100644 --- a/gtk/src/gtk_display_driver_opengl.h +++ b/gtk/src/gtk_display_driver_opengl.h @@ -9,6 +9,10 @@ #include #endif +#ifdef GDK_WINDOWING_WAYLAND +#include "gtk_wayland_helpers.h" +#endif + #include "shaders/glsl.h" #define PBO_FMT_16 0 @@ -85,6 +89,10 @@ class S9xOpenGLDisplayDriver : public S9xDisplayDriver XVisualInfo *vi; GLXContext glx_context; #endif + +#ifdef GDK_WINDOWING_WAYLAND + wlgl_helper wl; +#endif }; #endif /* __GTK_DISPLAY_DRIVER_OPENGL_H */