From 31e0f15797d0b6545ddc1a361252f267bf5d793d Mon Sep 17 00:00:00 2001 From: PoroCYon Date: Sun, 26 May 2019 00:37:51 +0200 Subject: fix oudated CMake compile settings, add OpenGL dependency for Linux --- src/libui_sdl/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/libui_sdl/CMakeLists.txt') diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index 40019db..0b7545b 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -10,6 +10,8 @@ SET(SOURCES_LIBUI DlgEmuSettings.cpp DlgInputConfig.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) -- cgit v1.2.3 From 891ab9fd3c91042d5097f38107cccfb47511e5e5 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Tue, 28 May 2019 19:48:59 +0200 Subject: Linux: start getting somewhere with the whole OpenGL shito --- CMakeLists.txt | 5 +- src/CMakeLists.txt | 7 +- src/OpenGLSupport.cpp | 1 - src/OpenGLSupport.h | 1 + src/libui_sdl/CMakeLists.txt | 2 +- src/libui_sdl/libui/ui.h | 2 + src/libui_sdl/libui/unix/area.c | 83 ++++++--- src/libui_sdl/libui/unix/gl.c | 391 +++++++++++++++++++++++++++++++++++++++- src/libui_sdl/main.cpp | 46 +++-- 9 files changed, 489 insertions(+), 49 deletions(-) (limited to 'src/libui_sdl/CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 9aa96ad..c127af5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,9 +21,12 @@ else() endif() if(ENABLE_LTO) - add_compile_options(-flto) + add_compile_options(-O2 -flto) endif() +add_compile_options(-fno-pic) +add_link_options(-no-pie) + option(BUILD_LIBUI "Build libui frontend" ON) option(BUILD_SDL "Build SDL2 frontend" OFF) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 702edf5..d096c02 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,22 +13,21 @@ add_library(core STATIC GPU.cpp GPU2D.cpp GPU3D.cpp + GPU3D_OpenGL.cpp GPU3D_Soft.cpp NDS.cpp NDSCart.cpp + OpenGLSupport.cpp RTC.cpp Savestate.cpp SPI.cpp SPU.cpp Wifi.cpp WifiAP.cpp - # opengl backend stuff - GPU3D_OpenGL.cpp - OpenGLSupport.cpp ) if (WIN32) target_link_libraries(core ole32 comctl32 ws2_32 opengl32) else() - target_link_libraries(core OpenGL) + target_link_libraries(core GL) endif() diff --git a/src/OpenGLSupport.cpp b/src/OpenGLSupport.cpp index bb9e180..11fd629 100644 --- a/src/OpenGLSupport.cpp +++ b/src/OpenGLSupport.cpp @@ -18,7 +18,6 @@ #include "OpenGLSupport.h" -#include DO_PROCLIST(DECLPROC); diff --git a/src/OpenGLSupport.h b/src/OpenGLSupport.h index 3f21a4c..239ae95 100644 --- a/src/OpenGLSupport.h +++ b/src/OpenGLSupport.h @@ -20,6 +20,7 @@ #define OPENGLSUPPORT_H #include +#include #include #include diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index 0b7545b..61e0981 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -47,7 +47,7 @@ if (UNIX) --generate-header "${CMAKE_SOURCE_DIR}/melon_grc.xml") if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_link_libraries(melonDS dl) + target_link_libraries(melonDS dl X11) endif () target_sources(melonDS PUBLIC melon_grc.c) diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h index d2e9960..0c89d90 100644 --- a/src/libui_sdl/libui/ui.h +++ b/src/libui_sdl/libui/ui.h @@ -615,6 +615,8 @@ _UI_EXTERN uiGLContext *uiAreaGetGLContext(uiArea* a); _UI_EXTERN void uiGLMakeContextCurrent(uiGLContext* ctx); _UI_EXTERN unsigned int uiGLGetVersion(uiGLContext* ctx); _UI_EXTERN void *uiGLGetProcAddress(const char* proc); +_UI_EXTERN int uiGLGetFramebuffer(uiGLContext* ctx); +_UI_EXTERN float uiGLGetFramebufferScale(uiGLContext* ctx); _UI_EXTERN void uiGLSwapBuffers(uiGLContext* ctx); diff --git a/src/libui_sdl/libui/unix/area.c b/src/libui_sdl/libui/unix/area.c index e518ae5..bf92ddf 100644 --- a/src/libui_sdl/libui/unix/area.c +++ b/src/libui_sdl/libui/unix/area.c @@ -28,6 +28,8 @@ struct areaWidgetClass { GtkDrawingAreaClass parent_class; }; +typedef struct uiGLContext uiGLContext; + struct uiArea { uiUnixControl c; GtkWidget *widget; // either swidget or areaWidget depending on whether it is scrolling @@ -41,7 +43,8 @@ struct uiArea { GtkGLArea *glArea; areaWidget *area; - GdkGLContext *glContext; + gboolean opengl; + uiGLContext *glContext; int bgR, bgG, bgB; @@ -125,6 +128,8 @@ static void loadAreaSize(uiArea *a, double *width, double *height) } } +void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx); + static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) { areaWidget *aw = areaWidget(w); @@ -136,21 +141,28 @@ static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) loadAreaSize(a, &(dp.AreaWidth), &(dp.AreaHeight)); - cairo_clip_extents(cr, &clipX0, &clipY0, &clipX1, &clipY1); - dp.ClipX = clipX0; - dp.ClipY = clipY0; - dp.ClipWidth = clipX1 - clipX0; - dp.ClipHeight = clipY1 - clipY0; - - if (a->bgR != -1) + if (!a->opengl) + { + cairo_clip_extents(cr, &clipX0, &clipY0, &clipX1, &clipY1); + dp.ClipX = clipX0; + dp.ClipY = clipY0; + dp.ClipWidth = clipX1 - clipX0; + dp.ClipHeight = clipY1 - clipY0; + + if (a->bgR != -1) + { + cairo_set_source_rgb(cr, a->bgR/255.0, a->bgG/255.0, a->bgB/255.0); + cairo_paint(cr); + } + + // no need to save or restore the graphics state to reset transformations; GTK+ does that for us + (*(a->ah->Draw))(a->ah, a, &dp); + } + else { - cairo_set_source_rgb(cr, a->bgR/255.0, a->bgG/255.0, a->bgB/255.0); - cairo_paint(cr); + areaDrawGL(w, &dp, cr, a->glContext); } - // no need to save or restore the graphics state to reset transformations; GTK+ does that for us - (*(a->ah->Draw))(a->ah, a, &dp); - freeContext(dp.Context); return FALSE; } @@ -714,11 +726,12 @@ void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge) uiArea *uiNewArea(uiAreaHandler *ah) { uiArea *a; - +printf("create regular area\n"); uiUnixNewControl(uiArea, a); a->ah = ah; a->scrolling = FALSE; + a->opengl = FALSE; a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType, "libui-area", a, @@ -733,35 +746,54 @@ uiArea *uiNewArea(uiAreaHandler *ah) return a; } +uiGLContext* FARTOMATIC(int major, int minor); +void databotte(GtkWidget* gla, uiGLContext* ctx); +void majoricc(GtkWidget* widget, gpointer data) +{ + printf("ACTUALLY CREATE CONTEXT\n"); + + uiArea* a = (uiArea*)data; + uiGLContext* ctx = a->glContext; + + databotte(a->widget, ctx); +} + uiArea *uiNewGLArea(uiAreaHandler *ah, const unsigned int* req_versions) { uiArea *a; - +printf("create glarea\n"); uiUnixNewControl(uiArea, a); a->ah = ah; a->scrolling = FALSE; + a->opengl = TRUE; - GtkGLArea* gla = (GtkGLArea*)gtk_gl_area_new(); - GdkGLContext* ctx = NULL; - + //GtkGLArea* gla = (GtkGLArea*)gtk_gl_area_new(); + uiGLContext* ctx = NULL; +printf("create sdfsf\n"); 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); + //gtk_gl_area_set_required_version(gla, major, minor); + //ctx = createGLContext(gla, major, minor); + ctx = FARTOMATIC(major, minor); } - +printf("create jfghjjgh: %p\n", ctx); a->glContext = ctx; - a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType, "libui-area", - a, NULL)); - a->glArea = gla; + //a->areaWidget = GTK_WIDGET(gla); + //a->glArea = gla; + a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType, + "libui-area", a, + NULL)); a->area = areaWidget(a->areaWidget); a->widget = a->areaWidget; + + g_signal_connect(a->widget, "realize", G_CALLBACK(majoricc), a); uiAreaSetBackgroundColor(a, -1, -1, -1); - + //printf("is area realized: %d\n", gtk_widget_get_realized(GTK_WIDGET(gla))); +printf("create qssssq\n"); return a; } @@ -781,6 +813,7 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height) a->scrolling = TRUE; a->scrollWidth = width; a->scrollHeight = height; + a->opengl = FALSE; a->swidget = gtk_scrolled_window_new(NULL, NULL); a->scontainer = GTK_CONTAINER(a->swidget); diff --git a/src/libui_sdl/libui/unix/gl.c b/src/libui_sdl/libui/unix/gl.c index da41437..3504d3a 100644 --- a/src/libui_sdl/libui/unix/gl.c +++ b/src/libui_sdl/libui/unix/gl.c @@ -1,6 +1,12 @@ // 26 may 2019 #include "uipriv_unix.h" +#include +#include +#include + +extern GThread* gtkthread; + /* *(melonDS:17013): Gtk-CRITICAL **: 00:28:09.095: gtk_gl_area_set_required_version: assertion 'GTK_IS_GL_AREA (area)' failed @@ -9,32 +15,409 @@ struct uiGLContext { GtkGLArea *gla; + GtkWidget* widget; + GdkWindow* window; GdkGLContext *gctx; + + Display* xdisp; + GLXPixmap glxpm; + GLXContext glxctx; int vermaj, vermin; + + int width, height; + int scale; + GLuint renderbuffer[2]; + GLuint framebuffer; }; +static PFNGLGENRENDERBUFFERSPROC _glGenRenderbuffers; +static PFNGLDELETERENDERBUFFERSPROC _glDeleteRenderbuffers; +static PFNGLBINDRENDERBUFFERPROC _glBindRenderbuffer; +static PFNGLRENDERBUFFERSTORAGEPROC _glRenderbufferStorage; +static PFNGLGETRENDERBUFFERPARAMETERIVPROC _glGetRenderbufferParameteriv; + +static PFNGLGENRENDERBUFFERSPROC _glGenFramebuffers; +static PFNGLDELETERENDERBUFFERSPROC _glDeleteFramebuffers; +static PFNGLBINDRENDERBUFFERPROC _glBindFramebuffer; +static PFNGLFRAMEBUFFERTEXTUREPROC _glFramebufferTexture; +static PFNGLFRAMEBUFFERRENDERBUFFERPROC _glFramebufferRenderbuffer; +static PFNGLCHECKFRAMEBUFFERSTATUSPROC _glCheckFramebufferStatus; + +static int _procsLoaded = 0; + +static void _loadGLProcs() +{ + if (_procsLoaded) return; + + _glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)uiGLGetProcAddress("glGenRenderbuffers"); + _glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)uiGLGetProcAddress("glDeleteRenderbuffers"); + _glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)uiGLGetProcAddress("glBindRenderbuffer"); + _glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)uiGLGetProcAddress("glRenderbufferStorage"); + _glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)uiGLGetProcAddress("glGetRenderbufferParameteriv"); + + _glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)uiGLGetProcAddress("glGenFramebuffers"); + _glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)uiGLGetProcAddress("glDeleteFramebuffers"); + _glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)uiGLGetProcAddress("glBindFramebuffer"); + _glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)uiGLGetProcAddress("glFramebufferTexture"); + _glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)uiGLGetProcAddress("glFramebufferRenderbuffer"); + _glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)uiGLGetProcAddress("glCheckFramebufferStatus"); + + _procsLoaded = 1; +} + +Display* derp; + uiGLContext *createGLContext(GtkGLArea* gla, int maj, int min) { - uiGLContext *ret = uiAlloc(sizeof(uiGLContext), "uiGLContext"); + printf("barp\n"); + uiGLContext *ret = uiNew(uiGLContext);//uiAlloc(sizeof(uiGLContext), "uiGLContext"); + + // herp + ret->gla = gla; + ret->gctx = NULL; + //while (!ret->gctx) + /*{ + gtk_widget_realize(GTK_WIDGET(gla)); + printf("is area realized: %d\n", gtk_widget_get_realized(GTK_WIDGET(gla))); ret->gla = gla; ret->gctx = gtk_gl_area_get_context(gla); + printf("context: %p\n", ret->gctx); + }*/ + + + + /* + GtkAllocation allocation; + GdkWindow *window; + Display *display; + int id; + + window = gtk_widget_get_window(widget); + display = gdk_x11_display_get_xdisplay(gdk_window_get_display(window)); + id = gdk_x11_window_get_xid(window); + + if (glXMakeCurrent(display, id, context) == TRUE) {*/ + + + /*GdkWindow* window; + Display* disp; + + window = gtk_widget_get_window(GTK_WIDGET(gla)); + display = */ + + + ret->vermaj = maj; ret->vermin = min; return ret; } +static void areaAllocRenderbuffer(uiGLContext* glctx); + +void databotte(GtkWidget* widget, uiGLContext* ctx) +{ + /*printf("is area realized: %d\n", gtk_widget_get_realized(GTK_WIDGET(gla))); + ctx->gctx = gtk_gl_area_get_context(gla); + printf("context: %p\n", ctx->gctx);*/ + + printf("DATABOTTE\n"); + + GdkWindow* gdkwin = gtk_widget_get_window(widget); + printf("window=%p\n", gdkwin); + + GError* err = NULL; + GdkGLContext* glctx = gdk_window_create_gl_context(gdkwin, &err); + if (err != NULL) + { + printf("CONTEXT SHAT ITSELF\n"); + return; + } + + gdk_gl_context_set_use_es(glctx, FALSE); + gdk_gl_context_set_required_version(glctx, 3, 2); + + gdk_gl_context_realize(glctx, &err); + if (err != NULL) + { + printf("CONTEXT REALIZE SHAT ITSELF\n"); + return; + } + + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); + int window_scale = gdk_window_get_scale_factor(gdkwin); + ctx->width = allocation.width; + ctx->height = allocation.height; + ctx->scale = window_scale; + + gdk_gl_context_make_current(glctx); + _loadGLProcs(); + areaAllocRenderbuffer(ctx); + + ctx->widget = widget; + ctx->window = gdkwin; + ctx->gctx = glctx; +} + +static void areaAllocRenderbuffer(uiGLContext* glctx) +{ + _glGenRenderbuffers(2, &glctx->renderbuffer[0]);printf("ylarg0 %04X, %d %d\n", glGetError(), glctx->width, glctx->height); + //glGenTextures(2, &glctx->renderbuffer[0]); + _glGenFramebuffers(1, &glctx->framebuffer);printf("ylarg1 %04X\n", glGetError()); + printf("FB %08X created under ctx %p (%p %p)\n", glctx?glctx->framebuffer:0, gdk_gl_context_get_current(), glctx?glctx->gctx:NULL, glctx); + /*glBindTexture(GL_TEXTURE_2D, glctx->renderbuffer[0]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glBindTexture(GL_TEXTURE_2D, glctx->renderbuffer[1]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);*/ + + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0]);printf("ylarg1 %04X\n", glGetError()); + _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale);printf("ylarg1 %04X\n", glGetError()); + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1]);printf("ylarg1 %04X\n", glGetError()); + _glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale);printf("ylarg1 %04X\n", glGetError()); + + _glBindFramebuffer(GL_FRAMEBUFFER, glctx->framebuffer);printf("ylarg2 %04X\n", glGetError()); + /*_glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, glctx->renderbuffer[0], 0); + _glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, glctx->renderbuffer[1], 0);*/ + _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, glctx->renderbuffer[0]);printf("ylarg3 %04X\n", glGetError()); + _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, glctx->renderbuffer[1]);printf("ylarg4 %04X\n", glGetError()); + //printf("ylarg: %08X, %04X, %08X %08X\n", glctx->framebuffer, glGetError(), glctx->renderbuffer[0], glctx->renderbuffer[1]); + + if(_glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + printf("FRAMEBUFFER IS BAD!! %04X\n", _glCheckFramebufferStatus(GL_FRAMEBUFFER)); + + int alpha_size; + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0]); + _glGetRenderbufferParameteriv (GL_RENDERBUFFER, GL_RENDERBUFFER_ALPHA_SIZE, &alpha_size); + printf("FRAMEBUFFER GOOD. ALPHA SIZE IS %d\n", alpha_size); +} + +static void areaRellocRenderbuffer(uiGLContext* glctx) +{ + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0]); + _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale); + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1]); + _glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale); +} + +void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx) +{ + int window_scale = gdk_window_get_scale_factor(glctx->window); + + if (glctx->width != dp->AreaWidth || glctx->height != dp->AreaHeight || glctx->scale != window_scale) + { + glctx->width = dp->AreaWidth; + glctx->height = dp->AreaHeight; + glctx->scale = window_scale; + areaRellocRenderbuffer(glctx); + } + + gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(widget), + glctx->renderbuffer[0], GL_RENDERBUFFER, + 1, 0, 0, glctx->width*glctx->scale, glctx->height*glctx->scale); +} + +uiGLContext* FARTOMATIC(int major, int minor) +{ + uiGLContext *_ret = uiNew(uiGLContext); + _ret->vermaj = major; + _ret->vermin = minor; + _ret->width = -1; + _ret->height = -1; + _ret->renderbuffer[0] = 0; + _ret->renderbuffer[1] = 0; + _ret->framebuffer = 0; + + return _ret; + + Display* disp; + XVisualInfo* vizir; + GLXFBConfig *cfg; + Pixmap pm; + GLXPixmap glxpm; + GLXContext ctx; + + disp = XOpenDisplay(NULL); + derp = disp; + + int kaa, baa; + glXQueryVersion(disp, &kaa, &baa); + printf("GL VERSION: %d.%d\n", kaa, baa); + + const int sbAttrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + None }; + const int dbAttrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + None }; + + int scrnum = DefaultScreen( disp ); + Window root = RootWindow( disp, scrnum ); + + vizir = glXChooseVisual( disp, scrnum, (int *) sbAttrib ); + if (!vizir) { + vizir = glXChooseVisual( disp, scrnum, (int *) dbAttrib ); + if (!vizir) { + printf("Error: couldn't get an RGB visual\n"); + return NULL; + } + } + + const int fb_attr[] = { + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, + GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, + GLX_DOUBLEBUFFER, True, + GLX_X_RENDERABLE, True, + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, + GLX_ALPHA_SIZE, 8, + GLX_DEPTH_SIZE, 24, + GLX_STENCIL_SIZE, 8, + None + }; + int configs; + cfg = glXChooseFBConfig(disp, scrnum, (int *)&fb_attr, &configs); + + if (!cfg) + { + printf("NO GOOD FBCONFIG\n"); + return NULL; + } + + /*ctx = glXCreateContext( disp, vizir, NULL, True ); + if (!ctx) + { + printf("Error: glXCreateContext failed\n"); + return NULL; + }*/ + + PFNGLXCREATECONTEXTATTRIBSARBPROC createctx; + createctx = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddressARB("glXCreateContextAttribsARB"); + if (!createctx) + { + printf("bad shito\n"); + return NULL; + } + + const int ctx_attr[] = + { + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + GLX_CONTEXT_MAJOR_VERSION_ARB, 3,//major, + GLX_CONTEXT_MINOR_VERSION_ARB, 2,//minor, + None + }; + + ctx = glXCreateContextAttribsARB(disp, cfg[0], 0, True, ctx_attr); + if (!ctx) + { + printf("FAILED TO CREATE FANCYPANTS GL CONTEXT\n"); + return NULL; + } + + //printf("CONTEXT GOOD. Direct rendering: %s\n", glXIsDirect(disp, ctx) ? "Yes" : "No"); + + printf("blorp: %d\n", vizir->depth); + pm = XCreatePixmap(disp, root, 256, 384, vizir->depth); + if (!pm) printf("PIXMAP SHAT ITSELF\n"); + else printf("PIXMAP GOOD\n"); + + glxpm = glXCreateGLXPixmap(disp, vizir, pm); + if (!glxpm) printf("GLXPIXMAP SHAT ITSELF\n"); + else printf("GLXPIXMAP GOOD\n"); + + uiGLContext *ret = uiNew(uiGLContext); + printf("CREATE CTX: %p, %p\n", ret, g_thread_self()); + ret->xdisp = disp; + ret->glxpm = glxpm; + ret->glxctx = ctx; + + return ret; +} + +int uiGLGetFramebuffer(uiGLContext* ctx) +{ + return ctx->framebuffer; +} + +float uiGLGetFramebufferScale(uiGLContext* ctx) +{ + return (float)ctx->scale; +} + void uiGLSwapBuffers(uiGLContext* ctx) { if (!ctx) return; - gtk_gl_area_attach_buffers(ctx->gla); + //gtk_gl_area_attach_buffers(ctx->gla); +} + +static volatile int _ctxset_done; + +gboolean _threadsafe_ctxset(gpointer data) +{ + uiGLContext* ctx = (uiGLContext*)data; + gtk_gl_area_make_current(ctx->gla); + _ctxset_done = 1; + return FALSE; } void uiGLMakeContextCurrent(uiGLContext* ctx) { - if (!ctx) return; - gtk_gl_area_make_current(ctx->gla); + //if (!ctx) return; + /*if (g_thread_self() != gtkthread) + { + _ctxset_done = 0; + g_idle_add(_threadsafe_ctxset, ctx); + while (!_ctxset_done); + } + else*/ + //gtk_gl_area_make_current(ctx->gla); + /*printf("MAKE CONTEXT CURRENT %p, %p\n", ctx, g_thread_self()); + if (!ctx) + { + // BLERUGEHZFZF + glXMakeCurrent(derp, None, NULL); + return; + } + Bool ret = True; + if (glXGetCurrentContext() != ctx->glxctx) + {printf("DZJSKFLD\n"); + ret = glXMakeCurrent(ctx->xdisp, ctx->glxpm, ctx->glxctx); + //glXMakeContextCurrent(ctx->xdisp, ctx->glxpm, ctx->glxpm, ctx->glxctx); + } + printf("WE MAED IT CURRENT: %d\n", ret);*/ + + printf("[%p] MAKE CONTEXT CURRENT %p, %p\n", g_thread_self(), ctx, ctx?ctx->gctx:NULL); + if (!ctx) + { + gdk_gl_context_clear_current(); + return; + } + //gtk_gl_area_make_current(ctx->gla); + gdk_gl_context_make_current(ctx->gctx); + GdkGLContext* burp = gdk_gl_context_get_current(); + //gtk_gl_area_attach_buffers(ctx->gla); + //printf("burp = %p / %p\n", burp, ctx->gctx); } void *uiGLGetProcAddress(const char* proc) { +printf("get: %s - ", proc); +void* a = dlsym(NULL, proc); +void* b = glXGetProcAddress(proc); +void* c = glXGetProcAddressARB(proc); +printf("%p / %p / %p\n", a, b, c); +return c; // this *will* break for older systems that don't have libglvnd! // TODO: use a real solution return dlsym(NULL /* RTLD_DEFAULT */, proc); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 0c7aacd..e2686f9 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -194,9 +194,16 @@ bool GLScreen_InitShader(GLuint* shader, const char* fs) } bool GLScreen_Init() -{ +{printf("BEGINNING GL SHITO\n"); if (!OpenGL_Init()) return false; + + printf("GL INIT: %p, %p\n", glGenFramebuffers, glCreateShader); + + const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string + const GLubyte* version = glGetString(GL_VERSION); // version as a string + printf("OpenGL: renderer: %s\n", renderer); + printf("OpenGL: version: %s\n", version); if (!GLScreen_InitShader(GL_ScreenShader, kScreenFS)) return false; @@ -204,7 +211,7 @@ bool GLScreen_Init() return false; memset(&GL_ShaderConfig, 0, sizeof(GL_ShaderConfig)); - +printf("morp0\n"); glGenBuffers(1, &GL_ShaderConfigUBO); glBindBuffer(GL_UNIFORM_BUFFER, GL_ShaderConfigUBO); glBufferData(GL_UNIFORM_BUFFER, sizeof(GL_ShaderConfig), &GL_ShaderConfig, GL_STATIC_DRAW); @@ -213,14 +220,14 @@ bool GLScreen_Init() glGenBuffers(1, &GL_ScreenVertexBufferID); glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); glBufferData(GL_ARRAY_BUFFER, sizeof(GL_ScreenVertices), NULL, GL_STATIC_DRAW); - +printf("morp1\n"); glGenVertexArrays(1, &GL_ScreenVertexArrayID); glBindVertexArray(GL_ScreenVertexArrayID); glEnableVertexAttribArray(0); // position glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4*4, (void*)(0)); glEnableVertexAttribArray(1); // texcoord glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4*4, (void*)(2*4)); - +printf("morp2\n"); glGenTextures(1, &GL_ScreenTexture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, GL_ScreenTexture); @@ -231,7 +238,7 @@ bool GLScreen_Init() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 256*3 + 1, 192*2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, NULL); GL_ScreenSizeDirty = true; - +printf("morp3\n"); return true; } @@ -248,6 +255,8 @@ void GLScreen_DeInit() void GLScreen_DrawScreen() { + float scale = uiGLGetFramebufferScale(GLContext); + if (GL_ScreenSizeDirty) { GL_ScreenSizeDirty = false; @@ -370,23 +379,26 @@ void GLScreen_DrawScreen() glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GL_ScreenVertices), GL_ScreenVertices); } - + printf("rarp4 %04X\n", glGetError()); glDisable(GL_DEPTH_TEST); glDisable(GL_STENCIL_TEST); glDisable(GL_BLEND); glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); +printf("rarp2 %04X\n", glGetError()); - glViewport(0, 0, WindowWidth, WindowHeight); + glViewport(0, 0, WindowWidth*scale, WindowHeight*scale); + printf("draw screen: viewport=%d/%d\n", WindowWidth, WindowHeight); if (GPU3D::Renderer == 0) OpenGL_UseShaderProgram(GL_ScreenShader); else OpenGL_UseShaderProgram(GL_ScreenShaderAccel); - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glClearColor(0, 0, 0, 1); +printf("rarp3 %04X\n", glGetError()); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, uiGLGetFramebuffer(GLContext)); + printf("rarp8 %04X\n", glGetError()); + glClearColor(0, 0, 1, 1); glClear(GL_COLOR_BUFFER_BIT); - +printf("rarp5 %04X\n", glGetError()); int frontbuf = GPU::FrontBuffer; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, GL_ScreenTexture); @@ -412,15 +424,21 @@ void GLScreen_DrawScreen() glActiveTexture(GL_TEXTURE1); if (GPU3D::Renderer != 0) GPU3D::GLRenderer::SetupAccelFrame(); - +printf("rarp6 %04X\n", glGetError()); glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); glBindVertexArray(GL_ScreenVertexArrayID); glDrawArrays(GL_TRIANGLES, 0, 4*3); - +printf("rarp7 %04X\n", glGetError()); glFlush(); uiGLSwapBuffers(GLContext); } +void norp(void* data) +{ + uiGLMakeContextCurrent(GLContext); + GLScreen_DrawScreen(); +} + void MicLoadWav(char* name) { SDL_AudioSpec format; @@ -901,6 +919,8 @@ int EmuThreadFunc(void* burp) { uiGLMakeContextCurrent(GLContext); GLScreen_DrawScreen(); + //uiGLMakeContextCurrent(NULL); + //uiQueueMain(norp, NULL); } uiAreaQueueRedrawAll(MainDrawArea); } -- cgit v1.2.3 From ce9d728fb6fe97a36eba5294a793f0d451c8fd6d Mon Sep 17 00:00:00 2001 From: StapleButter Date: Thu, 30 May 2019 17:29:41 +0200 Subject: fix cleanup of libui objects when closing melonDS fixes to Cmake shito attempt shit --- src/libui_sdl/CMakeLists.txt | 5 +- src/libui_sdl/libui/ui.h | 2 + src/libui_sdl/libui/unix/CMakeLists.txt | 1 + src/libui_sdl/libui/unix/area.c | 67 ++++++++--- src/libui_sdl/libui/unix/gl.c | 201 ++++++++++++++++++++++++++++---- src/libui_sdl/libui/unix/main.c | 31 +++++ src/libui_sdl/libui/unix/uipriv_unix.h | 20 +++- src/libui_sdl/main.cpp | 31 +++-- 8 files changed, 304 insertions(+), 54 deletions(-) (limited to 'src/libui_sdl/CMakeLists.txt') diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index 61e0981..e9a54e2 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -9,9 +9,8 @@ SET(SOURCES_LIBUI DlgAudioSettings.cpp DlgEmuSettings.cpp DlgInputConfig.cpp - DlgWifiSettings.cpp - # opengl backend stuff DlgVideoSettings.cpp + DlgWifiSettings.cpp ) option(BUILD_SHARED_LIBS "Whether to build libui as a shared library or a static library" ON) @@ -47,7 +46,7 @@ if (UNIX) --generate-header "${CMAKE_SOURCE_DIR}/melon_grc.xml") if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_link_libraries(melonDS dl X11) + target_link_libraries(melonDS dl) endif () target_sources(melonDS PUBLIC melon_grc.c) diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h index 0c89d90..47da54b 100644 --- a/src/libui_sdl/libui/ui.h +++ b/src/libui_sdl/libui/ui.h @@ -613,6 +613,8 @@ typedef struct uiGLContext uiGLContext; _UI_EXTERN uiGLContext *uiAreaGetGLContext(uiArea* a); _UI_EXTERN void uiGLMakeContextCurrent(uiGLContext* ctx); +_UI_EXTERN void uiGLBegin(uiGLContext* ctx); +_UI_EXTERN void uiGLEnd(uiGLContext* ctx); _UI_EXTERN unsigned int uiGLGetVersion(uiGLContext* ctx); _UI_EXTERN void *uiGLGetProcAddress(const char* proc); _UI_EXTERN int uiGLGetFramebuffer(uiGLContext* ctx); diff --git a/src/libui_sdl/libui/unix/CMakeLists.txt b/src/libui_sdl/libui/unix/CMakeLists.txt index ec9ab75..c69081e 100644 --- a/src/libui_sdl/libui/unix/CMakeLists.txt +++ b/src/libui_sdl/libui/unix/CMakeLists.txt @@ -63,6 +63,7 @@ macro(_handle_static) set(_oname libui-combined.o) add_custom_command( OUTPUT ${_oname} + DEPENDS ${_LIBUINAME} COMMAND ld -r --whole-archive ${_aname} -o ${_oname} COMMAND diff --git a/src/libui_sdl/libui/unix/area.c b/src/libui_sdl/libui/unix/area.c index bf92ddf..62a4cb0 100644 --- a/src/libui_sdl/libui/unix/area.c +++ b/src/libui_sdl/libui/unix/area.c @@ -3,18 +3,6 @@ extern GThread* gtkthread; -// notes: -// - G_DECLARE_DERIVABLE/FINAL_INTERFACE() requires glib 2.44 and that's starting with debian stretch (testing) (GTK+ 3.18) and ubuntu 15.04 (GTK+ 3.14) - debian jessie has 2.42 (GTK+ 3.14) -#define areaWidgetType (areaWidget_get_type()) -#define areaWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), areaWidgetType, areaWidget)) -#define isAreaWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), areaWidgetType)) -#define areaWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), areaWidgetType, areaWidgetClass)) -#define isAreaWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), areaWidget)) -#define getAreaWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), areaWidgetType, areaWidgetClass)) - -typedef struct areaWidget areaWidget; -typedef struct areaWidgetClass areaWidgetClass; - struct areaWidget { GtkDrawingArea parent_instance; uiArea *a; @@ -45,6 +33,7 @@ struct uiArea { gboolean opengl; uiGLContext *glContext; + gboolean drawreq; int bgR, bgG, bgB; @@ -63,6 +52,21 @@ struct uiArea { G_DEFINE_TYPE(areaWidget, areaWidget, GTK_TYPE_DRAWING_AREA) +int boub(GtkWidget* w) { return isAreaWidget(w); } +void baba(GtkWidget* w) +{ + if (!isAreaWidget(w)) return; + + areaWidget *aw = areaWidget(w); + uiArea *a = aw->a; + if (!a->opengl) return; + + GdkGLContext* oldctx = gdk_gl_context_get_current(); + uiGLMakeContextCurrent(a->glContext); + glFinish(); + gdk_gl_context_make_current(oldctx); +} + static void areaWidget_init(areaWidget *aw) { // for events @@ -130,6 +134,22 @@ static void loadAreaSize(uiArea *a, double *width, double *height) void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx); +void areaPreRedraw(areaWidget* widget) +{ + uiArea* a = widget->a; + if (!a->opengl) return; + + areaPreRedrawGL(a->glContext); +} + +void areaPostRedraw(areaWidget* widget) +{ + uiArea* a = widget->a; + if (!a->opengl) return; + + areaPostRedrawGL(a->glContext); +} + static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) { areaWidget *aw = areaWidget(w); @@ -161,6 +181,8 @@ static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) else { areaDrawGL(w, &dp, cr, a->glContext); + //if (a->drawreq) uiGLEnd(a->glContext); + a->drawreq = FALSE; } freeContext(dp.Context); @@ -613,7 +635,15 @@ static void areaWidget_class_init(areaWidgetClass *class) // control implementation -uiUnixControlAllDefaults(uiArea) +uiUnixControlAllDefaultsExceptDestroy(uiArea) + +static void uiAreaDestroy(uiControl *c) +{ + uiArea* a = uiArea(c); + if (a->opengl && a->glContext) freeGLContext(a->glContext); + g_object_unref(uiArea(c)->widget); + uiFreeControl(c); +} void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b) { @@ -634,6 +664,8 @@ void uiAreaSetSize(uiArea *a, int width, int height) gboolean _threadsaferefresh(gpointer data) { uiArea* a = (uiArea*)data; + a->drawreq = TRUE; + //if (a->opengl) uiGLBegin(a->glContext); gtk_widget_queue_draw(a->areaWidget); return FALSE; } @@ -644,7 +676,11 @@ void uiAreaQueueRedrawAll(uiArea *a) if (g_thread_self() != gtkthread) g_idle_add(_threadsaferefresh, a); else + { + a->drawreq = TRUE; + //if (a->opengl) uiGLBegin(a->glContext); gtk_widget_queue_draw(a->areaWidget); + } } void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height) @@ -767,10 +803,12 @@ printf("create glarea\n"); a->ah = ah; a->scrolling = FALSE; a->opengl = TRUE; + a->drawreq = FALSE; //GtkGLArea* gla = (GtkGLArea*)gtk_gl_area_new(); uiGLContext* ctx = NULL; printf("create sdfsf\n"); + // TODO: move this elsewhere!! so we can actually try all possible versions for (int i = 0; req_versions[i] && !ctx; i++) { int major = uiGLVerMajor(req_versions[i]); int minor = uiGLVerMinor(req_versions[i]); @@ -792,8 +830,7 @@ printf("create jfghjjgh: %p\n", ctx); g_signal_connect(a->widget, "realize", G_CALLBACK(majoricc), a); uiAreaSetBackgroundColor(a, -1, -1, -1); - //printf("is area realized: %d\n", gtk_widget_get_realized(GTK_WIDGET(gla))); -printf("create qssssq\n"); + return a; } diff --git a/src/libui_sdl/libui/unix/gl.c b/src/libui_sdl/libui/unix/gl.c index 3504d3a..3861cda 100644 --- a/src/libui_sdl/libui/unix/gl.c +++ b/src/libui_sdl/libui/unix/gl.c @@ -6,12 +6,35 @@ #include extern GThread* gtkthread; +extern GMutex glmutex; /* *(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' */ + +// MISERABLE LITTLE PILE OF HACKS +#define HAX_GDK_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_GL_CONTEXT, HAX_GdkGLContextClass)) +#define HAX_GDK_IS_GL_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_GL_CONTEXT)) +#define HAX_GDK_GL_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_GL_CONTEXT, HAX_GdkGLContextClass)) + +typedef struct _HAX_GdkGLContextClass HAX_GdkGLContextClass; + +struct _HAX_GdkGLContextClass +{ + GObjectClass parent_class; + + gboolean (* realize) (GdkGLContext *context, + GError **error); + + void (* end_frame) (GdkGLContext *context, + cairo_region_t *painted, + cairo_region_t *damage); + gboolean (* texture_from_surface) (GdkGLContext *context, + cairo_surface_t *surface, + cairo_region_t *region); +}; struct uiGLContext { GtkGLArea *gla; @@ -19,6 +42,11 @@ struct uiGLContext { GdkWindow* window; GdkGLContext *gctx; + GMutex mutex; + GLsync sync; + GLsync sync2; + int zog; + Display* xdisp; GLXPixmap glxpm; GLXContext glxctx; @@ -26,8 +54,8 @@ struct uiGLContext { int width, height; int scale; - GLuint renderbuffer[2]; - GLuint framebuffer; + GLuint renderbuffer[2][2]; + GLuint framebuffer[2]; }; static PFNGLGENRENDERBUFFERSPROC _glGenRenderbuffers; @@ -45,7 +73,16 @@ static PFNGLCHECKFRAMEBUFFERSTATUSPROC _glCheckFramebufferStatus; static int _procsLoaded = 0; -static void _loadGLProcs() +static void (*vniorp)(GdkGLContext*, cairo_region_t*, cairo_region_t*); + +static void class_hax(GdkGLContext* glctx, cairo_region_t* painted, cairo_region_t* damage) +{ + //printf("END FRAME HIJACK\n"); + //glClearColor(0, 1, 0, 1); + vniorp(glctx, painted, damage); +} + +static void _loadGLProcs(GdkGLContext* glctx) { if (_procsLoaded) return; @@ -63,17 +100,25 @@ static void _loadGLProcs() _glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)uiGLGetProcAddress("glCheckFramebufferStatus"); _procsLoaded = 1; + + HAX_GdkGLContextClass* class = HAX_GDK_GL_CONTEXT_GET_CLASS(glctx); + printf("HAX class = %p\n", class); + printf("class end_frame = %p\n", class->end_frame); + vniorp = class->end_frame; + class->end_frame = class_hax; } Display* derp; -uiGLContext *createGLContext(GtkGLArea* gla, int maj, int min) +int nswaps = 0; + +uiGLContext *createGLContext(GtkWidget* widget, int maj, int min) { printf("barp\n"); uiGLContext *ret = uiNew(uiGLContext);//uiAlloc(sizeof(uiGLContext), "uiGLContext"); // herp - ret->gla = gla; + ret->gla = widget; ret->gctx = NULL; //while (!ret->gctx) /*{ @@ -111,6 +156,14 @@ uiGLContext *createGLContext(GtkGLArea* gla, int maj, int min) return ret; } +void freeGLContext(uiGLContext* glctx) +{ + if (glctx == NULL) return; + gdk_gl_context_clear_current(); + g_object_unref(glctx->gctx); + uiFree(glctx); +} + static void areaAllocRenderbuffer(uiGLContext* glctx); void databotte(GtkWidget* widget, uiGLContext* ctx) @@ -150,7 +203,7 @@ void databotte(GtkWidget* widget, uiGLContext* ctx) ctx->scale = window_scale; gdk_gl_context_make_current(glctx); - _loadGLProcs(); + _loadGLProcs(glctx); areaAllocRenderbuffer(ctx); ctx->widget = widget; @@ -160,10 +213,10 @@ void databotte(GtkWidget* widget, uiGLContext* ctx) static void areaAllocRenderbuffer(uiGLContext* glctx) { - _glGenRenderbuffers(2, &glctx->renderbuffer[0]);printf("ylarg0 %04X, %d %d\n", glGetError(), glctx->width, glctx->height); + _glGenRenderbuffers(4, &glctx->renderbuffer[0][0]);printf("ylarg0 %04X, %d %d\n", glGetError(), glctx->width, glctx->height); //glGenTextures(2, &glctx->renderbuffer[0]); - _glGenFramebuffers(1, &glctx->framebuffer);printf("ylarg1 %04X\n", glGetError()); - printf("FB %08X created under ctx %p (%p %p)\n", glctx?glctx->framebuffer:0, gdk_gl_context_get_current(), glctx?glctx->gctx:NULL, glctx); + _glGenFramebuffers(2, &glctx->framebuffer[0]);printf("ylarg1 %04X\n", glGetError()); + printf("FB %08X created under ctx %p (%p %p)\n", glctx?glctx->framebuffer[0]:0, gdk_gl_context_get_current(), glctx?glctx->gctx:NULL, glctx); /*glBindTexture(GL_TEXTURE_2D, glctx->renderbuffer[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); @@ -176,37 +229,91 @@ static void areaAllocRenderbuffer(uiGLContext* glctx) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);*/ - _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0]);printf("ylarg1 %04X\n", glGetError()); + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][0]);printf("ylarg1 %04X\n", glGetError()); + _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale);printf("ylarg1 %04X\n", glGetError()); + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][1]);printf("ylarg1 %04X\n", glGetError()); + _glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale);printf("ylarg1 %04X\n", glGetError()); + + _glBindFramebuffer(GL_FRAMEBUFFER, glctx->framebuffer[0]);printf("ylarg2 %04X\n", glGetError()); + /*_glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, glctx->renderbuffer[0], 0); + _glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, glctx->renderbuffer[1], 0);*/ + _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, glctx->renderbuffer[0][0]);printf("ylarg3 %04X\n", glGetError()); + _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, glctx->renderbuffer[0][1]);printf("ylarg4 %04X\n", glGetError()); + //printf("ylarg: %08X, %04X, %08X %08X\n", glctx->framebuffer, glGetError(), glctx->renderbuffer[0], glctx->renderbuffer[1]); + + + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1][0]);printf("ylarg1 %04X\n", glGetError()); _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale);printf("ylarg1 %04X\n", glGetError()); - _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1]);printf("ylarg1 %04X\n", glGetError()); + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1][1]);printf("ylarg1 %04X\n", glGetError()); _glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale);printf("ylarg1 %04X\n", glGetError()); - _glBindFramebuffer(GL_FRAMEBUFFER, glctx->framebuffer);printf("ylarg2 %04X\n", glGetError()); + _glBindFramebuffer(GL_FRAMEBUFFER, glctx->framebuffer[1]);printf("ylarg2 %04X\n", glGetError()); /*_glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, glctx->renderbuffer[0], 0); _glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, glctx->renderbuffer[1], 0);*/ - _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, glctx->renderbuffer[0]);printf("ylarg3 %04X\n", glGetError()); - _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, glctx->renderbuffer[1]);printf("ylarg4 %04X\n", glGetError()); + _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, glctx->renderbuffer[1][0]);printf("ylarg3 %04X\n", glGetError()); + _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, glctx->renderbuffer[1][1]);printf("ylarg4 %04X\n", glGetError()); //printf("ylarg: %08X, %04X, %08X %08X\n", glctx->framebuffer, glGetError(), glctx->renderbuffer[0], glctx->renderbuffer[1]); if(_glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) printf("FRAMEBUFFER IS BAD!! %04X\n", _glCheckFramebufferStatus(GL_FRAMEBUFFER)); int alpha_size; - _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0]); + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][0]); _glGetRenderbufferParameteriv (GL_RENDERBUFFER, GL_RENDERBUFFER_ALPHA_SIZE, &alpha_size); printf("FRAMEBUFFER GOOD. ALPHA SIZE IS %d\n", alpha_size); } static void areaRellocRenderbuffer(uiGLContext* glctx) { - _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0]); + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][0]); _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale); - _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1]); + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][1]); + _glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale); + + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1][0]); + _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale); + _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1][1]); _glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale); } +void areaPreRedrawGL(uiGLContext* glctx) +{ + g_mutex_lock(&glctx->mutex); + + /*gdk_gl_context_make_current(glctx->gctx); + //glClientWaitSync(glctx->sync, 0, GL_TIMEOUT_IGNORED); + glDeleteSync(glctx->sync); + glFinish(); + gdk_gl_context_clear_current();*/ + /*GdkGLContext* oldctx = gdk_gl_context_get_current(); + gdk_gl_context_make_current(glctx->gctx); + printf("[%p] PRE DRAW\n", gdk_gl_context_get_current()); + + gdk_gl_context_make_current(oldctx);*/ + //glClearColor(0,1,0,1); glClear(GL_COLOR_BUFFER_BIT); + //glWaitSync(glctx->sync, 0, GL_TIMEOUT_IGNORED); + /*int ret = glClientWaitSync(glctx->sync, GL_SYNC_FLUSH_COMMANDS_BIT, 1000000*50); + printf("PRE-DRAW: SYNC %p, %04X, %04X\n", glctx->sync, ret, glGetError()); + glDeleteSync(glctx->sync); + glctx->sync = NULL;*/ + //glFlush(); + if (nswaps > 1) printf("MISSED %d FRAMES\n", nswaps-1); + nswaps = 0; + //glctx->zog ^= 1; +} + +void areaPostRedrawGL(uiGLContext* glctx) +{ + //glctx->sync2 = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + //glFlush(); + //printf("[%p] POST DRAW\n", gdk_gl_context_get_current()); + g_mutex_unlock(&glctx->mutex); +} + void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx) { + //uiGLBegin(glctx); + int window_scale = gdk_window_get_scale_factor(glctx->window); if (glctx->width != dp->AreaWidth || glctx->height != dp->AreaHeight || glctx->scale != window_scale) @@ -218,8 +325,10 @@ void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContex } gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(widget), - glctx->renderbuffer[0], GL_RENDERBUFFER, + glctx->renderbuffer[glctx->zog][0], GL_RENDERBUFFER, 1, 0, 0, glctx->width*glctx->scale, glctx->height*glctx->scale); + + //uiGLEnd(glctx); } uiGLContext* FARTOMATIC(int major, int minor) @@ -229,9 +338,15 @@ uiGLContext* FARTOMATIC(int major, int minor) _ret->vermin = minor; _ret->width = -1; _ret->height = -1; - _ret->renderbuffer[0] = 0; - _ret->renderbuffer[1] = 0; - _ret->framebuffer = 0; + _ret->renderbuffer[0][0] = 0; + _ret->renderbuffer[0][1] = 0; + _ret->framebuffer[0] = 0; + _ret->renderbuffer[1][0] = 0; + _ret->renderbuffer[1][1] = 0; + _ret->framebuffer[1] = 0; + _ret->zog = 0; + + g_mutex_init(&_ret->mutex); return _ret; @@ -348,7 +463,7 @@ uiGLContext* FARTOMATIC(int major, int minor) int uiGLGetFramebuffer(uiGLContext* ctx) { - return ctx->framebuffer; + return ctx->framebuffer[ctx->zog];// ? 0:1]; } float uiGLGetFramebufferScale(uiGLContext* ctx) @@ -358,8 +473,18 @@ float uiGLGetFramebufferScale(uiGLContext* ctx) void uiGLSwapBuffers(uiGLContext* ctx) { - if (!ctx) return; - //gtk_gl_area_attach_buffers(ctx->gla); + /*ctx->sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + //gdk_gl_context_clear_current(); + glWaitSync(ctx->sync, 0, GL_TIMEOUT_IGNORED); + glDeleteSync(ctx->sync);*/ + /*printf("[%p] SWAPBUFFERS\n", gdk_gl_context_get_current()); + glClearColor(0,1,0,1); glClear(GL_COLOR_BUFFER_BIT); + glFinish();*/ + //ctx->sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + //glFlush(); + //printf("SWAP: SYNC=%p\n", ctx->sync); + //glFinish(); + nswaps++; } static volatile int _ctxset_done; @@ -398,7 +523,7 @@ void uiGLMakeContextCurrent(uiGLContext* ctx) } printf("WE MAED IT CURRENT: %d\n", ret);*/ - printf("[%p] MAKE CONTEXT CURRENT %p, %p\n", g_thread_self(), ctx, ctx?ctx->gctx:NULL); + //printf("[%p] MAKE CONTEXT CURRENT %p, %p\n", g_thread_self(), ctx, ctx?ctx->gctx:NULL); if (!ctx) { gdk_gl_context_clear_current(); @@ -410,6 +535,32 @@ void uiGLMakeContextCurrent(uiGLContext* ctx) //gtk_gl_area_attach_buffers(ctx->gla); //printf("burp = %p / %p\n", burp, ctx->gctx); } + +void uiGLBegin(uiGLContext* ctx) +{ + //g_mutex_lock(&ctx->mutex); + if (g_thread_self() != gtkthread) + { + g_mutex_lock(&glmutex); + + //int ret = glClientWaitSync(ctx->sync2, GL_SYNC_FLUSH_COMMANDS_BIT, 1000000*50); + //printf("GLBEGIN: SYNC %p, %04X, %04X\n", ctx->sync2, ret, glGetError()); + //glDeleteSync(ctx->sync2); + } +} + +void uiGLEnd(uiGLContext* ctx) +{ + //g_mutex_unlock(&ctx->mutex); + if (g_thread_self() != gtkthread) + { + g_mutex_unlock(&glmutex); + + //ctx->sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + //glFlush(); + } +} + void *uiGLGetProcAddress(const char* proc) { printf("get: %s - ", proc); diff --git a/src/libui_sdl/libui/unix/main.c b/src/libui_sdl/libui/unix/main.c index 409b659..66bd335 100644 --- a/src/libui_sdl/libui/unix/main.c +++ b/src/libui_sdl/libui/unix/main.c @@ -6,6 +6,33 @@ uiInitOptions options; // kind of a hack GThread* gtkthread; +GMutex glmutex; +int boub(GtkWidget* w); +void baba(GtkWidget* w); + +static void _eventfilter(GdkEvent* evt, gpointer data) +{ + if (evt->type == GDK_EXPOSE) + { + GtkWidget* widget = gtk_get_event_widget(evt); + if (isAreaWidget(widget)) + { + areaWidget* area = areaWidget(widget); + areaPreRedraw(area); + gtk_main_do_event(evt); + areaPostRedraw(area); + return; + } + } + + gtk_main_do_event(evt); +} + +static void _eventfilterdestroy(gpointer data) +{ + printf("DELET\n"); +} + const char *uiInit(uiInitOptions *o) { GError *err = NULL; @@ -31,6 +58,10 @@ const char *uiInit(uiInitOptions *o) gtk_window_set_default_icon_list(iconlist); + g_mutex_init(&glmutex); + + gdk_event_handler_set(_eventfilter, NULL, _eventfilterdestroy); + return NULL; } diff --git a/src/libui_sdl/libui/unix/uipriv_unix.h b/src/libui_sdl/libui/unix/uipriv_unix.h index 42d5d76..7a7b208 100644 --- a/src/libui_sdl/libui/unix/uipriv_unix.h +++ b/src/libui_sdl/libui/unix/uipriv_unix.h @@ -65,5 +65,23 @@ 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); // gl.c -extern uiGLContext *createGLContext(GtkGLArea* gla, int maj, int min); +extern uiGLContext *createGLContext(GtkWidget* widget, int maj, int min); +extern void freeGLContext(uiGLContext* glctx); +extern void areaPreRedrawGL(uiGLContext* glctx); +extern void areaPostRedrawGL(uiGLContext* glctx); + +// notes: +// - G_DECLARE_DERIVABLE/FINAL_INTERFACE() requires glib 2.44 and that's starting with debian stretch (testing) (GTK+ 3.18) and ubuntu 15.04 (GTK+ 3.14) - debian jessie has 2.42 (GTK+ 3.14) +#define areaWidgetType (areaWidget_get_type()) +#define areaWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), areaWidgetType, areaWidget)) +#define isAreaWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), areaWidgetType)) +#define areaWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), areaWidgetType, areaWidgetClass)) +#define isAreaWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), areaWidget)) +#define getAreaWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), areaWidgetType, areaWidgetClass)) + +typedef struct areaWidget areaWidget; +typedef struct areaWidgetClass areaWidgetClass; + +extern void areaPreRedraw(areaWidget* widget); +extern void areaPostRedraw(areaWidget* widget); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index e2686f9..fa6a2b5 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -379,26 +379,24 @@ void GLScreen_DrawScreen() glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GL_ScreenVertices), GL_ScreenVertices); } - printf("rarp4 %04X\n", glGetError()); + glDisable(GL_DEPTH_TEST); glDisable(GL_STENCIL_TEST); glDisable(GL_BLEND); glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); -printf("rarp2 %04X\n", glGetError()); glViewport(0, 0, WindowWidth*scale, WindowHeight*scale); - printf("draw screen: viewport=%d/%d\n", WindowWidth, WindowHeight); if (GPU3D::Renderer == 0) OpenGL_UseShaderProgram(GL_ScreenShader); else OpenGL_UseShaderProgram(GL_ScreenShaderAccel); -printf("rarp3 %04X\n", glGetError()); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, uiGLGetFramebuffer(GLContext)); - printf("rarp8 %04X\n", glGetError()); + glClearColor(0, 0, 1, 1); glClear(GL_COLOR_BUFFER_BIT); -printf("rarp5 %04X\n", glGetError()); + int frontbuf = GPU::FrontBuffer; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, GL_ScreenTexture); @@ -424,11 +422,11 @@ printf("rarp5 %04X\n", glGetError()); glActiveTexture(GL_TEXTURE1); if (GPU3D::Renderer != 0) GPU3D::GLRenderer::SetupAccelFrame(); -printf("rarp6 %04X\n", glGetError()); + glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); glBindVertexArray(GL_ScreenVertexArrayID); glDrawArrays(GL_TRIANGLES, 0, 4*3); -printf("rarp7 %04X\n", glGetError()); + glFlush(); uiGLSwapBuffers(GLContext); } @@ -826,7 +824,11 @@ int EmuThreadFunc(void* burp) // microphone input FeedMicInput(); - if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); + if (Screen_UseGL) + { + uiGLBegin(GLContext); + uiGLMakeContextCurrent(GLContext); + } // auto screen layout { @@ -862,7 +864,11 @@ int EmuThreadFunc(void* burp) if (EmuRunning == 0) break; - if (Screen_UseGL) GLScreen_DrawScreen(); + if (Screen_UseGL) + { + GLScreen_DrawScreen(); + uiGLEnd(GLContext); + } uiAreaQueueRedrawAll(MainDrawArea); // framerate limiter based off SDL2_gfx @@ -917,8 +923,10 @@ int EmuThreadFunc(void* burp) { if (Screen_UseGL) { + uiGLBegin(GLContext); uiGLMakeContextCurrent(GLContext); GLScreen_DrawScreen(); + uiGLEnd(GLContext); //uiGLMakeContextCurrent(NULL); //uiQueueMain(norp, NULL); } @@ -2537,6 +2545,9 @@ int main(int argc, char** argv) if (MicDevice) SDL_CloseAudioDevice(MicDevice); if (MicWavBuffer) delete[] MicWavBuffer; + + if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); + if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); Config::ScreenRotation = ScreenRotation; Config::ScreenGap = ScreenGap; -- cgit v1.2.3 From 3aa971403bdf3ebd21082025a6b9d9e181f9816a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 2 Jun 2019 14:33:20 +0200 Subject: lay base for OSD --- src/libui_sdl/CMakeLists.txt | 1 + src/libui_sdl/OSD.cpp | 305 +++++++++++++++++++++++++++++++++++++++++++ src/libui_sdl/OSD.h | 36 +++++ src/libui_sdl/font.h | 135 +++++++++++++++++++ src/libui_sdl/main.cpp | 4 + 5 files changed, 481 insertions(+) create mode 100644 src/libui_sdl/OSD.cpp create mode 100644 src/libui_sdl/OSD.h create mode 100644 src/libui_sdl/font.h (limited to 'src/libui_sdl/CMakeLists.txt') diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index e9a54e2..63e9f48 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -11,6 +11,7 @@ SET(SOURCES_LIBUI DlgInputConfig.cpp DlgVideoSettings.cpp DlgWifiSettings.cpp + OSD.cpp ) option(BUILD_SHARED_LIBS "Whether to build libui as a shared library or a static library" ON) diff --git a/src/libui_sdl/OSD.cpp b/src/libui_sdl/OSD.cpp new file mode 100644 index 0000000..7e8c8f7 --- /dev/null +++ b/src/libui_sdl/OSD.cpp @@ -0,0 +1,305 @@ +/* + Copyright 2016-2019 Arisotura + + 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/. +*/ + +#include +#include +#include +#include +#include "types.h" +#include "OSD.h" + +#include "libui/ui.h" +#include "../OpenGLSupport.h" + +#include "font.h" + +extern int WindowWidth, WindowHeight; + +namespace OSD +{ + +const u32 kOSDMargin = 6; + +typedef struct +{ + Uint32 Timestamp; + u32 Width, Height; + u32* Bitmap; + + bool DrawBitmapLoaded; + uiDrawBitmap* DrawBitmap; + + bool GLTextureLoaded; + GLuint GLTexture; + +} Item; + +std::queue CurrentItems; + + +bool Init() +{ +} + +void DeInit() +{ +} + + +int FindBreakPoint(const char* text, int i) +{ + // i = character that went out of bounds + + for (int j = i; j >= 0; j--) + { + if (text[j] == ' ') + return j; + } + + return i; +} + +void LayoutText(const char* text, u32* width, u32* height, int* breaks) +{ + u32 w = 0; + u32 h = 14; + u32 totalw = 0; + u32 maxw = WindowWidth - (kOSDMargin*2); + int lastbreak = -1; + int numbrk = 0; + u16* ptr; + + memset(breaks, 0, sizeof(int)*64); + + for (int i = 0; text[i] != '\0'; ) + { + int glyphsize; + if (text[i] == ' ') + { + glyphsize = 6; + } + else + { + u32 ch = text[i]; + if (ch < 0x10 || ch > 0x7E) ch = 0x7F; + + ptr = &font[(ch-0x10) << 4]; + glyphsize = ptr[0]; + if (!glyphsize) glyphsize = 6; + else glyphsize += 2; // space around the character + } + + w += glyphsize; + if (w > maxw) + { + // wrap shit as needed + if (text[i] == ' ') + { + if (numbrk >= 64) break; + breaks[numbrk++] = i; + i++; + } + else + { + int brk = FindBreakPoint(text, i); + if (brk != lastbreak) i = brk; + + if (numbrk >= 64) break; + breaks[numbrk++] = i; + + lastbreak = brk; + } + + w = 0; + h += 14; + } + else + i++; + + if (w > totalw) totalw = w; + } + + *width = totalw; + *height = h; +} + +u32 RainbowColor(u32 inc) +{ + // inspired from Acmlmboard + + if (inc < 100) return 0xFFFF9BFF + (inc << 8); + else if (inc < 200) return 0xFFFFFF9B - ((inc-100) << 16); + else if (inc < 300) return 0xFF9BFF9B + (inc-200); + else if (inc < 400) return 0xFF9BFFFF - ((inc-300) << 8); + else if (inc < 500) return 0xFF9B9BFF + ((inc-400) << 16); + else return 0xFFFF9BFF - (inc-500); +} + +void RenderText(u32 color, const char* text, Item* item) +{ + u32 w, h; + int breaks[64]; + + bool rainbow = (color == 0); + u32 rainbowinc = rand() % 600; + + color |= 0xFF000000; + const u32 shadow = 0xC0000000; + + LayoutText(text, &w, &h, breaks); + + item->Width = w; + item->Height = h; + item->Bitmap = new u32[w*h]; + memset(item->Bitmap, 0, w*h*sizeof(u32)); + + u32 x = 0, y = 1; + u32 maxw = WindowWidth - (kOSDMargin*2); + int curline = 0; + u16* ptr; + + for (int i = 0; text[i] != '\0'; ) + { + int glyphsize; + if (text[i] == ' ') + { + x += 6; + } + else + { + u32 ch = text[i]; + if (ch < 0x10 || ch > 0x7E) ch = 0x7F; + + ptr = &font[(ch-0x10) << 4]; + int glyphsize = ptr[0]; + if (!glyphsize) x += 6; + else + { + x++; + + if (rainbow) + { + color = RainbowColor(rainbowinc); + rainbowinc = (rainbowinc + 30) % 600; + } + + // draw character + for (int cy = 0; cy < 12; cy++) + { + u16 val = ptr[4+cy]; + + for (int cx = 0; cx < glyphsize; cx++) + { + if (val & (1<Bitmap[((y+cy) * w) + x+cx] = color; + } + } + + x += glyphsize; + x++; + } + } + + i++; + if (breaks[curline] && i >= breaks[curline]) + { + i = breaks[curline++]; + if (text[i] == ' ') i++; + + x = 0; + y += 14; + } + } + + // shadow + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + u32 val; + + val = item->Bitmap[(y * w) + x]; + if ((val >> 24) == 0xFF) continue; + + if (x > 0) val = item->Bitmap[(y * w) + x-1]; + if (x < w-1) val |= item->Bitmap[(y * w) + x+1]; + if (y > 0) + { + if (x > 0) val |= item->Bitmap[((y-1) * w) + x-1]; + val |= item->Bitmap[((y-1) * w) + x]; + if (x < w-1) val |= item->Bitmap[((y-1) * w) + x+1]; + } + if (y < h-1) + { + if (x > 0) val |= item->Bitmap[((y+1) * w) + x-1]; + val |= item->Bitmap[((y+1) * w) + x]; + if (x < w-1) val |= item->Bitmap[((y+1) * w) + x+1]; + } + + if ((val >> 24) == 0xFF) + item->Bitmap[(y * w) + x] = shadow; + } + } +} + +void test(u32* berp) +{ + Item barp; + RenderText(0x000000, "This is a test of OSD, it can display really long messages, like thiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiis. Also, pancakes are the best thing ever.", &barp); + + for (int y = 0; y < barp.Height; y++) + { + for (int x = 0; x < barp.Width; x++) + { + u32 src = barp.Bitmap[(y*barp.Width)+x]; + u32 dst = berp[((y+6)*256)+x+6]; + + u32 sR = (src >> 16) & 0xFF; + u32 sG = (src >> 8) & 0xFF; + u32 sB = (src ) & 0xFF; + u32 sA = (src >> 24) & 0xFF; + + u32 dR = (dst >> 16) & 0xFF; + u32 dG = (dst >> 8) & 0xFF; + u32 dB = (dst ) & 0xFF; + + dR = ((sR * sA) + (dR * (255-sA))) >> 8; + dG = ((sG * sA) + (dG * (255-sA))) >> 8; + dB = ((sB * sA) + (dB * (255-sA))) >> 8; + + dst = (dR << 16) | (dG << 8) | dB; + + berp[((y+6)*256)+x+6] = dst | 0xFF000000; + } + } + + delete[] barp.Bitmap; +} + + +void AddMessage(u32 color, const char* text) +{ + // +} + +void Update(bool opengl) +{ + // +} + +} diff --git a/src/libui_sdl/OSD.h b/src/libui_sdl/OSD.h new file mode 100644 index 0000000..ed38490 --- /dev/null +++ b/src/libui_sdl/OSD.h @@ -0,0 +1,36 @@ +/* + Copyright 2016-2019 Arisotura + + 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 OSD_H +#define OSD_H + +namespace OSD +{ + +bool Init(); +void DeInit(); + +void test(u32* berp); + +void AddMessage(u32 color, const char* text); + +void Update(bool opengl); + +} + +#endif // OSD_H diff --git a/src/libui_sdl/font.h b/src/libui_sdl/font.h new file mode 100644 index 0000000..8647b7a --- /dev/null +++ b/src/libui_sdl/font.h @@ -0,0 +1,135 @@ +/* + Copyright 2016-2019 Arisotura + + 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 FONT_H +#define FONT_H +unsigned short font[] = { + 12, 0, 0, 0,0x0C03, 0x0E07, 0x070E, 0x039C, 0x01F8, 0x00F0, 0x00F0, 0x01F8, 0x039C, 0x070E, 0x0E07, 0x0C03, + 12, 0, 0, 0,0x01C0, 0x00E0, 0x0060, 0x0860, 0x0C60, 0x0FE0, 0x07F0, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, 0x0003, 0x0003, 0x0000, 0x0000, + 9, 0, 0, 0,0x01EF, 0x01EF, 0x018C, 0x01CE, 0x00E7, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 10, 0, 0, 0,0x00CC, 0x00CC, 0x03FF, 0x03FF, 0x00CC, 0x00CC, 0x03FF, 0x03FF, 0x00CC, 0x00CC, 0x0000, 0x0000, + 8, 0, 0, 0,0x0018, 0x00FE, 0x00FF, 0x001B, 0x007F, 0x00FE, 0x00D8, 0x00FF, 0x007F, 0x0018, 0x0000, 0x0000, + 10, 0, 0, 0,0x0306, 0x038F, 0x01CF, 0x00E6, 0x0070, 0x0038, 0x019C, 0x03CE, 0x03C7, 0x0183, 0x0000, 0x0000, + 10, 0, 0, 0,0x007C, 0x00FE, 0x00C6, 0x00EE, 0x007C, 0x037E, 0x03E7, 0x01F3, 0x03BF, 0x031E, 0x0000, 0x0000, + 4, 0, 0, 0,0x000F, 0x000F, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 4, 0, 0, 0,0x000C, 0x000E, 0x0007, 0x0003, 0x0003, 0x0003, 0x0003, 0x0007, 0x000E, 0x000C, 0x0000, 0x0000, + 4, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x000C, 0x000C, 0x000C, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, + 10, 0, 0, 0,0x0030, 0x0333, 0x03B7, 0x01FE, 0x00FC, 0x00FC, 0x01FE, 0x03B7, 0x0333, 0x0030, 0x0000, 0x0000, + 10, 0, 0, 0,0x0030, 0x0030, 0x0030, 0x0030, 0x03FF, 0x03FF, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, + 4, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000F, 0x000F, 0x000C, 0x000E, 0x0007, 0x0003, + 10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x03FF, 0x03FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 3, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0007, 0x0007, 0x0007, 0x0000, 0x0000, + 10, 0, 0, 0,0x0300, 0x0380, 0x01C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 4, 0, 0, 0,0x0006, 0x0007, 0x0007, 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x000F, 0x000F, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C0, 0x00FE, 0x007F, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0000, 0x0000, + 8, 0, 0, 0,0x007F, 0x00FF, 0x00C0, 0x00C0, 0x007C, 0x00FC, 0x00C0, 0x00C0, 0x00FF, 0x007F, 0x0000, 0x0000, + 8, 0, 0, 0,0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x00FF, 0x00FE, 0x0060, 0x0060, 0x0000, 0x0000, + 8, 0, 0, 0,0x00FF, 0x00FF, 0x0003, 0x0003, 0x007F, 0x00FF, 0x00C0, 0x00C0, 0x00FF, 0x007F, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x007F, 0x0003, 0x0003, 0x007F, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 8, 0, 0, 0,0x00FF, 0x00FF, 0x00C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000C, 0x000C, 0x000C, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x00FE, 0x00C0, 0x00C0, 0x00FE, 0x007E, 0x0000, 0x0000, + 3, 0, 0, 0,0x0000, 0x0000, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000, + 4, 0, 0, 0,0x0000, 0x0000, 0x000E, 0x000E, 0x0000, 0x0000, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, + 6, 0, 0, 0,0x0030, 0x0038, 0x001C, 0x000E, 0x0007, 0x0007, 0x000E, 0x001C, 0x0038, 0x0030, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x007F, 0x007F, 0x0000, 0x0000, 0x007F, 0x007F, 0x0000, 0x0000, 0x0000, + 6, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x001C, 0x0038, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00F0, 0x0078, 0x0018, 0x0000, 0x0018, 0x0018, 0x0000, 0x0000, + 10, 0, 0, 0,0x00FC, 0x01FE, 0x0387, 0x0333, 0x037B, 0x03FB, 0x01F3, 0x0007, 0x03FE, 0x03FC, 0x0000, 0x0000, + 9, 0, 0, 0,0x00FE, 0x01FF, 0x0183, 0x0183, 0x0183, 0x01FF, 0x01FF, 0x0183, 0x0183, 0x0183, 0x0000, 0x0000, + 9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0000, 0x0000, + 8, 0, 0, 0,0x00FE, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x00FF, 0x00FE, 0x0000, 0x0000, + 9, 0, 0, 0,0x007F, 0x00FF, 0x01C3, 0x0183, 0x0183, 0x0183, 0x0183, 0x01C3, 0x00FF, 0x007F, 0x0000, 0x0000, + 9, 0, 0, 0,0x01FF, 0x01FF, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0003, 0x0003, 0x01FF, 0x01FF, 0x0000, 0x0000, + 9, 0, 0, 0,0x01FF, 0x01FF, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 9, 0, 0, 0,0x01FE, 0x01FF, 0x0003, 0x0003, 0x01F3, 0x01F3, 0x0183, 0x0183, 0x01FF, 0x00FE, 0x0000, 0x0000, + 9, 0, 0, 0,0x0183, 0x0183, 0x0183, 0x0183, 0x01FF, 0x01FF, 0x0183, 0x0183, 0x0183, 0x0183, 0x0000, 0x0000, + 6, 0, 0, 0,0x003F, 0x003F, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x003F, 0x003F, 0x0000, 0x0000, + 9, 0, 0, 0,0x01F0, 0x01F0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 9, 0, 0, 0,0x0183, 0x01C3, 0x00E3, 0x0073, 0x003F, 0x003F, 0x0073, 0x00E3, 0x01C3, 0x0183, 0x0000, 0x0000, + 7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x007F, 0x007F, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0387, 0x03CF, 0x03FF, 0x037B, 0x0333, 0x0303, 0x0303, 0x0303, 0x0303, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0307, 0x030F, 0x031F, 0x033B, 0x0373, 0x03E3, 0x03C3, 0x0383, 0x0303, 0x0000, 0x0000, + 10, 0, 0, 0,0x01FE, 0x03FF, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x03FF, 0x01FE, 0x0000, 0x0000, + 9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 10, 0, 0, 0,0x01FE, 0x03FF, 0x0303, 0x0303, 0x0333, 0x0373, 0x03E3, 0x01C3, 0x03FF, 0x037E, 0x0000, 0x0000, + 9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0073, 0x00E3, 0x01C3, 0x0183, 0x0000, 0x0000, + 10, 0, 0, 0,0x01FE, 0x01FF, 0x0003, 0x0003, 0x01FF, 0x03FE, 0x0300, 0x0300, 0x03FE, 0x01FE, 0x0000, 0x0000, + 10, 0, 0, 0,0x03FF, 0x03FF, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, + 9, 0, 0, 0,0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x01FF, 0x00FE, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0303, 0x0303, 0x0303, 0x0333, 0x037B, 0x03FF, 0x03CF, 0x0387, 0x0303, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0078, 0x00FC, 0x01CE, 0x0387, 0x0303, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, + 10, 0, 0, 0,0x03FF, 0x03FF, 0x01C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x03FF, 0x03FF, 0x0000, 0x0000, + 4, 0, 0, 0,0x000F, 0x000F, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x000F, 0x000F, 0x0000, 0x0000, + 10, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x001C, 0x0038, 0x0070, 0x00E0, 0x01C0, 0x0380, 0x0300, 0x0000, 0x0000, + 4, 0, 0, 0,0x000F, 0x000F, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000F, 0x000F, 0x0000, 0x0000, + 8, 0, 0, 0,0x0018, 0x003C, 0x007E, 0x00E7, 0x00C3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03FF, 0x03FF, + 4, 0, 0, 0,0x000F, 0x000F, 0x0003, 0x0007, 0x000E, 0x000C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x003E, 0x007E, 0x0060, 0x007E, 0x007F, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000, + 7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x007F, 0x003F, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0003, 0x0003, 0x0003, 0x0003, 0x007F, 0x007E, 0x0000, 0x0000, + 7, 0, 0, 0,0x0060, 0x0060, 0x0060, 0x007E, 0x007F, 0x0063, 0x0063, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x003E, 0x007F, 0x0063, 0x007F, 0x003F, 0x0003, 0x003F, 0x003E, 0x0000, 0x0000, + 6, 0, 0, 0,0x003C, 0x003E, 0x0006, 0x0006, 0x001F, 0x001F, 0x0006, 0x0006, 0x0006, 0x0006, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0063, 0x0063, 0x007F, 0x007E, 0x0060, 0x0060, 0x007E, 0x003E, + 7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0000, 0x0000, + 2, 0, 0, 0,0x0003, 0x0003, 0x0000, 0x0000, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 7, 0, 0, 0,0x0060, 0x0060, 0x0000, 0x0000, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0063, 0x007F, 0x003E, + 8, 0, 0, 0,0x0003, 0x0003, 0x00E3, 0x0073, 0x003B, 0x001F, 0x001F, 0x003B, 0x0073, 0x00E3, 0x0000, 0x0000, + 4, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x000F, 0x000E, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x01FF, 0x03FF, 0x0333, 0x0333, 0x0333, 0x0333, 0x0333, 0x0333, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0000, 0x0000, + 8, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x003F, 0x007F, 0x0063, 0x0063, 0x007F, 0x003F, 0x0003, 0x0003, 0x0003, 0x0003, + 7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0063, 0x0063, 0x007F, 0x007E, 0x0060, 0x0060, 0x0060, 0x0060, + 7, 0, 0, 0,0x0000, 0x0000, 0x003B, 0x007F, 0x0067, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 8, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0003, 0x007F, 0x00FE, 0x00C0, 0x00FE, 0x007E, 0x0000, 0x0000, + 6, 0, 0, 0,0x0006, 0x0006, 0x003F, 0x003F, 0x0006, 0x0006, 0x0006, 0x0006, 0x003E, 0x003C, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0303, 0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0303, 0x0333, 0x037B, 0x03FF, 0x03CF, 0x0387, 0x0303, 0x0000, 0x0000, + 8, 0, 0, 0,0x0000, 0x0000, 0x00C3, 0x00E7, 0x007E, 0x003C, 0x003C, 0x007E, 0x00E7, 0x00C3, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0307, 0x038E, 0x01DC, 0x00F8, 0x0070, 0x0038, 0x001C, 0x000E, 0x0006, + 8, 0, 0, 0,0x0000, 0x0000, 0x00FF, 0x00FF, 0x0070, 0x0038, 0x001C, 0x000E, 0x00FF, 0x00FF, 0x0000, 0x0000, + 6, 0, 0, 0,0x0038, 0x003C, 0x000C, 0x000C, 0x000F, 0x000F, 0x000C, 0x000C, 0x003C, 0x0038, 0x0000, 0x0000, + 2, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 6, 0, 0, 0,0x0007, 0x000F, 0x000C, 0x000C, 0x003C, 0x003C, 0x000C, 0x000C, 0x000F, 0x0007, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x031C, 0x03BE, 0x01F7, 0x00E3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 11, 0, 0, 0,0x0555, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0555, 0x0000, +}; +#endif diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 5408586..fe1b745 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -46,6 +46,8 @@ #include "../Savestate.h" +#include "OSD.h" + // savestate slot mapping // 1-8: regular slots (quick access) @@ -972,6 +974,8 @@ void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) uiRect top = {0, 0, 256, 192}; uiRect bot = {0, 0, 256, 192}; + //OSD::test(GPU::Framebuffer[frontbuf][0]); + uiDrawBitmapUpdate(ScreenBitmap[0], GPU::Framebuffer[frontbuf][0]); uiDrawBitmapUpdate(ScreenBitmap[1], GPU::Framebuffer[frontbuf][1]); -- cgit v1.2.3