From 4ea2aca04699a9347d257b5bb96ded75adc4ccdb Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 19 Mar 2019 20:00:04 +1100 Subject: [PATCH] Add EGL backend also fixes #575 --- src/Window.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/Window.c b/src/Window.c index 7b18bb7ad..20787f6e3 100644 --- a/src/Window.c +++ b/src/Window.c @@ -663,6 +663,7 @@ void Window_DrawRaw(Rect2D r) { *#########################################################################################################################*/ #ifdef CC_BUILD_X11 #include +#include #define _NET_WM_STATE_REMOVE 0 #define _NET_WM_STATE_ADD 1 @@ -2973,4 +2974,79 @@ void GLContext_SetVSync(bool enabled) { SDL_GL_SetSwapInterval(enabled); } #endif + + +/*########################################################################################################################* +*-------------------------------------------------------EGL OpenGL--------------------------------------------------------* +*#########################################################################################################################*/ +#ifdef CC_BUILD_EGL +#include +static EGLDisplay ctx_display; +static EGLContext ctx_context; +static EGLSurface ctx_surface; +static EGLConfig ctx_config; +static EGLint ctx_numConfig; + +static XVisualInfo GLContext_SelectVisual(struct GraphicsMode* mode) { + XVisualInfo info = { 0 }; + info.depth = 24; + info.visual = CopyFromParent; + info.visualid = CopyFromParent; + return info; +} + +void GLContext_Init(struct GraphicsMode* mode) { + static EGLint attribs[19] = { + EGL_RED_SIZE, 0, EGL_GREEN_SIZE, 0, + EGL_BLUE_SIZE, 0, EGL_ALPHA_SIZE, 0, + EGL_DEPTH_SIZE,0, EGL_STENCIL_SIZE,0, + EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_NONE + }; + + attribs[1] = mode->R; attribs[3] = mode->G; + attribs[5] = mode->B; attribs[7] = mode->A; + attribs[9] = mode->DepthBits; + attribs[11] = mode->StencilBits; + + ctx_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(ctx_display, NULL, NULL); + eglBindAPI(EGL_OPENGL_ES_API); + eglChooseConfig(ctx_display, attribs, &ctx_config, 1, &ctx_numConfig); + + EGLint contextAttributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; + + ctx_context = eglCreateContext(ctx_display, ctx_config, EGL_NO_CONTEXT, contextAttributes); + ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, win_handle, NULL); + eglMakeCurrent(ctx_display, ctx_surface, ctx_surface, ctx_context);\ +} + +void GLContext_Update(void) { + eglMakeCurrent(ctx_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx_context); + eglDestroySurface(ctx_display, ctx_surface); + ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, win_handle, NULL); + eglMakeCurrent(ctx_display, ctx_surface, ctx_surface, ctx_context); +} + +void GLContext_Free(void) { + eglMakeCurrent(ctx_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx_context); + eglDestroyContext(ctx_display, ctx_context); + eglDestroySurface(ctx_display, ctx_surface); + eglTerminate(ctx_display); +} + +void* GLContext_GetAddress(const char* function) { + return eglGetProcAddress(function); +} + +void GLContext_SwapBuffers(void) { + eglSwapBuffers(ctx_display, ctx_surface); +} + +void GLContext_SetVSync(bool enabled) { + eglSwapInterval(ctx_display, enabled ? 1 : 0); +} +#endif #endif \ No newline at end of file