Shader compilation tool for dali-toolkit
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition-effects / cube-transition-effect-impl.cpp
index 3a31a49..bd52a8b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 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.
 // EXTERNAL INCLUDES
 #include <cstring> // for strcmp
 #include <dali/public-api/object/type-registry.h>
-#include <dali/devel-api/object/type-registry-helper.h>
-#include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
+#include <dali/public-api/object/type-registry-helper.h>
 #include <dali/integration-api/debug.h>
 
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+
 namespace Dali
 {
 
@@ -44,42 +48,10 @@ DALI_SIGNAL_REGISTRATION( Toolkit, CubeTransitionEffect, "transitionCompleted",
 
 DALI_TYPE_REGISTRATION_END()
 
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  varying mediump vec2 vTexCoord;\n
-  uniform mediump mat4 uMvpMatrix;\n
-  uniform mediump vec3 uSize;\n
-  uniform mediump vec4 uTextureRect;\n
-  \n
-  void main()\n
-  {\n
-    mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
-    vertexPosition.xyz *= uSize;\n
-    vertexPosition = uMvpMatrix * vertexPosition;\n
-    \n
-    vTexCoord = aPosition + vec2(0.5);\n
-    vTexCoord = mix(uTextureRect.xy, uTextureRect.zw, vTexCoord);\n
-
-    gl_Position = vertexPosition;\n
-  }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform lowp vec4 uColor;\n
-  uniform lowp vec4 uSamplerRect;
-  \n
-  void main()\n
-  {\n
-    gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
-  }\n
-);
-
 Actor CreateTile( const Vector4& samplerRect )
 {
  Actor tile = Actor::New();
-  tile.SetAnchorPoint( AnchorPoint::CENTER );
+  tile.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
   tile.RegisterProperty( "uTextureRect", samplerRect );
   return tile;
 }
@@ -90,7 +62,7 @@ const Vector4 CubeTransitionEffect::FULL_BRIGHTNESS( 1.0f, 1.0f, 1.0f, 1.0f );
 const Vector4 CubeTransitionEffect::HALF_BRIGHTNESS( 0.5f, 0.5f, 0.5f, 1.0f );
 
 CubeTransitionEffect::CubeTransitionEffect( unsigned int rows, unsigned int columns )
-: Control( ControlBehaviour( 0 ) ),
+: Control( ControlBehaviour( DISABLE_STYLE_CHANGE_SIGNALS ) ),
   mRows( rows ),
   mColumns( columns ),
   mIsAnimating( false ),
@@ -110,8 +82,8 @@ void CubeTransitionEffect::SetTargetRight( unsigned int idx )
 
   mBoxes[ idx ].SetProperty(Actor::Property::PARENT_ORIGIN_Z, 1.0f - mTileSize.x * 0.5f );
 
-  mTargetTiles[ idx ].SetParentOrigin( Vector3( 1.f, 0.5f, 0.5f) );
-  mTargetTiles[ idx ].SetOrientation( Degree( 90.f ), Vector3::YAXIS );
+  mTargetTiles[ idx ].SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 1.f, 0.5f, 0.5f) );
+  mTargetTiles[ idx ].SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( 90.f ), Vector3::YAXIS ) );
 }
 
 void CubeTransitionEffect::SetTargetLeft( unsigned int idx )
@@ -120,8 +92,8 @@ void CubeTransitionEffect::SetTargetLeft( unsigned int idx )
 
   mBoxes[ idx ].SetProperty(Actor::Property::PARENT_ORIGIN_Z, 1.0f - mTileSize.x * 0.5f );
 
-  mTargetTiles[ idx ].SetParentOrigin( Vector3( 0.f, 0.5f, 0.5f) );
-  mTargetTiles[ idx ].SetOrientation( Degree( -90.f ), Vector3::YAXIS );
+  mTargetTiles[ idx ].SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.f, 0.5f, 0.5f) );
+  mTargetTiles[ idx ].SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( -90.f ), Vector3::YAXIS ) );
 }
 
 void CubeTransitionEffect::SetTargetBottom( unsigned int idx )
@@ -130,8 +102,8 @@ void CubeTransitionEffect::SetTargetBottom( unsigned int idx )
 
   mBoxes[ idx ].SetProperty(Actor::Property::PARENT_ORIGIN_Z, 1.0f - mTileSize.y * 0.5f );
 
-  mTargetTiles[ idx ].SetParentOrigin( Vector3( 0.5f, 0.f, 0.5f) );
-  mTargetTiles[ idx ].SetOrientation( Degree( 90.f ), Vector3::XAXIS );
+  mTargetTiles[ idx ].SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.f, 0.5f) );
+  mTargetTiles[ idx ].SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( 90.f ), Vector3::XAXIS ) );
 }
 
 void CubeTransitionEffect::SetTargetTop( unsigned int idx )
@@ -140,8 +112,8 @@ void CubeTransitionEffect::SetTargetTop( unsigned int idx )
 
   mBoxes[ idx ].SetProperty(Actor::Property::PARENT_ORIGIN_Z, 1.0f - mTileSize.y * 0.5f );
 
-  mTargetTiles[ idx ].SetParentOrigin( Vector3( 0.5f, 1.f, 0.5f) );
-  mTargetTiles[ idx ].SetOrientation( Degree( -90.f ), Vector3::XAXIS );
+  mTargetTiles[ idx ].SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 1.f, 0.5f) );
+  mTargetTiles[ idx ].SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( -90.f ), Vector3::XAXIS ) );
 }
 
 void CubeTransitionEffect::OnRelayout( const Vector2& size, RelayoutContainer& container )
@@ -196,8 +168,8 @@ void CubeTransitionEffect::Initialize()
 
   //create the box parents
   mBoxRoot = Actor::New();
-  mBoxRoot.SetParentOrigin( ParentOrigin::CENTER );
-  mBoxRoot.SetAnchorPoint( AnchorPoint::CENTER );
+  mBoxRoot.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+  mBoxRoot.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
 
   mCurrentTiles.clear();
   mTargetTiles.clear();
@@ -218,7 +190,7 @@ void CubeTransitionEffect::Initialize()
 
       Actor currentTile = CreateTile( textureRect );
       currentTile.SetProperty( Actor::Property::COLOR, FULL_BRIGHTNESS );
-      currentTile.SetParentOrigin( ParentOrigin::CENTER );
+      currentTile.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
       mCurrentTiles.push_back( currentTile );
 
       Actor targetTile = CreateTile( textureRect );
@@ -226,8 +198,8 @@ void CubeTransitionEffect::Initialize()
       mTargetTiles.push_back( targetTile );
 
       Actor box = Actor::New();
-      box.SetParentOrigin( anchor + offset );
-      box.SetAnchorPoint( AnchorPoint::CENTER );
+      box.SetProperty( Actor::Property::PARENT_ORIGIN, anchor + offset );
+      box.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
 
       box.Add( currentTile );
       box.Add( targetTile );
@@ -241,27 +213,27 @@ void CubeTransitionEffect::Initialize()
   OnInitialize();
 }
 
-void CubeTransitionEffect::OnStageConnection( int depth )
+void CubeTransitionEffect::OnSceneConnection( int depth )
 {
-  Control::OnStageConnection( depth );
-
-  Geometry geometry = Geometry::QUAD();
-  Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+  Geometry geometry = VisualFactoryCache::CreateQuadGeometry();
+  Shader shader = Shader::New( SHADER_CUBE_TRANSITION_EFFECT_VERT, SHADER_CUBE_TRANSITION_EFFECT_FRAG );
 
   TextureSet textureSet = TextureSet::New();
 
-  if( mCurrentImage )
+  if( mCurrentTexture )
   {
-    textureSet.SetImage( 0u, mCurrentImage );
+    textureSet.SetTexture( 0u, mCurrentTexture );
   }
   mCurrentRenderer = Renderer::New( geometry, shader );
   mCurrentRenderer.SetTextures( textureSet );
 
   mCurrentRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, depth );
   Self().AddRenderer( mCurrentRenderer );
+
+  Control::OnSceneConnection( depth );
 }
 
-void CubeTransitionEffect::OnStageDisconnection()
+void CubeTransitionEffect::OnSceneDisconnection()
 {
   if( mCurrentRenderer )
   {
@@ -283,7 +255,7 @@ void CubeTransitionEffect::OnStageDisconnection()
     mTargetRenderer.Reset();
   }
 
-  Control::OnStageDisconnection();
+  Control::OnSceneDisconnection();
 }
 
 void CubeTransitionEffect::SetTransitionDuration( float duration )
@@ -311,30 +283,31 @@ bool CubeTransitionEffect::IsTransitioning()
   return mIsAnimating;
 }
 
-void CubeTransitionEffect::SetCurrentImage( Image image )
+void CubeTransitionEffect::SetCurrentTexture( Texture texture )
 {
-  mCurrentImage = image;
+  mCurrentTexture = texture;
+
   if( mCurrentRenderer )
   {
     TextureSet textureSet = mCurrentRenderer.GetTextures();
-    textureSet.SetImage( 0u, mCurrentImage );
+    textureSet.SetTexture( 0u, mCurrentTexture);
   }
 }
 
-void CubeTransitionEffect::SetTargetImage( Image image )
+void CubeTransitionEffect::SetTargetTexture( Texture texture )
 {
-  mTargetImage = image;
+  mTargetTexture = texture;
 
   if( mTargetRenderer )
   {
     TextureSet textureSet = mTargetRenderer.GetTextures();
-    textureSet.SetImage( 0u, mTargetImage );
+    textureSet.SetTexture( 0u, mTargetTexture );
   }
 }
 
 void CubeTransitionEffect::StartTransition( bool toNextImage )
 {
-  Vector3 size = Self().GetCurrentSize();
+  Vector3 size = Self().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
   if( toNextImage )
   {
     StartTransition( Vector2(size.x* 0.5f, size.y*0.5f), Vector2( -10.f, 0.f ) );
@@ -349,15 +322,15 @@ void CubeTransitionEffect::StartTransition( Vector2 panPosition, Vector2 panDisp
 {
   if( !mCurrentRenderer )
   {
-    DALI_LOG_ERROR( "Trying to transition a cube transition without an image set" );
+    DALI_LOG_ERROR( "Trying to transition a cube transition without an image set\n" );
     return;
   }
 
   //create the target renderer
   TextureSet textureSet = TextureSet::New();
-  if( mTargetImage )
+  if( mTargetTexture )
   {
-    textureSet.SetImage( 0u, mTargetImage );
+    textureSet.SetTexture( 0u, mTargetTexture );
   }
   Geometry geometry = mCurrentRenderer.GetGeometry();
   Shader shader( mCurrentRenderer.GetShader() );
@@ -374,7 +347,7 @@ void CubeTransitionEffect::StartTransition( Vector2 panPosition, Vector2 panDisp
 
   for( ActorArray::iterator it = mCurrentTiles.begin(); it != mCurrentTiles.end(); ++it )
   {
-    it->SetParentOrigin( Vector3( 0.5f, 0.5f, 1.0f) );
+    it->SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.5f, 1.0f) );
     it->SetProperty( Actor::Property::ORIENTATION, Quaternion( Radian( 0.0f ), Vector3::XAXIS ) );
     it->AddRenderer( mCurrentRenderer );
   }
@@ -436,7 +409,7 @@ void CubeTransitionEffect::ResetToInitialState()
 
   for( ActorArray::iterator it = mCurrentTiles.begin(); it != mCurrentTiles.end(); ++it )
   {
-    it->SetParentOrigin( Vector3( 0.5f, 0.5f, 1.0f) );
+    it->SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.5f, 1.0f) );
     it->SetProperty( Actor::Property::ORIENTATION, Quaternion( Radian( 0.0f ), Vector3::XAXIS ) );
     it->SetProperty( Actor::Property::COLOR, FULL_BRIGHTNESS );
   }
@@ -467,13 +440,13 @@ void CubeTransitionEffect::OnTransitionFinished(Animation& source)
 
   std::swap( mCurrentTiles, mTargetTiles );
   std::swap( mCurrentRenderer, mTargetRenderer );
-  std::swap( mCurrentImage, mTargetImage );
+  std::swap( mCurrentTexture, mTargetTexture );
 
   ResetToInitialState();
 
   //Emit signal
   Toolkit::CubeTransitionEffect handle( GetOwner() );
-  mTransitionCompletedSignal.Emit( handle, mCurrentImage );
+  mTransitionCompletedSignal.Emit( handle, mCurrentTexture );
 }
 
 Toolkit::CubeTransitionEffect::TransitionCompletedSignalType& CubeTransitionEffect::TransitionCompletedSignal()