*/}}
Browse Source

gles things

YimingWu 6 months ago
parent
commit
da35347b79
9 changed files with 69 additions and 13 deletions
  1. 4 1
      CMakeLists.txt
  2. 2 0
      la_data.c
  3. 1 0
      la_interface.h
  4. 5 3
      la_kernel.c
  5. 4 1
      la_tns.h
  6. 40 3
      la_tns_kernel.c
  7. 2 2
      la_util.c
  8. 4 0
      la_util.h
  9. 7 3
      resources/la_tns_shaders.cpp

+ 4 - 1
CMakeLists.txt

@@ -17,7 +17,7 @@ endif()
 
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
 
-if(${LAGUI_ANDROID} EQUAL True)
+if(NOT (${LAGUI_ANDROID}))
     find_package(OpenGL REQUIRED)
     find_package(X11 REQUIRED)
     find_package(Freetype REQUIRED)
@@ -46,10 +46,13 @@ find_package(Threads REQUIRED)
 
 add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
 add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
+
+if((${LAGUI_ANDROID}))
 add_compile_options(-fpermissive
     -Wno-error=incompatible-function-pointer-types
     -Wno-error=int-conversion
 )
+endif()
 
 file(GLOB SOURCE_FILES 
 	./*.c ./*.cpp ./resources/*.c ./resources/*.cpp)

+ 2 - 0
la_data.c

@@ -3917,6 +3917,8 @@ void laRefreshUDFResourcesIn(char* rootpath){
     struct dirent **NameList=0;
     NumFiles=scandir(rootpath,&NameList,0,alphasort);
 
+    logPrintNew("%d %s",NumFiles,rootpath);
+
     for(int i=0;i<NumFiles;i++){
         struct dirent* d = NameList[i]; int dlen;
         char *format = strGetLastSegment(d->d_name, '.'); int file_okay=0;

+ 1 - 0
la_interface.h

@@ -2125,6 +2125,7 @@ void laui_LinkerSelectionInstance(laUiList *uil, laPropPack *Base, laPropPack *O
 void laui_DefaultOperatorPanelTitleBar(laUiList *uil, laPropPack *Base, laPropPack *OperatorInst, laColumn *ExtraColumns, int context);
 void laui_ColumnItem(laUiList *uil, laPropPack *Base, laPropPack *UNUSED_This, laColumn *UNUSED_Colums, int context);
 void laui_DefaultMenuButtonsFileEntries(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context);
+void laui_DefaultMenuButtonsEditEntries(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context);
 void laui_DefaultMenuButtonsOptionEntries(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context);
 void laui_DefaultMenuButtons(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context);
 void laui_DefaultMenuExtras(laUiList *uil, laPropPack *pp, laPropPack *actinst, laColumn *extracol, int context);

+ 5 - 3
la_kernel.c

@@ -468,6 +468,9 @@ void la_DestroySystemWindowWin32(laWindow* w) {
 SYSWINDOW la_CreateWindowAndroid(){
     return 0;
 };
+
+void laShowCursor(){}
+void laHideCursor(){}
 #endif
 
 #ifdef LA_LINUX
@@ -1067,7 +1070,8 @@ int laGetReadyWith(laInitArguments* ia){
 
     eglBindAPI(EGL_OPENGL_ES_API);
     static const EGLint ctx_attribs[] = {
-        EGL_CONTEXT_CLIENT_VERSION, 2,
+        EGL_CONTEXT_CLIENT_VERSION, 3,
+        EGL_CONTEXT_MINOR_VERSION, 2,
         EGL_NONE
     };
     MAIN.glc = eglCreateContext(MAIN.egl_dpy, MAIN.BestFBC, EGL_NO_CONTEXT, ctx_attribs);
@@ -3976,7 +3980,6 @@ void laRedrawAllWindows(){ if((!MAIN.CurrentWindow) || (!MAIN.CurrentWindow->win
     laWindow* cur=MAIN.CurrentWindow;
     for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
         MAIN.CurrentWindow=w;
-    __android_log_print(ANDROID_LOG_DEBUG, "huh 5678", "call redraw");
         la_UpdateUiPlacement(w);
     }
     MAIN.CurrentWindow=cur;
@@ -8031,7 +8034,6 @@ void la_PrintOperatorStack(){
 
 void la_DrawWindow(laWindow *w){
     if(!w->Redraw) return; w->Redraw=0; w->RedrawTouched=1;
-    __android_log_print(ANDROID_LOG_DEBUG, "huh draw", "123 draw");
     MAIN.CurrentWindow = w;
     la_WindowDefDraw(w, 0);
 }

+ 4 - 1
la_tns.h

@@ -101,7 +101,7 @@ struct _tnsShader{
     int iUseNormal;
 
     int iTexColor,iTexNormal,iTexGPos;
-    int iTexColorMS;
+    int iTexColorMS,iTexColorU;
     int iMultiplyColor, StateMultiplyColor;
     int iTextureMode, StateTextureMode, iColorMode,iHCYGamma;
     int iSampleAmount, StateSampleAmount;
@@ -309,6 +309,7 @@ struct _tnsTexture
     GLuint GLTexHandle;
     GLint GLTexBitsType; //like GL_RGBA
     GLuint GLTexType; //like GL_TEXTURE_2D
+    int IsUIntTexture;
     int Multisample;
     int Width;
     int Height;
@@ -1411,6 +1412,8 @@ void tnsDraw2DTextureArg(tnsTexture *t,
                          real *MultiplyColor,
                          real LPadding, real RPadding, real TPadding, real BPadding);
 
+void tnsGet2DTextureSubImage(tnsTexture* t, int xoffset, int yoffset, uint32_t width, uint32_t height, int format, int type, size_t bufSize, void *pixels);
+
 int tnsTextureMemorySize(tnsTexture *t, int mem);
 
 void tnsDelete2DOffscreen(tnsOffscreen *o);

+ 40 - 3
la_tns_kernel.c

@@ -29,6 +29,33 @@
 
 #define HF 0.5
 
+#ifdef LA_USE_GLES
+void la_glUniform1f(int location, float v0){
+    glUniform1fv(location,1,&v0);
+}
+#endif
+
+void tnsGet2DTextureSubImage(tnsTexture* t, int xoffset, int yoffset, uint32_t width, uint32_t height, int format, int type, size_t bufSize, void *pixels){
+    int texture=t->GLTexHandle;
+#ifdef LA_USE_GLES
+    int offscreen_framebuffer;
+    glGenFramebuffers(1, &offscreen_framebuffer);
+    glBindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer);
+    glBindTexture(GL_TEXTURE_2D, texture);
+    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
+    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+    if(status != GL_FRAMEBUFFER_COMPLETE) {
+        logPrint("Failed to make complete framebuffer object in la_glGetTextureSubImage()", status);
+    }
+    glBindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer);
+    glViewport(0, 0, t->Width, t->Height);
+    glReadPixels(0, 0, width, height, format, type, pixels);
+#else
+    glGetTextureSubImage(texture,0,xoffset,yoffset,0,width,height,1,format,type,bufSize,pixels);
+#endif
+}
+
+
 //  1  2
 // 7 9 11     13  14
 //  3  4
@@ -285,9 +312,13 @@ void tnsShaderMakeIndex(tnsShader *tns){
     tns->iUV = glGetAttribLocation(program, "vUV");
 
     tns->iTexColor = glGetUniformLocation(program, "TexColor");
+    tns->iTexColorU = glGetUniformLocation(program, "TexColorUI");
+    tns->iTexColorMS = glGetUniformLocation(program, "TexColorMS");
+    if(tns->iTexColor>=0){glUniform1i(tns->iTexColor, 0);}
+    if(tns->iTexColorMS>=0){glUniform1i(tns->iTexColorMS, 1);}
+    if(tns->iTexColorU>=0){glUniform1i(tns->iTexColorU, 2);}
     tns->iTexNormal = glGetUniformLocation(program, "TexNormal");
     tns->iTexGPos = glGetUniformLocation(program, "TexGPos");
-    tns->iTexColorMS = glGetUniformLocation(program, "TexColorMS");
     tns->iMultiplyColor = glGetUniformLocation(program, "MultiplyColor");
     tns->iTextureMode = glGetUniformLocation(program, "TextureMode");
     tns->iColorMode = glGetUniformLocation(program, "ColorMode");
@@ -300,8 +331,6 @@ void tnsShaderMakeIndex(tnsShader *tns){
     tns->iComposing=glGetUniformLocation(program, "Composing");
     tns->iComposingGamma=glGetUniformLocation(program, "ComposingGamma");
     tns->iComposingBlackpoint=glGetUniformLocation(program, "ComposingBlackpoint");
-    if(tns->iTexColor>=0){glUniform1i(tns->iTexColor, 0);}
-    if(tns->iTexColorMS>=0){glUniform1i(tns->iTexColorMS, 1);}
     tns->iDoOffset = glGetUniformLocation(program, "DoOffset");
     tns->iUseHalftone = glGetUniformLocation(program, "UseHalftone");
     tns->iHalftoneSize = glGetUniformLocation(program, "HalftoneSize");
@@ -1740,12 +1769,17 @@ void tnsConfigure2DTexture(tnsTexture *t){
             t->GLTexBitsType==GL_DEPTH_COMPONENT24||t->GLTexBitsType==GL_DEPTH_COMPONENT32F;
         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_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;}
         if(t->Multisample) glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, t->Multisample, t->GLTexBitsType, t->Width, t->Height, GL_TRUE);
 #endif
         else{ glTexImage2D(GL_TEXTURE_2D, 0, t->GLTexBitsType, t->Width, t->Height, 0, format, type, 0);
+            if(t->IsUIntTexture){
+                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);
@@ -1839,6 +1873,7 @@ 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; }
 #ifndef LAGUI_ANDROID
     else if(t->GLTexType == GL_TEXTURE_2D_MULTISAMPLE){ T->StateTexColor = t; T->StateTextureMode=3; }
@@ -1869,6 +1904,7 @@ void tnsActiveTexture(GLenum tex){
 }
 void tnsBindTexture(tnsTexture *t){
     if ((!t) || T->TexColor==t) return;
+    if(t->IsUIntTexture){ tnsActiveTexture(GL_TEXTURE2); glBindTexture(t->GLTexType, t->GLTexHandle); T->TexColor=t; return; }
     if(t->GLTexType == GL_TEXTURE_2D){ tnsActiveTexture(GL_TEXTURE0); glBindTexture(t->GLTexType, t->GLTexHandle); T->TexColor=t;}
 #ifndef LAGUI_ANDROID
     elif(t->GLTexType == GL_TEXTURE_2D_MULTISAMPLE){ tnsActiveTexture(GL_TEXTURE1); glBindTexture(t->GLTexType, t->GLTexHandle); T->TexColor=t;}
@@ -1883,6 +1919,7 @@ void tnsUnbindTexture(){
     if(T->TexRenderbuffer){ if(T->TexRenderbuffer->GLTexType == GL_RENDERBUFFER){ glBindRenderbufferEXT(GL_RENDERBUFFER, 0); T->TexRenderbuffer=0;}}
 #endif
     if(T->TexColor){
+        if(T->TexColor->IsUIntTexture){ tnsActiveTexture(GL_TEXTURE2); glBindTexture(T->TexColor->GLTexType, 0); T->TexColor=0; return; }
         if(T->TexColor->GLTexType == GL_TEXTURE_2D){tnsActiveTexture(GL_TEXTURE0);}
 #ifndef LAGUI_ANDROID
         else if(T->TexColor->GLTexType == GL_TEXTURE_2D_MULTISAMPLE){tnsActiveTexture(GL_TEXTURE1);}

+ 2 - 2
la_util.c

@@ -1959,11 +1959,11 @@ void strSafeAppend(laSafeString **ss, char *Content){
     (*ss)->Ptr=mem;
 }
 void strSafePrint(laSafeString **ss, char *Format, ...){
-    char content[512]; va_list va; va_start(va, Format); vsprintf(content, Format, va); va_end(va);
+    char content[1024]; va_list va; va_start(va, Format); vsprintf(content, Format, va); va_end(va);
     strSafeAppend(ss,content);
 }
 void strSafePrintV(laSafeString **ss, char *Format, va_list args){
-    char content[512]; va_list va; vsprintf(content, Format, args);
+    char content[1024]; va_list va; vsprintf(content, Format, args);
     strSafeAppend(ss,content);
 }
 

+ 4 - 0
la_util.h

@@ -151,6 +151,10 @@ struct _##a
 #define LA_HYPER_CREATED_TIME(hi) \
 hi->TimeCreated.Year,hi->TimeCreated.Month,hi->TimeCreated.Day,hi->TimeCreated.Hour,hi->TimeCreated.Minute,hi->TimeCreated.Second
 
+#ifdef LA_USE_GLES
+#define glUniform1f la_glUniform1f // nvidia bug or something
+void la_glUniform1f(int location, float v0);
+#endif
 
 typedef double real;
 typedef unsigned long long u64bit;

+ 7 - 3
resources/la_tns_shaders.cpp

@@ -658,8 +658,9 @@ void main(){
 
 extern "C" const char* LA_IMM_FRAGMENT_SHADER = R"(#version 310 es
 precision highp float;
-uniform highp sampler2D TexColor;\
-uniform highp sampler2DMS TexColorMS;\
+uniform highp sampler2D TexColor;
+uniform highp usampler2D TexColorUI;
+uniform highp sampler2DMS TexColorMS;
 uniform int TextureMode;
 uniform int ColorMode;
 uniform int MultiplyColor;
@@ -727,7 +728,10 @@ void main(){
         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;}
-    }
+    }else if(TextureMode==4){
+		color=vec4(texture(TexColorUI,fUV.st))/vec4(65535.);
+        if(MultiplyColor!=0){color*=fColor;}
+	}
     if(UseNormal!=0){
 		color.a=HalftoneSingle(color.a,htsize,rad(7.),0.);
 		if(color.a==0.) discard;