diff options
Diffstat (limited to 'src/libui_sdl')
-rw-r--r-- | src/libui_sdl/Platform.cpp | 7 | ||||
-rw-r--r-- | src/libui_sdl/libui/ui.h | 2 | ||||
-rw-r--r-- | src/libui_sdl/libui/windows/gl.cpp | 69 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 11 |
4 files changed, 85 insertions, 4 deletions
diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 6ebe8c3..e3035b3 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -24,6 +24,7 @@ #include "PlatformConfig.h" #include "LAN_Socket.h" #include "LAN_PCap.h" +#include "libui/ui.h" #include <string> #ifdef __WIN32__ @@ -302,6 +303,12 @@ void Semaphore_Post(void* sema) } +void* GL_GetProcAddress(const char* proc) +{ + return uiGLGetProcAddress(proc); +} + + bool MP_Init() { int opt_true = 1; diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h index 381b85b..dd1c786 100644 --- a/src/libui_sdl/libui/ui.h +++ b/src/libui_sdl/libui/ui.h @@ -604,7 +604,7 @@ _UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayou typedef struct uiGLContext uiGLContext; -_UI_EXTERN uiGLContext *uiGLNewContext(uiControl* c); +_UI_EXTERN uiGLContext *uiGLNewContext(uiControl* c, int vermajor, int verminor); _UI_EXTERN void uiGLFreeContext(uiGLContext* ctx); _UI_EXTERN void uiGLMakeContextCurrent(uiGLContext* ctx); _UI_EXTERN void *uiGLGetProcAddress(const char* proc); diff --git a/src/libui_sdl/libui/windows/gl.cpp b/src/libui_sdl/libui/windows/gl.cpp index fe21ae4..eb7d33d 100644 --- a/src/libui_sdl/libui/windows/gl.cpp +++ b/src/libui_sdl/libui/windows/gl.cpp @@ -1,6 +1,9 @@ // 31 march 2019 #include "uipriv_windows.hpp" +#include <GL/gl.h> +#include <GL/wglext.h> + struct uiGLContext { uiControl* c; @@ -11,9 +14,10 @@ struct uiGLContext }; -uiGLContext* uiGLNewContext(uiControl* c) +uiGLContext* uiGLNewContext(uiControl* c, int vermajor, int verminor) { uiGLContext* ctx; + BOOL res; ctx = uiNew(uiGLContext); @@ -25,7 +29,10 @@ uiGLContext* uiGLNewContext(uiControl* c) else { // windowless context - ctx->hwnd = GetDesktopWindow(); + //ctx->hwnd = GetDesktopWindow(); + // nope. + uiFree(ctx); + return NULL; } PIXELFORMATDESCRIPTOR pfd; @@ -41,15 +48,71 @@ uiGLContext* uiGLNewContext(uiControl* c) pfd.iLayerType = PFD_MAIN_PLANE; ctx->dc = GetDC(ctx->hwnd); + if (!ctx->dc) + { + uiFree(ctx); + return NULL; + } int pixelformat = ChoosePixelFormat(ctx->dc, &pfd); - SetPixelFormat(ctx->dc, pixelformat, &pfd); + res = SetPixelFormat(ctx->dc, pixelformat, &pfd); + if (!res) + { + ReleaseDC(ctx->hwnd, ctx->dc); + uiFree(ctx); + return NULL; + } ctx->rc = wglCreateContext(ctx->dc); + if (!ctx->rc) + { + ReleaseDC(ctx->hwnd, ctx->dc); + uiFree(ctx); + return NULL; + } + + wglMakeCurrent(ctx->dc, ctx->rc); + + if (vermajor >= 3) + { + HGLRC (*wglCreateContextAttribsARB)(HDC,HGLRC,const int*); + HGLRC rc_better = NULL; + + wglCreateContextAttribsARB = (HGLRC(*)(HDC,HGLRC,const int*))wglGetProcAddress("wglCreateContextAttribsARB"); + if (wglCreateContextAttribsARB) + { + int attribs[15]; + int i = 0; + + attribs[i++] = WGL_CONTEXT_MAJOR_VERSION_ARB; + attribs[i++] = vermajor; + attribs[i++] = WGL_CONTEXT_MINOR_VERSION_ARB; + attribs[i++] = verminor; + + attribs[i] = 0; + rc_better = wglCreateContextAttribsARB(ctx->dc, NULL, attribs); + } + + wglMakeCurrent(NULL, NULL); + wglDeleteContext(ctx->rc); + + if (!rc_better) + { + ReleaseDC(ctx->hwnd, ctx->dc); + uiFree(ctx); + return NULL; + } + + ctx->rc = rc_better; + wglMakeCurrent(ctx->dc, ctx->rc); + } + + return ctx; } void uiGLFreeContext(uiGLContext* ctx) { + wglMakeCurrent(NULL, NULL); wglDeleteContext(ctx->rc); ReleaseDC(ctx->hwnd, ctx->dc); uiFree(ctx); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 566b346..d892912 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -392,6 +392,14 @@ void FeedMicInput() int EmuThreadFunc(void* burp) { + // TODO: fail gracefully, support older OpenGL, etc + uiGLContext* glctx = uiGLNewContext(uiControl(MainDrawArea), 4, 3); // haw haw haw + uiGLMakeContextCurrent(glctx); + + void* testor = uiGLGetProcAddress("glUseProgram"); + void* testor2 = uiGLGetProcAddress("glBindFramebuffer"); + printf("OPENGL: %p %p\n", testor, testor2); + NDS::Init(); MainScreenPos[0] = 0; @@ -616,6 +624,8 @@ int EmuThreadFunc(void* burp) NDS::DeInit(); Platform::LAN_DeInit(); + uiGLFreeContext(glctx); + return 44203; } @@ -1652,6 +1662,7 @@ void ApplyNewSettings(int type) if (type == 0) // general emu settings { + // TODO!! REMOVE ME GPU3D::SoftRenderer::SetupRenderThread(); } else if (type == 1) // wifi settings |