Support for ASTC compressed textures wrapped in KTX files 79/54479/9
authorTom Robinson <tom.robinson@samsung.com>
Tue, 15 Dec 2015 11:34:47 +0000 (11:34 +0000)
committerTom Robinson <tom.robinson@samsung.com>
Fri, 8 Jan 2016 16:40:17 +0000 (16:40 +0000)
ASTC is supported by OpenGL ES 3.1 and above.
To build this patch with ASTC support, a GLES 31 context must be specified.

To build for desktop with configure, the gles version must be set to 31.
Here is an example configure line:
CXXFLAGS="-g -O0 -Wno-unused-local-typedefs" CXX="ccache g++" ./configure --prefix=$DESKTOP_PREFIX --enable-debug=yes --enable-profile=UBUNTU --enable-gles=31

With GBS, add the following to your gbs build line:
--define "%target_gles_version 31"

Change-Id: I4f54f894dd4b8998f16aa98d3d0a06606f0eb7a2

build/tizen/CMakeLists.txt
examples/compressed-texture-formats/compressed-texture-formats-example.cpp [new file with mode: 0644]
resources/images/tx-astc-4x4-linear.ktx [new file with mode: 0644]
resources/images/tx-astc-4x4-srgb.ktx [new file with mode: 0644]
resources/images/tx-etc1.ktx [new file with mode: 0644]

index 2f6869794dbcc1774b387b23a37da188e705a540..b7b86b78e27366a740471057da2d5623d7ec8c4a 100644 (file)
@@ -48,8 +48,9 @@ FILE(GLOB LOCAL_IMAGES_GIF RELATIVE "${LOCAL_IMAGES_DIR}" "${LOCAL_IMAGES_DIR}/*
 FILE(GLOB LOCAL_IMAGES_BMP RELATIVE "${LOCAL_IMAGES_DIR}" "${LOCAL_IMAGES_DIR}/*.bmp")
 FILE(GLOB LOCAL_IMAGES_ICO RELATIVE "${LOCAL_IMAGES_DIR}" "${LOCAL_IMAGES_DIR}/*.ico")
 FILE(GLOB LOCAL_IMAGES_WBMP RELATIVE "${LOCAL_IMAGES_DIR}" "${LOCAL_IMAGES_DIR}/*.wbmp")
+FILE(GLOB LOCAL_IMAGES_KTX RELATIVE "${LOCAL_IMAGES_DIR}" "${LOCAL_IMAGES_DIR}/*.ktx")
 
-SET(LOCAL_IMAGES_LIST ${LOCAL_IMAGES_PNG};${LOCAL_IMAGES_JPG};${LOCAL_IMAGES_GIF};${LOCAL_IMAGES_BMP};${LOCAL_IMAGES_ICO};${LOCAL_IMAGES_WBMP})
+SET(LOCAL_IMAGES_LIST ${LOCAL_IMAGES_PNG};${LOCAL_IMAGES_JPG};${LOCAL_IMAGES_GIF};${LOCAL_IMAGES_BMP};${LOCAL_IMAGES_ICO};${LOCAL_IMAGES_WBMP};${LOCAL_IMAGES_KTX})
 FOREACH(flag ${LOCAL_IMAGES_LIST})
         INSTALL(FILES ${LOCAL_IMAGES_DIR}/${flag} DESTINATION ${IMAGES_DIR})
 ENDFOREACH(flag)
diff --git a/examples/compressed-texture-formats/compressed-texture-formats-example.cpp b/examples/compressed-texture-formats/compressed-texture-formats-example.cpp
new file mode 100644 (file)
index 0000000..25d1f32
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali-toolkit/dali-toolkit.h>
+
+using namespace Dali;
+using Dali::Toolkit::TextLabel;
+
+const char* IMAGE_FILENAME_ETC         = DALI_IMAGE_DIR "tx-etc1.ktx";
+const char* IMAGE_FILENAME_ASTC_LINEAR = DALI_IMAGE_DIR "tx-astc-4x4-linear.ktx";
+const char* IMAGE_FILENAME_ASTC_SRGB   = DALI_IMAGE_DIR "tx-astc-4x4-srgb.ktx";
+
+/**
+ * @brief This example shows 3 images, each of a different compressed texture type.
+ * If built and run on a OpenGL ES 3.1 compatable target, then all 3 images will display.
+ * Otherwise, the top image will display and the other 2 will appear as black squares.
+ */
+class CompressedTextureFormatsController : public ConnectionTracker
+{
+public:
+
+  CompressedTextureFormatsController( Application& application )
+  : mApplication( application )
+  {
+    // Connect to the Application's Init signal
+    mApplication.InitSignal().Connect( this, &CompressedTextureFormatsController::Create );
+  }
+
+  ~CompressedTextureFormatsController()
+  {
+    // Nothing to do here;
+  }
+
+  // The Init signal is received once (only) during the Application lifetime
+  void Create( Application& application )
+  {
+    // Get a handle to the stage
+    Stage stage = Stage::GetCurrent();
+    stage.SetBackgroundColor( Color::WHITE );
+
+    // Setup a TableView to hold a grid of images and labels.
+    Toolkit::TableView table = Toolkit::TableView::New( 3u, 2u );
+    table.SetAnchorPoint( AnchorPoint::CENTER );
+    table.SetParentOrigin( ParentOrigin::CENTER );
+    table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    table.SetFitHeight( 0u );
+    table.SetFitHeight( 1u );
+    table.SetFitHeight( 2u );
+    table.SetRelativeWidth( 0u, 0.5f );
+    table.SetRelativeWidth( 1u, 0.5f );
+
+    // Add text labels.
+    TextLabel textLabel = TextLabel::New( "ETC1:" );
+    textLabel.SetAnchorPoint( AnchorPoint::CENTER );
+    textLabel.SetParentOrigin( ParentOrigin::CENTER );
+    table.AddChild( textLabel, Toolkit::TableView::CellPosition( 0u, 0u ) );
+    table.SetCellAlignment( Toolkit::TableView::CellPosition( 0u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
+
+    textLabel = TextLabel::New( "ASTC 4x4 linear:" );
+    textLabel.SetAnchorPoint( AnchorPoint::CENTER );
+    textLabel.SetParentOrigin( ParentOrigin::CENTER );
+    table.AddChild( textLabel, Toolkit::TableView::CellPosition( 1u, 0u ) );
+    table.SetCellAlignment( Toolkit::TableView::CellPosition( 1u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
+
+    textLabel = TextLabel::New( "ASTC 4x4 sRGB:" );
+    textLabel.SetAnchorPoint( AnchorPoint::CENTER );
+    textLabel.SetParentOrigin( ParentOrigin::CENTER );
+    table.AddChild( textLabel, Toolkit::TableView::CellPosition( 2u, 0u ) );
+    table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
+
+    // Add images.
+    Toolkit::ImageView imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ETC ) );
+    imageView.SetAnchorPoint( AnchorPoint::CENTER );
+    imageView.SetParentOrigin( ParentOrigin::CENTER );
+    table.AddChild( imageView, Toolkit::TableView::CellPosition( 0u, 1u ) );
+
+    imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ASTC_LINEAR ) );
+    imageView.SetAnchorPoint( AnchorPoint::CENTER );
+    imageView.SetParentOrigin( ParentOrigin::CENTER );
+    table.AddChild( imageView, Toolkit::TableView::CellPosition( 1u, 1u ) );
+
+    imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ASTC_SRGB ) );
+    imageView.SetAnchorPoint( AnchorPoint::CENTER );
+    imageView.SetParentOrigin( ParentOrigin::CENTER );
+    table.AddChild( imageView, Toolkit::TableView::CellPosition( 2u, 1u ) );
+
+    stage.Add( table );
+
+    // Respond to a click anywhere on the stage
+    stage.GetRootLayer().TouchedSignal().Connect( this, &CompressedTextureFormatsController::OnTouch );
+  }
+
+  bool OnTouch( Actor actor, const TouchEvent& touch )
+  {
+    // quit the application
+    mApplication.Quit();
+    return true;
+  }
+
+private:
+  Application&  mApplication;
+};
+
+void RunTest( Application& application )
+{
+  CompressedTextureFormatsController test( application );
+
+  application.MainLoop();
+}
+
+// Entry point for Linux & Tizen applications
+//
+int main( int argc, char **argv )
+{
+  Application application = Application::New( &argc, &argv );
+
+  RunTest( application );
+
+  return 0;
+}
diff --git a/resources/images/tx-astc-4x4-linear.ktx b/resources/images/tx-astc-4x4-linear.ktx
new file mode 100644 (file)
index 0000000..1c310ca
Binary files /dev/null and b/resources/images/tx-astc-4x4-linear.ktx differ
diff --git a/resources/images/tx-astc-4x4-srgb.ktx b/resources/images/tx-astc-4x4-srgb.ktx
new file mode 100644 (file)
index 0000000..40e575a
Binary files /dev/null and b/resources/images/tx-astc-4x4-srgb.ktx differ
diff --git a/resources/images/tx-etc1.ktx b/resources/images/tx-etc1.ktx
new file mode 100644 (file)
index 0000000..68f1081
Binary files /dev/null and b/resources/images/tx-etc1.ktx differ