diff --git a/.gitignore b/.gitignore index 9a6f694..4f0ee13 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ dali-builder /packaging/home* *.mo demo-theme.json +simple-image-wall.js diff --git a/build/tizen/CMakeLists.txt b/build/tizen/CMakeLists.txt index 8a05b1f..11b2fec 100644 --- a/build/tizen/CMakeLists.txt +++ b/build/tizen/CMakeLists.txt @@ -76,7 +76,7 @@ FOREACH(flag ${LOCAL_MODELS_LIST}) INSTALL(FILES ${LOCAL_MODELS_DIR}/${flag} DESTINATION ${MODELS_DIR}) ENDFOREACH(flag) -FILE(GLOB LOCAL_SCRIPTS_LIST RELATIVE "${LOCAL_SCRIPTS_DIR}" "${LOCAL_SCRIPTS_DIR}/*") +FILE(GLOB LOCAL_SCRIPTS_LIST RELATIVE "${LOCAL_SCRIPTS_DIR}" "${LOCAL_SCRIPTS_DIR}/*.json") FOREACH(flag ${LOCAL_SCRIPTS_LIST}) INSTALL(FILES ${LOCAL_SCRIPTS_DIR}/${flag} DESTINATION ${SCRIPTS_DIR}) ENDFOREACH(flag) @@ -85,6 +85,8 @@ ENDFOREACH(flag) SET(DEMO_STYLE_IMAGE_DIR ${IMAGES_DIR}) CONFIGURE_FILE( ${LOCAL_STYLE_DIR}/demo-theme.json.in ${LOCAL_STYLE_DIR}/demo-theme.json ) INSTALL(FILES ${LOCAL_STYLE_DIR}/demo-theme.json DESTINATION ${STYLE_DIR}) +CONFIGURE_FILE( ${LOCAL_SCRIPTS_DIR}/simple-image-wall.js.in ${LOCAL_SCRIPTS_DIR}/simple-image-wall.js ) +INSTALL(FILES ${LOCAL_SCRIPTS_DIR}/simple-image-wall.js DESTINATION ${SCRIPTS_DIR}) SET(PKG_LIST dali-core dali-adaptor diff --git a/examples/benchmark/benchmark.cpp b/examples/benchmark/benchmark.cpp index e9fed0e..f4fa410 100644 --- a/examples/benchmark/benchmark.cpp +++ b/examples/benchmark/benchmark.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -15,12 +15,12 @@ * */ +// EXTERNAL INCLUDES +#include #include -#include -#include -#include -#include -#include + +// INTERNAL INCLUDES +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -183,29 +183,6 @@ const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( }\n ); - -Geometry& QuadMesh() -{ - static Geometry mesh; - if( !mesh ) - { - PropertyBuffer vertexBuffer; - Property::Map vertexFormat; - vertexFormat["aPosition"] = Property::VECTOR2; - vertexFormat["aTexCoord"] = Property::VECTOR2; - - //Create a vertex buffer for vertex positions and texture coordinates - vertexBuffer = PropertyBuffer::New( vertexFormat ); - vertexBuffer.SetData( gQuadWithTexture, 4u ); - - //Create the geometry - mesh = Geometry::New(); - mesh.AddVertexBuffer( vertexBuffer ); - mesh.SetGeometryType(Geometry::TRIANGLE_STRIP ); - } - return mesh; -} - bool gUseMesh(false); bool gUseImageActor(false); bool gNinePatch(false); @@ -213,33 +190,16 @@ unsigned int gRowsPerPage(25); unsigned int gColumnsPerPage( 25 ); unsigned int gPageCount(13); -Renderer CreateRenderer( unsigned int index ) +Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader ) { - - int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES; - static Renderer* renderers = new Renderer[numImages]; - if( !renderers[index] ) - { - //Create the renderer - Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); - - const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; - Image image = ResourceImage::New(imagePath); - TextureSet textureSet = TextureSet::New(); - textureSet.SetImage( 0u, image ); - renderers[index] = Renderer::New( QuadMesh(), shader ); - renderers[index].SetTextures( textureSet ); - renderers[index].SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); - } - return renderers[index]; -} - -Actor CreateMeshActor( unsigned int index) -{ - Renderer renderer = CreateRenderer(index); - Actor meshActor = Actor::New(); - meshActor.AddRenderer( renderer ); - return meshActor; + Renderer renderer = Renderer::New( geometry, shader ); + const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; + Texture texture = DemoHelper::LoadTexture( imagePath ); + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture( 0u, texture ); + renderer.SetTextures( textureSet ); + renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); + return renderer; } } @@ -348,15 +308,26 @@ public: void CreateMeshActors() { + unsigned int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES; + + //Create all the renderers + std::vector renderers( numImages ); + Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); + Geometry geometry = DemoHelper::CreateTexturedQuad(); + for( unsigned int i(0); i +#include #include +// INTERNAL INCLUDES +#include "shared/utility.h" + using namespace Dali; using Dali::Toolkit::TextLabel; +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. @@ -89,26 +148,37 @@ public: 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_LINEAR_NATIVE ) ); - 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 + // Respond to touch and key signals stage.GetRootLayer().TouchSignal().Connect( this, &CompressedTextureFormatsController::OnTouch ); + stage.KeyEventSignal().Connect(this, &CompressedTextureFormatsController::OnKeyEvent); } bool OnTouch( Actor actor, const TouchData& touch ) @@ -118,6 +188,17 @@ public: 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; }; diff --git a/examples/cube-transition-effect/cube-transition-effect-example.cpp b/examples/cube-transition-effect/cube-transition-effect-example.cpp index 7f50537..b50c3b0 100644 --- a/examples/cube-transition-effect/cube-transition-effect-example.cpp +++ b/examples/cube-transition-effect/cube-transition-effect-example.cpp @@ -148,15 +148,22 @@ private: /** * Callback function of cube transition completed signal * @param[in] effect The cube effect used for the transition - * @param[in] image The target Image of the completed transition + * @param[in] texture The target Texture of the completed transition */ - void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Image image ); + void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Texture image ); /** * Callback function of timer tick * The timer is used to count the image display duration in slideshow, */ bool OnTimerTick(); + /** + * Loads image, resizes it to the size of stage and creates a textue out of it + * @param[in] filepath Path to the image file + * @return New texture object + */ + Texture LoadStageFillingTexture( const char* filepath ); + private: Application& mApplication; Toolkit::Control mView; @@ -166,8 +173,8 @@ private: Vector2 mViewSize; - Image mCurrentImage; - Image mNextImage; + Texture mCurrentTexture; + Texture mNextTexture; unsigned int mIndex; bool mIsImageLoading; @@ -232,7 +239,7 @@ void CubeTransitionApp::OnInit( Application& application ) mViewSize = Stage::GetCurrent().GetSize(); // show the first image - mCurrentImage = DemoHelper::LoadStageFillingImage( IMAGES[mIndex] ); + mCurrentTexture = LoadStageFillingTexture( IMAGES[mIndex] ); //use small cubes mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New( NUM_ROWS_WAVE, NUM_COLUMNS_WAVE ); @@ -242,7 +249,7 @@ void CubeTransitionApp::OnInit( Application& application ) mCubeWaveEffect.SetSize( mViewSize ); mCubeWaveEffect.SetParentOrigin( ParentOrigin::CENTER ); - mCubeWaveEffect.SetCurrentImage( mCurrentImage ); + mCubeWaveEffect.SetCurrentTexture( mCurrentTexture ); // use big cubes mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS ); @@ -252,7 +259,7 @@ void CubeTransitionApp::OnInit( Application& application ) mCubeCrossEffect.SetSize( mViewSize ); mCubeCrossEffect.SetParentOrigin( ParentOrigin::CENTER ); - mCubeCrossEffect.SetCurrentImage( mCurrentImage ); + mCubeCrossEffect.SetCurrentTexture( mCurrentTexture ); mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New( NUM_ROWS_FOLD, NUM_COLUMNS_FOLD ); mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD ); @@ -260,7 +267,7 @@ void CubeTransitionApp::OnInit( Application& application ) mCubeFoldEffect.SetSize( mViewSize ); mCubeFoldEffect.SetParentOrigin( ParentOrigin::CENTER ); - mCubeFoldEffect.SetCurrentImage( mCurrentImage ); + mCubeFoldEffect.SetCurrentTexture( mCurrentTexture ); mViewTimer = Timer::New( VIEWINGTIME ); mViewTimer.TickSignal().Connect( this, &CubeTransitionApp::OnTimerTick ); @@ -303,11 +310,11 @@ void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) void CubeTransitionApp::GoToNextImage() { - mNextImage = DemoHelper::LoadStageFillingImage( IMAGES[ mIndex ] ); - mCurrentEffect.SetTargetImage( mNextImage ); + mNextTexture = LoadStageFillingTexture( IMAGES[ mIndex ] ); + mCurrentEffect.SetTargetTexture( mNextTexture ); mIsImageLoading = false; mCurrentEffect.StartTransition( mPanPosition, mPanDisplacement ); - mCurrentImage = mNextImage; + mCurrentTexture = mNextTexture; } bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) @@ -339,7 +346,7 @@ bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) // Set the current image to cube transition effect // only need to set at beginning or change from another effect - mCurrentEffect.SetCurrentImage( mCurrentImage ); + mCurrentEffect.SetCurrentTexture( mCurrentTexture ); return true; } @@ -365,7 +372,7 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button ) return true; } -void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Image image ) +void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Texture texture ) { if( mSlideshow ) { @@ -385,6 +392,17 @@ bool CubeTransitionApp::OnTimerTick() return false; } +Texture CubeTransitionApp::LoadStageFillingTexture( const char* filepath ) +{ + ImageDimensions dimensions( Stage::GetCurrent().GetSize().x, Stage::GetCurrent().GetSize().y ); + BitmapLoader loader = BitmapLoader::New( filepath, dimensions, FittingMode::SCALE_TO_FILL ); + loader.Load(); + PixelData pixelData = loader.GetPixelData(); + Texture texture = Texture::New( TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight() ); + texture.Upload( pixelData ); + return texture; +} + void CubeTransitionApp::OnKeyEvent(const KeyEvent& event) { if(event.state == KeyEvent::Down) diff --git a/examples/image-view/image-view-example.cpp b/examples/image-view/image-view-example.cpp index 89bd8d6..15d37e8 100644 --- a/examples/image-view/image-view-example.cpp +++ b/examples/image-view/image-view-example.cpp @@ -35,15 +35,7 @@ const char* IMAGE_PATH[] = { DEMO_IMAGE_DIR "heartsframe.9.png", }; -const char* RESOURCE_IMAGE_PATH[] = { - DEMO_IMAGE_DIR "contacts-image.png", - DEMO_IMAGE_DIR "gallery-small-27.jpg", - DEMO_IMAGE_DIR "selection-popup-bg.8.9.png", - DEMO_IMAGE_DIR "heartsframe.9.png", -}; - const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*); -const unsigned int NUM_RESOURCE_IMAGES = sizeof(RESOURCE_IMAGE_PATH) / sizeof(char*); const unsigned int COLUMNS = 3; const unsigned int ROWS = 4; @@ -59,7 +51,6 @@ class ImageViewController: public ConnectionTracker mCurrentPositionToggle( 0, 0 ), mCurrentPositionImage( 0, 0 ), mToggleOff( true ), - mUseResource( false ), mImageIdx( 1 ) { // Connect to the Application's Init signal @@ -131,14 +122,6 @@ class ImageViewController: public ConnectionTracker button2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); buttonsTable.AddChild( button2, Toolkit::TableView::CellPosition( 1, 0 ) ); - Toolkit::CheckBoxButton button3 = Toolkit::CheckBoxButton::New(); - button3.SetLabelText( "Use Resource Images" ); - button3.SetParentOrigin( ParentOrigin::CENTER ); - button3.SetAnchorPoint( AnchorPoint::CENTER ); - button3.ClickedSignal().Connect( this, &ImageViewController::UseResourceImagesClicked ); - button3.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - buttonsTable.AddChild( button3, Toolkit::TableView::CellPosition( 2, 0 ) ); - mContentLayer.Add(buttonsTable); Stage::GetCurrent().KeyEventSignal().Connect(this, &ImageViewController::OnKeyEvent); @@ -177,15 +160,7 @@ private: { Toolkit::ImageView imageView = mImageViews[ mCurrentPositionImage.columnIndex ][ mCurrentPositionImage.rowIndex ]; - if( mUseResource ) - { - ResourceImage image = ResourceImage::New( RESOURCE_IMAGE_PATH[ mImageIdx ] ); - imageView.SetImage( image ); - } - else - { - imageView.SetImage( IMAGE_PATH[ mImageIdx ] ); - } + imageView.SetImage( IMAGE_PATH[ mImageIdx ] ); ++mCurrentPositionImage.columnIndex; if( mCurrentPositionImage.columnIndex == COLUMNS ) @@ -198,8 +173,7 @@ private: mCurrentPositionImage.rowIndex = 0; ++mImageIdx; - int numImages = mUseResource ? NUM_RESOURCE_IMAGES : NUM_IMAGES; - if( mImageIdx == numImages ) + if( mImageIdx == NUM_IMAGES ) { mImageIdx = 0; } @@ -208,19 +182,6 @@ private: return true; } - bool UseResourceImagesClicked( Toolkit::Button button ) - { - mUseResource = !mUseResource; - - int numImages = mUseResource ? NUM_RESOURCE_IMAGES : NUM_IMAGES; - if( mImageIdx >= numImages ) - { - mImageIdx = 0; - } - - return true; - } - /** * Main key event handler */ @@ -248,7 +209,6 @@ private: Toolkit::TableView::CellPosition mCurrentPositionImage; bool mToggleOff; - bool mUseResource; int mImageIdx; }; diff --git a/examples/line-mesh/line-mesh-example.cpp b/examples/line-mesh/line-mesh-example.cpp index 79814a1..c61452a 100644 --- a/examples/line-mesh/line-mesh-example.cpp +++ b/examples/line-mesh/line-mesh-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -16,7 +16,7 @@ */ // EXTERNAL INCLUDES -#include +#include #include // INTERNAL INCLUDES diff --git a/examples/mesh-morph/mesh-morph-example.cpp b/examples/mesh-morph/mesh-morph-example.cpp index 9ab3b4b..7b59146 100644 --- a/examples/mesh-morph/mesh-morph-example.cpp +++ b/examples/mesh-morph/mesh-morph-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -16,7 +16,7 @@ */ // EXTERNAL INCLUDES -#include +#include #include // INTERNAL INCLUDES diff --git a/examples/mesh-sorting/mesh-sorting-example.cpp b/examples/mesh-sorting/mesh-sorting-example.cpp index a11e2e5..0b94968 100644 --- a/examples/mesh-sorting/mesh-sorting-example.cpp +++ b/examples/mesh-sorting/mesh-sorting-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -16,7 +16,7 @@ */ // EXTERNAL INCLUDES -#include +#include #include #include #include @@ -85,34 +85,6 @@ void main() } ); -Geometry CreateGeometry() -{ - // Create vertices - const float halfQuadSize = .5f; - struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; - TexturedQuadVertex texturedQuadVertexData[4] = { - { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, - { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, - { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, - { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; - - Property::Map texturedQuadVertexFormat; - texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; - texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2; - PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat ); - texturedQuadVertices.SetData( texturedQuadVertexData, 4 ); - - // Create indices - unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 }; - - // Create the geometry object - Geometry texturedQuadGeometry = Geometry::New(); - texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices ); - texturedQuadGeometry.SetIndexBuffer( &indexData[0], sizeof(indexData)/sizeof(unsigned short) ); - - return texturedQuadGeometry; -} - } // anonymous namespace // This example shows how to use a simple mesh @@ -159,7 +131,7 @@ public: application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); - mGeometry = CreateGeometry(); + mGeometry = DemoHelper::CreateTexturedQuad(); TextureSet firstTextureSet; diff --git a/examples/metaball-explosion/metaball-explosion-example.cpp b/examples/metaball-explosion/metaball-explosion-example.cpp index 5296b96..bd26be9 100644 --- a/examples/metaball-explosion/metaball-explosion-example.cpp +++ b/examples/metaball-explosion/metaball-explosion-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -15,13 +15,14 @@ * */ -//External includes +// EXTERNAL INCLUDES #include #include -//Internal includes +// INTERNAL INCLUDES #include -#include +#include +#include #include #include "shared/view.h" @@ -551,8 +552,8 @@ void MetaballExplosionController::AddRefractionImage() //Create new texture set TextureSet textureSet = TextureSet::New(); - textureSet.SetImage( 0u, mBackImage ); - textureSet.SetImage( 1u, fbo ); + TextureSetImage( textureSet, 0u, mBackImage ); + TextureSetImage( textureSet, 1u, fbo ); //Create geometry Geometry metaballGeom = CreateGeometryComposition(); diff --git a/examples/metaball-refrac/metaball-refrac-example.cpp b/examples/metaball-refrac/metaball-refrac-example.cpp index ce43545..2c86504 100644 --- a/examples/metaball-refrac/metaball-refrac-example.cpp +++ b/examples/metaball-refrac/metaball-refrac-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -16,7 +16,8 @@ */ #include -#include +#include +#include #include #include @@ -532,15 +533,15 @@ void MetaballRefracController::AddRefractionImage() //Create new texture set mTextureSetRefraction = TextureSet::New(); - mTextureSetRefraction.SetImage( 0u, mBackImage ); - mTextureSetRefraction.SetImage( 1u, mMetaballFBO ); + TextureSetImage( mTextureSetRefraction, 0u, mBackImage ); + TextureSetImage( mTextureSetRefraction, 1u, mMetaballFBO ); //Create normal shader mShaderNormal = Shader::New( METABALL_VERTEX_SHADER, FRAG_SHADER ); //Create new texture set mTextureSetNormal = TextureSet::New(); - mTextureSetNormal.SetImage( 0u, mBackImage ); + TextureSetImage( mTextureSetNormal, 0u, mBackImage ); //Create actor mCompositionActor = Actor::New( ); diff --git a/examples/native-image-source/native-image-source-example.cpp b/examples/native-image-source/native-image-source-example.cpp index 873260a..94243c9 100644 --- a/examples/native-image-source/native-image-source-example.cpp +++ b/examples/native-image-source/native-image-source-example.cpp @@ -15,15 +15,111 @@ * */ +// EXTERNAL INCLUDES #include +#include +#include +#include #include +#include + +// INTERNAL INCLUDES +#include "shared/utility.h" using namespace Dali; using namespace Toolkit; namespace { - const std::string JPG_FILENAME = DEMO_IMAGE_DIR "gallery-medium-4.jpg"; + +/** + * @brief Creates a shader used to render a native image + * @param[in] nativeImageInterface The native image interface + * @return A shader to render the native image + */ +Shader CreateShader( NativeImageInterface& nativeImageInterface ) +{ + static const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D"; + + 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 + ); + + NativeImageInterface::Extension* extension( nativeImageInterface.GetExtension() ); + if( extension ) + { + std::string fragmentShader; + + //Get custom fragment shader prefix + const char* fragmentPreFix = extension->GetCustomFragmentPreFix(); + if( fragmentPreFix ) + { + fragmentShader = fragmentPreFix; + fragmentShader += FRAGMENT_SHADER_TEXTURE; + } + else + { + fragmentShader = FRAGMENT_SHADER_TEXTURE; + } + + //Get custom sampler type name + const char* customSamplerTypename = extension->GetCustomSamplerTypename(); + if( customSamplerTypename ) + { + fragmentShader.replace( fragmentShader.find( DEFAULT_SAMPLER_TYPENAME ), strlen(DEFAULT_SAMPLER_TYPENAME), customSamplerTypename ); + } + + return Shader::New( VERTEX_SHADER_TEXTURE, fragmentShader ); + } + else + { + return Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); + } +} + +/** + * @brief Creates an actor to render a native image + * @param[in] texture The texture creates from a native image + * @param[in] nativeImageInterface The native image interface used to create the texture + * @return An actor that renders the texture + */ +Actor CreateNativeActor( Texture texture, NativeImageInterface& nativeImageInterface ) +{ + Actor actor = Actor::New(); + Geometry geometry = DemoHelper::CreateTexturedQuad(); + Shader shader = CreateShader(nativeImageInterface); + Renderer renderer = Renderer::New( geometry, shader ); + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture( 0u, texture ); + renderer.SetTextures( textureSet ); + + actor.AddRenderer( renderer ); + actor.SetSize( texture.GetWidth(), texture.GetHeight() ); + return actor; +} + +const std::string JPG_FILENAME = DEMO_IMAGE_DIR "gallery-medium-4.jpg"; } // This example shows how to create and use a NativeImageSource as the target of the render task. @@ -103,7 +199,9 @@ public: animation.Play(); // create a offscreen renderer task to render content into the native image source - FrameBufferImage targetBuffer = FrameBufferImage::New( *nativeImageSourcePtr ); + Texture nativeTexture = Texture::New( *nativeImageSourcePtr ); + FrameBuffer targetBuffer = FrameBuffer::New( nativeTexture.GetWidth(), nativeTexture.GetHeight(), FrameBuffer::COLOR ); + targetBuffer.AttachColorTexture( nativeTexture ); CameraActor cameraActor = CameraActor::New(imageSize); cameraActor.SetParentOrigin(ParentOrigin::TOP_CENTER); @@ -118,25 +216,24 @@ public: mOffscreenRenderTask.SetClearEnabled(true); mOffscreenRenderTask.SetCameraActor(cameraActor); mOffscreenRenderTask.GetCameraActor().SetInvertYAxis(true); - mOffscreenRenderTask.SetTargetFrameBuffer( targetBuffer ); + mOffscreenRenderTask.SetFrameBuffer( targetBuffer ); mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ALWAYS ); // Display the native image on the screen - NativeImage nativeImage = NativeImage::New( *nativeImageSourcePtr ); - ImageView nativeImageView = ImageView::New( nativeImage ); - nativeImageView.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - nativeImageView.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - stage.Add( nativeImageView ); + Actor nativeImageActor = CreateNativeActor( nativeTexture, *nativeImageSourcePtr ); + nativeImageActor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + nativeImageActor.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); + stage.Add( nativeImageActor ); TextLabel textLabel1 = TextLabel::New( "Resource Image" ); textLabel1.SetParentOrigin( ParentOrigin::TOP_CENTER ); textLabel1.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - nativeImageView.Add( textLabel1 ); + nativeImageActor.Add( textLabel1 ); TextLabel textLabel2 = TextLabel::New( "Native Image" ); textLabel2.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); textLabel2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - nativeImageView.Add( textLabel2 ); + nativeImageActor.Add( textLabel2 ); return false; } diff --git a/examples/new-window/new-window-example.cpp b/examples/new-window/new-window-example.cpp index a72e1de..0daf070 100644 --- a/examples/new-window/new-window-example.cpp +++ b/examples/new-window/new-window-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -15,7 +15,8 @@ */ // EXTERNAL INCLUDES -#include +#include +#include #include #include @@ -329,7 +330,8 @@ void NewWindowController::AddBlendingImageActor( Actor& parentActor ) blendActor.SetSize(140, 140); parentActor.Add(blendActor); - blendActor.GetRendererAt(0u).GetTextures().SetImage( 1u, fb2 ); + TextureSet textureSet = blendActor.GetRendererAt(0u).GetTextures(); + TextureSetImage( textureSet, 1u, fb2 ); } void NewWindowController::AddTextLabel( Actor& parentActor ) diff --git a/examples/perf-scroll/perf-scroll.cpp b/examples/perf-scroll/perf-scroll.cpp index f77d01f..ddfd9b8 100644 --- a/examples/perf-scroll/perf-scroll.cpp +++ b/examples/perf-scroll/perf-scroll.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -15,13 +15,8 @@ * */ +#include #include -#include -#include -#include -#include -#include -#include #include "shared/utility.h" @@ -186,29 +181,6 @@ const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( }\n ); - -Geometry& QuadMesh() -{ - static Geometry mesh; - if( !mesh ) - { - PropertyBuffer vertexBuffer; - Property::Map vertexFormat; - vertexFormat["aPosition"] = Property::VECTOR2; - vertexFormat["aTexCoord"] = Property::VECTOR2; - - //Create a vertex buffer for vertex positions and texture coordinates - vertexBuffer = PropertyBuffer::New( vertexFormat ); - vertexBuffer.SetData( gQuadWithTexture, 4u ); - - //Create the geometry - mesh = Geometry::New(); - mesh.AddVertexBuffer( vertexBuffer ); - mesh.SetGeometryType( Geometry::TRIANGLE_STRIP ); - } - return mesh; -} - bool gUseMesh(false); bool gNinePatch(false); unsigned int gRowsPerPage(15); @@ -216,35 +188,18 @@ unsigned int gColumnsPerPage(15); unsigned int gPageCount(10); float gDuration(10.0f); -Renderer CreateRenderer( unsigned int index ) +Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader ) { - - int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES; - static Renderer* renderers = new Renderer[numImages]; - if( !renderers[index] ) - { - //Create the renderer - Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); - - const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; - Texture texture = DemoHelper::LoadTexture( imagePath ); - - TextureSet textureSet = TextureSet::New(); - textureSet.SetTexture( 0u, texture ); - renderers[index] = Renderer::New( QuadMesh(), shader ); - renderers[index].SetTextures( textureSet ); - renderers[index].SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); - } - return renderers[index]; + Renderer renderer = Renderer::New( geometry, shader ); + const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; + Texture texture = DemoHelper::LoadTexture( imagePath ); + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture( 0u, texture ); + renderer.SetTextures( textureSet ); + renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); + return renderer; } -Actor CreateMeshActor( unsigned int index) -{ - Renderer renderer = CreateRenderer( index ); - Actor meshActor = Actor::New(); - meshActor.AddRenderer( renderer ); - return meshActor; -} } // Test application to compare performance between ImageActor and ImageView @@ -333,18 +288,27 @@ public: void CreateMeshActors() { - Stage stage = Stage::GetCurrent(); + unsigned int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES; - unsigned int actorCount( mRowsPerPage * mColumnsPerPage * mPageCount ); - mActor.resize( actorCount ); + //Create all the renderers + std::vector renderers( numImages ); + Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); + Geometry geometry = DemoHelper::CreateTexturedQuad(); + for( unsigned int i(0); i +#include #include // INTERNAL INCLUDES diff --git a/examples/radial-menu/radial-sweep-view-impl.cpp b/examples/radial-menu/radial-sweep-view-impl.cpp index 495e2ec..34bbe7c 100644 --- a/examples/radial-menu/radial-sweep-view-impl.cpp +++ b/examples/radial-menu/radial-sweep-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -17,7 +17,7 @@ #include "radial-sweep-view-impl.h" -#include +#include #include using namespace Dali; diff --git a/examples/refraction-effect/refraction-effect-example.cpp b/examples/refraction-effect/refraction-effect-example.cpp index d4e0213..c9930fe 100644 --- a/examples/refraction-effect/refraction-effect-example.cpp +++ b/examples/refraction-effect/refraction-effect-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -17,7 +17,7 @@ // EXTERNAL INCLUDES #include -#include +#include #include #include diff --git a/examples/textured-mesh/textured-mesh-example.cpp b/examples/textured-mesh/textured-mesh-example.cpp index 6285ae3..288e880 100644 --- a/examples/textured-mesh/textured-mesh-example.cpp +++ b/examples/textured-mesh/textured-mesh-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -16,7 +16,7 @@ */ // EXTERNAL INCLUDES -#include +#include #include // INTERNAL INCLUDES @@ -62,34 +62,6 @@ void main() } ); -Geometry CreateGeometry() -{ - // Create vertices - const float halfQuadSize = .5f; - struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; - TexturedQuadVertex texturedQuadVertexData[4] = { - { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, - { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, - { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, - { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; - - Property::Map texturedQuadVertexFormat; - texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; - texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2; - PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat ); - texturedQuadVertices.SetData( texturedQuadVertexData, 4 ); - - // Create indices - unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 }; - - // Create the geometry object - Geometry texturedQuadGeometry = Geometry::New(); - texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices ); - texturedQuadGeometry.SetIndexBuffer( &indexData[0], sizeof(indexData)/sizeof(indexData[0]) ); - - return texturedQuadGeometry; -} - /** * Sinusoidal curve starting at zero with 2 cycles */ @@ -151,7 +123,7 @@ public: mTextureSet2 = TextureSet::New(); mTextureSet2.SetTexture( 0u, texture2 ); - mGeometry = CreateGeometry(); + mGeometry = DemoHelper::CreateTexturedQuad(); mRenderer = Renderer::New( mGeometry, mShader ); mRenderer.SetTextures( mTextureSet1 ); diff --git a/packaging/com.samsung.dali-demo.spec b/packaging/com.samsung.dali-demo.spec index 34d1625..83740ba 100755 --- a/packaging/com.samsung.dali-demo.spec +++ b/packaging/com.samsung.dali-demo.spec @@ -2,7 +2,7 @@ Name: com.samsung.dali-demo Summary: The OpenGLES Canvas Core Demo -Version: 1.1.42 +Version: 1.1.43 Release: 1 Group: System/Libraries License: Apache-2.0 diff --git a/resources/scripts/simple-image-wall.js b/resources/scripts/simple-image-wall.js.in index 2620865..36aba3f 100644 --- a/resources/scripts/simple-image-wall.js +++ b/resources/scripts/simple-image-wall.js.in @@ -2,27 +2,12 @@ // // Example usage of Dali API // -// -// -// get the dali-demo image directory path -// hard code for the device to /usr/apps/com.samsung.dali-demo/images/ -var imageDir = dali.DALI_DATA_DIRECTORY; - -if (imageDir != "/usr/share/dali//") { - imageDir = imageDir.substring(0, imageDir.lastIndexOf("dali/")); - imageDir += "com.samsung.dali-demo/images/"; -} else // on device -{ - imageDir = "/usr/apps/com.samsung.dali-demo/images/"; -} +var imageDir = "@DEMO_STYLE_IMAGE_DIR@"; var NUMBER_OF_IMAGES = 40; // for now use 16 ( demo files go up to 30) -var DEMO_IMAGES = []; // array to store Dali Images -var VIDEO_WALL_ACTORS = []; // array to store Image actors var VIDEO_WALL_ROWS = 7; // use 3 rows for the video wall var VIDEO_WALL_COLUMNS = 12; // use 12 columns for the video wall -var VIDEO_WALL_TOTAL_ITEMS = VIDEO_WALL_COLUMNS * VIDEO_WALL_ROWS; // total items var VIDEO_WALL_ITEM_SIZE = 128; // width / height of a item in the video wall var BORDER_SIZE = 5; var VIDEO_WALL_ITEM_SIZE_NO_BORDER = VIDEO_WALL_ITEM_SIZE - BORDER_SIZE; @@ -39,14 +24,6 @@ daliApp.getFileName = function(index) { return fileName; } -// load the images -daliApp.loadImages = function() { - for (index = 0; index < NUMBER_OF_IMAGES; ++index) { - fileName = imageDir + daliApp.getFileName(index); - DEMO_IMAGES[index] = new dali.ResourceImage( { url:fileName } ); - } -} - daliApp.createRootActor = function() { wallRootActor = new dali.Actor(); wallRootActor.parentOrigin = dali.CENTER; @@ -54,8 +31,6 @@ daliApp.createRootActor = function() { dali.stage.add(wallRootActor); } - - daliApp.getWallActorIndex = function(x, y) { return x + y * VIDEO_WALL_COLUMNS; } @@ -67,16 +42,16 @@ daliApp.createActors = function() { for (x = 0; x < VIDEO_WALL_COLUMNS; ++x) { var actorIndex = daliApp.getWallActorIndex(x, y); - var imageActor = new dali.ImageActor(); + var imageView = new dali.Control("ImageView"); // wrap image index between 0 and NUMBER_OF_IMAGES var imageIndex = actorIndex % NUMBER_OF_IMAGES; - imageActor.setImage(DEMO_IMAGES[imageIndex]); + imageView.image = imageDir + daliApp.getFileName(imageIndex); - imageActor.parentOrigin = dali.CENTER; - imageActor.anchorPoint = dali.CENTER; - imageActor.size = [VIDEO_WALL_ITEM_SIZE_NO_BORDER, VIDEO_WALL_ITEM_SIZE_NO_BORDER, 1.0]; // start with zero size so it zooms up + imageView.parentOrigin = dali.CENTER; + imageView.anchorPoint = dali.CENTER; + imageView.size = [VIDEO_WALL_ITEM_SIZE_NO_BORDER, VIDEO_WALL_ITEM_SIZE_NO_BORDER, 1.0]; // start with zero size so it zooms up var xPosition = x * VIDEO_WALL_ITEM_SIZE; // as the middle the wall is at zero (relative to wallRootActor), we need to subtract half the wall width. @@ -86,23 +61,16 @@ daliApp.createActors = function() { var yPosition = y * VIDEO_WALL_ITEM_SIZE; yPosition = yPosition - (VIDEO_WALL_HEIGHT / 2) + (VIDEO_WALL_ITEM_SIZE / 2); - imageActor.position = [xPosition, yPosition, 0.0]; - // store the actor - VIDEO_WALL_ACTORS[actorIndex] = imageActor; + imageView.position = [xPosition, yPosition, 0.0]; // Add to the video wall root actor. - wallRootActor.add(imageActor); + wallRootActor.add(imageView); } } } function Initialise() { - - daliApp.loadImages(); - daliApp.createActors(); - - } Initialise(); diff --git a/shared/utility.h b/shared/utility.h index 3285b98..71a2150 100644 --- a/shared/utility.h +++ b/shared/utility.h @@ -1,8 +1,8 @@ -#ifndef __DALI_DEMO_UTILITY_H__ -#define __DALI_DEMO_UTILITY_H__ +#ifndef DALI_DEMO_UTILITY_H +#define DALI_DEMO_UTILITY_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * 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. @@ -20,8 +20,9 @@ #include #include -#include #include +#include +#include namespace DemoHelper { @@ -86,6 +87,35 @@ Dali::Texture LoadStageFillingTexture( const char* imagePath ) return LoadTexture( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); } +Dali::Geometry CreateTexturedQuad() +{ + struct Vertex + { + Dali::Vector2 position; + Dali::Vector2 texCoord; + }; + + static const Vertex data[] = {{ Dali::Vector2( -0.5f, -0.5f ), Dali::Vector2( 0.0f, 0.0f ) }, + { Dali::Vector2( 0.5f, -0.5f ), Dali::Vector2( 1.0f, 0.0f ) }, + { Dali::Vector2( -0.5f, 0.5f ), Dali::Vector2( 0.0f, 1.0f ) }, + { Dali::Vector2( 0.5f, 0.5f ), Dali::Vector2( 1.0f, 1.0f ) }}; + + Dali::PropertyBuffer vertexBuffer; + Dali::Property::Map vertexFormat; + vertexFormat["aPosition"] = Dali::Property::VECTOR2; + vertexFormat["aTexCoord"] = Dali::Property::VECTOR2; + + //Create a vertex buffer for vertex positions and texture coordinates + vertexBuffer = Dali::PropertyBuffer::New( vertexFormat ); + vertexBuffer.SetData( data, 4u ); + + //Create the geometry + Dali::Geometry geometry = Dali::Geometry::New(); + geometry.AddVertexBuffer( vertexBuffer ); + geometry.SetGeometryType(Dali::Geometry::TRIANGLE_STRIP ); + + return geometry; +} } // DemoHelper -#endif // __DALI_DEMO_HELPER_VIEW_H__ +#endif // DALI_DEMO_UTILITY_H