Further Setter/Getter public API removal from Dali::Actor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Shader.cpp
index cf419be..3336e20 100644 (file)
@@ -116,6 +116,25 @@ int UtcDaliShaderDownCast02(void)
   END_TEST;
 }
 
+int UtcDaliShaderDefaultProperties(void)
+{
+  TestApplication application;
+// from shader-impl.cpp
+// DALI_PROPERTY( "program",       MAP,     true,     false,     false,  Dali::Shader::Property::PROGRAM )
+
+  Shader shader = Shader::New(VertexSource, FragmentSource);
+  DALI_TEST_EQUALS( shader.GetPropertyCount(), 1, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( shader.GetPropertyName( Shader::Property::PROGRAM ), "program", TEST_LOCATION );
+  DALI_TEST_EQUALS( shader.GetPropertyIndex( "program" ), (Property::Index)Shader::Property::PROGRAM, TEST_LOCATION );
+  DALI_TEST_EQUALS( shader.GetPropertyType( Shader::Property::PROGRAM ), Property::MAP, TEST_LOCATION );
+  DALI_TEST_EQUALS( shader.IsPropertyWritable( Shader::Property::PROGRAM ), true, TEST_LOCATION );
+  DALI_TEST_EQUALS( shader.IsPropertyAnimatable( Shader::Property::PROGRAM ), false, TEST_LOCATION );
+  DALI_TEST_EQUALS( shader.IsPropertyAConstraintInput( Shader::Property::PROGRAM ), false, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliShaderConstraint01(void)
 {
   TestApplication application;
@@ -128,7 +147,7 @@ int UtcDaliShaderConstraint01(void)
 
   Actor actor = Actor::New();
   actor.AddRenderer(renderer);
-  actor.SetSize(400, 400);
+  actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
   Stage::GetCurrent().Add(actor);
 
   Vector4 initialColor = Color::WHITE;
@@ -170,7 +189,7 @@ int UtcDaliShaderConstraint02(void)
 
   Actor actor = Actor::New();
   actor.AddRenderer(renderer);
-  actor.SetSize(400, 400);
+  actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
   Stage::GetCurrent().Add(actor);
   application.SendNotification();
   application.Render(0);
@@ -224,7 +243,7 @@ int UtcDaliShaderAnimatedProperty01(void)
 
   Actor actor = Actor::New();
   actor.AddRenderer(renderer);
-  actor.SetSize(400, 400);
+  actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
   Stage::GetCurrent().Add(actor);
 
   Vector4 initialColor = Color::WHITE;
@@ -265,7 +284,7 @@ int UtcDaliShaderAnimatedProperty02(void)
 
   Actor actor = Actor::New();
   actor.AddRenderer(renderer);
-  actor.SetSize(400, 400);
+  actor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.0f ) );
   Stage::GetCurrent().Add(actor);
   application.SendNotification();
   application.Render(0);
@@ -299,6 +318,28 @@ int UtcDaliShaderAnimatedProperty02(void)
   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
 
+  // change shader program
+  Property::Map map;
+  map["vertex"] = VertexSource;
+  map["fragment"] = FragmentSource;
+  map["hints"] = "MODIFIES_GEOMETRY";
+  shader.SetProperty( Shader::Property::PROGRAM, Property::Value(map) );
+  application.SendNotification();
+  application.Render(100);
+
+  // register another custom property as well
+  Property::Index customIndex = shader.RegisterProperty( "uCustom", Vector3(1,2,3) );
+  DALI_TEST_EQUALS( shader.GetProperty<Vector3>( customIndex ), Vector3(1,2,3), TEST_LOCATION );
+
+  application.SendNotification();
+  application.Render(100);
+
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
+
+  Vector3 customValue;
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "uCustom", customValue ) );
+  DALI_TEST_EQUALS( customValue, Vector3(1,2,3), TEST_LOCATION );
   END_TEST;
 }
 
@@ -317,6 +358,9 @@ int UtcDaliShaderProgramProperty(void)
   map["hints"] = hintSet;
 
   shader.SetProperty( Shader::Property::PROGRAM, Property::Value(map) );
+  // register a custom property as well
+  Property::Index customIndex = shader.RegisterProperty( "custom", Vector3(1,2,3) );
+  DALI_TEST_EQUALS( shader.GetProperty<Vector3>( customIndex ), Vector3(1,2,3), TEST_LOCATION );
 
   Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
   DALI_TEST_CHECK( value.GetType() == Property::MAP);
@@ -333,6 +377,15 @@ int UtcDaliShaderProgramProperty(void)
   value = shader.GetCurrentProperty( Shader::Property::PROGRAM );
   DALI_TEST_CHECK( value.GetType() == Property::MAP);
   outMap = value.GetMap();
+  // check that changing the shader did not cause us to loose custom property
+  DALI_TEST_EQUALS( shader.GetProperty<Vector3>( customIndex ), Vector3(1,2,3), TEST_LOCATION );
+  using Dali::Animation;
+  Animation animation = Animation::New( 0.1f );
+  animation.AnimateTo( Property( shader, customIndex ), Vector3(4,5,6) );
+  animation.Play();
+  application.SendNotification();
+  application.Render(100);
+  DALI_TEST_EQUALS( shader.GetProperty<Vector3>( customIndex ), Vector3(4,5,6), TEST_LOCATION );
 
   v = (*outMap)["vertex"].Get<std::string>();
   f = (*outMap)["fragment"].Get<std::string>();