Merge pull request #412 from PoroCYon/master

Make OpenGL renderer work on Linux
This commit is contained in:
Arisotura 2019-05-26 00:52:11 +02:00 committed by GitHub
commit 23eccc9439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 124 additions and 2 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ obj
*.o *.o
melon_grc.c melon_grc.c
melon_grc.h melon_grc.h
cmake-build

View File

@ -22,8 +22,13 @@ add_library(core STATIC
SPU.cpp SPU.cpp
Wifi.cpp Wifi.cpp
WifiAP.cpp WifiAP.cpp
# opengl backend stuff
GPU3D_OpenGL.cpp
OpenGLSupport.cpp
) )
if (WIN32) if (WIN32)
target_link_libraries(core ole32 comctl32 ws2_32) target_link_libraries(core ole32 comctl32 ws2_32 opengl32)
else()
target_link_libraries(core OpenGL)
endif() endif()

View File

@ -18,6 +18,8 @@
#include "OpenGLSupport.h" #include "OpenGLSupport.h"
#include <cstring>
DO_PROCLIST(DECLPROC); DO_PROCLIST(DECLPROC);

View File

@ -10,6 +10,8 @@ SET(SOURCES_LIBUI
DlgEmuSettings.cpp DlgEmuSettings.cpp
DlgInputConfig.cpp DlgInputConfig.cpp
DlgWifiSettings.cpp DlgWifiSettings.cpp
# opengl backend stuff
DlgVideoSettings.cpp
) )
option(BUILD_SHARED_LIBS "Whether to build libui as a shared library or a static library" ON) option(BUILD_SHARED_LIBS "Whether to build libui as a shared library or a static library" ON)

View File

@ -43,6 +43,7 @@ list(APPEND _LIBUI_SOURCES
unix/text.c unix/text.c
unix/util.c unix/util.c
unix/window.c unix/window.c
unix/gl.c
) )
set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE)

View File

@ -38,7 +38,10 @@ struct uiArea {
GtkWidget *areaWidget; GtkWidget *areaWidget;
GtkDrawingArea *drawingArea; GtkDrawingArea *drawingArea;
GtkGLArea *glArea;
areaWidget *area; areaWidget *area;
GdkGLContext *glContext;
int bgR, bgG, bgB; int bgR, bgG, bgB;
@ -730,6 +733,44 @@ uiArea *uiNewArea(uiAreaHandler *ah)
return a; return a;
} }
uiArea *uiNewGLArea(uiAreaHandler *ah, const unsigned int* req_versions)
{
uiArea *a;
uiUnixNewControl(uiArea, a);
a->ah = ah;
a->scrolling = FALSE;
GtkGLArea* gla = (GtkGLArea*)gtk_gl_area_new();
GdkGLContext* ctx = NULL;
for (int i = 0; req_versions[i] && !ctx; i++) {
int major = uiGLVerMajor(req_versions[i]);
int minor = uiGLVerMinor(req_versions[i]);
gtk_gl_area_set_required_version(gla, major, minor);
ctx = createGLContext(gla, major, minor);
}
a->glContext = ctx;
a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType, "libui-area",
a, NULL));
a->glArea = gla;
a->area = areaWidget(a->areaWidget);
a->widget = a->areaWidget;
uiAreaSetBackgroundColor(a, -1, -1, -1);
return a;
}
uiGLContext *uiAreaGetGLContext(uiArea* a)
{
if (!a) return NULL;
return a->glContext;
}
uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height) uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
{ {
uiArea *a; uiArea *a;

View File

@ -0,0 +1,47 @@
// 26 may 2019
#include "uipriv_unix.h"
/*
*(melonDS:17013): Gtk-CRITICAL **: 00:28:09.095: gtk_gl_area_set_required_version: assertion 'GTK_IS_GL_AREA (area)' failed
(melonDS:17013): GLib-GObject-WARNING **: 00:28:09.096: invalid cast from 'GtkGLArea' to 'areaWidget'
*/
struct uiGLContext {
GtkGLArea *gla;
GdkGLContext *gctx;
int vermaj, vermin;
};
uiGLContext *createGLContext(GtkGLArea* gla, int maj, int min)
{
uiGLContext *ret = uiAlloc(sizeof(uiGLContext), "uiGLContext");
ret->gla = gla;
ret->gctx = gtk_gl_area_get_context(gla);
ret->vermaj = maj; ret->vermin = min;
return ret;
}
void uiGLSwapBuffers(uiGLContext* ctx)
{
if (!ctx) return;
gtk_gl_area_attach_buffers(ctx->gla);
}
void uiGLMakeContextCurrent(uiGLContext* ctx)
{
if (!ctx) return;
gtk_gl_area_make_current(ctx->gla);
}
void *uiGLGetProcAddress(const char* proc)
{
// this *will* break for older systems that don't have libglvnd!
// TODO: use a real solution
return dlsym(NULL /* RTLD_DEFAULT */, proc);
}
unsigned int uiGLGetVersion(uiGLContext* ctx)
{
if (!ctx) return 0;
return uiGLVersion(ctx->vermaj, ctx->vermin);
}

View File

@ -5,7 +5,7 @@
#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_10 #define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_10
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <math.h> #include <math.h>
#include <dlfcn.h> // see drawtext.c #include <dlfcn.h> // see drawtext.c, gl.c
#include <langinfo.h> #include <langinfo.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -63,3 +63,7 @@ extern GtkCellRenderer *newCellRendererButton(void);
extern void loadFutures(void); extern void loadFutures(void);
extern PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha); extern PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha);
extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name); extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name);
// gl.c
extern uiGLContext *createGLContext(GtkGLArea* gla, int maj, int min);

View File

@ -102,6 +102,23 @@ static void uiWindowDestroy(uiControl *c)
uiFreeControl(uiControl(w)); uiFreeControl(uiControl(w));
} }
void uiWindowSetPosition(uiWindow *w, int x, int y)
{
if (!w) return;
gtk_window_move(w->window, x, y);
}
void uiWindowPosition(uiWindow *w, int *x, int *y)
{
if (!w) return;
int xx, yy;
gtk_window_get_position(w->window, &xx, &yy);
if (x) *x = xx;
if (y) *y = yy;
}
uiUnixControlDefaultHandle(uiWindow) uiUnixControlDefaultHandle(uiWindow)
uiControl *uiWindowParent(uiControl *c) uiControl *uiWindowParent(uiControl *c)
@ -442,3 +459,4 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int maximized, i
return w; return w;
} }

View File

@ -29,6 +29,7 @@ list(APPEND _LIBUI_SOURCES
windows/fontbutton.cpp windows/fontbutton.cpp
windows/fontdialog.cpp windows/fontdialog.cpp
windows/form.cpp windows/form.cpp
windows/gl.cpp
windows/graphemes.cpp windows/graphemes.cpp
windows/grid.cpp windows/grid.cpp
windows/group.cpp windows/group.cpp