Browse Source

adding etc2 compression

[email protected] 7 years ago
parent
commit
302f21256e

+ 1 - 0
examples/Demo/build_atlasses_etc2.bat

@@ -0,0 +1 @@
+..\..\tools\oxyresbuild -x xmls/res.xml --src_data data --dest_data data --compress etc2 -q best

+ 5 - 0
oxygine/src/oxygine/Image.cpp

@@ -626,6 +626,11 @@ namespace oxygine
                         case 6:
                         case 6:
                             tf = TF_ETC1;
                             tf = TF_ETC1;
                             break;
                             break;
+                        case 23:
+                            tf = TF_ETC2;
+                            break;
+                        default:
+                            OX_ASSERT(!"unknown header format");
                     }
                     }
                     _image.format = tf;
                     _image.format = tf;
                     _offset = sizeof(*header) + header->meta_data_size;
                     _offset = sizeof(*header) + header->meta_data_size;

+ 5 - 0
oxygine/src/oxygine/core/ImageData.cpp

@@ -32,6 +32,7 @@ namespace oxygine
             case TF_PVRTCII_2:
             case TF_PVRTCII_2:
             case TF_PVRTCII_4:
             case TF_PVRTCII_4:
             case TF_ETC1:
             case TF_ETC1:
+            case TF_ETC2:
                 return 0;
                 return 0;
             case TF_UNDEFINED:
             case TF_UNDEFINED:
                 return 0;
                 return 0;
@@ -52,6 +53,7 @@ namespace oxygine
             case TF_PVRTCII_2:
             case TF_PVRTCII_2:
             case TF_PVRTCII_4:
             case TF_PVRTCII_4:
             case TF_ETC1:
             case TF_ETC1:
+            case TF_ETC2:
                 return true;
                 return true;
             default:
             default:
                 break;
                 break;
@@ -77,6 +79,7 @@ namespace oxygine
         CMP(PVRTCII_2, 0);
         CMP(PVRTCII_2, 0);
         CMP(PVRTCII_4, 0);
         CMP(PVRTCII_4, 0);
         CMP(ETC1, 0);
         CMP(ETC1, 0);
+        CMP(ETC2, 0);
 #undef  CMP
 #undef  CMP
         OX_ASSERT(!"string2TextureFormat undefined format");
         OX_ASSERT(!"string2TextureFormat undefined format");
         return TF_UNDEFINED;
         return TF_UNDEFINED;
@@ -116,6 +119,8 @@ namespace oxygine
                 return "PVRTCII_4";
                 return "PVRTCII_4";
             case TF_ETC1:
             case TF_ETC1:
                 return "ETC1";
                 return "ETC1";
+            case TF_ETC2:
+                return "ETC2";
             case TF_UNDEFINED:
             case TF_UNDEFINED:
                 return "undefined";
                 return "undefined";
             default:
             default:

+ 1 - 0
oxygine/src/oxygine/core/ImageData.h

@@ -25,6 +25,7 @@ namespace oxygine
         TF_PVRTCII_2,
         TF_PVRTCII_2,
         TF_PVRTCII_4,
         TF_PVRTCII_4,
         TF_ETC1,
         TF_ETC1,
+        TF_ETC2,
     };
     };
 
 
 #define ALL_FORMATS_SWITCH(format) \
 #define ALL_FORMATS_SWITCH(format) \

+ 9 - 0
oxygine/src/oxygine/core/gl/NativeTextureGLES.cpp

@@ -7,6 +7,10 @@
 #include "../log.h"
 #include "../log.h"
 #include <stdio.h>
 #include <stdio.h>
 
 
+#ifndef GL_COMPRESSED_RGBA8_ETC2_EAC
+#   define GL_COMPRESSED_RGBA8_ETC2_EAC      0x9278
+#endif
+
 namespace oxygine
 namespace oxygine
 {
 {
     struct glPixel
     struct glPixel
@@ -77,6 +81,11 @@ namespace oxygine
                 pixel.type = 0;
                 pixel.type = 0;
                 pixel.compressed = true;
                 pixel.compressed = true;
                 break;
                 break;
+            case TF_ETC2:
+                pixel.format = GL_COMPRESSED_RGBA8_ETC2_EAC;
+                pixel.type = 0;
+                pixel.compressed = true;
+                break;
             default:
             default:
                 logs::error("unknown format: %d\n", format);
                 logs::error("unknown format: %d\n", format);
                 OX_ASSERT(!"unknown format");
                 OX_ASSERT(!"unknown format");

+ 1 - 0
oxygine/src/oxygine/core/gl/oxgl.h

@@ -14,6 +14,7 @@
 
 
 #   define GL_ETC1_RGB8_OES                                        0x8D64
 #   define GL_ETC1_RGB8_OES                                        0x8D64
 
 
+
 extern "C"
 extern "C"
 {
 {
 //!--pfngl-begin--!
 //!--pfngl-begin--!

+ 3 - 0
oxygine/src/oxygine/dev_tools/TexturesInspector.cpp

@@ -155,6 +155,9 @@ namespace oxygine
                         case TF_ETC1:
                         case TF_ETC1:
                             ram /= 2;
                             ram /= 2;
                             break;
                             break;
+                        case TF_ETC2:
+                            ram /= 2;
+                            break;
                         default:
                         default:
                             break;
                             break;
                     }
                     }

+ 1 - 1
tools/oxyresbuild.py

@@ -48,7 +48,7 @@ def get_parser():
                         action="store_true", default=False)
                         action="store_true", default=False)
     parser.add_argument("-c", "--compression", help="type of image "
     parser.add_argument("-c", "--compression", help="type of image "
                         "compression. Defaults to pure rgba8888 packed to png",
                         "compression. Defaults to pure rgba8888 packed to png",
-                        choices=["pvrtc", "pvrtc2", "etc1", "no"], default="")
+                        choices=["pvrtc", "pvrtc2", "etc1", "etc2", "no"], default="")
     parser.add_argument("--npot", help="Atlasses dimensions are not power of twos",
     parser.add_argument("--npot", help="Atlasses dimensions are not power of twos",
                         action="store_true", default=False)
                         action="store_true", default=False)
     parser.add_argument("-q", "--quality", help="select quality to "
     parser.add_argument("-q", "--quality", help="select quality to "

+ 9 - 4
tools/resbuild/process_atlas.py

@@ -694,16 +694,21 @@ class atlas_Processor(process.Process):
                 if context.compression == "pvrtc":
                 if context.compression == "pvrtc":
                     ox_fmt = "PVRTC_4RGBA"
                     ox_fmt = "PVRTC_4RGBA"
 
 
-                    compress(path, context.get_inner_dest(
-                        base_name + ".pvr"), "PVRTC1_4")
+                    compress(path, context.get_inner_dest(base_name + ".pvr"), "PVRTC1_4")
                     image_atlas_el.setAttribute("file", base_name + ".pvr")
                     image_atlas_el.setAttribute("file", base_name + ".pvr")
                     os.remove(path)
                     os.remove(path)
 
 
                 if context.compression == "pvrtc2":
                 if context.compression == "pvrtc2":
                     ox_fmt = "PVRTC2_4RGBA"
                     ox_fmt = "PVRTC2_4RGBA"
 
 
-                    compress(path, context.get_inner_dest(
-                        base_name + ".pvr"), "PVRTC2_4")
+                    compress(path, context.get_inner_dest(base_name + ".pvr"), "PVRTC2_4")
+                    image_atlas_el.setAttribute("file", base_name + ".pvr")
+                    os.remove(path)
+
+                if context.compression == "etc2":
+                    ox_fmt = "etc2"
+
+                    compress(path, context.get_inner_dest(base_name + ".pvr"), "ETC2_RGBA")
                     image_atlas_el.setAttribute("file", base_name + ".pvr")
                     image_atlas_el.setAttribute("file", base_name + ".pvr")
                     os.remove(path)
                     os.remove(path)