Wired up material API for blending options 90/38790/2
authorDavid Steele <david.steele@partner.samsung.com>
Tue, 28 Apr 2015 13:52:03 +0000 (14:52 +0100)
committerDavid Steele <david.steele@partner.samsung.com>
Thu, 30 Apr 2015 09:26:40 +0000 (10:26 +0100)
Added Blending source/destination factors for RBG and Alpha
Added Blending equations for RGB and Alpha

Added test cases for the above.

Changed properties for the above to non-animated, non-constrainable, implemented
the scene graph property with a double-buffered int to hold the bitmask.

Change-Id: I767c859ae959e69ff4500d81f7721f4e7e3b08a5

automated-tests/src/dali/dali-test-suite-utils/mesh-builder.cpp
automated-tests/src/dali/dali-test-suite-utils/mesh-builder.h
automated-tests/src/dali/utc-Dali-Material.cpp
dali/internal/event/effects/material-impl.cpp
dali/internal/event/effects/material-impl.h
dali/internal/update/effects/scene-graph-material.cpp
dali/internal/update/effects/scene-graph-material.h
dali/internal/update/effects/scene-graph-sampler.cpp
dali/public-api/shader-effects/material.h

index 75e4152..dacecc2 100644 (file)
@@ -30,6 +30,22 @@ Material CreateMaterial(float opacity)
   return material;
 }
 
+Material CreateMaterial(float opacity, Image image)
+{
+  Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
+  Material material = Material::New(shader);
+
+  Vector4 color = Color::WHITE;
+  color.a = opacity;
+  material.SetProperty(Material::Property::COLOR, color);
+
+  Sampler sampler = Sampler::New( image, "sTexture" );
+  material.AddSampler( sampler );
+
+  return material;
+}
+
+
 Geometry CreateQuadGeometry()
 {
   Property::Map texturedQuadVertexFormat;
index 4b6dbfe..cdabbf5 100644 (file)
@@ -23,7 +23,7 @@ namespace Dali
 {
 
 Material CreateMaterial(float opacity);
-
+Material CreateMaterial(float opacity, Image image);
 Geometry CreateQuadGeometry();
 
 }
index 33732d5..7b853c3 100644 (file)
@@ -72,3 +72,325 @@ int UtcDaliMaterialDownCast02(void)
   DALI_TEST_EQUALS( (bool)material, false, TEST_LOCATION );
   END_TEST;
 }
+
+
+
+int UtcDaliMaterialBlendingOptions01(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test SetBlendFunc(src, dest) ");
+
+  Geometry geometry = CreateQuadGeometry();
+  Material material = CreateMaterial(0.5f);
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  material.SetBlendFunc(BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE);
+
+  // Test that Set was successful:
+  {
+    BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
+    BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
+    BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
+    BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
+    material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+
+    DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb,    TEST_LOCATION );
+    DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE,  destFactorRgb,   TEST_LOCATION );
+    DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha,  TEST_LOCATION );
+    DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE,  destFactorAlpha, TEST_LOCATION );
+  }
+
+  application.SendNotification();
+  application.Render();
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+
+  DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
+  DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
+  DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
+  DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialBlendingOptions02(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test SetBlendFunc(srcRgb, destRgb, srcAlpha, destAlpha) ");
+
+  Geometry geometry = CreateQuadGeometry();
+  Material material = CreateMaterial(0.5f);
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  material.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
+                         BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
+
+  // Test that Set was successful:
+  {
+    BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
+    BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
+    BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
+    BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
+    material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+
+    DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR,            srcFactorRgb,    TEST_LOCATION );
+    DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR,  destFactorRgb,   TEST_LOCATION );
+    DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA,            srcFactorAlpha,  TEST_LOCATION );
+    DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA,  destFactorAlpha, TEST_LOCATION );
+  }
+
+  application.SendNotification();
+  application.Render();
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR,           glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
+  DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
+  DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA,           glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
+  DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
+
+  END_TEST;
+}
+
+
+
+int UtcDaliMaterialBlendingOptions03(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test GetBlendEquation() defaults ");
+
+  Geometry geometry = CreateQuadGeometry();
+  Material material = CreateMaterial(0.5f);
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  // Test the defaults as documented int blending.h
+  {
+    BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
+    BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
+    material.GetBlendEquation( equationRgb, equationAlpha );
+    DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION );
+    DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION );
+  }
+
+  END_TEST;
+}
+
+
+int UtcDaliMaterialBlendingOptions04(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test SetBlendEquation() ");
+
+  Geometry geometry = CreateQuadGeometry();
+  Material material = CreateMaterial(0.5f);
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  // Test the single blending equation setting
+  {
+    material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT );
+    BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT );
+    material.GetBlendEquation( equationRgba, equationRgba );
+    DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION );
+  }
+
+  material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT );
+
+  // Test that Set was successful
+  {
+    BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
+    BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
+    material.GetBlendEquation( equationRgb, equationAlpha );
+    DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
+    DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
+  }
+
+  // Render & check GL commands
+  application.SendNotification();
+  application.Render();
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(),   TEST_LOCATION );
+  DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialSetBlendMode01(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
+
+  Geometry geometry = CreateQuadGeometry();
+  Material material = CreateMaterial(1.0f);
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  material.SetBlendMode(BlendingMode::ON);
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  glAbstraction.EnableCullFaceCallTrace(true);
+
+  application.SendNotification();
+  application.Render();
+
+  TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
+  std::ostringstream blendStr;
+  blendStr << GL_BLEND;
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+  END_TEST;
+}
+
+
+int UtcDaliMaterialSetBlendMode02(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
+
+  Geometry geometry = CreateQuadGeometry();
+  Material material = CreateMaterial(0.5f);
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  material.SetBlendMode(BlendingMode::OFF);
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  glAbstraction.EnableCullFaceCallTrace(true);
+
+  application.SendNotification();
+  application.Render();
+
+  TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
+  std::ostringstream blendStr;
+  blendStr << GL_BLEND;
+  DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialSetBlendMode03(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
+
+  Geometry geometry = CreateQuadGeometry();
+  Material material = CreateMaterial(0.5f);
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  material.SetBlendMode(BlendingMode::AUTO);
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  glAbstraction.EnableCullFaceCallTrace(true);
+
+  application.SendNotification();
+  application.Render();
+
+  TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
+  std::ostringstream blendStr;
+  blendStr << GL_BLEND;
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialSetBlendMode04(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
+
+  Geometry geometry = CreateQuadGeometry();
+  Material material = CreateMaterial(1.0f);
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  material.SetBlendMode(BlendingMode::AUTO);
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  glAbstraction.EnableCullFaceCallTrace(true);
+
+  application.SendNotification();
+  application.Render();
+
+  TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
+  std::ostringstream blendStr;
+  blendStr << GL_BLEND;
+  DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+  END_TEST;
+}
+
+int UtcDaliMaterialSetBlendMode05(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
+
+  Geometry geometry = CreateQuadGeometry();
+  BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
+  Material material = CreateMaterial(1.0f, image);
+  Renderer renderer = Renderer::New( geometry, material );
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetSize(400, 400);
+  Stage::GetCurrent().Add(actor);
+
+  material.SetBlendMode(BlendingMode::AUTO);
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  glAbstraction.EnableCullFaceCallTrace(true);
+
+  application.SendNotification();
+  application.Render();
+
+  TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
+  std::ostringstream blendStr;
+  blendStr << GL_BLEND;
+  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+  END_TEST;
+}
index aa86ef6..51a2841 100644 (file)
@@ -39,13 +39,14 @@ namespace
  */
 DALI_PROPERTY_TABLE_BEGIN
 DALI_PROPERTY( "color",                           VECTOR4,  true, true,   true, Dali::Material::Property::COLOR )
-DALI_PROPERTY( "face-culling-mode",               STRING,   true, false,  true, Dali::Material::Property::FACE_CULLING_MODE )
-DALI_PROPERTY( "blending-mode",                   STRING,   true, false,  true, Dali::Material::Property::BLENDING_MODE )
-DALI_PROPERTY( "blend-equation",                  STRING,   true, false,  true, Dali::Material::Property::BLEND_EQUATION )
-DALI_PROPERTY( "source-blend-factor-rgb",         STRING,   true, false,  true, Dali::Material::Property::BLENDING_SRC_FACTOR_RGB )
-DALI_PROPERTY( "destination-blend-factor-rgb",    STRING,   true, false,  true, Dali::Material::Property::BLENDING_DEST_FACTOR_RGB )
-DALI_PROPERTY( "source-blend-factor-alpha",       STRING,   true, false,  true, Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA )
-DALI_PROPERTY( "destination-blend-factor-alpha",  STRING,   true, false,  true, Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA )
+DALI_PROPERTY( "face-culling-mode",               STRING,   true, false,  false, Dali::Material::Property::FACE_CULLING_MODE )
+DALI_PROPERTY( "blending-mode",                   STRING,   true, false,  false, Dali::Material::Property::BLENDING_MODE )
+DALI_PROPERTY( "blend-equation-rgb",                  STRING,   true, false,  false, Dali::Material::Property::BLEND_EQUATION_RGB )
+DALI_PROPERTY( "blend-equation-alpha",                  STRING,   true, false,  false, Dali::Material::Property::BLEND_EQUATION_ALPHA )
+DALI_PROPERTY( "source-blend-factor-rgb",         STRING,   true, false,  false, Dali::Material::Property::BLENDING_SRC_FACTOR_RGB )
+DALI_PROPERTY( "destination-blend-factor-rgb",    STRING,   true, false,  false, Dali::Material::Property::BLENDING_DEST_FACTOR_RGB )
+DALI_PROPERTY( "source-blend-factor-alpha",       STRING,   true, false,  false, Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA )
+DALI_PROPERTY( "destination-blend-factor-alpha",  STRING,   true, false,  false, Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA )
 DALI_PROPERTY( "blend-color",                     VECTOR4,  true, true,   true, Dali::Material::Property::BLEND_COLOR )
 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
 
@@ -107,7 +108,6 @@ void Material::SetBlendMode( BlendingMode::Type mode )
   }
 }
 
-// @todo MESH_REWORK API change, or store here
 BlendingMode::Type Material::GetBlendMode() const
 {
   return mBlendingMode;
@@ -115,8 +115,8 @@ BlendingMode::Type Material::GetBlendMode() const
 
 void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
 {
-  // TODO: MESH_REWORK
-  DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
+  mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
+  SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
 }
 
 void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
@@ -124,8 +124,8 @@ void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
                              BlendingFactor::Type srcFactorAlpha,
                              BlendingFactor::Type destFactorAlpha )
 {
-  // TODO: MESH_REWORK
-  DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
+  mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+  SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
 }
 
 void Material::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
@@ -133,28 +133,31 @@ void Material::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
                              BlendingFactor::Type& srcFactorAlpha,
                              BlendingFactor::Type& destFactorAlpha ) const
 {
-  // TODO: MESH_REWORK
-  DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
+  srcFactorRgb    = mBlendingOptions.GetBlendSrcFactorRgb();
+  destFactorRgb   = mBlendingOptions.GetBlendDestFactorRgb();
+  srcFactorAlpha  = mBlendingOptions.GetBlendSrcFactorAlpha();
+  destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
 }
 
 void Material::SetBlendEquation( BlendingEquation::Type equationRgba )
 {
-  // TODO: MESH_REWORK
-  DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
+  mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
+  SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
 }
 
 void Material::SetBlendEquation( BlendingEquation::Type equationRgb,
                                  BlendingEquation::Type equationAlpha )
 {
-  // TODO: MESH_REWORK
-  DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
+  mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
+  SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
 }
 
 void Material::GetBlendEquation( BlendingEquation::Type& equationRgb,
                                  BlendingEquation::Type& equationAlpha ) const
 {
-  // TODO: MESH_REWORK
-  DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
+  // These are not animatable, the cached values are up-to-date.
+  equationRgb   = mBlendingOptions.GetBlendEquationRgb();
+  equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
 }
 
 void Material::SetBlendColor( const Vector4& color )
@@ -238,29 +241,68 @@ void Material::SetDefaultProperty( Property::Index index,
       }
       break;
     }
-    case Dali::Material::Property::BLEND_EQUATION:
+    case Dali::Material::Property::BLEND_EQUATION_RGB:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      BlendingEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
+      mBlendingOptions.SetBlendEquation( static_cast<BlendingEquation::Type>(propertyValue.Get<int>()), alphaEquation );
+      break;
+    }
+    case Dali::Material::Property::BLEND_EQUATION_ALPHA:
+    {
+      BlendingEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
+      mBlendingOptions.SetBlendEquation( rgbEquation, static_cast<BlendingEquation::Type>(propertyValue.Get<int>()) );
       break;
     }
     case Dali::Material::Property::BLENDING_SRC_FACTOR_RGB:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      BlendingFactor::Type srcFactorRgb;
+      BlendingFactor::Type destFactorRgb;
+      BlendingFactor::Type srcFactorAlpha;
+      BlendingFactor::Type destFactorAlpha;
+      GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+      SetBlendFunc( static_cast<BlendingFactor::Type>(propertyValue.Get<int>()),
+                    destFactorRgb,
+                    srcFactorAlpha,
+                    destFactorAlpha );
       break;
     }
     case Dali::Material::Property::BLENDING_DEST_FACTOR_RGB:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      BlendingFactor::Type srcFactorRgb;
+      BlendingFactor::Type destFactorRgb;
+      BlendingFactor::Type srcFactorAlpha;
+      BlendingFactor::Type destFactorAlpha;
+      GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+      SetBlendFunc( srcFactorRgb,
+                    static_cast<BlendingFactor::Type>(propertyValue.Get<int>()),
+                    srcFactorAlpha,
+                    destFactorAlpha );
       break;
     }
     case Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      BlendingFactor::Type srcFactorRgb;
+      BlendingFactor::Type destFactorRgb;
+      BlendingFactor::Type srcFactorAlpha;
+      BlendingFactor::Type destFactorAlpha;
+      GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+      SetBlendFunc( srcFactorRgb,
+                    destFactorRgb,
+                    static_cast<BlendingFactor::Type>(propertyValue.Get<int>()),
+                    destFactorAlpha );
       break;
     }
     case Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      BlendingFactor::Type srcFactorRgb;
+      BlendingFactor::Type destFactorRgb;
+      BlendingFactor::Type srcFactorAlpha;
+      BlendingFactor::Type destFactorAlpha;
+      GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+      SetBlendFunc( srcFactorRgb,
+                    destFactorRgb,
+                    srcFactorAlpha,
+                    static_cast<BlendingFactor::Type>(propertyValue.Get<int>()) );
       break;
     }
     case Dali::Material::Property::BLEND_COLOR:
@@ -310,29 +352,54 @@ Property::Value Material::GetDefaultProperty( Property::Index index ) const
       }
       break;
     }
-    case Dali::Material::Property::BLEND_EQUATION:
+    case Dali::Material::Property::BLEND_EQUATION_RGB:
+    {
+      value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
+      break;
+    }
+    case Dali::Material::Property::BLEND_EQUATION_ALPHA:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
       break;
     }
     case Dali::Material::Property::BLENDING_SRC_FACTOR_RGB:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      BlendingFactor::Type srcFactorRgb;
+      BlendingFactor::Type destFactorRgb;
+      BlendingFactor::Type srcFactorAlpha;
+      BlendingFactor::Type destFactorAlpha;
+      GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+      value = static_cast<int>( srcFactorRgb );
       break;
     }
     case Dali::Material::Property::BLENDING_DEST_FACTOR_RGB:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      BlendingFactor::Type srcFactorRgb;
+      BlendingFactor::Type destFactorRgb;
+      BlendingFactor::Type srcFactorAlpha;
+      BlendingFactor::Type destFactorAlpha;
+      GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+      value = static_cast<int>( destFactorRgb );
       break;
     }
     case Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      BlendingFactor::Type srcFactorRgb;
+      BlendingFactor::Type destFactorRgb;
+      BlendingFactor::Type srcFactorAlpha;
+      BlendingFactor::Type destFactorAlpha;
+      GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+      value = static_cast<int>( srcFactorAlpha );
       break;
     }
     case Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA:
     {
-      DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
+      BlendingFactor::Type srcFactorRgb;
+      BlendingFactor::Type destFactorRgb;
+      BlendingFactor::Type srcFactorAlpha;
+      BlendingFactor::Type destFactorAlpha;
+      GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+      value = static_cast<int>( destFactorAlpha );
       break;
     }
     case Dali::Material::Property::BLEND_COLOR:
@@ -424,36 +491,6 @@ const PropertyInputImpl* Material::GetSceneObjectInputProperty( Property::Index
           property = &mSceneObject->mFaceCullingMode;
           break;
         }
-        case Dali::Material::Property::BLENDING_MODE:
-        {
-          DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
-          break;
-        }
-        case Dali::Material::Property::BLEND_EQUATION:
-        {
-          DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
-          break;
-        }
-        case Dali::Material::Property::BLENDING_SRC_FACTOR_RGB:
-        {
-          DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
-          break;
-        }
-        case Dali::Material::Property::BLENDING_DEST_FACTOR_RGB:
-        {
-          DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
-          break;
-        }
-        case Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA:
-        {
-          DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
-          break;
-        }
-        case Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA:
-        {
-          DALI_ASSERT_ALWAYS( 0 && "Mesh Rework" );
-          break;
-        }
         case Dali::Material::Property::BLEND_COLOR:
         {
           property = &mSceneObject->mBlendColor;
index 96a573f..48392c2 100644 (file)
@@ -31,6 +31,7 @@
 #include <dali/internal/event/common/property-buffer-impl.h> // Dali::Internal::PropertyBuffer
 #include <dali/internal/event/effects/sampler-impl.h> // Dali::Internal::Sampler
 #include <dali/internal/event/effects/shader-impl.h> // Dali::Internal::Shader
+#include <dali/internal/common/blending-options.h>
 
 namespace Dali
 {
@@ -269,6 +270,7 @@ private: //data
   SceneGraph::Material* mSceneObject;
 
   BlendingMode::Type mBlendingMode; ///< Local store
+  BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
   bool mOnStage;
 };
 
index 744eba6..914f9b8 100644 (file)
@@ -20,8 +20,9 @@
 // INTERNAL HEADERS
 #include <dali/public-api/shader-effects/material.h>
 #include <dali/public-api/shader-effects/shader-effect.h>
-#include <dali/internal/render/data-providers/sampler-data-provider.h>
+#include <dali/internal/common/internal-constants.h>
 #include <dali/internal/update/effects/scene-graph-sampler.h>
+#include <dali/internal/render/data-providers/sampler-data-provider.h>
 #include <dali/internal/render/shaders/scene-graph-shader.h>
 #include <dali/public-api/actors/blending.h>
 
@@ -37,12 +38,7 @@ Material::Material()
   mBlendColor( Color::WHITE ),
   mFaceCullingMode(Dali::Material::NONE),
   mBlendingMode(Dali::BlendingMode::AUTO),
-  mBlendFuncSrcFactorRgb(DEFAULT_BLENDING_SRC_FACTOR_RGB),
-  mBlendFuncSrcFactorAlpha(DEFAULT_BLENDING_SRC_FACTOR_ALPHA),
-  mBlendFuncDestFactorRgb(DEFAULT_BLENDING_DEST_FACTOR_RGB),
-  mBlendFuncDestFactorAlpha(DEFAULT_BLENDING_SRC_FACTOR_ALPHA),
-  mBlendEquationRgb(DEFAULT_BLENDING_EQUATION_RGB),
-  mBlendEquationAlpha(DEFAULT_BLENDING_EQUATION_ALPHA),
+  mBlendingOptions(DEFAULT_BLENDING_EQUATION_ALPHA),
   mShader(NULL),
   mBlendingEnabled(false)
 {
@@ -124,6 +120,12 @@ void Material::PrepareRender( BufferIndex bufferIndex )
 
       if( opaque )
       {
+        // Check the material color:
+        opaque = ( mColor[ bufferIndex ].a >= FULLY_OPAQUE );
+      }
+
+      if( opaque )
+      {
         // Require that all affecting samplers are opaque
         unsigned int opaqueCount=0;
         unsigned int affectingCount=0;
@@ -162,6 +164,11 @@ bool Material::GetBlendingEnabled( BufferIndex bufferIndex ) const
   return mBlendingEnabled[bufferIndex];
 }
 
+void Material::SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options )
+{
+  mBlendingOptions.Set( updateBufferIndex, options );
+}
+
 const Vector4& Material::GetBlendColor(BufferIndex bufferIndex) const
 {
   return mBlendColor[bufferIndex];
@@ -169,32 +176,44 @@ const Vector4& Material::GetBlendColor(BufferIndex bufferIndex) const
 
 BlendingFactor::Type Material::GetBlendSrcFactorRgb( BufferIndex bufferIndex ) const
 {
-  return static_cast<Dali::BlendingFactor::Type>(mBlendFuncSrcFactorRgb[bufferIndex]);
+  BlendingOptions blendingOptions;
+  blendingOptions.SetBitmask( mBlendingOptions[ bufferIndex ] );
+  return blendingOptions.GetBlendSrcFactorRgb();
 }
 
 BlendingFactor::Type Material::GetBlendSrcFactorAlpha( BufferIndex bufferIndex ) const
 {
-  return static_cast<Dali::BlendingFactor::Type>(mBlendFuncSrcFactorAlpha[bufferIndex]);
+  BlendingOptions blendingOptions;
+  blendingOptions.SetBitmask( mBlendingOptions[ bufferIndex ] );
+  return blendingOptions.GetBlendSrcFactorAlpha();
 }
 
 BlendingFactor::Type Material::GetBlendDestFactorRgb( BufferIndex bufferIndex ) const
 {
-  return static_cast<Dali::BlendingFactor::Type>(mBlendFuncDestFactorRgb[bufferIndex]);
+  BlendingOptions blendingOptions;
+  blendingOptions.SetBitmask( mBlendingOptions[ bufferIndex ] );
+  return blendingOptions.GetBlendDestFactorRgb();
 }
 
 BlendingFactor::Type Material::GetBlendDestFactorAlpha( BufferIndex bufferIndex ) const
 {
-  return static_cast<Dali::BlendingFactor::Type>(mBlendFuncDestFactorAlpha[bufferIndex]);
+  BlendingOptions blendingOptions;
+  blendingOptions.SetBitmask( mBlendingOptions[ bufferIndex ] );
+  return blendingOptions.GetBlendDestFactorAlpha();
 }
 
 BlendingEquation::Type Material::GetBlendEquationRgb( BufferIndex bufferIndex ) const
 {
-  return static_cast<Dali::BlendingEquation::Type>(mBlendEquationRgb[bufferIndex]);
+  BlendingOptions blendingOptions;
+  blendingOptions.SetBitmask( mBlendingOptions[ bufferIndex ] );
+  return blendingOptions.GetBlendEquationRgb();
 }
 
 BlendingEquation::Type Material::GetBlendEquationAlpha( BufferIndex bufferIndex ) const
 {
-  return static_cast<Dali::BlendingEquation::Type>(mBlendEquationAlpha[bufferIndex]);
+  BlendingOptions blendingOptions;
+  blendingOptions.SetBitmask( mBlendingOptions[ bufferIndex ] );
+  return blendingOptions.GetBlendEquationAlpha();
 }
 
 void Material::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
@@ -239,12 +258,7 @@ void Material::ResetDefaultProperties( BufferIndex updateBufferIndex )
   mFaceCullingMode.CopyPrevious( updateBufferIndex );
 
   mBlendingMode.CopyPrevious( updateBufferIndex );
-  mBlendFuncSrcFactorRgb.CopyPrevious( updateBufferIndex );
-  mBlendFuncSrcFactorAlpha.CopyPrevious( updateBufferIndex );
-  mBlendFuncDestFactorRgb.CopyPrevious( updateBufferIndex );
-  mBlendFuncDestFactorAlpha.CopyPrevious( updateBufferIndex );
-  mBlendEquationRgb.CopyPrevious( updateBufferIndex );
-  mBlendEquationAlpha.CopyPrevious( updateBufferIndex );
+  mBlendingOptions.CopyPrevious( updateBufferIndex );
 }
 
 } // namespace SceneGraph
index 4245554..148433d 100644 (file)
@@ -84,6 +84,13 @@ public:
    */
   bool GetBlendingEnabled( BufferIndex bufferIndex ) const;
 
+  /**
+   * Set the blending options. This should only be called from the update-thread.
+   * @param[in] updateBufferIndex The current update buffer index.
+   * @param[in] options A bitmask of blending options.
+   */
+  void SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options );
+
 public: // Implementation of MaterialDataProvider
 
   /**
@@ -190,20 +197,13 @@ public: // Property data
   AnimatableProperty<Vector4> mBlendColor;
   DoubleBufferedProperty<int> mFaceCullingMode;
   DoubleBufferedProperty<int> mBlendingMode;
-
-  // @todo MESH_REWORK Consider storing only mBlendingOptions bitmask
-  DoubleBufferedProperty<int> mBlendFuncSrcFactorRgb;
-  DoubleBufferedProperty<int> mBlendFuncSrcFactorAlpha;
-  DoubleBufferedProperty<int> mBlendFuncDestFactorRgb;
-  DoubleBufferedProperty<int> mBlendFuncDestFactorAlpha;
-  DoubleBufferedProperty<int> mBlendEquationRgb;
-  DoubleBufferedProperty<int> mBlendEquationAlpha;
+  DoubleBufferedProperty<int> mBlendingOptions;
 
 private:
   Shader* mShader;
   Vector<Sampler*> mSamplers; // Not owned
   ConnectionChangePropagator mConnectionObservers;
-  DoubleBuffered<bool> mBlendingEnabled; // The output of the current blending mode and sampler properties
+  DoubleBuffered<int> mBlendingEnabled; // The output of the current blending mode and sampler properties
 };
 
 inline void SetShaderMessage( EventThreadServices& eventThreadServices, const Material& material, const Shader& shader )
@@ -239,6 +239,17 @@ inline void RemoveSamplerMessage( EventThreadServices& eventThreadServices, cons
   new (slot) LocalType( &material, &Material::RemoveSampler, const_cast<Sampler*>(&sampler) );
 }
 
+inline void SetBlendingOptionsMessage( EventThreadServices& eventThreadServices, const Material& material, unsigned int options )
+{
+  typedef MessageDoubleBuffered1< Material, unsigned int > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &material, &Material::SetBlendingOptions, options );
+}
+
+
 } // namespace SceneGraph
 } // namespace Internal
 } // namespace Dali
index 8bc3f3e..6904183 100644 (file)
@@ -32,7 +32,7 @@ Sampler::Sampler( const std::string& textureUnitUniformName )
   mMagFilter( Dali::Sampler::DEFAULT ),
   mUWrapMode( Dali::Sampler::CLAMP_TO_EDGE ),
   mVWrapMode( Dali::Sampler::CLAMP_TO_EDGE ),
-  mAffectsTransparency( false ),
+  mAffectsTransparency( true ),
   mTextureUnitUniformName( textureUnitUniformName ),
   mTextureId( 0u ),
   mFullyOpaque(true)
index 0d974b4..b6bcbe9 100644 (file)
@@ -69,7 +69,8 @@ public:
       COLOR = DEFAULT_OBJECT_PROPERTY_START_INDEX,  ///< name "color",                          type VECTOR4
       FACE_CULLING_MODE,                            ///< name "face-culling-mode",              type STRING
       BLENDING_MODE,                                ///< name "blending-mode",                  type STRING
-      BLEND_EQUATION,                               ///< name "blend-equation",                 type STRING
+      BLEND_EQUATION_RGB,                           ///< name "blend-equation-rgb",             type STRING
+      BLEND_EQUATION_ALPHA,                         ///< name "blend-equation-alpha",           type STRING
       BLENDING_SRC_FACTOR_RGB,                      ///< name "source-blend-factor-rgb",        type STRING
       BLENDING_DEST_FACTOR_RGB,                     ///< name "destination-blend-factor-rgb",   type STRING
       BLENDING_SRC_FACTOR_ALPHA,                    ///< name "source-blend-factor-alpha",      type STRING