*/}}
Browse Source

new chroma compression shader

YimingWu 4 months ago
parent
commit
1ebef77a0c
4 changed files with 40 additions and 3 deletions
  1. 1 1
      la_kernel.c
  2. 4 0
      la_tns.h
  3. 8 1
      la_tns_kernel.c
  4. 27 1
      resources/la_tns_shaders.cpp

+ 1 - 1
la_kernel.c

@@ -219,7 +219,7 @@ SYSWINDOW la_CreateWindowX11(int x, int y, int w, int h, char *title, int SyncTo
     XStoreName(MAIN.dpy, win, title);
 
 #ifdef LA_USE_GLES
-    static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
+    static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, 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;

+ 4 - 0
la_tns.h

@@ -299,6 +299,9 @@ struct _tnsMain {
     }Runtime;
 };
 
+#define TNS_CHROMA_COMPRESSION_YUYV 1
+#define TNS_CHROMA_COMPRESSION_UYVY 2
+
 typedef struct _tnsTexture tnsTexture;
 struct _tnsTexture
 {
@@ -311,6 +314,7 @@ struct _tnsTexture
     GLuint GLTexType; //like GL_TEXTURE_2D
     int IsUIntTexture;
     int Multisample;
+    int ChromaCompression;
     int Width;
     int Height;
     int Slices;

+ 8 - 1
la_tns_kernel.c

@@ -1875,7 +1875,14 @@ void tnsUseMaskTexture(tnsTexture *t){
 void tnsUseTexture(tnsTexture *t){
     if(!t){T->StateTextureMode=0; return;}
     if(t->IsUIntTexture){ T->StateTexColor = t; T->StateTextureMode=4; return; }
-    if(t->GLTexType == GL_TEXTURE_2D){ T->StateTexColor = t; T->StateTextureMode=2; }
+    if(t->GLTexType == GL_TEXTURE_2D){
+        T->StateTexColor = t;
+        switch(t->ChromaCompression){
+            case TNS_CHROMA_COMPRESSION_YUYV: T->StateTextureMode = 101; break;
+            case TNS_CHROMA_COMPRESSION_UYVY: T->StateTextureMode = 102; break;
+            default: T->StateTextureMode = 2;
+        }
+    }
 #ifndef LAGUI_ANDROID
     else if(t->GLTexType == GL_TEXTURE_2D_MULTISAMPLE){ T->StateTexColor = t; T->StateTextureMode=3; }
 #endif

+ 27 - 1
resources/la_tns_shaders.cpp

@@ -530,6 +530,15 @@ vec3 XYZ2Clay(vec3 xyz){
 				  vec3(0.0134474,-0.1183897,1.0154096));
 	return xyz*mat;
 }
+vec3 YUV2sRGB(vec3 yuv){
+    yuv[0]=1.1643*(yuv[0]-0.0625);
+    yuv[1]-=0.5; yuv[2]-=0.5;
+	vec3 rgb;
+    rgb[0] = (yuv[0] + 1.28033 * yuv[2]);
+    rgb[1] = (yuv[0] - 0.21482 * yuv[1] - 0.38059 * yuv[2]);
+    rgb[2] = (yuv[0] + 2.12798 * yuv[1]);
+	return rgb;
+}
 
 #define htsize HalftoneSize
 vec4 rgb2cmyk(vec3 rgb){
@@ -732,7 +741,24 @@ void main(){
     }else if(TextureMode==4){
 		color=vec4(texture(TexColorUI,fUV.st))/vec4(65535.);
         if(MultiplyColor!=0){color*=fColor;}
-	}
+	}else if(TextureMode==101){ // YUYV
+		ivec2 tsize = textureSize(TexColor,0);
+		vec2 pixel = fUV.st * vec2(tsize);
+		ivec2 tpixel = ivec2(pixel);
+        vec4 yuyv = texelFetch(TexColor,tpixel,0);
+		vec3 yuv; yuv.yz=yuyv.yw;
+		if(fract(pixel.x)<=1.){ yuv.x=yuyv.x; }else{ yuv.x=yuyv.z; }
+		color=vec4(YUV2sRGB(yuv),1.0f);
+        if(MultiplyColor!=0){color*=fColor;}
+    }else if(TextureMode==102){ // UYVY
+		ivec2 tsize = textureSize(TexColor,0);
+		ivec2 tpixel = ivec2(fUV.st * vec2(tsize));
+        vec4 uyvy = texelFetch(TexColor,tpixel,0);
+		vec3 yuv; yuv.yz=uyvy.xz;
+		if((tpixel.x % 2) !=0){ yuv.x=uyvy.y; }else{ yuv.x=uyvy.w; }
+		color=vec4(YUV2sRGB(yuv),1.0f);
+        if(MultiplyColor!=0){color*=fColor;}
+    }
     if(UseNormal!=0){
 		color.a=HalftoneSingle(color.a,htsize,rad(7.),0.);
 		if(color.a==0.) discard;