check for backend
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@688 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
parent
4df3f4658b
commit
2b7e1986a2
4 changed files with 135 additions and 88 deletions
|
|
@ -24,9 +24,15 @@ typedef void* MwLLColor;
|
||||||
typedef void* MwLLPixmap;
|
typedef void* MwLLPixmap;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum MwLLBackends {
|
||||||
|
MwLLBackendX11 = 0,
|
||||||
|
MwLLBackendGDI
|
||||||
|
};
|
||||||
|
|
||||||
struct _MwLLCommon {
|
struct _MwLLCommon {
|
||||||
void* user;
|
void* user;
|
||||||
int copy_buffer;
|
int copy_buffer;
|
||||||
|
int type;
|
||||||
|
|
||||||
MwLLHandler handler;
|
MwLLHandler handler;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||||
RegisterClassEx(&wc);
|
RegisterClassEx(&wc);
|
||||||
|
|
||||||
r->common.copy_buffer = 1;
|
r->common.copy_buffer = 1;
|
||||||
|
r->common.type = MwLLBackendGDI;
|
||||||
|
|
||||||
r->gdi.grabbed = 0;
|
r->gdi.grabbed = 0;
|
||||||
r->gdi.hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->gdi.hWnd, 0, wc.hInstance, NULL);
|
r->gdi.hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->gdi.hWnd, 0, wc.hInstance, NULL);
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
|
||||||
XSetICFocus(r->x11.xic);
|
XSetICFocus(r->x11.xic);
|
||||||
|
|
||||||
r->common.copy_buffer = 1;
|
r->common.copy_buffer = 1;
|
||||||
|
r->common.type = MwLLBackendX11;
|
||||||
|
|
||||||
r->x11.width = width;
|
r->x11.width = width;
|
||||||
r->x11.height = height;
|
r->x11.height = height;
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
#include <Mw/Widget/OpenGL.h>
|
#include <Mw/Widget/OpenGL.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef USE_GDI
|
||||||
typedef HGLRC(WINAPI* MWwglCreateContext)(HDC);
|
typedef HGLRC(WINAPI* MWwglCreateContext)(HDC);
|
||||||
typedef BOOL(WINAPI* MWwglMakeCurrent)(HDC, HGLRC);
|
typedef BOOL(WINAPI* MWwglMakeCurrent)(HDC, HGLRC);
|
||||||
typedef PROC(WINAPI* MWwglGetProcAddress)(LPCSTR);
|
typedef PROC(WINAPI* MWwglGetProcAddress)(LPCSTR);
|
||||||
typedef BOOL(WINAPI* MWwglDeleteContext)(HGLRC);
|
typedef BOOL(WINAPI* MWwglDeleteContext)(HGLRC);
|
||||||
|
|
||||||
typedef struct opengl {
|
typedef struct gdiopengl {
|
||||||
HDC dc;
|
HDC dc;
|
||||||
HGLRC gl;
|
HGLRC gl;
|
||||||
|
|
||||||
|
|
@ -18,8 +18,9 @@ typedef struct opengl {
|
||||||
MWwglMakeCurrent wglMakeCurrent;
|
MWwglMakeCurrent wglMakeCurrent;
|
||||||
MWwglDeleteContext wglDeleteContext;
|
MWwglDeleteContext wglDeleteContext;
|
||||||
MWwglGetProcAddress wglGetProcAddress;
|
MWwglGetProcAddress wglGetProcAddress;
|
||||||
} opengl_t;
|
} gdiopengl_t;
|
||||||
#else
|
#endif
|
||||||
|
#ifdef USE_X11
|
||||||
typedef XVisualInfo* (*MWglXChooseVisual)(Display* dpy, int screen, int* attribList);
|
typedef XVisualInfo* (*MWglXChooseVisual)(Display* dpy, int screen, int* attribList);
|
||||||
typedef GLXContext (*MWglXCreateContext)(Display* dpy, XVisualInfo* vis, GLXContext shareList, Bool direct);
|
typedef GLXContext (*MWglXCreateContext)(Display* dpy, XVisualInfo* vis, GLXContext shareList, Bool direct);
|
||||||
typedef void (*MWglXDestroyContext)(Display* dpy, GLXContext ctx);
|
typedef void (*MWglXDestroyContext)(Display* dpy, GLXContext ctx);
|
||||||
|
|
@ -27,7 +28,7 @@ typedef Bool (*MWglXMakeCurrent)(Display* dpy, GLXDrawable drawable, GLXContext
|
||||||
typedef void (*MWglXSwapBuffers)(Display* dpy, GLXDrawable drawable);
|
typedef void (*MWglXSwapBuffers)(Display* dpy, GLXDrawable drawable);
|
||||||
typedef void* (*MWglXGetProcAddress)(const GLubyte* procname);
|
typedef void* (*MWglXGetProcAddress)(const GLubyte* procname);
|
||||||
|
|
||||||
typedef struct opengl {
|
typedef struct x11opengl {
|
||||||
XVisualInfo* visual;
|
XVisualInfo* visual;
|
||||||
GLXContext gl;
|
GLXContext gl;
|
||||||
|
|
||||||
|
|
@ -39,14 +40,16 @@ typedef struct opengl {
|
||||||
MWglXMakeCurrent glXMakeCurrent;
|
MWglXMakeCurrent glXMakeCurrent;
|
||||||
MWglXSwapBuffers glXSwapBuffers;
|
MWglXSwapBuffers glXSwapBuffers;
|
||||||
MWglXGetProcAddress glXGetProcAddress;
|
MWglXGetProcAddress glXGetProcAddress;
|
||||||
} opengl_t;
|
} x11opengl_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int create(MwWidget handle) {
|
static int create(MwWidget handle) {
|
||||||
opengl_t* o = malloc(sizeof(*o));
|
void* r = NULL;
|
||||||
#ifdef _WIN32
|
#ifdef USE_GDI
|
||||||
|
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
||||||
PIXELFORMATDESCRIPTOR pfd;
|
PIXELFORMATDESCRIPTOR pfd;
|
||||||
int pf;
|
int pf;
|
||||||
|
gdiopengl_t* o = r = malloc(sizeof(*o));
|
||||||
|
|
||||||
memset(&pfd, 0, sizeof(pfd));
|
memset(&pfd, 0, sizeof(pfd));
|
||||||
pfd.nSize = sizeof(pfd);
|
pfd.nSize = sizeof(pfd);
|
||||||
|
|
@ -60,15 +63,18 @@ static int create(MwWidget handle) {
|
||||||
pf = ChoosePixelFormat(o->dc, &pfd);
|
pf = ChoosePixelFormat(o->dc, &pfd);
|
||||||
SetPixelFormat(o->dc, pf, &pfd);
|
SetPixelFormat(o->dc, pf, &pfd);
|
||||||
|
|
||||||
o->lib = LoadLibrary("opengl32.dll");
|
o->lib = MwDynamicOpen("opengl32.dll");
|
||||||
|
|
||||||
o->wglCreateContext = (MWwglCreateContext)(void*)GetProcAddress(o->lib, "wglCreateContext");
|
o->wglCreateContext = (MWwglCreateContext)(void*)MwDynamicSymbol(o->lib, "wglCreateContext");
|
||||||
o->wglMakeCurrent = (MWwglMakeCurrent)(void*)GetProcAddress(o->lib, "wglMakeCurrent");
|
o->wglMakeCurrent = (MWwglMakeCurrent)(void*)MwDynamicSymbol(o->lib, "wglMakeCurrent");
|
||||||
o->wglDeleteContext = (MWwglDeleteContext)(void*)GetProcAddress(o->lib, "wglDeleteContext");
|
o->wglDeleteContext = (MWwglDeleteContext)(void*)MwDynamicSymbol(o->lib, "wglDeleteContext");
|
||||||
o->wglGetProcAddress = (MWwglGetProcAddress)(void*)GetProcAddress(o->lib, "wglGetProcAddress");
|
o->wglGetProcAddress = (MWwglGetProcAddress)(void*)MwDynamicSymbol(o->lib, "wglGetProcAddress");
|
||||||
|
|
||||||
o->gl = o->wglCreateContext(o->dc);
|
o->gl = o->wglCreateContext(o->dc);
|
||||||
#else
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_X11
|
||||||
|
if(handle->lowlevel->common.type == MwLLBackendX11) {
|
||||||
int attribs[5];
|
int attribs[5];
|
||||||
const char* glpath[] = {
|
const char* glpath[] = {
|
||||||
"libGL.so",
|
"libGL.so",
|
||||||
|
|
@ -76,6 +82,7 @@ static int create(MwWidget handle) {
|
||||||
"/usr/X11R7/lib/libGL.so",
|
"/usr/X11R7/lib/libGL.so",
|
||||||
"/usr/pkg/lib/libGL.so"};
|
"/usr/pkg/lib/libGL.so"};
|
||||||
int glincr = 0;
|
int glincr = 0;
|
||||||
|
x11opengl_t* o = r = malloc(sizeof(*o));
|
||||||
|
|
||||||
attribs[0] = GLX_RGBA;
|
attribs[0] = GLX_RGBA;
|
||||||
attribs[1] = GLX_DOUBLEBUFFER;
|
attribs[1] = GLX_DOUBLEBUFFER;
|
||||||
|
|
@ -83,20 +90,21 @@ static int create(MwWidget handle) {
|
||||||
attribs[3] = 24;
|
attribs[3] = 24;
|
||||||
attribs[4] = None;
|
attribs[4] = None;
|
||||||
|
|
||||||
while(glpath[glincr] != NULL && (o->lib = dlopen(glpath[glincr++], RTLD_LAZY)) == NULL);
|
while(glpath[glincr] != NULL && (o->lib = MwDynamicOpen(glpath[glincr++])) == NULL);
|
||||||
|
|
||||||
o->glXChooseVisual = (MWglXChooseVisual)dlsym(o->lib, "glXChooseVisual");
|
o->glXChooseVisual = (MWglXChooseVisual)MwDynamicSymbol(o->lib, "glXChooseVisual");
|
||||||
o->glXCreateContext = (MWglXCreateContext)dlsym(o->lib, "glXCreateContext");
|
o->glXCreateContext = (MWglXCreateContext)MwDynamicSymbol(o->lib, "glXCreateContext");
|
||||||
o->glXDestroyContext = (MWglXDestroyContext)dlsym(o->lib, "glXDestroyContext");
|
o->glXDestroyContext = (MWglXDestroyContext)MwDynamicSymbol(o->lib, "glXDestroyContext");
|
||||||
o->glXMakeCurrent = (MWglXMakeCurrent)dlsym(o->lib, "glXMakeCurrent");
|
o->glXMakeCurrent = (MWglXMakeCurrent)MwDynamicSymbol(o->lib, "glXMakeCurrent");
|
||||||
o->glXSwapBuffers = (MWglXSwapBuffers)dlsym(o->lib, "glXSwapBuffers");
|
o->glXSwapBuffers = (MWglXSwapBuffers)MwDynamicSymbol(o->lib, "glXSwapBuffers");
|
||||||
o->glXGetProcAddress = (MWglXGetProcAddress)dlsym(o->lib, "glXGetProcAddress");
|
o->glXGetProcAddress = (MWglXGetProcAddress)MwDynamicSymbol(o->lib, "glXGetProcAddress");
|
||||||
|
|
||||||
/* XXX: fix this */
|
/* XXX: fix this */
|
||||||
o->visual = o->glXChooseVisual(handle->lowlevel->x11.display, DefaultScreen(handle->lowlevel->x11.display), attribs);
|
o->visual = o->glXChooseVisual(handle->lowlevel->x11.display, DefaultScreen(handle->lowlevel->x11.display), attribs);
|
||||||
o->gl = o->glXCreateContext(handle->lowlevel->x11.display, o->visual, NULL, GL_TRUE);
|
o->gl = o->glXCreateContext(handle->lowlevel->x11.display, o->visual, NULL, GL_TRUE);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
handle->internal = o;
|
handle->internal = r;
|
||||||
handle->lowlevel->common.copy_buffer = 0;
|
handle->lowlevel->common.copy_buffer = 0;
|
||||||
|
|
||||||
MwSetDefault(handle);
|
MwSetDefault(handle);
|
||||||
|
|
@ -105,49 +113,80 @@ static int create(MwWidget handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy(MwWidget handle) {
|
static void destroy(MwWidget handle) {
|
||||||
opengl_t* o = (opengl_t*)handle->internal;
|
#ifdef USE_GDI
|
||||||
#ifdef _WIN32
|
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
||||||
|
gdiopengl_t* o = handle->internal;
|
||||||
|
|
||||||
o->wglMakeCurrent(NULL, NULL);
|
o->wglMakeCurrent(NULL, NULL);
|
||||||
DeleteDC(o->dc);
|
DeleteDC(o->dc);
|
||||||
o->wglDeleteContext(o->gl);
|
o->wglDeleteContext(o->gl);
|
||||||
|
|
||||||
FreeLibrary(o->lib);
|
MwDynamicClose(o->lib);
|
||||||
#else
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_X11
|
||||||
|
if(handle->lowlevel->common.type == MwLLBackendX11) {
|
||||||
|
x11opengl_t* o = handle->internal;
|
||||||
|
|
||||||
o->glXMakeCurrent(handle->lowlevel->x11.display, None, NULL);
|
o->glXMakeCurrent(handle->lowlevel->x11.display, None, NULL);
|
||||||
o->glXDestroyContext(handle->lowlevel->x11.display, o->gl);
|
o->glXDestroyContext(handle->lowlevel->x11.display, o->gl);
|
||||||
|
|
||||||
dlclose(o->lib);
|
MwDynamicClose(o->lib);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
free(o);
|
free(handle->internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
|
static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
|
||||||
opengl_t* o = (opengl_t*)handle->internal;
|
#ifdef USE_GDI
|
||||||
#ifdef _WIN32
|
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
||||||
|
gdiopengl_t* o = handle->internal;
|
||||||
|
|
||||||
o->wglMakeCurrent(o->dc, o->gl);
|
o->wglMakeCurrent(o->dc, o->gl);
|
||||||
#else
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_X11
|
||||||
|
if(handle->lowlevel->common.type == MwLLBackendX11) {
|
||||||
|
x11opengl_t* o = handle->internal;
|
||||||
|
|
||||||
o->glXMakeCurrent(handle->lowlevel->x11.display, handle->lowlevel->x11.window, o->gl);
|
o->glXMakeCurrent(handle->lowlevel->x11.display, handle->lowlevel->x11.window, o->gl);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mwOpenGLSwapBufferImpl(MwWidget handle) {
|
static void mwOpenGLSwapBufferImpl(MwWidget handle) {
|
||||||
opengl_t* o = (opengl_t*)handle->internal;
|
#ifdef USE_GDI
|
||||||
#ifdef _WIN32
|
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
||||||
|
gdiopengl_t* o = handle->internal;
|
||||||
|
|
||||||
SwapBuffers(o->dc);
|
SwapBuffers(o->dc);
|
||||||
#else
|
}
|
||||||
(void)o;
|
#endif
|
||||||
|
#ifdef USE_X11
|
||||||
|
if(handle->lowlevel->common.type == MwLLBackendX11) {
|
||||||
|
x11opengl_t* o = handle->internal;
|
||||||
|
|
||||||
o->glXSwapBuffers(handle->lowlevel->x11.display, handle->lowlevel->x11.window);
|
o->glXSwapBuffers(handle->lowlevel->x11.display, handle->lowlevel->x11.window);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* mwOpenGLGetProcAddressImpl(MwWidget handle, const char* name) {
|
static void* mwOpenGLGetProcAddressImpl(MwWidget handle, const char* name) {
|
||||||
opengl_t* o = (opengl_t*)handle->internal;
|
#ifdef USE_GDI
|
||||||
#ifdef _WIN32
|
if(handle->lowlevel->common.type == MwLLBackendGDI) {
|
||||||
|
gdiopengl_t* o = handle->internal;
|
||||||
|
|
||||||
return o->wglGetProcAddress(name);
|
return o->wglGetProcAddress(name);
|
||||||
#else
|
}
|
||||||
return o->glXGetProcAddress((const GLubyte*)name);
|
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_X11
|
||||||
|
if(handle->lowlevel->common.type == MwLLBackendX11) {
|
||||||
|
x11opengl_t* o = handle->internal;
|
||||||
|
|
||||||
|
return o->glXGetProcAddress((const GLubyte*)name);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
|
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue