*/}}
Browse Source

Use nearest filter for integer textures

YimingWu 3 months ago
parent
commit
d9c25e0c0f
3 changed files with 21 additions and 14 deletions
  1. 1 1
      la_kernel.c
  2. 18 12
      la_tns_kernel.c
  3. 2 1
      resources/la_tns_shaders.cpp

+ 1 - 1
la_kernel.c

@@ -489,7 +489,7 @@ void la_glDebugOutput(GLenum source, GLenum type, unsigned int id,
     GLenum severity, GLsizei length, const char* message, const void* userParam) {
 //#ifndef LAGUI_ANDROID
     // ignore non-significant error/warning codes
-    if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076) return;
+    if (id==131169 || id==131185 || id==131218 || id==131204 || id==131076 || id==7||id==8) return;
 
     logPrint("GL %d: %s\n", id, message);
 

+ 18 - 12
la_tns_kernel.c

@@ -405,10 +405,11 @@ int tnsNewVertexShader(char *Content){
     glCompileShader(VertexShaderObject);
     glGetShaderiv(VertexShaderObject, GL_COMPILE_STATUS, &status);
     if (status == GL_FALSE){
-        glGetShaderInfoLog(VertexShaderObject, sizeof(error), 0, error);
-        printf("Vertex shader error:\n%s", error);
+        glGetShaderInfoLog(VertexShaderObject, sizeof(error), 0, error); logPrint("Vertex shader error:\n%s", error);
         glDeleteShader(VertexShaderObject); free(UseContent);
         return -1;
+    } else {
+        glGetShaderInfoLog(VertexShaderObject, sizeof(error), 0, error); if(error[0]) logPrint("Vertex shader info:\n%s", error);
     }
     free(UseContent);
 
@@ -429,10 +430,11 @@ int tnsNewFragmentShaderMaterial(char *Content, char* Library, char* Material){
     glCompileShader(FragmentShaderObject);
     glGetShaderiv(FragmentShaderObject, GL_COMPILE_STATUS, &status);
     if (status == GL_FALSE){
-        glGetShaderInfoLog(FragmentShaderObject, sizeof(error), 0, error);
-        printf("Fragment shader error:\n%s", error);
+        glGetShaderInfoLog(FragmentShaderObject, sizeof(error), 0, error); logPrint("Fragment shader error:\n%s", error);
         glDeleteShader(FragmentShaderObject); free(UseContent);
         return -1;
+    } else {
+        glGetShaderInfoLog(FragmentShaderObject, sizeof(error), 0, error); if (error[0]) logPrint("Fragment shader info:\n%s", error);
     }
     free(UseContent);
 
@@ -457,10 +459,11 @@ int tnsNewGeometryShader(char *Content){
     glCompileShader(GeometryShaderObject);
     glGetShaderiv(GeometryShaderObject, GL_COMPILE_STATUS, &status);
     if (status == GL_FALSE){
-        glGetShaderInfoLog(GeometryShaderObject, sizeof(error), 0, error);
-        printf("Geometry shader error:\n%s", error);
+        glGetShaderInfoLog(GeometryShaderObject, sizeof(error), 0, error); logPrint("Geometry shader error:\n%s", error);
         glDeleteShader(GeometryShaderObject); free(UseContent);
         return -1;
+    } else {
+        glGetShaderInfoLog(GeometryShaderObject, sizeof(error), 0, error); if(error[0]) logPrint("Geometry shader info:\n%s", error);
     }
     free(UseContent);
     
@@ -1466,7 +1469,7 @@ void tnsQuit(){
 void tnsRestoreFromNanoVG(){
     glBindVertexArray(T->CurrentVAO);
     tnsUseImmShader(); tnsEnableShaderv(T->immShader);
-	glActiveTexture(GL_TEXTURE0);
+    glActiveTexture(GL_TEXTURE0); tnsActiveTexture(GL_TEXTURE0);
     glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
 }
 
@@ -1770,8 +1773,9 @@ void tnsConfigure2DTexture(tnsTexture *t){
         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=isDepth?GL_UNSIGNED_INT:GL_UNSIGNED_BYTE;
         if(t->GLTexBitsType==GL_RGBA16UI){ format=GL_RGBA_INTEGER; type=GL_UNSIGNED_SHORT; t->IsUIntTexture=1; }
-        if(t->GLTexBitsType==GL_RGBA16F){ format=GL_RGBA; type=GL_FLOAT; }
+        if(t->GLTexBitsType==GL_RGBA32UI){ format=GL_RGBA_INTEGER; type=GL_UNSIGNED_INT; t->IsUIntTexture=1; }
         if(t->GLTexBitsType==GL_R32UI){ format=GL_RED_INTEGER; type=GL_UNSIGNED_INT; t->IsUIntTexture=1; }
+        if(t->GLTexBitsType==GL_RGBA16F){ format=GL_RGBA; type=GL_FLOAT; }
         if(t->GLTexBitsType==GL_DEPTH_STENCIL){ format=GL_DEPTH_STENCIL; type=GL_UNSIGNED_INT_24_8; t->GLTexBitsType=GL_DEPTH24_STENCIL8; }
 #ifndef LAGUI_ANDROID
         if(isDepth){t->GLTexBitsType=GL_DEPTH_COMPONENT24; type=GL_UNSIGNED_INT;}
@@ -1782,10 +1786,12 @@ void tnsConfigure2DTexture(tnsTexture *t){
                 glTexStorage2D(GL_TEXTURE_2D, 1,t->GLTexBitsType,t->Width, t->Height);
             }
             int a=glGetError();
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+            int clamp = GL_CLAMP_TO_EDGE;
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp);
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp);
+            int filter = GL_LINEAR; if (t->IsUIntTexture) { filter = GL_NEAREST; }
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
             //glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
         }
     }

+ 2 - 1
resources/la_tns_shaders.cpp

@@ -666,11 +666,12 @@ void main(){
 })";
 
 extern "C" const char* LA_IMM_FRAGMENT_SHADER = R"(#version 310 es
+
 precision highp float;
 precision highp int;
 uniform highp sampler2D TexColor;
-uniform highp usampler2D TexColorUI;
 uniform highp sampler2DMS TexColorMS;
+uniform highp usampler2D TexColorUI;
 uniform int TextureMode;
 uniform int ColorMode;
 uniform int MultiplyColor;