mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-21 08:34:11 +00:00
wayland: opengl support
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <Mw/Milsko.h>
|
||||
#include <Mw/Widget/OpenGL.h>
|
||||
|
||||
#ifdef HAS_OPENGL
|
||||
#ifdef USE_GDI
|
||||
typedef HGLRC(WINAPI* MWwglCreateContext)(HDC);
|
||||
typedef BOOL(WINAPI* MWwglMakeCurrent)(HDC, HGLRC);
|
||||
@@ -42,6 +43,19 @@ typedef struct x11opengl {
|
||||
} x11opengl_t;
|
||||
#endif
|
||||
|
||||
#ifdef USE_WAYLAND
|
||||
#include <EGL/egl.h>
|
||||
#include <wayland-egl-core.h>
|
||||
|
||||
typedef struct waylandopengl {
|
||||
EGLNativeWindowType egl_window_native;
|
||||
EGLDisplay egl_display;
|
||||
EGLContext egl_context;
|
||||
EGLSurface egl_surface;
|
||||
EGLConfig egl_config;
|
||||
} waylandopengl_t;
|
||||
#endif
|
||||
|
||||
static int create(MwWidget handle) {
|
||||
void* r = NULL;
|
||||
#ifdef USE_GDI
|
||||
@@ -105,7 +119,89 @@ static int create(MwWidget handle) {
|
||||
#endif
|
||||
#ifdef USE_WAYLAND
|
||||
if(handle->lowlevel->common.type == MwLLBackendWayland) {
|
||||
/* todo */
|
||||
int err;
|
||||
EGLint numConfigs;
|
||||
EGLint majorVersion;
|
||||
EGLint minorVersion;
|
||||
EGLContext context;
|
||||
EGLSurface surface;
|
||||
EGLint fbAttribs[] =
|
||||
{
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||
EGL_NONE};
|
||||
EGLint contextAttribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 1,
|
||||
EGL_CONTEXT_MAJOR_VERSION, 1,
|
||||
EGL_CONTEXT_MINOR_VERSION, 1,
|
||||
EGL_NONE};
|
||||
EGLDisplay display;
|
||||
waylandopengl_t* o = r = malloc(sizeof(*o));
|
||||
MwLL topmost_parent = handle->lowlevel->wayland.parent;
|
||||
topmost_parent->wayland.always_render = MwTRUE;
|
||||
|
||||
while(topmost_parent->wayland.parent != NULL) {
|
||||
topmost_parent = topmost_parent->wayland.parent;
|
||||
topmost_parent->wayland.always_render = MwTRUE;
|
||||
}
|
||||
|
||||
display = eglGetDisplay((EGLNativeDisplayType)handle->lowlevel->wayland.display);
|
||||
if(display == EGL_NO_DISPLAY) {
|
||||
printf("ERROR: eglGetDisplay, %0X\n", eglGetError());
|
||||
return MwFALSE;
|
||||
}
|
||||
/* Initialize EGL */
|
||||
if(!eglInitialize(display, &majorVersion, &minorVersion)) {
|
||||
printf("ERROR: eglInitialize, %0X\n", eglGetError());
|
||||
return MwFALSE;
|
||||
}
|
||||
|
||||
/* Get configs */
|
||||
if((eglGetConfigs(display, NULL, 0, &numConfigs) != EGL_TRUE) || (numConfigs == 0)) {
|
||||
printf("ERROR: eglGetConfigs, %0X\n", eglGetError());
|
||||
return MwFALSE;
|
||||
}
|
||||
|
||||
/* Choose config */
|
||||
if((eglChooseConfig(display, fbAttribs, &o->egl_config, 1, &numConfigs) != EGL_TRUE) || (numConfigs != 1)) {
|
||||
printf("ERROR: eglChooseConfig, %0X\n", eglGetError());
|
||||
return MwFALSE;
|
||||
}
|
||||
|
||||
o->egl_window_native =
|
||||
(EGLNativeWindowType)wl_egl_window_create(handle->lowlevel->wayland.framebuffer.surface, handle->lowlevel->wayland.ww, handle->lowlevel->wayland.wh);
|
||||
if(o->egl_window_native == EGL_NO_SURFACE) {
|
||||
printf("ERROR: wl_egl_window_create, EGL_NO_SURFACE\n");
|
||||
return MwFALSE;
|
||||
}
|
||||
|
||||
/* Create a surface */
|
||||
surface = eglCreateWindowSurface(display, o->egl_config, o->egl_window_native, NULL);
|
||||
if(surface == EGL_NO_SURFACE) {
|
||||
printf("ERROR: eglCreateWindowSurface, %0X\n", eglGetError());
|
||||
return MwFALSE;
|
||||
}
|
||||
|
||||
eglBindAPI(EGL_OPENGL_API);
|
||||
|
||||
/* Create a GL context */
|
||||
context = eglCreateContext(display, o->egl_config, EGL_NO_CONTEXT, contextAttribs);
|
||||
if(context == EGL_NO_CONTEXT) {
|
||||
printf("ERROR: eglCreateContext, %0X\n", eglGetError());
|
||||
return MwFALSE;
|
||||
}
|
||||
|
||||
if(!eglMakeCurrent(display, surface, surface, context)) {
|
||||
printf("ERROR: eglMakeCurrent (setup): %0X\n", eglGetError());
|
||||
}
|
||||
|
||||
o->egl_display = display;
|
||||
o->egl_surface = surface;
|
||||
o->egl_context = context;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -165,7 +261,11 @@ static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
|
||||
#endif
|
||||
#ifdef USE_WAYLAND
|
||||
if(handle->lowlevel->common.type == MwLLBackendWayland) {
|
||||
/* todo */
|
||||
waylandopengl_t* o = handle->internal;
|
||||
|
||||
if(!eglMakeCurrent(o->egl_display, o->egl_surface, o->egl_surface, o->egl_context)) {
|
||||
printf("ERROR: eglMakeCurrent, %0X\n", eglGetError());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -187,7 +287,13 @@ static void mwOpenGLSwapBufferImpl(MwWidget handle) {
|
||||
#endif
|
||||
#ifdef USE_WAYLAND
|
||||
if(handle->lowlevel->common.type == MwLLBackendWayland) {
|
||||
/* todo */
|
||||
waylandopengl_t* o = handle->internal;
|
||||
eglSwapInterval(o->egl_display, 0);
|
||||
if(!eglSwapBuffers(o->egl_display, o->egl_surface)) {
|
||||
printf("ERROR: eglSwapBuffers, %0X\n", eglGetError());
|
||||
};
|
||||
wl_egl_window_resize((struct wl_egl_window*)o->egl_window_native, handle->lowlevel->wayland.ww, handle->lowlevel->wayland.wh, 0, 0);
|
||||
MwLLForceRender(handle->lowlevel);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -209,11 +315,85 @@ static void* mwOpenGLGetProcAddressImpl(MwWidget handle, const char* name) {
|
||||
#endif
|
||||
#ifdef USE_WAYLAND
|
||||
if(handle->lowlevel->common.type == MwLLBackendWayland) {
|
||||
/* todo */
|
||||
return eglGetProcAddress(name);
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
#ifdef USE_GDI
|
||||
typedef HGLRC(WINAPI* MWwglCreateContext)(HDC);
|
||||
typedef BOOL(WINAPI* MWwglMakeCurrent)(HDC, HGLRC);
|
||||
typedef PROC(WINAPI* MWwglGetProcAddress)(LPCSTR);
|
||||
typedef BOOL(WINAPI* MWwglDeleteContext)(HGLRC);
|
||||
|
||||
typedef struct gdiopengl {
|
||||
HDC dc;
|
||||
HGLRC gl;
|
||||
|
||||
void* lib;
|
||||
|
||||
MWwglCreateContext wglCreateContext;
|
||||
MWwglMakeCurrent wglMakeCurrent;
|
||||
MWwglDeleteContext wglDeleteContext;
|
||||
MWwglGetProcAddress wglGetProcAddress;
|
||||
} gdiopengl_t;
|
||||
#endif
|
||||
#ifdef USE_X11
|
||||
typedef XVisualInfo* (*MWglXChooseVisual)(Display* dpy, int screen, int* attribList);
|
||||
typedef GLXContext (*MWglXCreateContext)(Display* dpy, XVisualInfo* vis, GLXContext shareList, Bool direct);
|
||||
typedef void (*MWglXDestroyContext)(Display* dpy, GLXContext ctx);
|
||||
typedef Bool (*MWglXMakeCurrent)(Display* dpy, GLXDrawable drawable, GLXContext ctx);
|
||||
typedef void (*MWglXSwapBuffers)(Display* dpy, GLXDrawable drawable);
|
||||
typedef void* (*MWglXGetProcAddress)(const GLubyte* procname);
|
||||
|
||||
typedef struct x11opengl {
|
||||
XVisualInfo* visual;
|
||||
GLXContext gl;
|
||||
|
||||
void* lib;
|
||||
|
||||
MWglXChooseVisual glXChooseVisual;
|
||||
MWglXCreateContext glXCreateContext;
|
||||
MWglXDestroyContext glXDestroyContext;
|
||||
MWglXMakeCurrent glXMakeCurrent;
|
||||
MWglXSwapBuffers glXSwapBuffers;
|
||||
MWglXGetProcAddress glXGetProcAddress;
|
||||
} x11opengl_t;
|
||||
#endif
|
||||
|
||||
#ifdef USE_WAYLAND
|
||||
#include <EGL/egl.h>
|
||||
#include <wayland-egl.h>
|
||||
|
||||
typedef struct waylandopengl {
|
||||
struct wl_egl_window* egl_window_native;
|
||||
EGLDisplay egl_display;
|
||||
EGLContext egl_context;
|
||||
EGLSurface egl_surface;
|
||||
EGLConfig egl_config;
|
||||
} waylandopengl_t;
|
||||
|
||||
#endif
|
||||
|
||||
static int create(MwWidget handle) {
|
||||
printf("Milsko compiled without OpenGL support! OpenGL widgets will not work properly.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void destroy(MwWidget handle) {
|
||||
}
|
||||
|
||||
static void mwOpenGLMakeCurrentImpl(MwWidget handle) {
|
||||
}
|
||||
|
||||
static void mwOpenGLSwapBufferImpl(MwWidget handle) {
|
||||
}
|
||||
|
||||
static void* mwOpenGLGetProcAddressImpl(MwWidget handle, const char* name) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
|
||||
if(strcmp(name, "mwOpenGLMakeCurrent") == 0) {
|
||||
|
||||
Reference in New Issue
Block a user