X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fcompressed-texture-formats%2Fcompressed-texture-formats-example.cpp;h=d53b8cf96e8780b8bbfc6dccc19e0e15acf9678b;hb=a832af2813558a32f0a18747f3e6134ff6f6f301;hp=25d1f3271486844646545e2e792dac6688054816;hpb=7223cb68283116d53454b12c0cf15fda306c2172;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/compressed-texture-formats/compressed-texture-formats-example.cpp b/examples/compressed-texture-formats/compressed-texture-formats-example.cpp index 25d1f32..d53b8cf 100644 --- a/examples/compressed-texture-formats/compressed-texture-formats-example.cpp +++ b/examples/compressed-texture-formats/compressed-texture-formats-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -15,15 +15,73 @@ * */ +// EXTERNAL INCLUDES +#include #include +// INTERNAL INCLUDES +#include "shared/utility.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"; +namespace +{ + +const char* IMAGE_FILENAME_ETC = DEMO_IMAGE_DIR "tx-etc1.ktx"; +const char* IMAGE_FILENAME_ASTC_LINEAR = DEMO_IMAGE_DIR "tx-astc-4x4-linear.ktx"; +const char* IMAGE_FILENAME_ASTC_LINEAR_NATIVE = DEMO_IMAGE_DIR "tx-astc-4x4-linear-native.astc"; + + +static const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( + attribute mediump vec2 aPosition;\n + attribute mediump vec2 aTexCoord;\n + uniform mediump mat4 uMvpMatrix;\n + uniform mediump vec3 uSize;\n + varying mediump vec2 vTexCoord;\n + void main()\n + {\n + vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0);\n + gl_Position = uMvpMatrix * position;\n + vTexCoord = aTexCoord;\n + }\n +); + +static const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( + uniform lowp vec4 uColor;\n + uniform sampler2D sTexture;\n + varying mediump vec2 vTexCoord;\n + + void main()\n + {\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n + }\n +); + +/** + * @brief Create a renderer to render an image and adds it to an actor + * @param[in] imagePath The path where the image file is located + * @param[in] actor The actor that will be used to render the image + * @param[in[ geometry The geometry to use + * @param[in] shader The shader to use + */ +void AddImage( const char*imagePath, Actor& actor, Geometry& geometry, Shader& shader ) +{ + //Load the texture + Texture texture = DemoHelper::LoadTexture( imagePath ); + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture( 0u, texture ); + + //Create the renderer + Renderer renderer = Renderer::New( geometry, shader ); + renderer.SetTextures( textureSet ); + + //Set actor size and add the renderer + actor.SetSize( texture.GetWidth(), texture.GetHeight() ); + actor.AddRenderer( renderer ); +} +} /** * @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. @@ -57,60 +115,89 @@ public: 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 ); + table.SetRelativeHeight( 0u, 1.0f / 3.0f ); + table.SetRelativeHeight( 1u, 1.0f / 3.0f ); + table.SetRelativeHeight( 2u, 1.0f / 3.0f ); + // Add text labels. - TextLabel textLabel = TextLabel::New( "ETC1:" ); + TextLabel textLabel = TextLabel::New( "ETC1 (KTX):" ); textLabel.SetAnchorPoint( AnchorPoint::CENTER ); textLabel.SetParentOrigin( ParentOrigin::CENTER ); + textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); 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 = TextLabel::New( "ASTC (KTX) 4x4 linear:" ); textLabel.SetAnchorPoint( AnchorPoint::CENTER ); textLabel.SetParentOrigin( ParentOrigin::CENTER ); + textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); 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 = TextLabel::New( "ASTC (Native) 4x4 linear:" ); textLabel.SetAnchorPoint( AnchorPoint::CENTER ); textLabel.SetParentOrigin( ParentOrigin::CENTER ); + textLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + textLabel.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); 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 ) ); + //Create the geometry and the shader renderers will use + Geometry geometry = DemoHelper::CreateTexturedQuad(); + Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); - 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 ) ); + // Add images. + Actor actor = Actor::New(); + actor.SetAnchorPoint( AnchorPoint::CENTER ); + actor.SetParentOrigin( ParentOrigin::CENTER ); + AddImage( IMAGE_FILENAME_ETC, actor, geometry, shader ); + table.AddChild( actor, Toolkit::TableView::CellPosition( 0u, 1u ) ); + table.SetCellAlignment( Toolkit::TableView::CellPosition( 0u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + + actor = Actor::New(); + actor.SetAnchorPoint( AnchorPoint::CENTER ); + actor.SetParentOrigin( ParentOrigin::CENTER ); + AddImage( IMAGE_FILENAME_ASTC_LINEAR, actor, geometry, shader ); + table.AddChild( actor, Toolkit::TableView::CellPosition( 1u, 1u ) ); + table.SetCellAlignment( Toolkit::TableView::CellPosition( 1u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); + + actor = Actor::New(); + actor.SetAnchorPoint( AnchorPoint::CENTER ); + actor.SetParentOrigin( ParentOrigin::CENTER ); + AddImage( IMAGE_FILENAME_ASTC_LINEAR_NATIVE, actor, geometry, shader ); + table.AddChild( actor, Toolkit::TableView::CellPosition( 2u, 1u ) ); + table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER ); stage.Add( table ); - // Respond to a click anywhere on the stage - stage.GetRootLayer().TouchedSignal().Connect( this, &CompressedTextureFormatsController::OnTouch ); + // Respond to touch and key signals + stage.GetRootLayer().TouchSignal().Connect( this, &CompressedTextureFormatsController::OnTouch ); + stage.KeyEventSignal().Connect(this, &CompressedTextureFormatsController::OnKeyEvent); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch( Actor actor, const TouchData& touch ) { // quit the application mApplication.Quit(); return true; } + void OnKeyEvent(const KeyEvent& event) + { + if(event.state == KeyEvent::Down) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) + { + mApplication.Quit(); + } + } + } + private: Application& mApplication; }; @@ -124,7 +211,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv );