modify libui GL support so that it will be compatible with GTK
This commit is contained in:
parent
139c2d24ec
commit
c835b24f07
|
@ -106,8 +106,8 @@
|
|||
<Unit filename="src/GPU2D.h" />
|
||||
<Unit filename="src/GPU3D.cpp" />
|
||||
<Unit filename="src/GPU3D.h" />
|
||||
<Unit filename="src/GPU3D_OpenGL43.cpp" />
|
||||
<Unit filename="src/GPU3D_OpenGL43_shaders.h" />
|
||||
<Unit filename="src/GPU3D_OpenGL.cpp" />
|
||||
<Unit filename="src/GPU3D_OpenGL_shaders.h" />
|
||||
<Unit filename="src/GPU3D_Soft.cpp" />
|
||||
<Unit filename="src/NDS.cpp" />
|
||||
<Unit filename="src/NDS.h" />
|
||||
|
|
|
@ -432,7 +432,7 @@ void Open(int type)
|
|||
uiLabel* dummy = uiNewLabel("");
|
||||
uiBoxAppend(in_ctrl, uiControl(dummy), 1);
|
||||
|
||||
dlg->keypresscatcher = uiNewArea(&dlg->areahandler, 0);
|
||||
dlg->keypresscatcher = uiNewArea(&dlg->areahandler);
|
||||
uiControl(dlg->keypresscatcher)->UserData = dlg;
|
||||
uiBoxAppend(in_ctrl, uiControl(dlg->keypresscatcher), 0);
|
||||
|
||||
|
|
|
@ -326,6 +326,10 @@ _UI_ENUM(uiWindowResizeEdge) {
|
|||
// TODO way to bring up the system menu instead?
|
||||
};
|
||||
|
||||
#define uiGLVersion(major, minor) ((major) | ((minor)<<16))
|
||||
#define uiGLVerMajor(ver) ((ver) & 0xFFFF)
|
||||
#define uiGLVerMinor(ver) ((ver) >> 16)
|
||||
|
||||
#define uiArea(this) ((uiArea *) (this))
|
||||
// TODO give a better name
|
||||
// TODO document the types of width and height
|
||||
|
@ -341,7 +345,8 @@ _UI_EXTERN void uiAreaScrollTo(uiArea *a, double x, double y, double width, doub
|
|||
_UI_EXTERN void uiAreaBeginUserWindowMove(uiArea *a);
|
||||
_UI_EXTERN void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge);
|
||||
_UI_EXTERN void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b);
|
||||
_UI_EXTERN uiArea *uiNewArea(uiAreaHandler *ah, int opengl);
|
||||
_UI_EXTERN uiArea *uiNewArea(uiAreaHandler *ah);
|
||||
_UI_EXTERN uiArea *uiNewGLArea(uiAreaHandler *ah, const unsigned int* req_versions);
|
||||
_UI_EXTERN uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height);
|
||||
|
||||
struct uiAreaDrawParams {
|
||||
|
@ -604,9 +609,9 @@ _UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayou
|
|||
|
||||
typedef struct uiGLContext uiGLContext;
|
||||
|
||||
_UI_EXTERN uiGLContext *uiGLNewContext(uiControl* c, int vermajor, int verminor);
|
||||
_UI_EXTERN void uiGLFreeContext(uiGLContext* ctx);
|
||||
_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 void uiGLSwapBuffers(uiGLContext* ctx);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -64,6 +64,9 @@ char* EmuDirectory;
|
|||
|
||||
uiWindow* MainWindow;
|
||||
uiArea* MainDrawArea;
|
||||
uiAreaHandler MainDrawAreaHandler;
|
||||
|
||||
const u32 kGLVersions[] = {uiGLVersion(3,1), 0};
|
||||
uiGLContext* GLContext;
|
||||
|
||||
int WindowWidth, WindowHeight;
|
||||
|
@ -1792,7 +1795,7 @@ void OnOpenHotkeyConfig(uiMenuItem* item, uiWindow* window, void* blarg)
|
|||
{
|
||||
DlgInputConfig::Open(1);
|
||||
}
|
||||
uiAreaHandler eeareahandler;
|
||||
|
||||
void OnOpenVideoSettings(uiMenuItem* item, uiWindow* window, void* blarg)
|
||||
{
|
||||
//DlgVideoSettings::Open();
|
||||
|
@ -1805,25 +1808,17 @@ void OnOpenVideoSettings(uiMenuItem* item, uiWindow* window, void* blarg)
|
|||
GPU3D::GLRenderer::DeInit();
|
||||
GLDrawing_DeInit();
|
||||
uiGLMakeContextCurrent(NULL);
|
||||
uiGLFreeContext(GLContext);
|
||||
|
||||
uiWindowSetChild(MainWindow, NULL);
|
||||
uiControlDestroy(uiControl(MainDrawArea));
|
||||
|
||||
|
||||
eeareahandler.Draw = OnAreaDraw;
|
||||
eeareahandler.MouseEvent = OnAreaMouseEvent;
|
||||
eeareahandler.MouseCrossed = OnAreaMouseCrossed;
|
||||
eeareahandler.DragBroken = OnAreaDragBroken;
|
||||
eeareahandler.KeyEvent = OnAreaKeyEvent;
|
||||
eeareahandler.Resize = OnAreaResize;
|
||||
|
||||
MainDrawArea = uiNewArea(&eeareahandler, 1);
|
||||
MainDrawArea = uiNewGLArea(&MainDrawAreaHandler, kGLVersions);
|
||||
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
|
||||
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
|
||||
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0);
|
||||
//uiControlShow(uiControl(MainDrawArea));
|
||||
GLContext = uiGLNewContext(uiControl(MainDrawArea), 3, 1);
|
||||
GLContext = uiAreaGetGLContext(MainDrawArea);
|
||||
|
||||
uiGLMakeContextCurrent(GLContext);
|
||||
GLDrawing_Init();
|
||||
|
@ -2343,16 +2338,16 @@ int main(int argc, char** argv)
|
|||
uiMenuItemDisable(MenuItem_Reset);
|
||||
uiMenuItemDisable(MenuItem_Stop);
|
||||
|
||||
uiAreaHandler areahandler;
|
||||
areahandler.Draw = OnAreaDraw;
|
||||
areahandler.MouseEvent = OnAreaMouseEvent;
|
||||
areahandler.MouseCrossed = OnAreaMouseCrossed;
|
||||
areahandler.DragBroken = OnAreaDragBroken;
|
||||
areahandler.KeyEvent = OnAreaKeyEvent;
|
||||
areahandler.Resize = OnAreaResize;
|
||||
MainDrawAreaHandler.Draw = OnAreaDraw;
|
||||
MainDrawAreaHandler.MouseEvent = OnAreaMouseEvent;
|
||||
MainDrawAreaHandler.MouseCrossed = OnAreaMouseCrossed;
|
||||
MainDrawAreaHandler.DragBroken = OnAreaDragBroken;
|
||||
MainDrawAreaHandler.KeyEvent = OnAreaKeyEvent;
|
||||
MainDrawAreaHandler.Resize = OnAreaResize;
|
||||
|
||||
ScreenDrawInited = false;
|
||||
MainDrawArea = uiNewArea(&areahandler, 1);
|
||||
//MainDrawArea = uiNewArea(&MainDrawAreaHandler);
|
||||
MainDrawArea = uiNewGLArea(&MainDrawAreaHandler, kGLVersions);
|
||||
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
|
||||
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
|
||||
uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); // TODO: make configurable?
|
||||
|
@ -2383,7 +2378,7 @@ int main(int argc, char** argv)
|
|||
OnSetScreenRotation(MenuItem_ScreenRot[ScreenRotation], MainWindow, (void*)&kScreenRot[ScreenRotation]);
|
||||
|
||||
// TODO: fail gracefully, support older OpenGL, etc
|
||||
GLContext = uiGLNewContext(uiControl(MainDrawArea), 3, 1); // haw haw haw
|
||||
GLContext = uiAreaGetGLContext(MainDrawArea);
|
||||
uiGLMakeContextCurrent(GLContext);
|
||||
|
||||
void* testor = uiGLGetProcAddress("glUseProgram");
|
||||
|
@ -2472,8 +2467,6 @@ int main(int argc, char** argv)
|
|||
|
||||
if (MicWavBuffer) delete[] MicWavBuffer;
|
||||
|
||||
uiGLFreeContext(GLContext);
|
||||
|
||||
Config::ScreenRotation = ScreenRotation;
|
||||
Config::ScreenGap = ScreenGap;
|
||||
Config::ScreenLayout = ScreenLayout;
|
||||
|
|
Loading…
Reference in New Issue