*/}}
YimingWu 1 anno fa
parent
commit
005fa43433
7 ha cambiato i file con 136 aggiunte e 103 eliminazioni
  1. 1 0
      la_interface.h
  2. 8 5
      la_kernel.c
  3. 38 29
      la_tns_kernel.c
  4. 1 0
      la_util.h
  5. 1 1
      resources/la_modelling.c
  6. 87 67
      resources/la_tns_shaders.cpp
  7. 0 1
      resources/la_widgets_viewers.c

+ 1 - 0
la_interface.h

@@ -20,6 +20,7 @@
 
 #ifdef LA_USE_GLES
 #include <EGL/egl.h>
+#include <GL/gl.h>
 #else
 #include <GL/glew.h>
 #include <GL/gl.h>

+ 8 - 5
la_kernel.c

@@ -239,7 +239,9 @@ SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncTo
 void la_DestroySystemWindowX11(laWindow* w) {
     tnsContextMakeCurrent(0,0,0);
     tnsDeleteContext(w->glc);
+#ifdef LA_USE_GLES
     eglDestroySurface(MAIN.egl_dpy, w->egl_surf);
+#endif
     XDestroyWindow(MAIN.dpy, w->win);
 };
 #endif //linux
@@ -931,6 +933,8 @@ int laGetReadyWith(laInitArguments* ia){
         printf("Error: eglCreateContext failed\n"); exit(1);
     }
 
+    eglMakeCurrent(MAIN.egl_dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,MAIN.glc);
+
 #else
 
     int visual_attribs[] = {
@@ -7529,11 +7533,6 @@ void laMainLoop(){
     while (1){
         laRecordTime(&FrameStartTime);
 
-        if(MAIN.GLDebugNeedsUpdate){
-            tnsContextMakeWindowCurrent(w);
-            la_SetCurrentGLContextDebug(); MAIN.GLDebugNeedsUpdate=0;
-        }
-
         la_PreFrame();
 
         if(!la_ProcessSysMessage()){ return; }
@@ -7552,6 +7551,9 @@ void laMainLoop(){
 
         for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
             tnsSwitchToCurrentWindowContext(w); la_SetupWindowGLStates(w);
+            if(MAIN.GLDebugNeedsUpdate){
+                la_SetCurrentGLContextDebug();
+            }
             la_DrawWindow(w);
         }
         for(w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
@@ -7567,6 +7569,7 @@ void laMainLoop(){
             SwapBuffers(w->hdc);
 #endif
         }
+        MAIN.GLDebugNeedsUpdate=0;
 
         la_PostFrame();
 

+ 38 - 29
la_tns_kernel.c

@@ -119,7 +119,7 @@ void InitGLRenderEnviornment(){
 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);
+    if(gles_surf){ EGLSurface* surf=gles_surf; T->CurrentSurface=(*surf); }else{ T->CurrentSurface=0; }
 #else
     glXMakeContextCurrent(MAIN.dpy, win, win, context);
 #endif
@@ -139,6 +139,13 @@ void tnsContextMakeFBOCurrent(tnsOffscreen* off){
 void tnsContextMakeWindowCurrent(laWindow* w){
     tnsContextMakeCurrent(w->glc,w->win,w->egl_surf);
 }
+#else
+void tnsContextMakeFBOCurrent(tnsOffscreen* off){
+    tnsContextMakeCurrent(off->FboContext,off->FboWindow,0);
+}
+void tnsContextMakeWindowCurrent(laWindow* w){
+    tnsContextMakeCurrent(w->glc,w->win,0);
+}
 #endif
 void tnsSwitchToCurrentWindowContext(laWindow* w){
     tnsContextMakeWindowCurrent(w);
@@ -294,7 +301,7 @@ void tnsShaderApplyProjection(tnsShader *tns, tnsMatrix44d m){
     tnsMatrix44f mf;
     if (T->BindedShader != tns){ glUseProgram(tns->glProgramID); T->BindedShader = tns; }
     tnsConvert44df(m, mf);
-    glUniformMatrix4fv(tns->iProjection, 1, 0, mf);
+    if(tns->iProjection>-1) glUniformMatrix4fv(tns->iProjection, 1, 0, mf);
 }
 void tnsShaderApplyProjectionInverse(tnsShader *tns, tnsMatrix44d m){
     tnsMatrix44f mf;
@@ -302,19 +309,19 @@ void tnsShaderApplyProjectionInverse(tnsShader *tns, tnsMatrix44d m){
     if (T->BindedShader != tns){ glUseProgram(tns->glProgramID); T->BindedShader = tns; }
     tnsInverse44d(i, m);
     tnsConvert44df(i, mf);
-    glUniformMatrix4fv(tns->iProjectionInverse, 1, 0, mf);
+    if(tns->iProjectionInverse>-1) glUniformMatrix4fv(tns->iProjectionInverse, 1, 0, mf);
 }
 void tnsShaderApplyModel(tnsShader *tns, tnsMatrix44d m){
     tnsMatrix44f mf;
     if (T->BindedShader != tns){ glUseProgram(tns->glProgramID); T->BindedShader = tns; }
     tnsConvert44df(m, mf);
-    glUniformMatrix4fv(tns->iModel, 1, 0, mf);
+    if(tns->iModel>-1) glUniformMatrix4fv(tns->iModel, 1, 0, mf);
 }
 void tnsShaderApplyView(tnsShader *tns, tnsMatrix44d m){
     tnsMatrix44f mf;
     if (T->BindedShader != tns){ glUseProgram(tns->glProgramID); T->BindedShader = tns; }
     tnsConvert44df(m, mf);
-    glUniformMatrix4fv(tns->iView, 1, 0, mf);
+    if(tns->iView>-1) glUniformMatrix4fv(tns->iView, 1, 0, mf);
 }
 void tnsShaderApplyNormalScaler(tnsShader *tns, tnsMatrix44d m){
     tnsMatrix44f mf;
@@ -341,7 +348,7 @@ char* tnsEnsureShaderCommoms(char* Content, char* Library, char* Material){
 }
 int tnsNewVertexShader(char *Content){
     int status = 0;
-    char error[1024];
+    char error[8192]={0};
     GLuint VertexShaderObject;
     tnsShader *s = 0;
 
@@ -365,7 +372,7 @@ int tnsNewVertexShader(char *Content){
 }
 int tnsNewFragmentShaderMaterial(char *Content, char* Library, char* Material){
     int status = 0;
-    char error[1024];
+    char error[8192]={0};
     GLuint FragmentShaderObject;
     tnsShader *s = 0;
 
@@ -392,7 +399,7 @@ int tnsNewFragmentShader(char *Content){
 }
 int tnsNewGeometryShader(char *Content){
     int status = 0;
-    char error[1024];
+    char error[8192]={0};
     GLuint GeometryShaderObject;
     tnsShader *s = 0;
 
@@ -421,7 +428,7 @@ tnsShader *tnsNewShaderProgram(int VertexShaderID, int FragmentShaderID, int Geo
     int gso = GeometryShaderID;
     tnsShader *tns = 0;
     int status = 0;
-    char error[1024];
+    char error[8192];
 
     if (!vso || !fso) return 0;
 
@@ -484,11 +491,11 @@ int tnsEnableShaderv(tnsShader *shader){
     tnsShaderApplyView(s, tmsi->view);
     tnsShaderApplyModel(s, tmsi->model); tnsUseShader(s);
 
-    if(s->iUseNormal) glUniform1i(s->iUseNormal,T->SetUseNormal);
-    if(s->uViewPos) glUniform3fv(s->uViewPos,1,T->SetViewPos);
-    if(s->uViewDir) glUniform3fv(s->uViewDir,1,T->SetViewDir);
-    if(s->iUseHalftone) glUniform1f(s->iUseHalftone,T->SetUseHalftone);
-    if(s->iHalftoneSize) glUniform1f(s->iHalftoneSize,T->SetHalftoneSize);
+    if(s->iUseNormal>-1) glUniform1i(s->iUseNormal,T->SetUseNormal);
+    if(s->uViewPos>-1) glUniform3fv(s->uViewPos,1,T->SetViewPos);
+    if(s->uViewDir>-1) glUniform3fv(s->uViewDir,1,T->SetViewDir);
+    if(s->iUseHalftone>-1) glUniform1f(s->iUseHalftone,T->SetUseHalftone);
+    if(s->iHalftoneSize>-1) glUniform1f(s->iHalftoneSize,T->SetHalftoneSize);
     //if(s->iTextureMode) glUniform1i(s->iTextureMode,T->StateTextureMode);
     //if(cs->iSampleAmount) glUniform1i(cs->iSampleAmount);
     
@@ -1715,7 +1722,8 @@ void tnsConfigure2DTexture(tnsTexture *t){
     }else{
         int isDepth=t->GLTexBitsType==GL_DEPTH_COMPONENT||t->GLTexBitsType==GL_DEPTH_COMPONENT16||
             t->GLTexBitsType==GL_DEPTH_COMPONENT24||t->GLTexBitsType==GL_DEPTH_COMPONENT32F;
-        int format=isDepth?GL_DEPTH_COMPONENT:GL_RGBA; int type=GL_UNSIGNED_BYTE;
+        int format=isDepth?GL_DEPTH_COMPONENT:(t->GLTexBitsType==GL_R8?GL_RED:(t->GLTexBitsType==GL_RG8?GL_RG:(t->GLTexBitsType==GL_RGB8?GL_RGB:GL_RGBA)));
+        int type=GL_UNSIGNED_BYTE;
         if(t->GLTexBitsType==GL_DEPTH_STENCIL){ format=GL_DEPTH_STENCIL; type=GL_UNSIGNED_INT_24_8_EXT; }
         if(t->Multisample) glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, t->Multisample, t->GLTexBitsType, t->Width, t->Height, GL_TRUE);
         else{ glTexImage2D(GL_TEXTURE_2D, 0, t->GLTexBitsType, t->Width, t->Height, 0, format, type, 0);
@@ -1947,16 +1955,16 @@ int tnsTextureMemorySize(tnsTexture *t, int Mem){
 
     switch (t->GLTexBitsType){
     default:
-    case GL_RED:
+    case GL_R8:
         ElemSize = sizeof(char) * 1;
         break;
-    case GL_RG:
+    case GL_RG8:
         ElemSize = sizeof(char) * 2;
         break;
-    case GL_RGB:
+    case GL_RGB8:
         ElemSize = sizeof(char) * 3;
         break;
-    case GL_RGBA:
+    case GL_RGBA8:
         ElemSize = sizeof(char) * 4;
         break;
     case GL_RGBA32F:
@@ -2515,18 +2523,18 @@ 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; void* gls;
+        SYSWINDOW sw=T->CurrentWindow; SYSGLCONTEXT sc=T->CurrentContext; void* gls=0;
 #ifdef LA_USE_GLES
         gls=&T->CurrentSurface;
 #endif
-        tnsContextMakeCurrent(off->FboContext,off->FboWindow,off->FboSurface);
+        tnsContextMakeFBOCurrent(off);
         glDeleteFramebuffers(1, &off->FboHandle);
         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,0);
+        tnsContextMakeFBOCurrent(off);
         glDeleteFramebuffers(1, &off->FboHandle);
         tnsContextMakeCurrent(sc,sd,0);
         off->FboContext=sc; off->FboDC=sd;
@@ -2672,7 +2680,7 @@ const char* TNS_FONT_LOAD_OPTIONS[9]={"","fonts/","lagui/fonts/","../","../fonts
 const char* TNS_FONT_LOAD_OPTIONS_FROM_HOME[2]={".local/share/fonts/lagui/",".local/share/fonts/"};
 
 int tnsLoadSystemFontMono(char* from, char* mono){
-    char buf[1024]; if(!FM->UsingFont || !mono || !mono[0]) return 0;
+    char buf[8192]; if(!FM->UsingFont || !mono || !mono[0]) return 0;
     tnsFont *f=FM->UsingFont;
     int GenHeight=LA_RH*MAIN.FontSize;
 
@@ -2703,14 +2711,14 @@ int tnsLoadSystemFontMono(char* from, char* mono){
     return 0;
 };
 int tnsLoadSystemFont(char* from, char* name){
-    char buf[1024];
+    char buf[8192];
 
     tnsFont *f=FM->UsingFont; if(!f){
         f = CreateNew(tnsFont);
         f->characters=calloc(1, sizeof(tnsFontSingleCharacter*)*TNS_UNICODE_COUNT);
         f->monocharacters=calloc(1, sizeof(tnsFontSingleCharacter*)*TNS_MONO_COUNT);
         f->height = LA_RH*(MAIN.FontSize/2.0f+0.5f);
-        tnsInit2DTexture(&f->TexBuffer, GL_RED, FM->BufferWidth, FM->BufferWidth, 0);
+        tnsInit2DTexture(&f->TexBuffer, GL_R8, FM->BufferWidth, FM->BufferWidth, 0);
         lstAppendItem(&FM->Fonts, f); FM->UsingFont=f;
         if (FT_Init_FreeType(&f->ftlib)) SEND_PANIC_ERROR("Freetype Init Failed!");
         logPrintNew("Loading fonts...\n");
@@ -4902,14 +4910,15 @@ void tnsDrawFloor(real* CamPosition, real Far, int *ShowAxis){
     real spanl=1e-3,spanh=1e-3;
     while((spanl*10)<spanstart){ spanl*=10; } spanh=spanl;
     while((spanh*10)<Far){ spanh*=10; }
+    float usefar=Far;
 
     tnsFlush();
 
     glEnable(GL_BLEND); glDepthMask(GL_FALSE); glEnable(GL_DEPTH_TEST);
     tnsUseShader(T->FloorShader);
     tnsEnableShaderv(T->FloorShader);
-    glUniform3f(T->FloorShader->uViewPos,LA_COLOR3(CamPosition));
-    glUniform1f(T->FloorShader->uFar,Far);
+    //glUniform3f(T->FloorShader->uViewPos,1,1,1);
+    usefar=Far; glUniform1fv(T->FloorShader->uFar,1,&usefar);
     
     real sp=spanh;
     while(sp>=spanl){
@@ -4921,7 +4930,7 @@ void tnsDrawFloor(real* CamPosition, real Far, int *ShowAxis){
         tnsFlush();
         Far/=3; if(Far<height) break;
         dist=sqrt(fabs(Far*Far-height*height)); sp/=10;
-        glUniform1f(T->FloorShader->uFar,Far);
+    usefar=Far; glUniform1fv(T->FloorShader->uFar,1,&usefar);
     }
 
     //for (i; i < Lim; i++){
@@ -4938,7 +4947,7 @@ void tnsDrawFloor(real* CamPosition, real Far, int *ShowAxis){
 
     //tnsPackAs(GL_LINES);
 
-    glUniform1f(T->FloorShader->uFar,OrigFar);
+    usefar=OrigFar; glUniform1fv(T->FloorShader->uFar,1,&usefar);
 
     if (ShowAxis[0]){ tnsColor4d(1, 0, 0, 1);
         tnsVertex3d(-OrigFar, 0, 0); tnsVertex3d(OrigFar, 0, 0);

+ 1 - 0
la_util.h

@@ -25,6 +25,7 @@
 
 #ifdef LA_USE_GLES
 #include <EGL/egl.h>
+#include <GL/gl.h>
 #else
 #include <GL/glew.h>
 #include <GL/gl.h>

+ 1 - 1
resources/la_modelling.c

@@ -101,7 +101,7 @@ MSelectData* la_InitSelectData(int w, int h, tnsCamera* camera){
     MSelectData* sd=memAcquireSimple(sizeof(MSelectData));
     if (!sd->FBO || sd->FBO->pColor[0]->Height != h || sd->FBO->pColor[0]->Width != w){
         if (sd->FBO) tnsDelete2DOffscreen(sd->FBO);
-        sd->FBO = tnsCreate2DOffscreen(GL_RGB, w, h, 0, 1, 0); sd->Color=sd->FBO->pColor[0];
+        sd->FBO = tnsCreate2DOffscreen(GL_RGB8, w, h, 0, 0, 0); sd->Color=sd->FBO->pColor[0];
     }
     tnsDrawToOffscreen(sd->FBO, 1, 0);
     return sd;

+ 87 - 67
resources/la_tns_shaders.cpp

@@ -531,36 +531,36 @@ vec3 XYZ2Clay(vec3 xyz){
 	return xyz*mat;
 }
 
-float htsize=HalftoneSize;
+#define htsize HalftoneSize
 vec4 rgb2cmyk(vec3 rgb){
-	vec4 cmyk; cmyk.w=1-max(max(rgb.r,rgb.g),rgb.b);
-	float k1=1-cmyk.w;
+	vec4 cmyk; cmyk.w=1.-max(max(rgb.r,rgb.g),rgb.b);
+	float k1=1.-cmyk.w;
 	cmyk.r=(k1-rgb.r)/k1; cmyk.g=(k1-rgb.g)/k1; cmyk.b=(k1-rgb.b)/k1;
 	return cmyk;
 }
 vec3 cmyk2rgb(vec4 cmyk){
-	vec3 rgb; float k1=1-cmyk.w;
-	rgb.r=(1-cmyk.r)*k1; rgb.g=(1-cmyk.g)*k1; rgb.b=(1-cmyk.b)*k1;
+	vec3 rgb; float k1=1.-cmyk.w;
+	rgb.r=(1.-cmyk.r)*k1; rgb.g=(1.-cmyk.g)*k1; rgb.b=(1.-cmyk.b)*k1;
 	return rgb;
 }
 float rand(vec2 co){
     return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
 }
 float HalftoneSingle(float a,float ps,float theta,float sm){
-	float psize=ps; vec2 ctr=vec2(psize/2,psize/2); vec2 pt=vec2(psize,psize);
+	float psize=ps; vec2 ctr=vec2(psize/2.,psize/2.); vec2 pt=vec2(psize,psize);
     vec2 xy=gl_FragCoord.xy; xy=vec2(sin(theta)*xy.x-cos(theta)*xy.y,cos(theta)*xy.x+sin(theta)*xy.y);
-	xy.x=xy.x+rand(xy)/1; xy.y=xy.y+rand(xy)/1; ivec2 xyi=ivec2(int(xy.x/psize),int(xy.y/psize));
+	xy.x=xy.x+rand(xy)/1.; xy.y=xy.y+rand(xy)/1.; ivec2 xyi=ivec2(int(xy.x/psize),int(xy.y/psize));
 	vec2 xyf=mod(xy,pt);
-	float px1=(sm==1)?(3.0f/psize):(0.000001);
-	float cmp=(pow(a,1)*psize/2*(1.414+px1)); float fac=distance(xyf,ctr)/cmp;
-	return smoothstep(1+px1,1-px1,fac);
+	float px1=(sm==1.)?(3.0f/psize):(0.000001);
+	float cmp=(pow(a,1.)*psize/2.*(1.414+px1)); float fac=distance(xyf,ctr)/cmp;
+	return smoothstep(1.+px1,1.-px1,fac);
 }
 vec4 halftone(vec4 color){
 	vec4 cmyk=rgb2cmyk(color.rgb); float a=color.a*(gl_FragCoord.x/400.0f);
-	cmyk.r=HalftoneSingle(cmyk.r,htsize,rad(15.0),1);
-	cmyk.g=HalftoneSingle(cmyk.g,htsize,rad(75.0),1);
-	cmyk.b=HalftoneSingle(cmyk.b,htsize,rad(0),1);
-	cmyk.a=HalftoneSingle(cmyk.a,htsize,rad(45.0),1);
+	cmyk.r=HalftoneSingle(cmyk.r,htsize,rad(15.0),1.);
+	cmyk.g=HalftoneSingle(cmyk.g,htsize,rad(75.0),1.);
+	cmyk.b=HalftoneSingle(cmyk.b,htsize,rad(0.),1.);
+	cmyk.a=HalftoneSingle(cmyk.a,htsize,rad(45.0),1.);
 	color.rgb=cmyk2rgb(cmyk);
 	//color.a=HalftoneSingle(a,htsize,rad(30),0);
 	return color;
@@ -568,7 +568,8 @@ vec4 halftone(vec4 color){
 )";
 
 
-extern "C" const char* TNS_VERTEX_SIMPLE_MATCAP = R"(#version 330
+extern "C" const char* TNS_VERTEX_SIMPLE_MATCAP = R"(#version 310 es
+precision highp float;
 uniform mat4 mProjection;
 uniform mat4 mModel;
 uniform mat4 mView;
@@ -583,11 +584,13 @@ void main(){
     fNormal = normalize(N);
 })";
 
-extern "C" const char* TNS_FRAGMENT_SIMPLE_MATCAP = R"(#version 330
+extern "C" const char* TNS_FRAGMENT_SIMPLE_MATCAP = R"(#version 310 es
+precision highp float;
 smooth in vec3 fNormal;
+out vec4 outColor;
 float Interpolate(float between1,float between2,float value1,float value2,float key){
     float i = (key-between1)/(between2-between1);
-    return value1*(1-i)+value2*i;
+    return value1*(1.-i)+value2*i;
 }
 void main(){
     float value = dot(vec3(0,0,1),fNormal);
@@ -595,10 +598,11 @@ void main(){
     else if(value>=0.65 && value<0.85) value=Interpolate(0.65,0.85,0.15,0.75,value);
     else if(value>=0.85 && value<0.95) value=0.75;
     else if(value>=0.95) value=0.9;
-    gl_FragColor = vec4(vec3(0.84, 0.41, 0.16)*value,1);
+    outColor = vec4(vec3(0.84, 0.41, 0.16)*value,1);
 })";
 
-extern "C" const char* TNS_VERTEX_GRID = R"(#version 330
+extern "C" const char* TNS_VERTEX_GRID = R"(#version 310 es
+precision highp float;
 
 uniform mat4 mProjection;
 uniform mat4 mModel;
@@ -617,18 +621,19 @@ void main(){
     uv = vUV;
 })";
 
-extern "C" const char* TNS_FRAGMENT_TRANSPARNT_GRID = R"(#version 330
-
+extern "C" const char* TNS_FRAGMENT_TRANSPARNT_GRID = R"(#version 310 es
+precision highp float;
 in vec4 fColor;
 in vec2 uv;
-
+out vec4 outColor;
 void main(){
     vec4 c = fColor;
-    c.a = sin(uv.x)*sin(uv.y)>0?c.a:0;
-    gl_FragColor = c;
+    c.a = sin(uv.x)*sin(uv.y)>0.?c.a:0.;
+    outColor = c;
 })";
 
-extern "C" const char* LA_IMM_VERTEX_SHADER = R"(#version 330
+extern "C" const char* LA_IMM_VERTEX_SHADER = R"(#version 310 es
+precision highp float;
 uniform mat4 mProjection;
 uniform mat4 mModel;
 uniform mat4 mView;
@@ -651,9 +656,10 @@ void main(){
     fNormal= normalize((mModel * vec4(vNormal,0.)).xyz);
 })";
 
-extern "C" const char* LA_IMM_FRAGMENT_SHADER = R"(#version 330
-uniform sampler2D TexColor;\
-uniform sampler2DMS TexColorMS;\
+extern "C" const char* LA_IMM_FRAGMENT_SHADER = R"(#version 310 es
+precision highp float;
+uniform highp sampler2D TexColor;\
+uniform highp sampler2DMS TexColorMS;\
 uniform int TextureMode;
 uniform int ColorMode;
 uniform int MultiplyColor;
@@ -690,13 +696,13 @@ vec3 ConvertColorSpace(vec3 color){
             if(InputColorSpace==0) color=to_linear_srgb(color);
             else if(InputColorSpace==1) color=to_linear_clay(color);
         } 
-        vec3 xyz; if(ColorMode==1){ color.y=pow(color.y,max(HCYGamma,1)); color=okhsl_to_linear_srgb(color); }
+        vec3 xyz; if(ColorMode==1){ color.y=pow(color.y,max(HCYGamma,1.)); color=okhsl_to_linear_srgb(color); }
         if(InputColorSpace==1){ xyz=Clay2XYZ(color); }
         if(InputColorSpace==0){ xyz=sRGB2XYZ(color); }
         if(OutputColorSpace==0){ color=to_log_srgb(XYZ2sRGB(xyz)); }
         if(OutputColorSpace==1){ color=to_log_clay(XYZ2Clay(xyz)); }
     }else{
-        if(ColorMode==1){ color.y=pow(color.y,max(HCYGamma,1)); color=okhsl_to_srgb(color); }
+        if(ColorMode==1){ color.y=pow(color.y,max(HCYGamma,1.)); color=okhsl_to_srgb(color); }
         else if(ColorMode==0){ color=color; }
         else{
             if(OutputColorSpace==0){ color=to_log_srgb(color); }
@@ -704,38 +710,38 @@ vec3 ConvertColorSpace(vec3 color){
         }
     }
     if(ShowStripes!=0){
-        if(color.r>1.00001||color.g>1.00001||color.b>1.00001||color.r<0||color.g<0||color.b<0){ color=mix(color,vec3(0.5,0.5,0.5),(sin((gl_FragCoord.x+gl_FragCoord.y)/2)>0)?1:0.5); }
+        if(color.r>1.00001||color.g>1.00001||color.b>1.00001||color.r<0.||color.g<0.||color.b<0.){ color=mix(color,vec3(0.5,0.5,0.5),(sin((gl_FragCoord.x+gl_FragCoord.y)/2.)>0.)?1.:0.5); }
     }
     return color;
 }
 void main(){
     vec4 color=vec4(1,0,1,1);
-    if(TextureMode==0){ color = fColor; if(UseHalftone>0) color.a=HalftoneSingle(color.a,htsize,rad(7),0); }
-    else if(TextureMode==1){color = vec4(fColor.rgb,fColor.a*texture2D(TexColor,fUV.st).r);}
+    if(TextureMode==0){ color = fColor; if(UseHalftone>0.) color.a=HalftoneSingle(color.a,htsize,rad(7.),0.); }
+    else if(TextureMode==1){color = vec4(fColor.rgb,fColor.a*texture(TexColor,fUV.st).r);}
     else if(TextureMode==2){
-        color=texture2D(TexColor,fUV.st);
+        color=texture(TexColor,fUV.st);
         if(MultiplyColor!=0){color*=fColor;}
     }else if(TextureMode==3){
         color=vec4(0,0,0,0);
         ivec2 texSize = textureSize(TexColorMS);
-        for(int i=0;i<SampleAmount;i++){ vec4 res=texelFetch(TexColorMS, ivec2(fUV * texSize),i); if(res[0]>-1e19) color+=res; };
-        color/=SampleAmount;
+        for(int i=0;i<SampleAmount;i++){ vec4 res=texelFetch(TexColorMS, ivec2(fUV * vec2(texSize)),i); if(res[0]>-1e19) color+=res; };
+        color/=float(SampleAmount);
         if(MultiplyColor!=0){color*=fColor;}
     }
     if(UseNormal!=0){
-		color.a=HalftoneSingle(color.a,htsize,rad(7),0);
-		if(color.a==0) discard;
+		color.a=HalftoneSingle(color.a,htsize,rad(7.),0.);
+		if(color.a==0.) discard;
         float light_factor=dot(fNormal,vec3(0,0,1));
 		vec3 vd=uViewDir;
 		if(length(uViewDir)<0.5){ vd=fGPos-uViewPos; }
         float view=dot(fNormal,vd);
         float factor=abs(light_factor);
-        if(light_factor*view>0){ factor=0; }
+        if(light_factor*view>0.){ factor=0.; }
         color=vec4(color.rgb*mix(0.2,1.,factor),color.a);
-        vec3 oNormal=fNormal; if(view<0){ oNormal=-fNormal; }
+        vec3 oNormal=fNormal; if(view<0.){ oNormal=-fNormal; }
         outNormal = oNormal;
     }
-    color=vec4(ConvertColorSpace(color.rgb),color.a); color.a=clamp(color.a,0,1);
+    color=vec4(ConvertColorSpace(color.rgb),color.a); color.a=clamp(color.a,0.,1.);
 	if(Composing!=0){
 		if(color.rgb!=vec3(0,0,0)){
 			//vec3 cl=srgb_to_okhsl(color.rgb);
@@ -755,7 +761,8 @@ void main(){
     outGPos = fGPos;
 })";
 
-extern "C" const char* LA_OBJECT_FRAGMENT_SHADER = R"(#version 330
+extern "C" const char* LA_OBJECT_FRAGMENT_SHADER = R"(#version 310 es
+precision highp float;
 uniform int UseNormal;
 uniform float UseHalftone;
 uniform float HalftoneSize;
@@ -797,7 +804,8 @@ void main(){
     outColor = color; outGPos = fGPos;
 })";
 
-extern "C" const char* LA_FLOOR_VERTEX_SHADER = R"(#version 330
+extern "C" const char* LA_FLOOR_VERTEX_SHADER = R"(#version 310 es
+precision highp float;
 uniform mat4 mProjection;
 uniform mat4 mModel;
 uniform mat4 mView;
@@ -811,18 +819,20 @@ void main(){
 	fColor=vColor;
 })";
 
-extern "C" const char* LA_FLOOR_FRAGMENT_SHADER = R"(#version 330
+extern "C" const char* LA_FLOOR_FRAGMENT_SHADER = R"(#version 310 es
+precision highp float;
 uniform vec3 uViewPos;
 uniform float uFar;
 in vec4 fColor;
 in vec3 fGPos;
 layout(location = 0) out vec4 outColor;
 void main(){
-	float fac=1-pow(clamp(length(uViewPos-fGPos)/uFar,0,1),0.4);
+	float fac=1.-pow(clamp(length(uViewPos-fGPos)/uFar,0.,1.),0.4);
 	outColor=vec4(fColor.rgb,fColor.a*fac);
 })";
 
-extern "C" const char* LA_RAY_VERTEX_SHADER = R"(#version 330
+extern "C" const char* LA_RAY_VERTEX_SHADER = R"(#version 310 es
+precision highp float;
 in vec3 vUV;
 in vec4 vVertex;
 out vec3 fViewDir;
@@ -875,27 +885,30 @@ vec4 fxaa(in sampler2D tex, vec2 uv, vec2 texsize) {
     return vec4(texture(tex, offuv).rgb,colm4.a);  
 })";
 
-extern "C" const char* LA_RAY_FRAGMENT_SHADER = R"(#version 330
+extern "C" const char* LA_RAY_FRAGMENT_SHADER = R"(#version 310 es
+precision highp float;
 uniform vec3 uViewDir;
 uniform vec3 uViewPos;
 uniform float uFOV;
 in vec3 fViewDir;
-uniform sampler2D TexColor;
-uniform sampler2D TexNormal;
-uniform sampler2D TexGPos;
+uniform highp sampler2D TexColor;
+uniform highp sampler2D TexNormal;
+uniform highp sampler2D TexGPos;
 #with LA_SHADER_LIB_FXAA
+out vec4 outColor;
 void main(){
     float d=dot(uViewDir,normalize(fViewDir));
     float target=cos(uFOV/2.);
     vec4 color=vec4(1.,1.,1.,1.); float mul=0.;
     //if(d<(target+0.005)&&d>target) mul=1.0;
-    vec2 uv=gl_FragCoord.xy/textureSize(TexColor,0);
-    vec4 buffer_color=fxaa(TexColor,uv,textureSize(TexColor,0));
-    //vec4 buffer_color=texture2D(TexColor,uv);
-    gl_FragColor = mul*color+buffer_color;
+    vec2 uv=gl_FragCoord.xy/vec2(textureSize(TexColor,0));
+    vec4 buffer_color=fxaa(TexColor,uv,vec2(textureSize(TexColor,0)));
+    //vec4 buffer_color=texture(TexColor,uv);
+    outColor = mul*color+buffer_color;
 })";
 
-extern "C" const char* LA_SCENE_VERTEX_SHADER = R"(#version 330
+extern "C" const char* LA_SCENE_VERTEX_SHADER = R"(#version 310 es
+precision highp float;
 uniform mat4 mProjection;
 uniform mat4 mModel;
 uniform mat4 mView;
@@ -916,9 +929,10 @@ void main(){
     fGPos= mShadow * mModel * vVertex;\
 })";
 
-extern "C" const char* LA_SCENE_FRAGMENT_SHADER = R"(#version 330
-uniform sampler2D TexColor;
-uniform sampler2DMS TexColorMS;\
+extern "C" const char* LA_SCENE_FRAGMENT_SHADER = R"(#version 310 es
+precision highp float;
+uniform highp sampler2D TexColor;
+uniform highp sampler2DMS TexColorMS;\
 uniform int TextureMode;
 uniform int SampleAmount;
 uniform int MultiplyColor;
@@ -926,13 +940,14 @@ in vec4 fColor;
 //in vec4 fNormal;
 in vec2 fUV;
 in vec4 fGPos;
+out vec4 outColor;
 vec4 GetTexture(vec2 uv){
     vec4 color=vec4(1,0,1,1);
-    if(TextureMode==1 || TextureMode==2){ return texture2D(TexColor,uv); }
+    if(TextureMode==1 || TextureMode==2){ return texture(TexColor,uv); }
     else if(TextureMode==3){
         ivec2 texSize = textureSize(TexColorMS);
-        for(int i=0;i<SampleAmount;i++) color+=texelFetch(TexColorMS, ivec2(fUV * texSize),i);
-        color/=SampleAmount;
+        for(int i=0;i<SampleAmount;i++) color+=texelFetch(TexColorMS, ivec2(fUV * vec2(texSize)),i);
+        color/=float(SampleAmount);
         if(MultiplyColor!=0){color*=fColor;}
         return color;
     }
@@ -947,10 +962,11 @@ float GetShadow(vec4 GPos){
     return shadow;
 }
 void main(){
-    gl_FragColor=GetShadow(fGPos)*fColor;
+    outColor=GetShadow(fGPos)*fColor;
 })";
 
-extern "C" const char* LA_CASCADE_SHADOW_VERTEX_SHADER = R"(#version 330
+extern "C" const char* LA_CASCADE_SHADOW_VERTEX_SHADER = R"(#version 310 es
+precision highp float;
 in vec4 vVertex;
 uniform mat4 mModel;
 uniform mat4 mShadow;
@@ -958,9 +974,11 @@ void main(){
     gl_Position=mShadow*mModel*vVertex;
 })";
 
-extern "C" const char* LA_CASCADE_SHADOW_FRAGMENT_SHADER = "#version 330\nvoid main(){gl_FragDepth = gl_FragCoord.z;}";
+extern "C" const char* LA_CASCADE_SHADOW_FRAGMENT_SHADER = "#version 310 es\n \
+precision highp float;\nvoid main(){gl_FragDepth = gl_FragCoord.z;}";
 
-extern "C" const char* LA_SELECTION_VERTEX_SHADER = R"(#version 330
+extern "C" const char* LA_SELECTION_VERTEX_SHADER = R"(#version 310 es
+precision highp float;
 in vec4 vVertex;
 in vec3 vColor;
 uniform mat4 mProjection;
@@ -975,9 +993,11 @@ void main(){
     fIdColor = vColor;
 })";
 
-extern "C" const char* LA_SELECTION_FRAGMENT_SHADER = R"(#version 330
+extern "C" const char* LA_SELECTION_FRAGMENT_SHADER = R"(#version 310 es
+precision highp float;
 flat in vec3 fIdColor;
+out vec4 outColor;
 void main(){
-    gl_FragColor=vec4(fIdColor,1.);
+    outColor=vec4(fIdColor,1.);
 })";
 

+ 0 - 1
resources/la_widgets_viewers.c

@@ -209,7 +209,6 @@ void la_RootObjectDraw(laBoxedTheme *bt, tnsObject *root, laUiItem* ui){
             tnsDrawObjectTree(root,TNS_EVAL_LAYER_OUTLINE|Do2DInstance,0,e->AsPlayer);
             glDepthMask(GL_TRUE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
             glLineWidth(1); tnsUniformUseOffset(T->immShader,0);
-            glDisable(GL_POLYGON_OFFSET_LINE);
 
             tnsEvaluateData* ed=e->AsPlayer?(&root->EvaluatedPlay):(&root->Evaluated);
             if(!ed->Has2D){ break; }