{
TestApplication application;
- tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
+ tet_infoline("Test setting the blend mode to auto with a transparent material color renders with blending enabled");
Geometry geometry = CreateQuadGeometry();
Material material = CreateMaterial(0.5f);
END_TEST;
}
+int UtcDaliMaterialSetBlendMode04b(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test setting the blend mode to auto with an opaque material color and a transparent actor 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);
+ actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
+ 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 UtcDaliMaterialSetBlendMode04c(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test setting the blend mode to auto with an opaque material color and an opaque actor 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);
+ actor.SetColor( Color::MAGENTA );
+ 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;
END_TEST;
}
+
+int UtcDaliMaterialSetBlendMode06(void)
+{
+ TestApplication application;
+ tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_TRANSPARENT renders with blending enabled");
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_TRANSPARENT );
+ Material material = Material::New(shader);
+ material.SetProperty(Material::Property::COLOR, Color::WHITE);
+
+ 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 UtcDaliMaterialSetBlendMode07(void)
+{
+ TestApplication application;
+ tet_infoline("Test setting the blend mode to auto with a transparent color and an image without an alpha channel and a shader with the hint OUTPUT_IS_OPAQUE renders with blending disabled");
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
+ Material material = Material::New(shader);
+ material.SetProperty(Material::Property::COLOR, Color::TRANSPARENT);
+
+ 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 UtcDaliMaterialSetBlendMode08(void)
+{
+ TestApplication application;
+ tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel and a shader with the hint OUTPUT_IS_OPAQUE renders with blending disabled");
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
+ Material material = Material::New(shader);
+ material.SetProperty(Material::Property::COLOR, Color::WHITE);
+ BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
+ Sampler sampler = Sampler::New( image, "sTexture" );
+ material.AddSampler( sampler );
+ 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;
+}
namespace SceneGraph
{
+namespace
+{
+const unsigned int DEFAULT_BLENDING_OPTIONS( BlendingOptions().GetBitmask() );
+}
+
Material::Material()
: mColor( Color::WHITE ),
mBlendColor( Color::WHITE ),
mFaceCullingMode(Dali::Material::NONE),
mBlendingMode(Dali::BlendingMode::AUTO),
- mBlendingOptions(DEFAULT_BLENDING_EQUATION_ALPHA),
+ mBlendingOptions( DEFAULT_BLENDING_OPTIONS ),
mShader(NULL),
- mBlendingEnabled(false)
+ mBlendPolicy(OPAQUE)
{
// Observe own property-owner's uniform map
AddUniformMapObserver( *this );
void Material::PrepareRender( BufferIndex bufferIndex )
{
- mBlendingEnabled[bufferIndex] = false; // The best default
+ mBlendPolicy = OPAQUE;
+
+ // @todo MESH_REWORK Add dirty flags to reduce processing.
switch(mBlendingMode[bufferIndex])
{
case BlendingMode::OFF:
{
- mBlendingEnabled[bufferIndex] = false;
+ mBlendPolicy = OPAQUE;
break;
}
case BlendingMode::ON:
{
- mBlendingEnabled[bufferIndex] = true;
+ mBlendPolicy = TRANSPARENT;
break;
}
case BlendingMode::AUTO:
{
bool opaque = true;
- // @todo: MESH_REWORK - Change hints for new SceneGraphShader
+ // @todo: MESH_REWORK - Change hints for new SceneGraphShader:
+ // If shader hint OUTPUT_IS_OPAQUE is enabled, set policy to ALWAYS_OPAQUE
+ // If shader hint OUTPUT_IS_TRANSPARENT is enabled, set policy to ALWAYS_TRANSPARENT
+ // else test remainder, and set policy to either ALWAYS_TRANSPARENT or USE_ACTOR_COLOR
+
if( mShader->GeometryHintEnabled( Dali::ShaderEffect::HINT_BLENDING ) )
{
opaque = false;
opaque = (opaqueCount == affectingCount);
}
- mBlendingEnabled[bufferIndex] = ! opaque;
+ mBlendPolicy = opaque ? Material::USE_ACTOR_COLOR : Material::TRANSPARENT;
}
}
}
return mSamplers;
}
-bool Material::GetBlendingEnabled( BufferIndex bufferIndex ) const
+Material::BlendPolicy Material::GetBlendPolicy() const
{
- return mBlendingEnabled[bufferIndex];
+ return mBlendPolicy;
}
void Material::SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options )
{
public:
/**
+ * This enum defines the outputs of the PrepareRender step, and is used
+ * by the Renderer to determine final opacity.
+ */
+ enum BlendPolicy
+ {
+ OPAQUE, ///< If the renderer should always be opaque
+ TRANSPARENT, ///< If the renderer should always be transparent
+ USE_ACTOR_COLOR ///< If the renderer should determine opacity using the actor color
+ };
+
+ /**
* Constructor
*/
Material();
void PrepareRender( BufferIndex bufferIndex );
/**
- * Return true if the material requires blending
- * @return true if the material requires blending
+ * Return the blend policy ( a combination of all the different shader hints, color, samper and image properties ).
+ * This should only be called from the update thread
+ * @return The material's blend policy
*/
- bool GetBlendingEnabled( BufferIndex bufferIndex ) const;
+ BlendPolicy GetBlendPolicy() const;
/**
- * Set the blending options. This should only be called from the update-thread.
+ * 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.
*/
Shader* mShader;
Vector<Sampler*> mSamplers; // Not owned
ConnectionChangePropagator mConnectionObservers;
- DoubleBuffered<int> mBlendingEnabled; // The output of the current blending mode and sampler properties
+ BlendPolicy mBlendPolicy; ///< The blend policy as determined by PrepareRender
};
inline void SetShaderMessage( EventThreadServices& eventThreadServices, const Material& material, const Shader& shader )