aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/windows
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2019-05-21 14:53:22 +0200
committerArisotura <thetotalworm@gmail.com>2019-05-21 14:53:22 +0200
commitc835b24f07a317ea435b742ec2fae12dc619c01b (patch)
treea90aa6d5aaaa6422f9d7383e44c1c55ea948ac18 /src/libui_sdl/libui/windows
parent139c2d24ec253f1688b12b667ce6a090a43bbd57 (diff)
modify libui GL support so that it will be compatible with GTK
Diffstat (limited to 'src/libui_sdl/libui/windows')
-rw-r--r--src/libui_sdl/libui/windows/area.cpp56
-rw-r--r--src/libui_sdl/libui/windows/area.hpp5
-rw-r--r--src/libui_sdl/libui/windows/gl.cpp33
3 files changed, 75 insertions, 19 deletions
diff --git a/src/libui_sdl/libui/windows/area.cpp b/src/libui_sdl/libui/windows/area.cpp
index 99c843e..72d5145 100644
--- a/src/libui_sdl/libui/windows/area.cpp
+++ b/src/libui_sdl/libui/windows/area.cpp
@@ -61,7 +61,15 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
// control implementation
-uiWindowsControlAllDefaults(uiArea)
+uiWindowsControlAllDefaultsExceptDestroy(uiArea)
+
+static void uiAreaDestroy(uiControl *c)
+{
+ uiArea* a = uiArea(c);
+ if (a->openGL && a->glcontext) freeGLContext(a->glcontext);
+ uiWindowsEnsureDestroyWindow(a->hwnd);
+ uiFreeControl(c);
+}
static void uiAreaMinimumSize(uiWindowsControl *c, int *width, int *height)
{
@@ -181,7 +189,7 @@ void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b)
}
-uiArea *uiNewArea(uiAreaHandler *ah, int opengl)
+uiArea *uiNewArea(uiAreaHandler *ah)
{
uiArea *a;
@@ -203,7 +211,49 @@ uiArea *uiNewArea(uiAreaHandler *ah, int opengl)
uiAreaSetBackgroundColor(a, -1, -1, -1);
- a->openGL = opengl;
+ a->openGL = 0;
+
+ return a;
+}
+
+uiGLContext *uiAreaGetGLContext(uiArea* a)
+{
+ if (!a->openGL) userbug("trying to get GL context from non-GL area");
+
+ return a->glcontext;
+}
+
+uiArea *uiNewGLArea(uiAreaHandler *ah, const unsigned int* req_versions)
+{
+ uiArea *a;
+
+ uiWindowsNewControl(uiArea, a);
+
+ a->width = -1;
+ a->height = -1;
+
+ a->ah = ah;
+ a->scrolling = FALSE;
+ clickCounterReset(&(a->cc));
+
+ // a->hwnd is assigned in areaWndProc()
+ uiWindowsEnsureCreateControlHWND(0,
+ areaClass, L"",
+ 0,
+ hInstance, a,
+ FALSE);
+
+ uiAreaSetBackgroundColor(a, -1, -1, -1);
+
+ a->openGL = 1;
+
+ for (int i = 0; req_versions[i]; i++)
+ {
+ int major = uiGLVerMajor(req_versions[i]);
+ int minor = uiGLVerMinor(req_versions[i]);
+ a->glcontext = createGLContext(a, major, minor);
+ if (a->glcontext) break;
+ }
return a;
}
diff --git a/src/libui_sdl/libui/windows/area.hpp b/src/libui_sdl/libui/windows/area.hpp
index f8abd4f..cfc45a4 100644
--- a/src/libui_sdl/libui/windows/area.hpp
+++ b/src/libui_sdl/libui/windows/area.hpp
@@ -29,6 +29,7 @@ struct uiArea {
int bgR, bgG, bgB;
int openGL;
+ uiGLContext* glcontext;
ID2D1HwndRenderTarget *rt;
};
@@ -49,3 +50,7 @@ extern BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRE
extern void loadAreaSize(uiArea *a, double *width, double *height);
extern void pixelsToDIP(uiArea *a, double *x, double *y);
extern void dipToPixels(uiArea *a, double *x, double *y);
+
+// gl.cpp
+extern uiGLContext* createGLContext(uiArea* a, int vermajor, int verminor);
+extern void freeGLContext(uiGLContext* c);
diff --git a/src/libui_sdl/libui/windows/gl.cpp b/src/libui_sdl/libui/windows/gl.cpp
index 832a2e5..1e3732c 100644
--- a/src/libui_sdl/libui/windows/gl.cpp
+++ b/src/libui_sdl/libui/windows/gl.cpp
@@ -1,39 +1,31 @@
// 31 march 2019
#include "uipriv_windows.hpp"
+#include "area.hpp"
#include <GL/gl.h>
#include <GL/wglext.h>
struct uiGLContext
{
- uiControl* c;
+ uiArea* a;
HWND hwnd;
HDC dc;
HGLRC rc;
+
+ unsigned int version;
};
-uiGLContext* uiGLNewContext(uiControl* c, int vermajor, int verminor)
+uiGLContext* createGLContext(uiArea* a, int vermajor, int verminor)
{
uiGLContext* ctx;
BOOL res;
ctx = uiNew(uiGLContext);
- ctx->c = c;
- if (c)
- {
- ctx->hwnd = (HWND)c->Handle(c); // welp
- }
- else
- {
- // windowless context
- //ctx->hwnd = GetDesktopWindow();
- // nope.
- uiFree(ctx);
- return NULL;
- }
+ ctx->a = a;
+ ctx->hwnd = a->hwnd;
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(pfd));
@@ -103,6 +95,7 @@ uiGLContext* uiGLNewContext(uiControl* c, int vermajor, int verminor)
return NULL;
}
+ ctx->version = uiGLVersion(vermajor, verminor);
ctx->rc = rc_better;
wglMakeCurrent(ctx->dc, ctx->rc);
}
@@ -110,8 +103,9 @@ uiGLContext* uiGLNewContext(uiControl* c, int vermajor, int verminor)
return ctx;
}
-void uiGLFreeContext(uiGLContext* ctx)
+void freeGLContext(uiGLContext* ctx)
{
+ if (ctx == NULL) return;
wglMakeCurrent(NULL, NULL);
wglDeleteContext(ctx->rc);
ReleaseDC(ctx->hwnd, ctx->dc);
@@ -130,6 +124,12 @@ void uiGLMakeContextCurrent(uiGLContext* ctx)
int res = wglMakeCurrent(ctx->dc, ctx->rc);
}
+unsigned int uiGLGetVersion(uiGLContext* ctx)
+{
+ if (ctx == NULL) return 0;
+ return ctx->version;
+}
+
void *uiGLGetProcAddress(const char* proc)
{
return (void*)wglGetProcAddress(proc);
@@ -137,5 +137,6 @@ void *uiGLGetProcAddress(const char* proc)
void uiGLSwapBuffers(uiGLContext* ctx)
{
+ if (ctx == NULL) return;
SwapBuffers(ctx->dc);
}