From e8b1320f91838a29891c6a5b377160e27a0adcf5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 4 Aug 2024 20:27:26 +0200 Subject: Add option to choose render api (glx or egl) in window creation --- include/mgl/gl.h | 37 +++++++++++++++++++++++++++++++++---- include/mgl/gl_macro.h | 13 +++++++++++++ include/mgl/window/window.h | 6 ++++++ 3 files changed, 52 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/mgl/gl.h b/include/mgl/gl.h index c96beea..397d608 100644 --- a/include/mgl/gl.h +++ b/include/mgl/gl.h @@ -10,10 +10,25 @@ typedef struct _XDisplay Display; typedef struct __GLXcontextRec *GLXContext; typedef unsigned long GLXDrawable; typedef struct __GLXFBConfigRec *GLXFBConfig; +typedef void(*__GLXextFuncPtr)(void); + +typedef void (*FUNC_glXSwapIntervalEXT)(Display * dpy, GLXDrawable drawable, int interval); +typedef int (*FUNC_glXSwapIntervalMESA)(unsigned int interval); +typedef int (*FUNC_glXSwapIntervalSGI)(int interval); + +typedef void* EGLDisplay; +typedef void* EGLNativeDisplayType; +typedef uintptr_t EGLNativeWindowType; +typedef void* EGLConfig; +typedef void* EGLSurface; +typedef void* EGLContext; typedef struct { - void *handle; + void *gl_library; + void *glx_library; + void *egl_library; + __GLXextFuncPtr (*glXGetProcAddress)(const unsigned char *procName); GLXContext (*glXCreateNewContext)(Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, int direct); int (*glXMakeContextCurrent)(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); void (*glXDestroyContext)(Display *dpy, GLXContext ctx); @@ -21,6 +36,20 @@ typedef struct { GLXFBConfig* (*glXChooseFBConfig)(Display *dpy, int screen, const int *attribList, int *nitems); _XVisualInfo* (*glXGetVisualFromFBConfig)(Display *dpy, GLXFBConfig config); + EGLDisplay (*eglGetDisplay)(EGLNativeDisplayType display_id); + unsigned int (*eglInitialize)(EGLDisplay dpy, int32_t *major, int32_t *minor); + unsigned int (*eglTerminate)(EGLDisplay dpy); + unsigned int (*eglChooseConfig)(EGLDisplay dpy, const int32_t *attrib_list, EGLConfig *configs, int32_t config_size, int32_t *num_config); + EGLSurface (*eglCreateWindowSurface)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const int32_t *attrib_list); + EGLContext (*eglCreateContext)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const int32_t *attrib_list); + unsigned int (*eglMakeCurrent)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); + unsigned int (*eglDestroyContext)(EGLDisplay dpy, EGLContext ctx); + unsigned int (*eglDestroySurface)(EGLDisplay dpy, EGLSurface surface); + unsigned int (*eglSwapInterval)(EGLDisplay dpy, int32_t interval); + unsigned int (*eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface); + unsigned int (*eglBindAPI)(unsigned int api); + unsigned int (*eglGetConfigAttrib)(EGLDisplay dpy, EGLConfig config, int32_t attribute, int32_t *value); + void (*glViewport)(int x, int y, int width, int height); void (*glScissor)(int x, int y, int width, int height); void (*glClearColor)(float red, float green, float blue, float alpha); @@ -82,9 +111,9 @@ typedef struct { void (*glFinish)(void); /* Optional*/ - void (*glXSwapIntervalEXT)(Display * dpy, GLXDrawable drawable, int interval); - int (*glXSwapIntervalMESA)(unsigned int interval); - int (*glXSwapIntervalSGI)(int interval); + FUNC_glXSwapIntervalEXT glXSwapIntervalEXT; + FUNC_glXSwapIntervalMESA glXSwapIntervalMESA; + FUNC_glXSwapIntervalSGI glXSwapIntervalSGI; void (*glGenerateMipmap)(unsigned int target); } mgl_gl; diff --git a/include/mgl/gl_macro.h b/include/mgl/gl_macro.h index ba2d3f1..bfeffce 100644 --- a/include/mgl/gl_macro.h +++ b/include/mgl/gl_macro.h @@ -91,4 +91,17 @@ #define GL_SCISSOR_TEST 0x0C11 +#define EGL_SUCCESS 0x3000 +#define EGL_BUFFER_SIZE 0x3020 +#define EGL_RED_SIZE 0x3024 +#define EGL_GREEN_SIZE 0x3023 +#define EGL_BLUE_SIZE 0x3022 +#define EGL_ALPHA_SIZE 0x3021 +#define EGL_RENDERABLE_TYPE 0x3040 +#define EGL_OPENGL_API 0x30A2 +#define EGL_OPENGL_BIT 0x0008 +#define EGL_NONE 0x3038 +#define EGL_CONTEXT_CLIENT_VERSION 0x3098 +#define EGL_NATIVE_VISUAL_ID 0x302E + #endif /* MGL_GL_MACRO_H */ diff --git a/include/mgl/window/window.h b/include/mgl/window/window.h index fdffd8d..7370df9 100644 --- a/include/mgl/window/window.h +++ b/include/mgl/window/window.h @@ -66,6 +66,11 @@ typedef enum { MGL_WINDOW_TYPE_NOTIFICATION /* Also sets the window as always on top */ } mgl_window_type; +typedef enum { + MGL_RENDER_API_GLX, + MGL_RENDER_API_EGL +} mgl_render_api; + /* TODO: Some of these parameters only apply to new window */ typedef struct { mgl_vec2i position; @@ -81,6 +86,7 @@ typedef struct { const char *class_name; mgl_window_type window_type; /* default: normal */ mgl_window_handle transient_for_window; + mgl_render_api render_api; /* default: MGL_RENDER_API_GLX */ } mgl_window_create_params; typedef enum { -- cgit v1.2.3