mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 06:10:03 -06:00
first attempt at things
(also fix softrenderer reset)
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user