Move blending and culling options from Material to Renderer
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-devel / utc-Dali-Material.cpp
index 848d0f3..4ec8459 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
  *
  */
 
-#include <iostream>
-
-#include <stdlib.h>
 #include <dali/public-api/dali-core.h>
-#include <dali/devel-api/actors/mesh-actor.h>
-#include <dali/devel-api/geometry/mesh.h>
-#include <dali/devel-api/geometry/animatable-mesh.h>
 #include <dali-test-suite-utils.h>
 
 using namespace Dali;
 
+#include <mesh-builder.h>
 
-void utc_dali_material_startup(void)
+namespace
+{
+void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
+{
+  current.b = 0.0f;
+}
+}
+
+
+void material_test_startup(void)
 {
   test_return_value = TET_UNDEF;
 }
 
-void utc_dali_material_cleanup(void)
+void material_test_cleanup(void)
 {
   test_return_value = TET_PASS;
 }
 
-namespace
+int UtcDaliMaterialNew01(void)
 {
+  TestApplication application;
+
+  Shader shader = Shader::New("vertexSrc", "fragmentSrc");
+  Material material = Material::New(shader);
 
-static AnimatableMesh CreateMeshData(Material material)
+  DALI_TEST_CHECK( material );
+  END_TEST;
+}
+
+int UtcDaliMaterialNew02(void)
 {
-  AnimatableMesh::Faces faces;
-  for(int i=0; i<10-3; i++)
-  {
-    faces.push_back(i);
-    faces.push_back(i+1);
-    faces.push_back(i+2);
-  }
-  return AnimatableMesh::New(10, faces, material);
+  TestApplication application;
+  Material material;
+  DALI_TEST_CHECK( !material );
+  END_TEST;
 }
 
-}// anonymous namespace
+int UtcDaliMaterialCopyConstructor(void)
+{
+  TestApplication application;
 
+  Shader shader = Shader::New("vertexSrc", "fragmentSrc");
+  Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
+  Material material = Material::New(shader);
+  material.AddTexture( image, "sTexture" );
 
-// Positive test case for a method
-int UtcDaliMaterialNew01(void)
+  Material materialCopy(material);
+
+  DALI_TEST_CHECK( materialCopy );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialAssignmentOperator(void)
 {
   TestApplication application;
-  tet_infoline("Testing constructors, New and destructors");
 
-  Material material;
-  DALI_TEST_CHECK( ! material );
+  Shader shader = Shader::New("vertexSrc", "fragmentSrc");
+  Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
+  Material material = Material::New(shader);
 
-  material = Material::New("material");
-  DALI_TEST_CHECK( material );
+  Material material2;
+  DALI_TEST_CHECK( !material2 );
 
-  Material* material2 = new Material();
-  DALI_TEST_CHECK( ! *material2 );
-  delete material2;
+  material2 = material;
+  DALI_TEST_CHECK( material2 );
 
-  Material material3 = material;
-  Material material4;
-  material4 = material;
-  Material material5 = material;
   END_TEST;
 }
 
-
-int UtcDaliMaterialDownCast(void)
+int UtcDaliMaterialDownCast01(void)
 {
   TestApplication application;
+  Shader shader = Shader::New("vertexSrc", "fragmentSrc");
+  Material material = Material::New(shader);
 
-  Material material = Material::New("material");
   BaseHandle handle(material);
+  Material material2 = Material::DownCast(handle);
+  DALI_TEST_CHECK( material2 );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialDownCast02(void)
+{
+  TestApplication application;
+
+  Handle handle = Handle::New(); // Create a custom object
+  Material material = Material::DownCast(handle);
+  DALI_TEST_CHECK( !material );
+  END_TEST;
+}
+
+int UtcDaliMaterialSetShader(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test SetShader(shader) ");
+
+  Shader shader1 = Shader::New( "vertexSrc1", "fragmentSrc1" );
+  shader1.RegisterProperty( "uFadeColor", Color::CYAN );
+
+  Shader shader2 = Shader::New( "vertexSrc1", "fragmentSrc1" );
+  shader2.RegisterProperty( "uFadeColor", Color::MAGENTA );
+
+  // shader1
+  Material material = Material::New(shader1);
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+  application.SendNotification();
+  application.Render(0);
+  Vector4 actualValue(Vector4::ZERO);
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
+
+  // shader2
+  material.SetShader( shader2 );
+
+  application.SendNotification();
+  application.Render(0);
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
+
+  // shader1
+  material.SetShader( shader1 );
+
+  application.SendNotification();
+  application.Render(0);
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialGetShader(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test GetShader() ");
+
+  Shader shader1 = Shader::New( "vertexSrc1", "fragmentSrc1" );
+  Shader shader2 = Shader::New( "vertexSrc1", "fragmentSrc1" );
+
+  // shader1
+  Material material = Material::New(shader1);
+  DALI_TEST_EQUALS( shader1, material.GetShader(), TEST_LOCATION );
+
+  // shader2
+  material.SetShader( shader2 );
+  DALI_TEST_EQUALS( shader2, material.GetShader(), TEST_LOCATION );
+
+  // shader1
+  material.SetShader( shader1 );
+  DALI_TEST_EQUALS( shader1, material.GetShader(), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialGetNumberOfTextures(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test GetNumberOfTextures()");
+
+  Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
+  Material material = CreateMaterial();
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add( actor );
+
+  material.AddTexture( image, "sTexture0" );
+  material.AddTexture( image, "sTexture1" );
+  DALI_TEST_EQUALS( material.GetNumberOfTextures(), 2u, TEST_LOCATION );
+
+  material.AddTexture( image, "sTexture2" );
+  material.AddTexture( image, "sTexture3" );
+  material.AddTexture( image, "sTexture4" );
+  DALI_TEST_EQUALS( material.GetNumberOfTextures(), 5u, TEST_LOCATION );
+
+  material.RemoveTexture(3);
+  DALI_TEST_EQUALS( material.GetNumberOfTextures(), 4u, TEST_LOCATION );
+
+  material.RemoveTexture(3);
+  material.RemoveTexture(0);
+  DALI_TEST_EQUALS( material.GetNumberOfTextures(), 2u, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialConstraint(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test that a custom material property can be constrained");
+
+  Shader shader = Shader::New( "VertexSource", "FragmentSource");
+  Material material = Material::New( shader );
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  Vector4 initialColor = Color::WHITE;
+  Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
+
+  application.SendNotification();
+  application.Render(0);
+  DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
+
+  // Apply constraint
+  Constraint constraint = Constraint::New<Vector4>( material, colorIndex, TestConstraintNoBlue );
+  constraint.Apply();
+  application.SendNotification();
+  application.Render(0);
+
+  // Expect no blue component in either buffer - yellow
+  DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
+  application.Render(0);
+  DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
+
+  material.RemoveConstraints();
+  material.SetProperty(colorIndex, Color::WHITE );
+  application.SendNotification();
+  application.Render(0);
+  DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialConstraint02(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test that a uniform map material property can be constrained");
+
+  Shader shader = Shader::New( "VertexSource", "FragmentSource");
+  Material material = Material::New( shader );
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+  application.SendNotification();
+  application.Render(0);
+
+  Vector4 initialColor = Color::WHITE;
+  Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  application.SendNotification();
+  application.Render(0);
+
+  Vector4 actualValue(Vector4::ZERO);
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
+
+  // Apply constraint
+  Constraint constraint = Constraint::New<Vector4>( material, colorIndex, TestConstraintNoBlue );
+  constraint.Apply();
+  application.SendNotification();
+  application.Render(0);
+
+   // Expect no blue component in either buffer - yellow
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
+
+  application.Render(0);
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
+
+  material.RemoveConstraints();
+  material.SetProperty(colorIndex, Color::WHITE );
+  application.SendNotification();
+  application.Render(0);
+
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialAnimatedProperty01(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test that a non-uniform material property can be animated");
+
+  Shader shader = Shader::New( "VertexSource", "FragmentSource");
+  Material material = Material::New( shader );
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  Vector4 initialColor = Color::WHITE;
+  Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
+
+  application.SendNotification();
+  application.Render(0);
+  DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
+
+  Animation  animation = Animation::New(1.0f);
+  KeyFrames keyFrames = KeyFrames::New();
+  keyFrames.Add(0.0f, initialColor);
+  keyFrames.Add(1.0f, Color::TRANSPARENT);
+  animation.AnimateBetween( Property( material, colorIndex ), keyFrames );
+  animation.Play();
+
+  application.SendNotification();
+  application.Render(500);
+
+  DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
+
+  application.Render(500);
+
+  DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialAnimatedProperty02(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test that a uniform map material property can be animated");
+
+  Shader shader = Shader::New( "VertexSource", "FragmentSource");
+  Material material = Material::New( shader );
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+  application.SendNotification();
+  application.Render(0);
+
+  Vector4 initialColor = Color::WHITE;
+  Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  application.SendNotification();
+  application.Render(0);
+
+  Vector4 actualValue(Vector4::ZERO);
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
+
+  Animation  animation = Animation::New(1.0f);
+  KeyFrames keyFrames = KeyFrames::New();
+  keyFrames.Add(0.0f, initialColor);
+  keyFrames.Add(1.0f, Color::TRANSPARENT);
+  animation.AnimateBetween( Property( material, colorIndex ), keyFrames );
+  animation.Play();
+
+  application.SendNotification();
+  application.Render(500);
+
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
+
+  application.Render(500);
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+  DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
 
-  Material mat2 = Material::DownCast( handle );
-  DALI_TEST_CHECK( mat2 );
   END_TEST;
 }
 
-int UtcDaliMaterialSettersAndGetters(void)
+
+int UtcDaliMaterialSetTextureUniformName01(void)
 {
   TestApplication application;
-  Material material = Material::New("material");
-  DALI_TEST_EQUALS( material.GetName(), "material", TEST_LOCATION );
-  material.SetName( "AnotherMaterial" );
-  DALI_TEST_EQUALS( material.GetName(), "AnotherMaterial", TEST_LOCATION );
-
-  DALI_TEST_EQUALS( material.GetOpacity(), Material::DEFAULT_OPACITY, 0.001, TEST_LOCATION);
-  material.SetOpacity(0.38f);
-  DALI_TEST_EQUALS( material.GetOpacity(), 0.38f, 0.001, TEST_LOCATION);
-
-  DALI_TEST_EQUALS( material.GetShininess(), Material::DEFAULT_SHININESS, 0.001, TEST_LOCATION);
-  material.SetShininess(0.47f);
-  DALI_TEST_EQUALS( material.GetShininess(), 0.47f, 0.001, TEST_LOCATION);
-
-  DALI_TEST_EQUALS( material.GetAmbientColor(), Material::DEFAULT_AMBIENT_COLOR, 0.001, TEST_LOCATION);
-  material.SetAmbientColor(Color::BLACK);
-  DALI_TEST_EQUALS( material.GetAmbientColor(), Color::BLACK, 0.001, TEST_LOCATION);
-
-  DALI_TEST_EQUALS( material.GetDiffuseColor(), Material::DEFAULT_DIFFUSE_COLOR, 0.001, TEST_LOCATION);
-  material.SetDiffuseColor(Color::BLUE);
-  DALI_TEST_EQUALS( material.GetDiffuseColor(), Color::BLUE, 0.001, TEST_LOCATION);
-
-  DALI_TEST_EQUALS( material.GetSpecularColor(), Material::DEFAULT_SPECULAR_COLOR, 0.001, TEST_LOCATION);
-  material.SetSpecularColor(Color::GREEN);
-  DALI_TEST_EQUALS( material.GetSpecularColor(), Color::GREEN, 0.001, TEST_LOCATION);
-
-  DALI_TEST_EQUALS( material.GetEmissiveColor(), Material::DEFAULT_EMISSIVE_COLOR, 0.001, TEST_LOCATION);
-  material.SetEmissiveColor(Color::MAGENTA);
-  DALI_TEST_EQUALS( material.GetEmissiveColor(), Color::MAGENTA, 0.001, TEST_LOCATION);
-
-  material.SetDiffuseTextureFileName("diffuse-texture.png");
-  DALI_TEST_EQUALS( material.GetDiffuseFileName(), "diffuse-texture.png", TEST_LOCATION);
-
-  material.SetOpacityTextureFileName("opacity-texture.png");
-  DALI_TEST_EQUALS( material.GetOpacityTextureFileName(), "opacity-texture.png", TEST_LOCATION);
-
-  material.SetNormalMapFileName("normal-map.png");
-  DALI_TEST_EQUALS( material.GetNormalMapFileName(), "normal-map.png", TEST_LOCATION);
-
-  Image diffuseTexture = ResourceImage::New("diffuse-texture.png");
-  material.SetDiffuseTexture(diffuseTexture);
-  DALI_TEST_EQUALS( material.GetDiffuseTexture(), diffuseTexture, TEST_LOCATION );
-
-  Image opacityTexture = ResourceImage::New("opacity-texture.png");
-  material.SetOpacityTexture(opacityTexture);
-  DALI_TEST_EQUALS( material.GetOpacityTexture(), opacityTexture, TEST_LOCATION);
-
-  Image normalMap = ResourceImage::New("normal-map.png");
-  material.SetNormalMap(normalMap);
-  DALI_TEST_EQUALS( material.GetNormalMap(), normalMap, TEST_LOCATION);
-
-  DALI_TEST_EQUALS( material.GetMapU(), (unsigned int)Material::DEFAULT_MAPPING_MODE, TEST_LOCATION );
-  DALI_TEST_EQUALS( material.GetMapV(), (unsigned int)Material::DEFAULT_MAPPING_MODE, TEST_LOCATION );
-  material.SetMapU( Material::MAPPING_MODE_WRAP );
-  material.SetMapV( Material::MAPPING_MODE_MIRROR );
-  DALI_TEST_EQUALS( material.GetMapU(), (unsigned int)Material::MAPPING_MODE_WRAP, TEST_LOCATION );
-  DALI_TEST_EQUALS( material.GetMapV(), (unsigned int)Material::MAPPING_MODE_MIRROR, TEST_LOCATION );
-
-  DALI_TEST_EQUALS( material.GetDiffuseUVIndex(), Material::DEFAULT_DIFFUSE_UV_INDEX, TEST_LOCATION );
-  material.SetDiffuseUVIndex( 1u );
-  DALI_TEST_EQUALS( material.GetDiffuseUVIndex(), 1u, TEST_LOCATION );
-
-  DALI_TEST_EQUALS( material.GetOpacityUVIndex(), Material::DEFAULT_OPACITY_UV_INDEX, TEST_LOCATION );
-  material.SetOpacityUVIndex( 1u );
-  DALI_TEST_EQUALS( material.GetOpacityUVIndex(), 1u, TEST_LOCATION );
-
-  DALI_TEST_EQUALS( material.GetNormalUVIndex(), Material::DEFAULT_NORMAL_UV_INDEX, TEST_LOCATION );
-  material.SetNormalUVIndex( 1u );
-  DALI_TEST_EQUALS( material.GetNormalUVIndex(), 1u, TEST_LOCATION );
-
-  DALI_TEST_EQUALS( material.GetHasHeightMap(), Material::DEFAULT_HAS_HEIGHT_MAP, TEST_LOCATION );
-  material.SetHasHeightMap(true);
-  DALI_TEST_EQUALS( material.GetHasHeightMap(), true, TEST_LOCATION );
+
+  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+
+  Material material = CreateMaterial();
+  material.AddTexture( image, "sTexture" );
+
+  int textureIndex = material.GetTextureIndex( "sTexture" );
+  DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
+
+  material.SetTextureUniformName( 0, "sEffectTexture" );
+  textureIndex = material.GetTextureIndex( "sEffectTexture" );
+  DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+
+  Stage::GetCurrent().Add( actor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  application.SendNotification();
+  application.Render();
+
+  int textureUnit=-1;
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
+
   END_TEST;
 }
 
-int UtcDaliMaterialStage01(void)
+int UtcDaliMaterialSetTextureUniformName02(void)
 {
   TestApplication application;
-  TraceCallStack& textureTrace = application.GetGlAbstraction().GetTextureTrace();
-  textureTrace.Enable(true);
-  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
-
-  {
-    Material material = Material::New("material");
-    Image image = ResourceImage::New( "image.png", ResourceImage::IMMEDIATE, Image::NEVER );
-    DALI_TEST_CHECK(image);
-    application.SendNotification();
-    application.Render(16);
-
-    std::vector<GLuint> ids;
-    ids.push_back( 23 );
-    application.GetGlAbstraction().SetNextTextureIds( ids );
-    Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
-    Integration::ResourcePointer resource(bitmap);
-    bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
-    DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
-    Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
-    DALI_TEST_CHECK( request != NULL );
-    if(request)
-    {
-      application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
-    }
-
-    material.SetDiffuseTexture(image);
-    application.SendNotification();
-    application.Render();
-
-    AnimatableMesh mesh = CreateMeshData(material);
-
-    application.SendNotification();
-    application.Render();
-    {
-      MeshActor meshActor = MeshActor::New(mesh);
-      meshActor.SetSize(100, 100);
-      Stage::GetCurrent().Add(meshActor);
-      application.SendNotification();
-      application.Render();
-
-      material.SetOpacity(0.5f);
-      application.SendNotification();
-      application.Render();
-      DALI_TEST_EQUALS( material.GetOpacity(), 0.5f, 0.001f, TEST_LOCATION );
-
-      Stage::GetCurrent().Remove(meshActor);
-      application.SendNotification();
-      application.Render();
-
-      DALI_TEST_CHECK( glAbstraction.CheckNoTexturesDeleted() );
-      DALI_TEST_CHECK( ! textureTrace.FindMethod( "DeleteTextures" ) );
-    }
-    application.SendNotification();
-    application.Render();
-
-    // Mesh should be destroyed, reducing connection count on material to zero.
-    // This should also reduce connection count on image to zero
-    DALI_TEST_EQUALS( material.GetOpacity(), 0.5f, 0.001f, TEST_LOCATION );
-  }
-  // SceneGraph::Material & SceneGraph::RenderMaterial should be destroyed
-  // Image should be destroyed
+
+  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+
+  Material material = CreateMaterial();
+  material.AddTexture( image, "sTexture");
+  material.SetTextureUniformName( 0, "sEffectTexture" );
+  material.AddTexture( image2, "sTexture2");
+
+  int textureIndex = material.GetTextureIndex( "sEffectTexture" );
+  DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
+
+  textureIndex = material.GetTextureIndex( "sTexture2" );
+  DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION );
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+
+  Stage::GetCurrent().Add( actor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
   application.SendNotification();
   application.Render();
 
+  int textureUnit=-1;
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
+
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialAddTexture01(void)
+{
+  TestApplication application;
+
+  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+
+  Material material = CreateMaterial();
+  material.AddTexture( image, "sTexture");
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+
+  Stage::GetCurrent().Add( actor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+  texParameterTrace.Reset();
+  texParameterTrace.Enable( true );
+  application.SendNotification();
   application.Render();
-  DALI_TEST_CHECK( textureTrace.FindMethod( "DeleteTextures" ) );
-  DALI_TEST_CHECK( glAbstraction.CheckTextureDeleted( 23 ) );
+
+  int textureUnit=-1;
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
+
+  texParameterTrace.Enable( false );
+
+  // Verify gl state
+  // There are three calls to TexParameteri when the texture is first created
+  // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
+
   END_TEST;
 }
 
+int UtcDaliMaterialAddTexture02(void)
+{
+  TestApplication application;
+
+  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+
+  Material material = CreateMaterial();
+
+  Sampler sampler = Sampler::New();
+  sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+  material.AddTexture( image, "sTexture", sampler );
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+
+  Stage::GetCurrent().Add( actor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+  texParameterTrace.Reset();
+  texParameterTrace.Enable( true );
+  application.SendNotification();
+  application.Render();
+
+  int textureUnit=-1;
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
 
-int UtcDaliMaterialStage01MemCheck(void)
+  texParameterTrace.Enable( false );
+
+  // Verify gl state
+  // There are three calls to TexParameteri when the texture is first created
+  // Texture minification and magnification filters are now different than default so
+  //there should have been two extra TexParameteri calls to set the new filter mode
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliMaterialRemoveTexture(void)
 {
   TestApplication application;
-  tet_result(TET_PASS);
+
+  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+
+  Material material = CreateMaterial();
+  material.RemoveTexture(0);
+  DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0u, TEST_LOCATION );
+
+  material.RemoveTexture(1);
+  DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0u, TEST_LOCATION );
+
+  Sampler sampler = Sampler::New();
+  sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+  material.AddTexture( image, "sTexture", sampler );
+  DALI_TEST_EQUALS( material.GetNumberOfTextures(), 1u, TEST_LOCATION );
+
+  material.RemoveTexture(1);
+  DALI_TEST_EQUALS( material.GetNumberOfTextures(), 1u, TEST_LOCATION );
+
+  material.RemoveTexture(0);
+  DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0u, TEST_LOCATION );
+
   END_TEST;
 }
 
-int UtcDaliMaterialStage02(void)
+int UtcDaliMaterialSetSampler(void)
 {
   TestApplication application;
-  TraceCallStack& textureTrace = application.GetGlAbstraction().GetTextureTrace();
-  textureTrace.Enable(true);
-  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
-
-  {
-    Material material = Material::New("material");
-
-    Image image = ResourceImage::New( "image.png", ResourceImage::ON_DEMAND, Image::UNUSED );
-    DALI_TEST_CHECK(image);
-    application.SendNotification();
-    application.Render(16);
-    DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
-    DALI_TEST_CHECK( application.GetPlatform().GetRequest() == NULL );
-
-    std::vector<GLuint> ids;
-    ids.push_back( 23 );
-    application.GetGlAbstraction().SetNextTextureIds( ids );
-
-    material.SetDiffuseTexture(image);
-    application.SendNotification();
-    application.Render();
-    DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
-    DALI_TEST_CHECK( application.GetPlatform().GetRequest() == NULL );
-
-    AnimatableMesh mesh = CreateMeshData(material);
-
-    application.SendNotification();
-    application.Render();
-    DALI_TEST_CHECK( !application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
-    DALI_TEST_CHECK( application.GetPlatform().GetRequest() == NULL );
-
-    {
-      MeshActor meshActor = MeshActor::New(mesh);
-      meshActor.SetSize(100, 100);
-      Stage::GetCurrent().Add(meshActor);
-      application.SendNotification();
-      application.Render();
-
-      // Image connection count should go to one - image should get loaded
-      DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
-      Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
-      DALI_TEST_CHECK( request != NULL );
-
-      Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
-      Integration::ResourcePointer resource(bitmap);
-      bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
-      if(request)
-      {
-        application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
-      }
-      application.Render();
-
-      material.SetOpacity(0.5f);
-      application.SendNotification();
-      application.Render();
-      DALI_TEST_EQUALS( material.GetOpacity(), 0.5f, 0.001f, TEST_LOCATION );
-
-      Stage::GetCurrent().Remove(meshActor);
-      application.SendNotification();
-      application.Render();
-
-      // This should reduce connection count on material to zero, freeing the texture:
-      DALI_TEST_CHECK( textureTrace.FindMethod( "DeleteTextures" ) );
-      DALI_TEST_CHECK( glAbstraction.CheckTextureDeleted( 23 ) );
-    }
-    application.SendNotification();
-    application.Render();
-
-    // Mesh should be destroyed, reducing connection count on material to zero.
-    // This should also reduce connection count on image to zero, freeing it
-    DALI_TEST_EQUALS( material.GetOpacity(), 0.5f, 0.001f, TEST_LOCATION );
-  }
+
+  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+
+  Material material = CreateMaterial();
+  material.AddTexture( image, "sTexture");
+
+  Geometry geometry = CreateQuadGeometry();
+  Renderer renderer = Renderer::New( geometry, material );
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  actor.SetSize(400, 400);
+
+  Stage::GetCurrent().Add( actor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+  texParameterTrace.Reset();
+  texParameterTrace.Enable( true );
   application.SendNotification();
   application.Render();
 
-  // SceneGraph::Material & SceneGraph::RenderMaterial should be destroyed
+  int textureUnit=-1;
+  DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
+  DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
+
+  texParameterTrace.Enable( false );
+
+  // Verify gl state
+  // There are three calls to TexParameteri when the texture is first created
+  // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
+
+  texParameterTrace.Reset();
+  texParameterTrace.Enable( true );
+
+  Sampler sampler = Sampler::New();
+  sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+  material.SetTextureSampler(0, sampler );
+
+
+  application.SendNotification();
+  application.Render();
+
+  texParameterTrace.Enable( false );
+
+  // Verify gl state
+  //There should have been two calls to TexParameteri to set the new filtering mode
+  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
+
+
+  END_TEST;
+}
+
+int UtcDaliMaterialGetTextureIndex(void)
+{
+  TestApplication application;
+
+  Image image0 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  Image image1 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  Image image3 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+
+
+  Material material = CreateMaterial();
+  material.AddTexture( image0, "sTexture0");
+  material.AddTexture( image1, "sTexture1");
+  material.AddTexture( image2, "sTexture2");
+  material.AddTexture( image3, "sTexture3");
+
+  int textureIndex = material.GetTextureIndex( "sTexture0" );
+  DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
+
+  textureIndex = material.GetTextureIndex( "sTexture1" );
+  DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION );
+
+  textureIndex = material.GetTextureIndex( "sTexture2" );
+  DALI_TEST_EQUALS( textureIndex, 2, TEST_LOCATION );
+
+  textureIndex = material.GetTextureIndex( "sTexture3" );
+  DALI_TEST_EQUALS( textureIndex, 3, TEST_LOCATION );
+
+  material.RemoveTexture(1);
+
+  textureIndex = material.GetTextureIndex( "sTexture0" );
+  DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION );
+
+  textureIndex = material.GetTextureIndex( "sTexture2" );
+  DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION );
+
+  textureIndex = material.GetTextureIndex( "sTexture3" );
+  DALI_TEST_EQUALS( textureIndex, 2, TEST_LOCATION );
+
   END_TEST;
 }
+
+int UtcDaliMaterialGetTextureP(void)
+{
+  TestApplication application;
+
+  Image image0 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  Image image1 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+  Image image3 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+
+
+  Material material = CreateMaterial();
+  material.AddTexture( image0, "sTexture0");
+  material.AddTexture( image1, "sTexture1");
+  material.AddTexture( image2, "sTexture2");
+  material.AddTexture( image3, "sTexture3");
+
+  Image textureImage0 = material.GetTexture( "sTexture0" );
+  DALI_TEST_EQUALS( textureImage0, image0, TEST_LOCATION );
+
+  Image textureImage1 = material.GetTexture( "sTexture1" );
+  DALI_TEST_EQUALS( textureImage1, image1, TEST_LOCATION );
+
+  Image textureImage2 = material.GetTexture( "sTexture2" );
+  DALI_TEST_EQUALS( textureImage2, image2, TEST_LOCATION );
+
+  Image textureImage3 = material.GetTexture( "sTexture3" );
+  DALI_TEST_EQUALS( textureImage3, image3, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialGetTextureN(void)
+{
+  TestApplication application;
+
+  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
+
+  Material material = CreateMaterial();
+  material.AddTexture( image, "sTexture");
+
+  Image textureImage = material.GetTexture( "sTextureTEST" );
+  DALI_TEST_CHECK( !textureImage );
+
+  END_TEST;
+}
+