*/}}
1
0
Prechádzať zdrojové kódy

GLES window support, shader all broken

YimingWu 1 rok pred
rodič
commit
9db4e7ad26
7 zmenil súbory, kde vykonal 197 pridanie a 64 odobranie
  1. 6 2
      CMakeLists.txt
  2. 12 1
      la_interface.h
  3. 106 29
      la_kernel.c
  4. 10 4
      la_tns.h
  5. 42 24
      la_tns_kernel.c
  6. 11 3
      la_util.h
  7. 10 1
      lagui-config.cmake

+ 6 - 2
CMakeLists.txt

@@ -6,11 +6,16 @@ if (POLICY CMP0072)
 endif()
 
 SET(LAGUI_FONT_CUSTOM_PATH  $ENV{HOME}/.local/share/fonts/lagui CACHE STRING "Where to install lagui fonts")
-
 if (NOT DEFINED ${LAGUI_FONT_CUSTOM_PATH})
     set(LAGUI_FONT_CUSTOM_PATH $ENV{HOME}/.local/share/fonts/lagui)
 endif()
 
+SET(LAGUI_USE_GLES false CACHE BOOL "Whether to use GLES in LaGUI")
+if(${LAGUI_USE_GLES})
+    add_definitions(-DLA_USE_GLES)
+endif()
+
+
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
 
 find_package(OpenGL REQUIRED)
@@ -32,7 +37,6 @@ file(GLOB SOURCE_FILES
 file(GLOB HEADER_FILES 
 	./*.h ./*.hpp ./resources/*.h ./resources/*.hpp)
 
-
 add_definitions(-DLAGUI_FONT_CUSTOM_PATH=\"${LAGUI_FONT_CUSTOM_PATH}\")
 add_definitions(-w)
 

+ 12 - 1
la_interface.h

@@ -18,9 +18,12 @@
 
 #pragma once
 
+#ifdef LA_USE_GLES
+#include <EGL/egl.h>
+#else
 #include <GL/glew.h>
-//#include <GL/glxew.h>
 #include <GL/gl.h>
+#endif
 
 #ifdef __linux__
 #include <X11/Xlib.h>
@@ -362,7 +365,12 @@ STRUCTURE(LA){
 #ifdef __linux__
     Window* win;
     XVisualInfo* xvi;
+#ifdef LA_USE_GLES
+    EGLConfig BestFBC;
+    EGLDisplay egl_dpy;
+#else
     GLXFBConfig BestFBC;
+#endif
     Colormap cmap;
     XIM im;
     XIC ic;
@@ -609,6 +617,9 @@ STRUCTURE(laWindow){
 
     SYSWINDOW* win;
     SYSGLCONTEXT glc;
+#ifdef LA_USE_GLES
+    EGLSurface egl_surf;
+#endif
     int GLDebugNeedsUpdate;
     GLuint vao;
     struct NVGcontext* nvg;

+ 106 - 29
la_kernel.c

@@ -16,7 +16,11 @@
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#ifdef LA_USE_GLES
+#define NANOVG_GLES3_IMPLEMENTATION
+#else
 #define NANOVG_GL3_IMPLEMENTATION
+#endif
 #include "la_5.h"
 
 #include <stdio.h>
@@ -170,7 +174,7 @@ void la_XErrorHandler(Display *display, XErrorEvent *event){
     printf("X Error:\n%s\n",buf);
 }
 
-SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc){
+SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncToVBlank, GLXContext* r_glc, void* egl_surf){
     XSetWindowAttributes swa;
     XWindowAttributes wa;
     swa.event_mask = 
@@ -187,17 +191,24 @@ SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncTo
         my_hints.x = x; my_hints.y = y;
         XSetNormalHints(MAIN.dpy, win, &my_hints);
     }
+    XStoreName(MAIN.dpy, win, title);
 
+#ifdef LA_USE_GLES
+    static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
+    (*r_glc)=eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, MAIN.glc, ctx_attribs );
+    if (!(*r_glc)){ printf("\n\tcannot create gl context\n\n"); exit(0); }
+    EGLSurface* surf=egl_surf;
+    (*surf)=eglCreateWindowSurface(MAIN.egl_dpy, MAIN.BestFBC, win, NULL);
+    if (!(*surf)) { printf("Error: eglCreateWindowSurface failed %d\n",eglGetError()); exit(1); }
+    tnsContextMakeCurrent((*r_glc),win,(*surf));
+#else
     int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
     if (((*r_glc) = glXCreateContextAttribsF(MAIN.dpy, MAIN.BestFBC, MAIN.glc, GL_TRUE, attribs)) == NULL){
         printf("\n\tcannot create gl context\n\n"); exit(0);
     }
-
-    XStoreName(MAIN.dpy, win, title);
-    //XMapWindow(MAIN.dpy, win);
-    tnsContextMakeCurrent((*r_glc),win);
-
+    tnsContextMakeCurrent((*r_glc),win,0);
     int sync=SyncToVBlank?1:0; glXSwapIntervalEXTF(MAIN.dpy, win, sync);
+#endif
 
     MAIN.im = XOpenIM(MAIN.dpy, NULL, NULL, NULL);
     MAIN.ic = XCreateIC(MAIN.im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL);
@@ -226,8 +237,9 @@ SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncTo
     return win;
 };
 void la_DestroySystemWindowX11(laWindow* w) {
-    tnsContextMakeCurrent(0,0);
+    tnsContextMakeCurrent(0,0,0);
     tnsDeleteContext(w->glc);
+    eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
     XDestroyWindow(MAIN.dpy, w->win);
 };
 #endif //linux
@@ -358,7 +370,7 @@ void la_SetupGLEnviornment(laWindow* window, HWND hwnd, int Sync) {
 
     if (!hglrc) SEND_PANIC_ERROR("Can't Create Opengl Context!\n", );
 
-    tnsContextMakeCurrent(hglrc, hdc);
+    tnsContextMakeCurrent(hglrc, hdc,0);
 
     //int sync = Sync ? 1 : 0; wglSwapIntervalEXT(sync);
     wglSwapIntervalEXT(-1);
@@ -375,7 +387,7 @@ SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int Sync
     return hwnd;
 };
 void la_DestroySystemWindowWin32(laWindow* w) {
-    tnsContextMakeCurrent(0,0);
+    tnsContextMakeCurrent(0,0,0);
     tnsDeleteContext(w->glc);
     ReleaseDC(w->win, w->hdc);
     DestroyWindow(w->win);
@@ -457,12 +469,7 @@ void la_NotifyGLDebugChanges(){
 void la_SetupWindowGLStates(laWindow* w){
     tnsBindVertexArray(w->vao); tnsUnbindTexture(); tnsUseImmShader(); tnsEnableShaderv(T->immShader);
     if(w->GLDebugNeedsUpdate){
-#ifdef __linux__
-        tnsContextMakeCurrent(w->glc,w->win);
-#endif
-#ifdef _WIN32
-        tnsContextMakeCurrent(w->glc,w->hdc);
-#endif
+        tnsContextMakeWindowCurrent(w);
         la_SetCurrentGLContextDebug(); w->GLDebugNeedsUpdate=0;
     }
 }
@@ -470,7 +477,11 @@ void la_SetupWindowGLStates(laWindow* w){
 int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
     SYSGLCONTEXT glc;
 #ifdef __linux__
-    SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
+    void* egl_surf=0;
+#ifdef LA_USE_GLES
+    egl_surf=&window->egl_surf;
+#endif
+    SYSWINDOW hwnd = la_CreateWindowX11(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc, egl_surf);
 #endif
 #ifdef _WIN32
     SYSWINDOW hwnd = la_CreateWindowWin32(window->X, window->Y, window->W, window->H, window->Title->Ptr, SyncToVBlank, &glc);
@@ -495,7 +506,11 @@ int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
     glGenVertexArrays(1,&window->vao); tnsBindVertexArray(window->vao);
     la_SetupWindowGLStates(window);
 
+#ifdef LA_USE_GLES
+    window->nvg=nvgCreateGLES3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
+#else
     window->nvg=nvgCreateGL3(NVG_STENCIL_STROKES|NVG_DEBUG|NVG_ANTIALIAS);
+#endif
 
     window->OutputShowStripes=1; window->Redraw=1;
     window->GLDebugNeedsUpdate=1;
@@ -505,7 +520,11 @@ int la_CreateSystemWindow(laWindow *window, int SyncToVBlank){
 };
 
 int la_DestroySystemWindow(laWindow* wnd){
+#ifdef LA_USE_GLES
+    nvgDeleteGLES3(wnd->nvg);
+#else
     nvgDeleteGL3(wnd->nvg);
+#endif
 #ifdef __linux__
     la_DestroySystemWindowX11(wnd);
 #endif
@@ -787,7 +806,7 @@ void laSetFontFolderPath(char* absolute){
 }
 
 void laSetDefaultInitArguments(laInitArguments* ia){
-    ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0;
+    ia->GLMajor=3; ia->GLMinor=3; ia->BufferSamples=0; ia->GLDebug=1;
     ia->UseColorManagement=0;
     ia->HasWorldObjects=0;
     ia->HasAction=0;
@@ -860,6 +879,60 @@ int laGetReadyWith(laInitArguments* ia){
     MAIN.GLMajor=MAIN.InitArgs.GLMajor; MAIN.GLMinor=MAIN.InitArgs.GLMinor; MAIN.BufferSamples=MAIN.InitArgs.BufferSamples;
     logPrint("Chosen OpenGL version %d.%d\n",MAIN.GLMajor,MAIN.GLMinor);
 
+#ifdef LA_USE_GLES
+
+    MAIN.egl_dpy=eglGetDisplay(MAIN.dpy);
+    if(!MAIN.egl_dpy){ printf("Error: eglGetDisplay() failed\n"); exit(1); }
+    EGLint egl_major, egl_minor;
+    if (!eglInitialize(MAIN.egl_dpy, &egl_major, &egl_minor)) {
+        printf("Error: eglInitialize() failed\n"); return -1;
+    }
+
+    int scrnum;
+    XSetWindowAttributes attr;
+    XVisualInfo *visInfo, visTemplate;
+    int num_visuals;
+    EGLContext ctx;
+    EGLint num_configs;
+    EGLint vid;
+    static const EGLint attribs[] = {
+        EGL_RED_SIZE, 8,
+        EGL_GREEN_SIZE, 8,
+        EGL_BLUE_SIZE, 8,
+        EGL_DEPTH_SIZE, 1,
+        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+        EGL_NONE
+    };
+    if (!eglChooseConfig(MAIN.egl_dpy, attribs, &MAIN.BestFBC, 1, &num_configs)) {
+        printf("Error: couldn't get an EGL visual config\n"); exit(1);
+    }
+    if (!eglGetConfigAttrib(MAIN.egl_dpy, MAIN.BestFBC, EGL_NATIVE_VISUAL_ID, &vid)) {
+        printf("Error: eglGetConfigAttrib() failed\n"); exit(1);
+    }
+    visTemplate.visualid = vid;
+    visInfo = XGetVisualInfo(MAIN.dpy, VisualIDMask, &visTemplate, &num_visuals);
+    if (!visInfo) {
+        printf("Error: couldn't get X visual\n"); exit(1);
+    }
+    MAIN.xvi=visInfo;
+
+    root = DefaultRootWindow(MAIN.dpy);
+    if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
+        printf("\n\tcannot create colormap\n\n"); exit(1);
+    }
+
+    eglBindAPI(EGL_OPENGL_ES_API);
+    static const EGLint ctx_attribs[] = {
+        EGL_CONTEXT_CLIENT_VERSION, 2,
+        EGL_NONE
+    };
+    MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
+    if (!MAIN.glc) {
+        printf("Error: eglCreateContext failed\n"); exit(1);
+    }
+
+#else
+
     int visual_attribs[] = {
         GLX_X_RENDERABLE    , True,
         GLX_DRAWABLE_TYPE   , GLX_WINDOW_BIT,
@@ -901,7 +974,7 @@ int laGetReadyWith(laInitArguments* ia){
 
     swa.colormap = MAIN.cmap;
     root = DefaultRootWindow(MAIN.dpy);
-    win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWColormap | CWEventMask, &swa);
+    win = XCreateWindow(MAIN.dpy, root, 0, 0, 100, 100, 0, MAIN.xvi->depth, InputOutput, MAIN.xvi->visual, CWBackPixel | CWBorderPixel|CWColormap | CWEventMask, &swa);
     MAIN.win=win;
     int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, MAIN.GLMajor, GLX_CONTEXT_MINOR_VERSION_ARB, MAIN.GLMinor, 0};
     glXCreateContextAttribsF = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
@@ -910,7 +983,7 @@ int laGetReadyWith(laInitArguments* ia){
     }
     glXSwapIntervalEXTF = (glXSwapIntervalEXTProc) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalEXT" );
 
-    tnsContextMakeCurrent(MAIN.glc,win);
+    tnsContextMakeCurrent(MAIN.glc,win,0);
 
     int major,minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor);
     logPrint("    OpenGL Version: %d.%d\n",major,minor);
@@ -921,6 +994,8 @@ int laGetReadyWith(laInitArguments* ia){
         printf("%d\n",err); printf("%s\n",glewGetErrorString(err));
     };
 
+#endif /* gles or glx */
+
     glGenVertexArrays(1,&MAIN.TempVAO); tnsBindVertexArray(MAIN.TempVAO);
 
     la_SetCurrentGLContextDebug();
@@ -980,7 +1055,7 @@ int laGetReadyWith(laInitArguments* ia){
 
     SetPixelFormat(hdc, 1, &cpfd);
     hglrc = wglCreateContext(hdc);
-    tnsContextMakeCurrent(hglrc, hdc);
+    tnsContextMakeCurrent(hglrc, hdc,0);
 
     //MAIN.hdc = hdc;
    // MAIN.tWND = hwnd;
@@ -1173,11 +1248,14 @@ void laShutoff(int SavePrefereces){
     tnsBindVertexArray(0); glDeleteVertexArrays(1,&MAIN.TempVAO);
 
 #ifdef __linux__
-    tnsContextMakeCurrent(0,0);
+    tnsContextMakeCurrent(0,0,0);
     tnsDeleteContext(MAIN.glc);
+    #ifdef LA_USE_GLES
+        eglTerminate(MAIN.egl_dpy);
+    #endif
 #endif
 #ifdef _WIN32
-    tnsContextMakeCurrent(0,0);
+    tnsContextMakeCurrent(0,0,0);
     tnsDeleteContext(MAIN.glc);
     UnloadWintab();
 #endif
@@ -2531,7 +2609,7 @@ void la_WindowDefDraw(laWindow *w, laBoxedTheme *bt){
 int laStartWindow(laWindow *w){
 #ifdef __linux__
     XMapWindow(MAIN.dpy,w->win);
-    tnsContextMakeCurrent(w->glc,w->win);
+    tnsContextMakeWindowCurrent(w);
 #endif
 #ifdef _WIN32
     ShowWindow(w->win, SW_SHOWNORMAL);
@@ -7452,12 +7530,7 @@ void laMainLoop(){
         laRecordTime(&FrameStartTime);
 
         if(MAIN.GLDebugNeedsUpdate){
-#ifdef __linux__
-            tnsContextMakeCurrent(MAIN.glc,MAIN.win);
-#endif
-#ifdef _WIN32
-            tnsContextMakeCurrent(MAIN.glc,MAIN.hdc);
-#endif
+            tnsContextMakeWindowCurrent(w);
             la_SetCurrentGLContextDebug(); MAIN.GLDebugNeedsUpdate=0;
         }
 
@@ -7484,7 +7557,11 @@ void laMainLoop(){
         for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
             if(!w->RedrawTouched) continue; w->RedrawTouched=0;
 #ifdef __linux__
+    #ifdef LA_USE_GLES
+            eglSwapBuffers(MAIN.egl_dpy, w->egl_surf);
+    #else
             glXSwapBuffers(MAIN.dpy, w->win); //XSync(MAIN.dpy,0);
+    #endif
 #endif
 #ifdef _WIN32
             SwapBuffers(w->hdc);

+ 10 - 4
la_tns.h

@@ -197,6 +197,9 @@ struct _tnsMain {
 
     GLuint CurrentVAO;
     SYSGLCONTEXT CurrentContext;
+#ifdef LA_USE_GLES
+    EGLSurface CurrentSurface;
+#endif
 #ifdef _WIN32
     SYSTEMDC CurrentDC;
 #endif
@@ -328,6 +331,9 @@ struct _tnsOffscreen
 
     GLuint FboHandle;
     SYSGLCONTEXT FboContext;
+#ifdef LA_USE_GLES
+    EGLSurface FboSurface;
+#endif
 #ifdef _WIN32
     SYSTEMDC FboDC;
 #endif
@@ -1295,12 +1301,14 @@ void tnsClearAll();
 void tnsClearColorv(real *rgba);
 void tnsClearColor(real r, real g, real b, real a);
 #ifdef __linux__
-void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSWINDOW win);
+void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSWINDOW win,void* gles_surf);
 #endif
 #ifdef _WIN32
-void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSTEMDC hdc);
+void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSTEMDC hdc,void* unused);
 #endif
 NEED_STRUCTURE(laWindow)
+void tnsContextMakeFBOCurrent(tnsOffscreen* off);
+void tnsContextMakeWindowCurrent(laWindow* w);
 void tnsSwitchToCurrentWindowContext(laWindow* w);
 void tnsDeleteContext(SYSGLCONTEXT glc);
 void tnsBindVertexArray(GLuint vao);
@@ -1373,8 +1381,6 @@ void tnsDrawToExtraNormalAttachment(tnsOffscreen *toff);
 void tnsDrawToAllExtraAttachments(tnsOffscreen *toff);
 void tnsDrawToOffscreenOnlyBind(tnsOffscreen *toff, int HowMany, GLuint *AttachmentArray);
 void tnsReadFromOffscreen(tnsOffscreen *toff);
-void tnsPassColorBetweenOffscreens(tnsOffscreen *from, tnsOffscreen *to,
-                                   GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLenum FilterMode);
 
 void tnsDrawToScreen();
 

+ 42 - 24
la_tns_kernel.c

@@ -116,29 +116,41 @@ void InitGLRenderEnviornment(){
     glEnable(GL_SCISSOR_TEST);
 };
 #ifdef __linux__
-void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSWINDOW win){
-    glXMakeContextCurrent(MAIN.dpy, win, win, context); T->CurrentContext=context; T->CurrentWindow=win;
-    tnsUnbindTexture(); tnsUseNoTexture();
+void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSWINDOW win, void* gles_surf){
+#ifdef LA_USE_GLES
+    eglMakeCurrent(MAIN.egl_dpy,gles_surf,gles_surf,context);
+    EGLSurface* surf=gles_surf; T->CurrentSurface=(*surf);
+#else
+    glXMakeContextCurrent(MAIN.dpy, win, win, context);
+#endif
+    T->CurrentContext=context; T->CurrentWindow=win; tnsUnbindTexture(); tnsUseNoTexture();
 };
 #endif
 #ifdef _WIN32
-void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSTEMDC hdc){
+void tnsContextMakeCurrent(SYSGLCONTEXT context, SYSTEMDC hdc,void* unused){
     wglMakeCurrent(hdc, context); T->CurrentContext=context; T->CurrentDC=hdc;
     tnsUnbindTexture(); tnsUseNoTexture();
 };
 #endif
-void tnsSwitchToCurrentWindowContext(laWindow* w){
-#ifdef __linux__
-    tnsContextMakeCurrent(w->glc,w->win);
-#endif
-#ifdef _WIN32
-    tnsContextMakeCurrent(w->glc,w->hdc);
+#ifdef LA_USE_GLES
+void tnsContextMakeFBOCurrent(tnsOffscreen* off){
+    tnsContextMakeCurrent(off->FboContext,off->FboWindow,off->FboSurface);
+}
+void tnsContextMakeWindowCurrent(laWindow* w){
+    tnsContextMakeCurrent(w->glc,w->win,w->egl_surf);
+}
 #endif
+void tnsSwitchToCurrentWindowContext(laWindow* w){
+    tnsContextMakeWindowCurrent(w);
 };
 
 void tnsDeleteContext(SYSGLCONTEXT glc){
 #ifdef __linux__
-    glXDestroyContext(MAIN.dpy,glc);
+    #ifdef LA_USE_GLES
+        eglDestroyContext(MAIN.egl_dpy,glc);
+    #else
+        glXDestroyContext(MAIN.dpy,glc);
+    #endif
 #endif
 #ifdef _WIN32
     wglDeleteContext(glc);
@@ -1825,11 +1837,15 @@ void tnsBindTexture(tnsTexture *t){
     if ((!t) || T->TexColor==t) return;
     if(t->GLTexType == GL_TEXTURE_2D){ tnsActiveTexture(GL_TEXTURE0); glBindTexture(t->GLTexType, t->GLTexHandle); T->TexColor=t;}
     elif(t->GLTexType == GL_TEXTURE_2D_MULTISAMPLE){ tnsActiveTexture(GL_TEXTURE1); glBindTexture(t->GLTexType, t->GLTexHandle); T->TexColor=t;}
+#ifndef LA_USE_GLES
     elif(t->GLTexType == GL_RENDERBUFFER){ glBindRenderbufferEXT(GL_RENDERBUFFER, t->GLTexHandle); T->TexRenderbuffer = t;}
+#endif
     elif(t->GLTexType == GL_TEXTURE_3D){ tnsActiveTexture(GL_TEXTURE0); glBindTexture(t->GLTexType, t->GLTexHandle); T->TexColor=t;}
 }
 void tnsUnbindTexture(){
+#ifndef LA_USE_GLES
     if(T->TexRenderbuffer){ if(T->TexRenderbuffer->GLTexType == GL_RENDERBUFFER){ glBindRenderbufferEXT(GL_RENDERBUFFER, 0); T->TexRenderbuffer=0;}}
+#endif
     if(T->TexColor){
         if(T->TexColor->GLTexType == GL_TEXTURE_2D){tnsActiveTexture(GL_TEXTURE0);}
         else if(T->TexColor->GLTexType == GL_TEXTURE_2D_MULTISAMPLE){tnsActiveTexture(GL_TEXTURE1);}
@@ -1910,8 +1926,10 @@ void tnsDeleteTexture(tnsTexture *t){
     if (!t) return;
 
     if (t->GLTexType == GL_RENDERBUFFER){
+#ifndef LA_USE_GLES
         glBindRenderbufferEXT(GL_RENDERBUFFER, t->GLTexHandle);
         glDeleteRenderbuffersEXT(1, &t->GLTexHandle);
+#endif
     }else{
         //glBindTexture(t->GLTexType, 0);
         glDeleteTextures(1, &t->GLTexHandle);
@@ -2396,6 +2414,9 @@ const GLenum TNS_WINDOW_DRAWBUFFER_ARRAY[] = {GL_BACK};
 tnsOffscreen *tnsCreateOffscreenHandle(){
     if(!T->CurrentContext){ printf("tnsCreateOffscreenHandle() called without GL Context. Exiting"); exit(0); }
     tnsOffscreen *toff = CreateNew(tnsOffscreen); toff->FboContext=T->CurrentContext;
+#ifdef LA_USE_GLES
+    toff->FboSurface=T->CurrentSurface;
+#endif
 #ifdef _WIN32
     toff->FboDC=T->CurrentDC;
 #endif
@@ -2494,17 +2515,20 @@ tnsOffscreen *tnsCreateDeferredOffscreen(int w, int h, int Multisample){
 void tnsRecreateFBO(tnsOffscreen *off){
     if(off->FboContext){
 #ifdef __linux__
-        SYSWINDOW sw=T->CurrentWindow; SYSGLCONTEXT sc=T->CurrentContext;
-        tnsContextMakeCurrent(off->FboContext,off->FboWindow);
+        SYSWINDOW sw=T->CurrentWindow; SYSGLCONTEXT sc=T->CurrentContext; void* gls;
+#ifdef LA_USE_GLES
+        gls=&T->CurrentSurface;
+#endif
+        tnsContextMakeCurrent(off->FboContext,off->FboWindow,off->FboSurface);
         glDeleteFramebuffers(1, &off->FboHandle);
-        tnsContextMakeCurrent(sc,sw);
+        tnsContextMakeCurrent(sc,sw,gls);
         off->FboContext=sc; off->FboWindow=sw;
 #endif
 #ifdef _WIN32
         SYSTEMDC sd=T->CurrentDC; SYSGLCONTEXT sc=T->CurrentContext;
-        tnsContextMakeCurrent(off->FboContext,off->FboDC);
+        tnsContextMakeCurrent(off->FboContext,off->FboDC,0);
         glDeleteFramebuffers(1, &off->FboHandle);
-        tnsContextMakeCurrent(sc,sd);
+        tnsContextMakeCurrent(sc,sd,0);
         off->FboContext=sc; off->FboDC=sd;
 #endif
     }
@@ -2570,14 +2594,6 @@ void tnsReadFromOffscreen(tnsOffscreen *toff){
     if (!toff) return;
     glBindFramebuffer(GL_READ_FRAMEBUFFER, toff->FboHandle);
 }
-void tnsPassColorBetweenOffscreens(tnsOffscreen *from, tnsOffscreen *to,
-                                   GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLenum FilterMode){
-    if (!from || !to) return;
-    glBlitFramebufferEXT(
-        srcX0, srcY0, srcX1, srcY1,
-        dstX0, dstY0, dstX1, dstY1,
-        GL_COLOR_BUFFER_BIT, FilterMode);
-}
 void tnsDrawToScreen(){
     glBindFramebuffer(GL_FRAMEBUFFER, 0);
     //glDrawBuffer(GL_BACK); printf("%d\n", glGetError());
@@ -2640,7 +2656,9 @@ int tnsInvalidateFontCache(){
         f->MonoAdvance=(real)f->ftfacemono->glyph->advance.x/64.0;
         if(glyph) FT_Done_Glyph(glyph);
     }
+#ifndef LA_USE_GLES
     if(glClearTexImage) glClearTexImage(f->TexBuffer.GLTexHandle, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+#endif
 }
 tnsFontSingleCharacter *tfntFetchCharTextureIDW(uint32_t ch, int UseMono);
 

+ 11 - 3
la_util.h

@@ -23,9 +23,13 @@
 
 #include <time.h>
 
-#include "GL/glew.h"
+#ifdef LA_USE_GLES
+#include <EGL/egl.h>
+#else
+#include <GL/glew.h>
+#include <GL/gl.h>
+#endif
 
-#include "GL/gl.h"
 #include "ft2build.h"
 #include "freetype/freetype.h"
 #include "la_icon.h"
@@ -38,7 +42,11 @@
 #include <errno.h>
 #include <wchar.h>
 #define SYSWINDOW Window
-#define SYSGLCONTEXT GLXContext
+#ifdef LA_USE_GLES
+	#define SYSGLCONTEXT EGLContext
+#else
+	#define SYSGLCONTEXT GLXContext
+#endif
 #define SYSTEMDC DC
 #define SYSTEMRC RC
 #define SYSTEMDISPLAY Display

+ 10 - 1
lagui-config.cmake

@@ -10,6 +10,14 @@ endif()
 
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR})
 
+SET(LAGUI_USE_GLES false CACHE BOOL "Whether to use GLES in LaGUI")
+if(${LAGUI_USE_GLES})
+    add_definitions(-DLA_USE_GLES)
+    set(LAGUI_GL_LIB ${OPENGL_egl_LIBRARY} ${OPENGL_gles2_LIBRARY} ${OPENGL_opengl_LIBRARY})
+else()
+    set(LAGUI_GL_LIB ${OPENGL_glx_LIBRARY} ${OPENGL_opengl_LIBRARY})
+endif()
+
 find_package(OpenGL REQUIRED)
 find_package(X11 REQUIRED)
 find_package(Freetype REQUIRED)
@@ -21,12 +29,13 @@ set(CMAKE_THREAD_PREFER_PTHREAD ON)
 set(THREADS_PREFER_PTHREAD_FLAG ON)
 find_package(Threads REQUIRED)
 
+
 if (CMAKE_SYSTEM_NAME MATCHES "Linux")
     set(LAGUI_SHARED_LIBS
         ${X11_LIBRARIES}
         ${X11_X11_LIB}
         ${GLEW_LIBRARIES}
-        ${OPENGL_LIBRARY}
+        ${LAGUI_GL_LIB}
         ${FREETYPE_LIBRARIES}
         ${X11_Xfixes_LIB}
         ${X11_Xrandr_LIB}