END_TEST;
}
-int UtcDaliMaterialSetFaceCullingMode(void)
-{
- TestApplication application;
-
- tet_infoline("Test SetFaceCullingMode(cullingMode)");
- Geometry geometry = CreateQuadGeometry();
- Material material = CreateMaterial();
- 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();
- TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
- gl.EnableCullFaceCallTrace(true);
-
- {
- cullFaceStack.Reset();
- material.SetFaceCullingMode( Material::CULL_BACK_AND_FRONT );
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
-
- std::ostringstream cullModeString;
- cullModeString << GL_FRONT_AND_BACK;
-
- DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
- }
-
- {
- cullFaceStack.Reset();
- material.SetFaceCullingMode( Material::CULL_BACK );
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
-
- std::ostringstream cullModeString;
- cullModeString << GL_BACK;
-
- DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
- }
-
- {
- cullFaceStack.Reset();
- material.SetFaceCullingMode( Material::CULL_FRONT );
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
-
- std::ostringstream cullModeString;
- cullModeString << GL_FRONT;
-
- DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
- }
-
- {
- cullFaceStack.Reset();
- material.SetFaceCullingMode( Material::NONE );
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
- }
-
- END_TEST;
-}
-
-int UtcDaliMaterialBlendingOptions01(void)
-{
- TestApplication application;
-
- tet_infoline("Test SetBlendFunc(src, dest) ");
-
- Geometry geometry = CreateQuadGeometry();
- Material material = CreateMaterial();
- Renderer renderer = Renderer::New( geometry, material );
-
- Actor actor = Actor::New();
- // set a transparent actor color so that blending is enabled
- actor.SetOpacity( 0.5f );
- 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();
- Renderer renderer = Renderer::New( geometry, material );
-
- Actor actor = Actor::New();
- actor.SetOpacity( 0.5f ); // enable blending
- 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();
- 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 in 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();
- Renderer renderer = Renderer::New( geometry, material );
-
- Actor actor = Actor::New();
- actor.SetOpacity( 0.1f );
- 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();
- Renderer renderer = Renderer::New( geometry, material );
-
- Actor actor = Actor::New();
- actor.SetOpacity( 0.98f );
- actor.AddRenderer(renderer);
- actor.SetSize(400, 400);
- Stage::GetCurrent().Add(actor);
-
- material.SetBlendMode(BlendingMode::ON);
-
- TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
- glAbstraction.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- 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();
- Renderer renderer = Renderer::New( geometry, material );
-
- Actor actor = Actor::New();
- actor.SetOpacity( 0.15f );
- actor.AddRenderer(renderer);
- actor.SetSize(400, 400);
- Stage::GetCurrent().Add(actor);
-
- material.SetBlendMode(BlendingMode::OFF);
-
- TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
- glAbstraction.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- 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 material color renders with blending enabled");
-
- Geometry geometry = CreateQuadGeometry();
- Material material = CreateMaterial();
- Renderer renderer = Renderer::New( geometry, material );
-
- Actor actor = Actor::New();
- actor.SetOpacity( 0.75f );
- actor.AddRenderer(renderer);
- actor.SetSize(400, 400);
- Stage::GetCurrent().Add(actor);
-
- material.SetBlendMode(BlendingMode::AUTO);
-
- TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
- glAbstraction.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- 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();
- 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.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- std::ostringstream blendStr;
- blendStr << GL_BLEND;
- DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
-
- 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();
- 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.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- 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();
- 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.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- 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( 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.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- std::ostringstream blendStr;
- blendStr << GL_BLEND;
- DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
-
- 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);
-
- 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.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- std::ostringstream blendStr;
- blendStr << GL_BLEND;
- DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
-
- END_TEST;
-}
-
-
-//Todo: test the Shader::HINT_OUTPUT_IS_OPAQUE would disable the blending, the test cannot pass with current implementation
-/*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);
-
- 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.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- 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 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);
- BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
- material.AddTexture( image, "sTexture" );
- 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.EnableEnableDisableCallTrace(true);
-
- application.SendNotification();
- application.Render();
-
- TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
- DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
-
- END_TEST;
-}
-
-int UtcDaliMaterialGetBlendMode(void)
-{
- TestApplication application;
-
- tet_infoline("Test GetBlendMode()");
-
- Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
- Material material = Material::New(shader);
-
- // default value
- DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::AUTO, TEST_LOCATION );
-
- // ON
- material.SetBlendMode(BlendingMode::ON);
- DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::ON, TEST_LOCATION );
-
- // OFF
- material.SetBlendMode(BlendingMode::OFF);
- DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::OFF, TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliMaterialSetBlendColor(void)
-{
- TestApplication application;
-
- tet_infoline("Test SetBlendColor(color)");
-
- Geometry geometry = CreateQuadGeometry();
- Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
- Material material = Material::New(shader);
- BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
- material.AddTexture( image, "sTexture" );
- Renderer renderer = Renderer::New( geometry, material );
-
- Actor actor = Actor::New();
- actor.AddRenderer(renderer);
- actor.SetSize(400, 400);
- Stage::GetCurrent().Add(actor);
-
- TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
-
- material.SetBlendColor( Color::TRANSPARENT );
- application.SendNotification();
- application.Render();
- DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
-
- material.SetBlendColor( Color::MAGENTA );
- application.SendNotification();
- application.Render();
- DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
-
- Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
- material.SetBlendColor( color );
- application.SendNotification();
- application.Render();
- DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliMaterialGetBlendColor(void)
-{
- TestApplication application;
-
- tet_infoline("Test GetBlendColor()");
-
- Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
- Material material = Material::New(shader);
-
- DALI_TEST_EQUALS( material.GetBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
-
- material.SetBlendColor( Color::MAGENTA );
- application.SendNotification();
- application.Render();
- DALI_TEST_EQUALS( material.GetBlendColor(), Color::MAGENTA, TEST_LOCATION );
-
- Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
- material.SetBlendColor( color );
- application.SendNotification();
- application.Render();
- DALI_TEST_EQUALS( material.GetBlendColor(), color, TEST_LOCATION );
-
- END_TEST;
-}
-
int UtcDaliMaterialConstraint(void)
{
TestApplication application;
application.SendNotification();
application.Render(0);
- DALI_TEST_EQUALS( renderer.GetDepthIndex(), 0, TEST_LOCATION );
DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
- renderer.SetDepthIndex(1);
+ renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
application.SendNotification();
application.Render(0);
- DALI_TEST_EQUALS( renderer.GetDepthIndex(), 1, TEST_LOCATION );
DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
- renderer.SetDepthIndex(10);
+ renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
application.SendNotification();
application.Render(0);
- DALI_TEST_EQUALS( renderer.GetDepthIndex(), 10, TEST_LOCATION );
DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
END_TEST;
}
+int UtcDaliRendererSetGetFaceCullingMode(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test SetFaceCullingMode(cullingMode)");
+ Geometry geometry = CreateQuadGeometry();
+ Material material = CreateMaterial();
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ // By default, none of the faces should be culled
+ unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
+ DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::NONE );
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
+ gl.EnableCullFaceCallTrace(true);
+
+ {
+ cullFaceStack.Reset();
+ renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, Renderer::CULL_BACK_AND_FRONT );
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
+
+ std::ostringstream cullModeString;
+ cullModeString << GL_FRONT_AND_BACK;
+
+ DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
+ cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
+ DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::CULL_BACK_AND_FRONT);
+ }
+
+ {
+ cullFaceStack.Reset();
+ renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, Renderer::CULL_BACK );
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
+
+ std::ostringstream cullModeString;
+ cullModeString << GL_BACK;
+
+ DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
+ cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
+ DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::CULL_BACK );
+ }
+
+ {
+ cullFaceStack.Reset();
+ renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, Renderer::CULL_FRONT );
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
+
+ std::ostringstream cullModeString;
+ cullModeString << GL_FRONT;
+
+ DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
+ cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
+ DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::CULL_FRONT );
+ }
+
+ {
+ cullFaceStack.Reset();
+ renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, Renderer::NONE );
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
+ cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
+ DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::NONE );
+ }
+
+ END_TEST;
+}
+
+int UtcDaliRendererBlendingOptions01(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test SetBlendFunc(src, dest) ");
+
+ Geometry geometry = CreateQuadGeometry();
+ Material material = CreateMaterial();
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ // set a transparent actor color so that blending is enabled
+ actor.SetOpacity( 0.5f );
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ renderer.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 );
+ renderer.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 UtcDaliRendererBlendingOptions02(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test SetBlendFunc(srcRgb, destRgb, srcAlpha, destAlpha) ");
+
+ Geometry geometry = CreateQuadGeometry();
+ Material material = CreateMaterial();
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.SetOpacity( 0.5f ); // enable blending
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ renderer.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 );
+ renderer.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 UtcDaliRendererBlendingOptions03(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test GetBlendEquation() defaults ");
+
+ Geometry geometry = CreateQuadGeometry();
+ Material material = CreateMaterial();
+ 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 in blending.h
+ BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
+ BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
+ renderer.GetBlendEquation( equationRgb, equationAlpha );
+ DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION );
+ DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliRendererBlendingOptions04(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test SetBlendEquation() ");
+
+ Geometry geometry = CreateQuadGeometry();
+ Material material = CreateMaterial();
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.SetOpacity( 0.1f );
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ // Test the single blending equation setting
+ {
+ renderer.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT );
+ BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT );
+ renderer.GetBlendEquation( equationRgba, equationRgba );
+ DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION );
+ }
+
+ renderer.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT );
+
+ // Test that Set was successful
+ {
+ BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
+ BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
+ renderer.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 UtcDaliRendererSetBlendMode01(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();
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.SetOpacity( 0.98f );
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
+ std::ostringstream blendStr;
+ blendStr << GL_BLEND;
+ DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetBlendMode02(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();
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.SetOpacity( 0.15f );
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::OFF);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
+ std::ostringstream blendStr;
+ blendStr << GL_BLEND;
+ DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetBlendMode03(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test setting the blend mode to auto with a transparent material color renders with blending enabled");
+
+ Geometry geometry = CreateQuadGeometry();
+ Material material = CreateMaterial();
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.SetOpacity( 0.75f );
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
+ std::ostringstream blendStr;
+ blendStr << GL_BLEND;
+ DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetBlendMode04(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();
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
+ std::ostringstream blendStr;
+ blendStr << GL_BLEND;
+ DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetBlendMode04b(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();
+ 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);
+
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
+ std::ostringstream blendStr;
+ blendStr << GL_BLEND;
+ DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetBlendMode04c(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();
+ 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);
+
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
+ std::ostringstream blendStr;
+ blendStr << GL_BLEND;
+ DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetBlendMode05(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( image );
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
+ std::ostringstream blendStr;
+ blendStr << GL_BLEND;
+ DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetBlendMode06(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);
+
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
+ std::ostringstream blendStr;
+ blendStr << GL_BLEND;
+ DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetBlendMode07(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_OPAQUE renders with blending disabled");
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
+ Material material = Material::New(shader);
+ BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
+ material.AddTexture( image, "sTexture" );
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+
+ application.SendNotification();
+ application.Render();
+
+ TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
+ DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererGetBlendMode(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test GetBlendMode()");
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
+ Material material = Material::New(shader);
+ Renderer renderer = Renderer::New( geometry, material );
+
+ // default value
+ unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLENDING_MODE );
+ DALI_TEST_EQUALS( static_cast< BlendingMode::Type >( mode ), BlendingMode::AUTO, TEST_LOCATION );
+
+ // ON
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON );
+ mode = renderer.GetProperty<int>( Renderer::Property::BLENDING_MODE );
+ DALI_TEST_EQUALS( static_cast< BlendingMode::Type >( mode ), BlendingMode::ON, TEST_LOCATION );
+
+ // OFF
+ renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::OFF );
+ mode = renderer.GetProperty<int>( Renderer::Property::BLENDING_MODE );
+ DALI_TEST_EQUALS( static_cast< BlendingMode::Type >( mode ), BlendingMode::OFF, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetBlendColor(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test SetBlendColor(color)");
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
+ Material material = Material::New(shader);
+ BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
+ material.AddTexture( image, "sTexture" );
+ Renderer renderer = Renderer::New( geometry, material );
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage::GetCurrent().Add(actor);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+
+ renderer.SetProperty( Renderer::Property::BLENDING_COLOR, Color::TRANSPARENT );
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
+
+ renderer.SetProperty( Renderer::Property::BLENDING_COLOR, Color::MAGENTA );
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
+
+ Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
+ renderer.SetProperty( Renderer::Property::BLENDING_COLOR, color );
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliRendererGetBlendColor(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test GetBlendColor()");
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
+ Material material = Material::New(shader);
+ Renderer renderer = Renderer::New( geometry, material );
+
+ DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLENDING_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
+
+ renderer.SetProperty( Renderer::Property::BLENDING_COLOR, Color::MAGENTA );
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLENDING_COLOR ), Color::MAGENTA, TEST_LOCATION );
+
+ Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
+ renderer.SetProperty( Renderer::Property::BLENDING_COLOR, color );
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLENDING_COLOR ), color, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliRendererPreMultipledAlpha(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
+ Material material = Material::New(shader);
+
+ 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);
+
+ Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
+ bool preMultipliedAlpha;
+ DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
+ DALI_TEST_CHECK( !preMultipliedAlpha );
+
+ BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
+ BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
+ BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
+ BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
+ renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+ DALI_TEST_EQUALS( DEFAULT_BLENDING_SRC_FACTOR_RGB, srcFactorRgb, TEST_LOCATION );
+ DALI_TEST_EQUALS( DEFAULT_BLENDING_DEST_FACTOR_RGB, destFactorRgb, TEST_LOCATION );
+ DALI_TEST_EQUALS( DEFAULT_BLENDING_SRC_FACTOR_ALPHA, srcFactorAlpha, TEST_LOCATION );
+ DALI_TEST_EQUALS( DEFAULT_BLENDING_DEST_FACTOR_ALPHA, destFactorAlpha, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ Vector4 actualValue(Vector4::ZERO);
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
+ DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
+
+ renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
+
+ application.SendNotification();
+ application.Render();
+
+ value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
+ DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
+ DALI_TEST_CHECK( preMultipliedAlpha );
+
+ renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+ DALI_TEST_EQUALS( BlendingFactor::ONE, srcFactorRgb, TEST_LOCATION );
+ DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
+ DALI_TEST_EQUALS( BlendingFactor::ONE, srcFactorAlpha, TEST_LOCATION );
+ DALI_TEST_EQUALS( BlendingFactor::ONE, destFactorAlpha, TEST_LOCATION );
+
+ DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
+ DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliRendererConstraint01(void)
{
TestApplication application;
Material material0 = Material::New( shader );
material0.AddTexture( image0, "sTexture0" );
Renderer renderer0 = Renderer::New( geometry, material0 );
- renderer0.SetDepthIndex( 2 );
+ renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, 2 );
actor0.AddRenderer(renderer0);
application.SendNotification();
application.Render(0);
Material material1 = Material::New( shader );
material1.AddTexture( image1, "sTexture1" );
Renderer renderer1 = Renderer::New( geometry, material1 );
- renderer1.SetDepthIndex( 0 );
+ renderer1.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
actor0.AddRenderer(renderer1);
application.SendNotification();
application.Render(0);
Material material2 = Material::New( shader );
material2.AddTexture( image2, "sTexture2" );
Renderer renderer2 = Renderer::New( geometry, material2 );
- renderer2.SetDepthIndex( 1 );
+ renderer2.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
actor0.AddRenderer(renderer2);
application.SendNotification();
application.Render(0);
Material material3 = Material::New( shader );
material3.AddTexture( image3, "sTexture3" );
Renderer renderer3 = Renderer::New( geometry, material3 );
- renderer3.SetDepthIndex( 1 );
+ renderer3.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
actor1.AddRenderer(renderer3);
application.SendNotification();
application.Render(0);
Material material4 = Material::New( shader );
material4.AddTexture( image4, "sTexture4" );
Renderer renderer4 = Renderer::New( geometry, material4 );
- renderer4.SetDepthIndex( 0 );
+ renderer4.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
actor1.AddRenderer(renderer4);
application.SendNotification();
application.Render(0);
Material material5 = Material::New( shader );
material5.AddTexture( image5, "sTexture5" );
Renderer renderer5 = Renderer::New( geometry, material5 );
- renderer5.SetDepthIndex( -1 );
+ renderer5.SetProperty( Renderer::Property::DEPTH_INDEX, -1 );
actor1.AddRenderer(renderer5);
application.SendNotification();
application.Render(0);
}
-void Material::SetFaceCullingMode( FaceCullingMode cullingMode )
-{
- GetImplementation(*this).SetFaceCullingMode( cullingMode );
-}
-
-Material::FaceCullingMode Material::GetFaceCullingMode()
-{
- return GetImplementation(*this).GetFaceCullingMode();
-}
-
-void Material::SetBlendMode( BlendingMode::Type mode )
-{
- GetImplementation(*this).SetBlendMode( mode );
-}
-
-BlendingMode::Type Material::GetBlendMode() const
-{
- return GetImplementation(*this).GetBlendMode();
-}
-
-void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgba,
- BlendingFactor::Type destFactorRgba )
-{
- GetImplementation(*this).SetBlendFunc( srcFactorRgba, destFactorRgba );
-}
-
-void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
- BlendingFactor::Type destFactorRgb,
- BlendingFactor::Type srcFactorAlpha,
- BlendingFactor::Type destFactorAlpha )
-{
- GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
-}
-
-void Material::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
- BlendingFactor::Type& destFactorRgb,
- BlendingFactor::Type& srcFactorAlpha,
- BlendingFactor::Type& destFactorAlpha ) const
-{
- GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
-}
-
-void Material::SetBlendEquation( BlendingEquation::Type equationRgba )
-{
- GetImplementation(*this).SetBlendEquation( equationRgba );
-}
-
-void Material::SetBlendEquation( BlendingEquation::Type equationRgb,
- BlendingEquation::Type equationAlpha )
-{
- GetImplementation(*this).SetBlendEquation( equationRgb, equationAlpha );
-}
-
-void Material::GetBlendEquation( BlendingEquation::Type& equationRgb,
- BlendingEquation::Type& equationAlpha ) const
-{
- GetImplementation(*this).GetBlendEquation( equationRgb, equationAlpha );
-}
-
-void Material::SetBlendColor( const Vector4& color )
-{
- GetImplementation(*this).SetBlendColor( color );
-}
-
-Vector4 Material::GetBlendColor() const
-{
- return GetImplementation(*this).GetBlendColor();
-}
-
Material::Material( Internal::Material* pointer )
: Handle( pointer )
{
#include <string> // std::string
// INTERNAL INCLUDES
-#include <dali/public-api/actors/blending.h> // Dali::BlendingMode, Dali::BlendingEquation, Dali::BlendingFactor
#include <dali/public-api/images/image.h> // Dali::Image
#include <dali/public-api/object/handle.h> // Dali::Handle
-#include <dali/public-api/object/property-index-ranges.h> // DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX
#include <dali/devel-api/rendering/sampler.h> // Dali::Sampler
#include <dali/devel-api/rendering/shader.h> // Dali::Shader
public:
/**
- * @brief Set face culling mode.
- */
- enum FaceCullingMode
- {
- NONE, ///< None of the faces should be culled
- CULL_FRONT, ///< Cull front face, back face should never be shown
- CULL_BACK, ///< Cull back face, back face should never be shown
- CULL_BACK_AND_FRONT, ///< Cull back and front faces, if the geometry is composed of triangles none of the faces will be shown
- };
-
- /**
- * @brief An enumeration of properties belonging to the Material class.
- */
- struct Property
- {
- enum
- {
- FACE_CULLING_MODE = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "faceCullingMode", type INTEGER
- BLENDING_MODE, ///< name "blendingMode", type INTEGER
- BLEND_EQUATION_RGB, ///< name "blendEquationRgb", type INTEGER
- BLEND_EQUATION_ALPHA, ///< name "blendEquationAlpha", type INTEGER
- BLENDING_SRC_FACTOR_RGB, ///< name "sourceBlendFactorRgb", type INTEGER
- BLENDING_DEST_FACTOR_RGB, ///< name "destinationBlendFactorRgb", type INTEGER
- BLENDING_SRC_FACTOR_ALPHA, ///< name "sourceBlendFactorAlpha", type INTEGER
- BLENDING_DEST_FACTOR_ALPHA, ///< name "destinationBlendFactorAlpha", type INTEGER
- BLEND_COLOR, ///< name "blendColor", type VECTOR4
- };
- };
-
- /**
* @brief Creates a new Material object
*
* @return A handle to a newly allocated Material
*/
std::size_t GetNumberOfTextures() const;
- /**
- * @brief Set the culling mode for this material
- *
- * Calling this function sets the property CULLING_MODE
- *
- * @param[in] cullingMode The culling mode for this material
- */
- void SetFaceCullingMode( FaceCullingMode cullingMode );
-
- /**
- * @brief Get the face culling mode for this material
- *
- * @return The face culling mode for this material
- */
- FaceCullingMode GetFaceCullingMode();
-
- /**
- * @brief Sets the blending mode.
- *
- * Possible values are: BlendingMode::OFF, BlendingMode::AUTO and BlendingMode::ON. Default is BlendingMode::AUTO.
- *
- * If blending is disabled (BlendingMode::OFF) fade in and fade out animations do not work.
- *
- * <ul>
- * <li> \e OFF Blending is disabled.
- * <li> \e AUTO Blending is enabled only if the renderable actor has alpha channel.
- * <li> \e ON Blending is enabled.
- * </ul>
- *
- * @param[in] mode The blending mode.
- */
- void SetBlendMode( BlendingMode::Type mode );
-
- /**
- * @brief Retrieves the blending mode.
- *
- * @return The blending mode, one of BlendingMode::OFF, BlendingMode::AUTO or BlendingMode::ON.
- */
- BlendingMode::Type GetBlendMode() const;
-
- /**
- * @brief Specify the pixel arithmetic used when the actor is blended.
- *
- * @param[in] srcFactorRgba Specifies how the red, green, blue, and alpha source blending factors are computed.
- * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
- * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
- * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
- *
- * @param[in] destFactorRgba Specifies how the red, green, blue, and alpha destination blending factors are computed.
- * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
- * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
- * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
- */
- void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
-
- /**
- * @brief Specify the pixel arithmetic used when the actor is blended.
- *
- * @param[in] srcFactorRgb Specifies how the red, green, and blue source blending factors are computed.
- * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
- * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
- * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
- *
- * @param[in] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
- * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
- * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
- * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
- *
- * @param[in] srcFactorAlpha Specifies how the alpha source blending factor is computed.
- * The options are the same as for srcFactorRgb.
- *
- * @param[in] destFactorAlpha Specifies how the alpha source blending factor is computed.
- * The options are the same as for destFactorRgb.
- */
- void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
- BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
-
- /**
- * @brief Query the pixel arithmetic used when the actor is blended.
- *
- * @param[out] srcFactorRgb Specifies how the red, green, blue, and alpha source blending factors are computed.
- * @param[out] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
- * @param[out] srcFactorAlpha Specifies how the red, green, blue, and alpha source blending factors are computed.
- * @param[out] destFactorAlpha Specifies how the red, green, blue, and alpha destination blending factors are computed.
- */
- void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
- BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
-
- /**
- * @brief Specify the equation used when the actor is blended.
- *
- * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
- * @param[in] equationRgba The equation used for combining red, green, blue, and alpha components.
- */
- void SetBlendEquation( BlendingEquation::Type equationRgba );
-
- /**
- * @brief Specify the equation used when the actor is blended.
- *
- * @param[in] equationRgb The equation used for combining red, green, and blue components.
- * @param[in] equationAlpha The equation used for combining the alpha component.
- * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
- */
- void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
-
- /**
- * @brief Query the equation used when the actor is blended.
- *
- * @param[out] equationRgb The equation used for combining red, green, and blue components.
- * @param[out] equationAlpha The equation used for combining the alpha component.
- */
- void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
-
- /**
- * @brief Specify the color used when the actor is blended; the default is Vector4::ZERO.
- *
- * @param[in] color The blend color.
- */
- void SetBlendColor( const Vector4& color );
-
- /**
- * @brief Query the color used when the actor is blended.
- *
- * @return The blend color.
- */
- Vector4 GetBlendColor() const;
-
public:
/**
* @brief The constructor
return Dali::Material( materialPtr );
}
-void Renderer::SetDepthIndex( int depthIndex )
+void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgba,
+ BlendingFactor::Type destFactorRgba )
{
- GetImplementation(*this).SetDepthIndex( depthIndex );
+ GetImplementation(*this).SetBlendFunc( srcFactorRgba, destFactorRgba );
}
-int Renderer::GetDepthIndex()
+void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
+ BlendingFactor::Type destFactorRgb,
+ BlendingFactor::Type srcFactorAlpha,
+ BlendingFactor::Type destFactorAlpha )
{
- return GetImplementation(*this).GetDepthIndex();
+ GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+}
+
+void Renderer::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
+ BlendingFactor::Type& destFactorRgb,
+ BlendingFactor::Type& srcFactorAlpha,
+ BlendingFactor::Type& destFactorAlpha ) const
+{
+ GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+}
+
+void Renderer::SetBlendEquation( BlendingEquation::Type equationRgba )
+{
+ GetImplementation(*this).SetBlendEquation( equationRgba );
+}
+
+void Renderer::SetBlendEquation( BlendingEquation::Type equationRgb,
+ BlendingEquation::Type equationAlpha )
+{
+ GetImplementation(*this).SetBlendEquation( equationRgb, equationAlpha );
+}
+
+void Renderer::GetBlendEquation( BlendingEquation::Type& equationRgb,
+ BlendingEquation::Type& equationAlpha ) const
+{
+ GetImplementation(*this).GetBlendEquation( equationRgb, equationAlpha );
}
Renderer::Renderer( Internal::Renderer* pointer )
#include <string> // std::string
// INTERNAL INCLUDES
+#include <dali/public-api/actors/blending.h> // Dali::BlendingMode, Dali::BlendingEquation, Dali::BlendingFactor
#include <dali/public-api/object/handle.h> // Dali::Handle
-#include <dali/public-api/object/property-index-ranges.h> // DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX
+#include <dali/public-api/object/property-index-ranges.h> // DEFAULT_OBJECT_PROPERTY_START_INDEX
#include <dali/devel-api/rendering/geometry.h> // Dali::Geometry
#include <dali/devel-api/rendering/material.h> // Dali::Material
public:
/**
+ * @brief Set face culling mode.
+ */
+ enum FaceCullingMode
+ {
+ NONE, ///< None of the faces should be culled
+ CULL_FRONT, ///< Cull front face, back face should never be shown
+ CULL_BACK, ///< Cull back face, back face should never be shown
+ CULL_BACK_AND_FRONT, ///< Cull back and front faces, if the geometry is composed of triangles none of the faces will be shown
+ };
+
+ /**
* @brief An enumeration of properties belonging to the Renderer class.
*/
struct Property
enum
{
DEPTH_INDEX = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "depthIndex", type INTEGER
+ FACE_CULLING_MODE, ///< name "faceCullingMode", type INTEGER
+ BLENDING_MODE, ///< name "blendingMode", type INTEGER
+ BLEND_EQUATION_RGB, ///< name "blendEquationRgb", type INTEGER
+ BLEND_EQUATION_ALPHA, ///< name "blendEquationAlpha", type INTEGER
+ BLENDING_SRC_FACTOR_RGB, ///< name "sourceBlendFactorRgb", type INTEGER
+ BLENDING_DEST_FACTOR_RGB, ///< name "destinationBlendFactorRgb", type INTEGER
+ BLENDING_SRC_FACTOR_ALPHA, ///< name "sourceBlendFactorAlpha", type INTEGER
+ BLENDING_DEST_FACTOR_ALPHA, ///< name "destinationBlendFactorAlpha", type INTEGER
+ BLENDING_COLOR, ///< name "blendingColor", type VECTOR4
+ BLEND_PRE_MULTIPLIED_ALPHA, ///< name "blendPreMultipledAlpha", type BOOLEAN
};
};
Material GetMaterial() const;
/**
- * @brief Set the depth index of this renderer
+ * @brief Specify the pixel arithmetic used when the actor is blended.
+ *
+ * @param[in] srcFactorRgba Specifies how the red, green, blue, and alpha source blending factors are computed.
+ * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
+ * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
+ * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
+ *
+ * @param[in] destFactorRgba Specifies how the red, green, blue, and alpha destination blending factors are computed.
+ * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
+ * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
+ * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
+ */
+ void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
+
+ /**
+ * @brief Specify the pixel arithmetic used when the actor is blended.
+ *
+ * @param[in] srcFactorRgb Specifies how the red, green, and blue source blending factors are computed.
+ * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
+ * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
+ * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
+ *
+ * @param[in] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
+ * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
+ * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
+ * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
*
- * Renderer with higher depth indices are rendered in front of other renderers with smaller values
+ * @param[in] srcFactorAlpha Specifies how the alpha source blending factor is computed.
+ * The options are the same as for srcFactorRgb.
*
- * @param[in] depthIndex The depth index of this renderer
+ * @param[in] destFactorAlpha Specifies how the alpha source blending factor is computed.
+ * The options are the same as for destFactorRgb.
*/
- void SetDepthIndex( int depthIndex );
+ void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
+ BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
- //@todo No interface to remove geometry / material? I guess you have to throw away
- // this renderer if you don't want it to work any more...
+ /**
+ * @brief Query the pixel arithmetic used when the actor is blended.
+ *
+ * @param[out] srcFactorRgb Specifies how the red, green, blue, and alpha source blending factors are computed.
+ * @param[out] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
+ * @param[out] srcFactorAlpha Specifies how the red, green, blue, and alpha source blending factors are computed.
+ * @param[out] destFactorAlpha Specifies how the red, green, blue, and alpha destination blending factors are computed.
+ */
+ void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
+ BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
+
+ /**
+ * @brief Specify the equation used when the actor is blended.
+ *
+ * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
+ * @param[in] equationRgba The equation used for combining red, green, blue, and alpha components.
+ */
+ void SetBlendEquation( BlendingEquation::Type equationRgba );
+
+ /**
+ * @brief Specify the equation used when the actor is blended.
+ *
+ * @param[in] equationRgb The equation used for combining red, green, and blue components.
+ * @param[in] equationAlpha The equation used for combining the alpha component.
+ * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
+ */
+ void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
/**
- * @brief Get the depth index of this renderer
+ * @brief Query the equation used when the actor is blended.
*
- * @sa SetDepthIndex()
- * @return the depth index
+ * @param[out] equationRgb The equation used for combining red, green, and blue components.
+ * @param[out] equationAlpha The equation used for combining the alpha component.
*/
- int GetDepthIndex();
+ void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
public:
/**
BlendingOptions::BlendingOptions()
: mBitmask( 0u ),
- mOptionalColor( NULL )
+ mBlendColor( NULL )
{
SetBlendFunc( DEFAULT_BLENDING_SRC_FACTOR_RGB, DEFAULT_BLENDING_DEST_FACTOR_RGB,
DEFAULT_BLENDING_SRC_FACTOR_ALPHA, DEFAULT_BLENDING_DEST_FACTOR_ALPHA );
BlendingOptions::~BlendingOptions()
{
- delete mOptionalColor;
+ delete mBlendColor;
}
void BlendingOptions::SetBitmask( unsigned int bitmask )
return RetrieveBlendingEquation( mBitmask, MASK_EQUATION_ALPHA, SHIFT_TO_EQUATION_ALPHA );
}
-bool BlendingOptions::SetBlendColor( const Vector4& color )
+void BlendingOptions::SetBlendColor( const Vector4& color )
{
- bool changed( false );
-
if( Vector4::ZERO == color )
{
- if( mOptionalColor )
+ if( mBlendColor )
{
// Discard unnecessary vector
- delete mOptionalColor;
- mOptionalColor = NULL;
-
- changed = true;
+ delete mBlendColor;
+ mBlendColor = NULL;
}
+ return;
}
- else if( !mOptionalColor )
+
+ if( mBlendColor )
{
- // Lazy allocation when non-default is set
- mOptionalColor = new Vector4( color );
- changed = true;
+ *mBlendColor = color;
}
- else if( *mOptionalColor != color )
+ else
{
- *mOptionalColor = color;
- changed = true;
+ // Lazy allocation when non-default is set
+ mBlendColor = new Vector4( color );
}
-
- return changed;
}
const Vector4* BlendingOptions::GetBlendColor() const
{
- return mOptionalColor;
+ return mBlendColor;
}
} // namespace Internal
* @param[in] color The blend color.
* @return True if the blend color changed, otherwise it was already the same color.
*/
- bool SetBlendColor( const Vector4& color );
+ void SetBlendColor( const Vector4& color );
/**
* Query the blend color.
unsigned int mBitmask; ///< A bitmask of blending options
- Vector4* mOptionalColor; ///< A heap-allocated color (owned)
+ Vector4* mBlendColor; ///< A heap-allocated color (owned)
+
};
} // namespace Internal
#include <dali/public-api/actors/blending.h>
#include <dali/public-api/shader-effects/shader-effect.h>
#include <dali/devel-api/rendering/cull-face.h>
-#include <dali/devel-api/rendering/material.h>
+#include <dali/devel-api/rendering/renderer.h>
#include <dali/internal/common/type-abstraction.h>
#include <dali/internal/event/effects/shader-declarations.h>
{
template <> struct ParameterType< CullFaceMode > : public BasicType< CullFaceMode > {};
-template <> struct ParameterType< Dali::Material::FaceCullingMode > : public BasicType< Dali::Material::FaceCullingMode > {};
+template <> struct ParameterType< Dali::Renderer::FaceCullingMode > : public BasicType< Dali::Renderer::FaceCullingMode > {};
template <> struct ParameterType< BlendingMode::Type > : public BasicType< BlendingMode::Type > {};
} //namespace Internal
void ImageActor::SetCullFace(CullFaceMode mode)
{
- mRenderer->GetMaterial()->SetFaceCullingMode( static_cast< Dali::Material::FaceCullingMode >( mode ) );
+ mRenderer->SetFaceCullingMode( static_cast< Dali::Renderer::FaceCullingMode >( mode ) );
}
CullFaceMode ImageActor::GetCullFace() const
{
- return static_cast< CullFaceMode >( mRenderer->GetMaterial()->GetFaceCullingMode() );
+ return static_cast< CullFaceMode >( mRenderer->GetFaceCullingMode() );
}
void ImageActor::SetBlendMode( BlendingMode::Type mode )
{
- mRenderer->GetMaterial()->SetBlendMode( mode );
+ mRenderer->SetBlendMode( mode );
}
BlendingMode::Type ImageActor::GetBlendMode() const
{
- return mRenderer->GetMaterial()->GetBlendMode();
+ return mRenderer->GetBlendMode();
}
void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
{
- mRenderer->GetMaterial()->SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
+ mRenderer->SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
}
void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
{
- mRenderer->GetMaterial()->SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+ mRenderer->SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
}
void ImageActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
{
- mRenderer->GetMaterial()->GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+ mRenderer->GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
}
void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgba )
{
- mRenderer->GetMaterial()->SetBlendEquation( equationRgba, equationRgba );
+ mRenderer->SetBlendEquation( equationRgba, equationRgba );
}
void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
{
- mRenderer->GetMaterial()->SetBlendEquation( equationRgb, equationAlpha );
+ mRenderer->SetBlendEquation( equationRgb, equationAlpha );
}
void ImageActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
{
- mRenderer->GetMaterial()->GetBlendEquation( equationRgb, equationAlpha );
+ mRenderer->GetBlendEquation( equationRgb, equationAlpha );
}
void ImageActor::SetBlendColor( const Vector4& color )
{
mBlendColor = color;
- mRenderer->GetMaterial()->SetBlendColor( mBlendColor );
+ mRenderer->SetBlendColor( mBlendColor );
}
const Vector4& ImageActor::GetBlendColor() const
namespace
{
-/**
- * |name |type |writable|animatable|constraint-input|enum for index-checking|
- */
-DALI_PROPERTY_TABLE_BEGIN
-DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Material::Property::FACE_CULLING_MODE )
-DALI_PROPERTY( "blendingMode", INTEGER, true, false, false, Dali::Material::Property::BLENDING_MODE )
-DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Material::Property::BLEND_EQUATION_RGB )
-DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Material::Property::BLEND_EQUATION_ALPHA )
-DALI_PROPERTY( "sourceBlendFactorRgb", INTEGER, true, false, false, Dali::Material::Property::BLENDING_SRC_FACTOR_RGB )
-DALI_PROPERTY( "destinationBlendFactorRgb", INTEGER, true, false, false, Dali::Material::Property::BLENDING_DEST_FACTOR_RGB )
-DALI_PROPERTY( "sourceBlendFactorAlpha", INTEGER, true, false, false, Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA )
-DALI_PROPERTY( "destinationBlendFactorAlpha", INTEGER, true, false, false, Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA )
-DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Material::Property::BLEND_COLOR )
-DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
-
-const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> MATERIAL_IMPL = { DEFAULT_PROPERTY_DETAILS };
+const ObjectImplHelper<0> MATERIAL_IMPL = { NULL };
BaseHandle Create()
{
return mTextures.size();
}
-void Material::SetFaceCullingMode( Dali::Material::FaceCullingMode cullingMode )
-{
- if( mFaceCullingMode != cullingMode )
- {
- mFaceCullingMode = cullingMode;
-
- SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, mFaceCullingMode );
- }
-}
-
-Dali::Material::FaceCullingMode Material::GetFaceCullingMode()
-{
- return mFaceCullingMode;
-}
-
-void Material::SetBlendMode( BlendingMode::Type mode )
-{
- if( mBlendingMode != mode )
- {
- mBlendingMode = mode;
-
- SetBlendingModeMessage( GetEventThreadServices(), *mSceneObject, mBlendingMode );
- }
-}
-
-BlendingMode::Type Material::GetBlendMode() const
-{
- return mBlendingMode;
-}
-
-void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
-{
- mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
- SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
-}
-
-void Material::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
- BlendingFactor::Type destFactorRgb,
- BlendingFactor::Type srcFactorAlpha,
- BlendingFactor::Type destFactorAlpha )
-{
- mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
- SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
-}
-
-void Material::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
- BlendingFactor::Type& destFactorRgb,
- BlendingFactor::Type& srcFactorAlpha,
- BlendingFactor::Type& destFactorAlpha ) const
-{
- srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb();
- destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb();
- srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha();
- destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
-}
-
-void Material::SetBlendEquation( BlendingEquation::Type equationRgba )
-{
- mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
- SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
-}
-
-void Material::SetBlendEquation( BlendingEquation::Type equationRgb,
- BlendingEquation::Type equationAlpha )
-{
- mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
- SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
-}
-
-void Material::GetBlendEquation( BlendingEquation::Type& equationRgb,
- BlendingEquation::Type& equationAlpha ) const
-{
- // These are not animatable, the cached values are up-to-date.
- equationRgb = mBlendingOptions.GetBlendEquationRgb();
- equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
-}
-
-void Material::SetBlendColor( const Vector4& color )
-{
- if( !mBlendColor )
- {
- mBlendColor = new Vector4();
- }
- if( *mBlendColor != color )
- {
- *mBlendColor = color;
- SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
- }
-}
-
-Vector4 Material::GetBlendColor() const
-{
- if( mBlendColor )
- {
- return *mBlendColor;
- }
- return Color::TRANSPARENT; // GL default
-}
-
const SceneGraph::Material* Material::GetMaterialSceneObject() const
{
return mSceneObject;
void Material::SetDefaultProperty( Property::Index index,
const Property::Value& propertyValue )
{
- switch( index )
- {
- case Dali::Material::Property::FACE_CULLING_MODE:
- {
- int faceCullingMode;
- if( propertyValue.Get( faceCullingMode ) )
- {
- SetFaceCullingMode( Dali::Material::FaceCullingMode( faceCullingMode ) );
- }
- break;
- }
- case Dali::Material::Property::BLENDING_MODE:
- {
- int blendingMode;
- if( propertyValue.Get( blendingMode ) )
- {
- SetBlendMode( BlendingMode::Type( blendingMode ) );
- }
- break;
- }
- case Dali::Material::Property::BLEND_EQUATION_RGB:
- {
- int blendingEquation;
- if( propertyValue.Get( blendingEquation ) )
- {
- BlendingEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
- mBlendingOptions.SetBlendEquation( static_cast<BlendingEquation::Type>( blendingEquation ), alphaEquation );
- SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
- }
- break;
- }
- case Dali::Material::Property::BLEND_EQUATION_ALPHA:
- {
- int blendingEquation;
- if( propertyValue.Get( blendingEquation ) )
- {
- BlendingEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
- mBlendingOptions.SetBlendEquation( rgbEquation, static_cast<BlendingEquation::Type>( blendingEquation ) );
- SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
- }
- break;
- }
- case Dali::Material::Property::BLENDING_SRC_FACTOR_RGB:
- {
- int blendingFactor;
- if( propertyValue.Get( blendingFactor ) )
- {
- BlendingFactor::Type srcFactorRgb;
- BlendingFactor::Type destFactorRgb;
- BlendingFactor::Type srcFactorAlpha;
- BlendingFactor::Type destFactorAlpha;
- GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
- SetBlendFunc( static_cast<BlendingFactor::Type>( blendingFactor ),
- destFactorRgb,
- srcFactorAlpha,
- destFactorAlpha );
- }
- break;
- }
- case Dali::Material::Property::BLENDING_DEST_FACTOR_RGB:
- {
- int blendingFactor;
- if( propertyValue.Get( blendingFactor ) )
- {
- BlendingFactor::Type srcFactorRgb;
- BlendingFactor::Type destFactorRgb;
- BlendingFactor::Type srcFactorAlpha;
- BlendingFactor::Type destFactorAlpha;
- GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
- SetBlendFunc( srcFactorRgb,
- static_cast<BlendingFactor::Type>( blendingFactor ),
- srcFactorAlpha,
- destFactorAlpha );
- }
- break;
- }
- case Dali::Material::Property::BLENDING_SRC_FACTOR_ALPHA:
- {
- int blendingFactor;
- if( propertyValue.Get( blendingFactor ) )
- {
- BlendingFactor::Type srcFactorRgb;
- BlendingFactor::Type destFactorRgb;
- BlendingFactor::Type srcFactorAlpha;
- BlendingFactor::Type destFactorAlpha;
- GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
- SetBlendFunc( srcFactorRgb,
- destFactorRgb,
- static_cast<BlendingFactor::Type>( blendingFactor ),
- destFactorAlpha );
- }
- break;
- }
- case Dali::Material::Property::BLENDING_DEST_FACTOR_ALPHA:
- {
- int blendingFactor;
- if( propertyValue.Get( blendingFactor ) )
- {
- 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>( blendingFactor ) );
- }
- break;
- }
- case Dali::Material::Property::BLEND_COLOR:
- {
- Vector4 blendColor;
- if( propertyValue.Get( blendColor ) )
- {
- SetBlendColor( blendColor );
- }
- break;
- }
- }
}
void Material::SetSceneGraphProperty( Property::Index index,
Property::Value Material::GetDefaultProperty( Property::Index index ) const
{
Property::Value value;
-
- switch( index )
- {
- case Dali::Material::Property::FACE_CULLING_MODE:
- {
- value = mFaceCullingMode;
- break;
- }
- case Dali::Material::Property::BLENDING_MODE:
- {
- value = mBlendingMode;
- break;
- }
- case Dali::Material::Property::BLEND_EQUATION_RGB:
- {
- value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
- break;
- }
- case Dali::Material::Property::BLEND_EQUATION_ALPHA:
- {
- value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
- break;
- }
- case Dali::Material::Property::BLENDING_SRC_FACTOR_RGB:
- {
- 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:
- {
- 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:
- {
- 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:
- {
- 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:
- {
- value = mBlendColor;
- break;
- }
- }
-
return value;
}
: mSceneObject( NULL ),
mShader( NULL ),
mTextures(),
- mFaceCullingMode( Dali::Material::NONE ),
- mBlendingMode( Dali::BlendingMode::AUTO ),
- mBlendingOptions(), // initialises to defaults
- mBlendColor( NULL ),
mOnStage( false )
{
}
Material::~Material()
{
- delete mBlendColor;
if( EventThreadServices::IsCoreRunning() )
{
EventThreadServices& eventThreadServices = GetEventThreadServices();
#include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
#include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
#include <dali/devel-api/rendering/material.h> // Dali::Material
-#include <dali/internal/common/blending-options.h>
#include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
#include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
#include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
*/
size_t GetNumberOfTextures() const;
- /**
- * @copydoc Dali::Material::SetFaceCullingMode()
- */
- void SetFaceCullingMode( Dali::Material::FaceCullingMode cullingMode );
-
- /**
- * @copydoc Dali::Material::GetFaceCullingMode()
- */
- Dali::Material::FaceCullingMode GetFaceCullingMode();
-
- /**
- * @copydoc Dali::Material::SetBlendMode()
- */
- void SetBlendMode( BlendingMode::Type mode );
-
- /**
- * @copydoc Dali::Material::GetBlendMode()
- */
- BlendingMode::Type GetBlendMode() const;
-
- /**
- * @copydoc Dali::Material::SetBlendFunc()
- */
- void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
-
- /**
- * @copydoc Dali::Material::SetBlendFunc()
- */
- void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
- BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
-
- /**
- * @copydoc Dali::Material::GetBlendFunc()
- */
- void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
- BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
-
- /**
- * @copydoc Dali::Material::SetBlendEquation()
- */
- void SetBlendEquation( BlendingEquation::Type equationRgba );
-
- /**
- * @copydoc Dali::Material::SetBlendEquation()
- */
- void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
-
- /**
- * @copydoc Dali::Material::GetBlendEquation()
- */
- void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
-
- /**
- * @copydoc Dali::Material::SetBlendColor()
- */
- void SetBlendColor( const Vector4& color );
-
- /**
- * @copydoc Dali::Material::GetBlendColor()
- */
- Vector4 GetBlendColor() const;
-
- /**
+ /**
* @brief Get the material scene object
*
* @return the material scene object
IntrusivePtr<Shader> mShader; ///< Connector that holds the shader used by this material
std::vector<Material::Texture> mTextures; ///<Vector of textures used by this material
- Dali::Material::FaceCullingMode mFaceCullingMode; ///< Local copy of face culling mode
- BlendingMode::Type mBlendingMode; ///< Local copy of blending mode
- BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
- Vector4* mBlendColor; ///< Local copy of blend color, pointer only as its rarely used
bool mOnStage;
};
{
/**
- * |name |type |writable|animatable|constraint-input|enum for index-checking|
+ * |name |type |writable|animatable|constraint-input|enum for index-checking|
*/
DALI_PROPERTY_TABLE_BEGIN
-DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
+DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
+DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
+DALI_PROPERTY( "blendingMode", INTEGER, true, false, false, Dali::Renderer::Property::BLENDING_MODE )
+DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
+DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
+DALI_PROPERTY( "sourceBlendFactorRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB )
+DALI_PROPERTY( "destinationBlendFactorRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB )
+DALI_PROPERTY( "sourceBlendFactorAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA )
+DALI_PROPERTY( "destinationBlendFactorAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA )
+DALI_PROPERTY( "blendingColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLENDING_COLOR )
+DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
return mDepthIndex;
}
+void Renderer::SetFaceCullingMode( Dali::Renderer::FaceCullingMode cullingMode )
+{
+ if( mFaceCullingMode != cullingMode )
+ {
+ mFaceCullingMode = cullingMode;
+
+ SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, mFaceCullingMode );
+ }
+}
+
+Dali::Renderer::FaceCullingMode Renderer::GetFaceCullingMode()
+{
+ return mFaceCullingMode;
+}
+
+void Renderer::SetBlendMode( BlendingMode::Type mode )
+{
+ if( mBlendingMode != mode )
+ {
+ mBlendingMode = mode;
+
+ SetBlendingModeMessage( GetEventThreadServices(), *mSceneObject, mBlendingMode );
+ }
+}
+
+BlendingMode::Type Renderer::GetBlendMode() const
+{
+ return mBlendingMode;
+}
+
+void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
+{
+ mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
+ SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
+}
+
+void Renderer::SetBlendFunc( BlendingFactor::Type srcFactorRgb,
+ BlendingFactor::Type destFactorRgb,
+ BlendingFactor::Type srcFactorAlpha,
+ BlendingFactor::Type destFactorAlpha )
+{
+ mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+ SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
+}
+
+void Renderer::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,
+ BlendingFactor::Type& destFactorRgb,
+ BlendingFactor::Type& srcFactorAlpha,
+ BlendingFactor::Type& destFactorAlpha ) const
+{
+ srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb();
+ destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb();
+ srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha();
+ destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
+}
+
+void Renderer::SetBlendEquation( BlendingEquation::Type equationRgba )
+{
+ mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
+ SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
+}
+
+void Renderer::SetBlendEquation( BlendingEquation::Type equationRgb,
+ BlendingEquation::Type equationAlpha )
+{
+ mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
+ SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
+}
+
+void Renderer::GetBlendEquation( BlendingEquation::Type& equationRgb,
+ BlendingEquation::Type& equationAlpha ) const
+{
+ // These are not animatable, the cached values are up-to-date.
+ equationRgb = mBlendingOptions.GetBlendEquationRgb();
+ equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
+}
+
+void Renderer::SetBlendColor( const Vector4& color )
+{
+ if( !mBlendColor )
+ {
+ mBlendColor = new Vector4();
+ }
+ if( *mBlendColor != color )
+ {
+ *mBlendColor = color;
+ SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
+ }
+}
+
+Vector4 Renderer::GetBlendColor() const
+{
+ if( mBlendColor )
+ {
+ return *mBlendColor;
+ }
+ return Color::TRANSPARENT; // GL default
+}
+
+void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
+{
+ if( mPremultipledAlphaEnabled != preMultipled )
+ {
+ if( preMultipled )
+ {
+ SetBlendFunc( BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA, BlendingFactor::ONE, BlendingFactor::ONE );
+ }
+ mPremultipledAlphaEnabled = preMultipled;
+ SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
+ }
+}
+
+bool Renderer::IsPreMultipliedAlphaEnabled() const
+{
+ return mPremultipledAlphaEnabled;
+}
+
SceneGraph::Renderer* Renderer::GetRendererSceneObject()
{
return mSceneObject;
case Dali::Renderer::Property::DEPTH_INDEX:
{
SetDepthIndex( propertyValue.Get<int>() );
+ break;
+ }
+ case Dali::Renderer::Property::FACE_CULLING_MODE:
+ {
+ int faceCullingMode;
+ if( propertyValue.Get( faceCullingMode ) )
+ {
+ SetFaceCullingMode( Dali::Renderer::FaceCullingMode( faceCullingMode ) );
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLENDING_MODE:
+ {
+ int blendingMode;
+ if( propertyValue.Get( blendingMode ) )
+ {
+ SetBlendMode( BlendingMode::Type( blendingMode ) );
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLEND_EQUATION_RGB:
+ {
+ int blendingEquation;
+ if( propertyValue.Get( blendingEquation ) )
+ {
+ BlendingEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
+ mBlendingOptions.SetBlendEquation( static_cast<BlendingEquation::Type>( blendingEquation ), alphaEquation );
+ SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
+ {
+ int blendingEquation;
+ if( propertyValue.Get( blendingEquation ) )
+ {
+ BlendingEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
+ mBlendingOptions.SetBlendEquation( rgbEquation, static_cast<BlendingEquation::Type>( blendingEquation ) );
+ SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
+ {
+ int blendingFactor;
+ if( propertyValue.Get( blendingFactor ) )
+ {
+ BlendingFactor::Type srcFactorRgb;
+ BlendingFactor::Type destFactorRgb;
+ BlendingFactor::Type srcFactorAlpha;
+ BlendingFactor::Type destFactorAlpha;
+ GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+ SetBlendFunc( static_cast<BlendingFactor::Type>( blendingFactor ),
+ destFactorRgb,
+ srcFactorAlpha,
+ destFactorAlpha );
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
+ {
+ int blendingFactor;
+ if( propertyValue.Get( blendingFactor ) )
+ {
+ BlendingFactor::Type srcFactorRgb;
+ BlendingFactor::Type destFactorRgb;
+ BlendingFactor::Type srcFactorAlpha;
+ BlendingFactor::Type destFactorAlpha;
+ GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+ SetBlendFunc( srcFactorRgb,
+ static_cast<BlendingFactor::Type>( blendingFactor ),
+ srcFactorAlpha,
+ destFactorAlpha );
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
+ {
+ int blendingFactor;
+ if( propertyValue.Get( blendingFactor ) )
+ {
+ BlendingFactor::Type srcFactorRgb;
+ BlendingFactor::Type destFactorRgb;
+ BlendingFactor::Type srcFactorAlpha;
+ BlendingFactor::Type destFactorAlpha;
+ GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
+ SetBlendFunc( srcFactorRgb,
+ destFactorRgb,
+ static_cast<BlendingFactor::Type>( blendingFactor ),
+ destFactorAlpha );
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
+ {
+ int blendingFactor;
+ if( propertyValue.Get( blendingFactor ) )
+ {
+ 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>( blendingFactor ) );
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLENDING_COLOR:
+ {
+ Vector4 blendColor;
+ if( propertyValue.Get( blendColor ) )
+ {
+ SetBlendColor( blendColor );
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
+ {
+ bool preMultipled;
+ if( propertyValue.Get( preMultipled ) )
+ {
+ EnablePreMultipliedAlpha( preMultipled );
+ }
+ break;
}
- break;
}
}
case Dali::Renderer::Property::DEPTH_INDEX:
{
value = GetDepthIndex();
+ break;
+ }
+ case Dali::Renderer::Property::FACE_CULLING_MODE:
+ {
+ value = mFaceCullingMode;
+ break;
+ }
+ case Dali::Renderer::Property::BLENDING_MODE:
+ {
+ value = mBlendingMode;
+ break;
+ }
+ case Dali::Renderer::Property::BLEND_EQUATION_RGB:
+ {
+ value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
+ break;
+ }
+ case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
+ {
+ value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
+ break;
+ }
+ case Dali::Renderer::Property::BLENDING_SRC_FACTOR_RGB:
+ {
+ 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::Renderer::Property::BLENDING_DEST_FACTOR_RGB:
+ {
+ 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::Renderer::Property::BLENDING_SRC_FACTOR_ALPHA:
+ {
+ 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::Renderer::Property::BLENDING_DEST_FACTOR_ALPHA:
+ {
+ 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::Renderer::Property::BLENDING_COLOR:
+ {
+ if( mBlendColor )
+ {
+ value = *mBlendColor;
+ }
+ else
+ {
+ value = Color::TRANSPARENT;
+ }
+ break;
+ }
+ case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
+ {
+ value = IsPreMultipliedAlphaEnabled();
+ break;
}
- break;
}
return value;
}
Renderer::Renderer()
: mSceneObject(NULL),
+ mBlendColor( NULL ),
mDepthIndex(0),
- mOnStageCount(0)
+ mOnStageCount(0),
+ mFaceCullingMode(Dali::Renderer::NONE),
+ mBlendingMode( Dali::BlendingMode::AUTO ),
+ mBlendingOptions(),
+ mPremultipledAlphaEnabled( false )
{
}
#include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
#include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
#include <dali/devel-api/rendering/renderer.h> // Dali::Renderer
+#include <dali/internal/common/blending-options.h>
#include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
#include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
#include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
int GetDepthIndex() const;
/**
+ * @copydoc Dali::Renderer::SetFaceCullingMode()
+ */
+ void SetFaceCullingMode( Dali::Renderer::FaceCullingMode cullingMode );
+
+ /**
+ * @copydoc Dali::Renderer::GetFaceCullingMode()
+ */
+ Dali::Renderer::FaceCullingMode GetFaceCullingMode();
+
+ /**
+ * @copydoc Dali::Renderer::SetBlendMode()
+ */
+ void SetBlendMode( BlendingMode::Type mode );
+
+ /**
+ * @copydoc Dali::Renderer::GetBlendMode()
+ */
+ BlendingMode::Type GetBlendMode() const;
+
+ /**
+ * @copydoc Dali::Renderer::SetBlendFunc()
+ */
+ void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
+
+ /**
+ * @copydoc Dali::Renderer::SetBlendFunc()
+ */
+ void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
+ BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
+
+ /**
+ * @copydoc Dali::Renderer::GetBlendFunc()
+ */
+ void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
+ BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
+
+ /**
+ * @copydoc Dali::Renderer::SetBlendEquation()
+ */
+ void SetBlendEquation( BlendingEquation::Type equationRgba );
+
+ /**
+ * @copydoc Dali::Renderer::SetBlendEquation()
+ */
+ void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
+
+ /**
+ * @copydoc Dali::Renderer::GetBlendEquation()
+ */
+ void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
+
+ /**
+ * @copydoc Dali::Renderer::SetBlendColor()
+ */
+ void SetBlendColor( const Vector4& color );
+
+ /**
+ * @copydoc Dali::Renderer::GetBlendColor()
+ */
+ Vector4 GetBlendColor() const;
+
+ /**
+ * @brief Set whether the Pre-multiplied Alpha Blending is required
+ *
+ * @param[in] preMultipled whether alpha is pre-multiplied.
+ */
+ void EnablePreMultipliedAlpha( bool preMultipled );
+
+ /**
+ * @brief Query whether alpha is pre-multiplied.
+ *
+ * @return True is alpha is pre-multiplied, false otherwise.
+ */
+ bool IsPreMultipliedAlphaEnabled() const;
+
+ /**
* @brief Get the scene graph object ( the node attachment )
*
* @return the scene object
private: // data
SceneGraph::Renderer* mSceneObject;
+ Vector4* mBlendColor; ///< Local copy of blend color, pointer only as its rarely used
ObjectConnector<Geometry> mGeometryConnector; ///< Connector that holds the geometry used by this renderer
ObjectConnector<Material> mMaterialConnector; ///< Connector that holds the material used by this renderer
+
int mDepthIndex;
int mOnStageCount;
+
+ Dali::Renderer::FaceCullingMode mFaceCullingMode; ///< Local copy of face culling mode
+ BlendingMode::Type mBlendingMode; ///< Local copy of blending mode
+ BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
+ bool mPremultipledAlphaEnabled; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
+
};
} // namespace Internal
+++ /dev/null
-#ifndef DALI_INTERNAL_SCENE_GRAPH_MATERIAL_DATA_PROVIDER_H
-#define DALI_INTERNAL_SCENE_GRAPH_MATERIAL_DATA_PROVIDER_H
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dali/internal/common/buffer-index.h>
-#include <dali/devel-api/rendering/material.h>
-#include <dali/public-api/common/dali-vector.h>
-#include <dali/public-api/actors/blending.h>
-
-namespace Dali
-{
-namespace Internal
-{
-struct BlendingOptions;
-
-namespace SceneGraph
-{
-
-/**
- * Interface to provide data of the material to the renderer.
- * This interface must not be used to pass object pointers.
- */
-class MaterialDataProvider
-{
-public:
- /**
- * Construtor
- */
- MaterialDataProvider()
- {
- }
-
- /**
- * Get the blend color
- * @return blend color of NULL if blend color is not set
- */
- virtual Vector4* GetBlendColor() const = 0;
-
- /**
- * Get the blending options
- * @return the blending options
- */
- virtual const BlendingOptions& GetBlendingOptions() const = 0;
-
- /**
- * Get the cull face mode
- * @return the cull face mode
- */
- virtual Dali::Material::FaceCullingMode GetFaceCullingMode() const = 0;
-
-protected:
- /**
- * Destructor. No deletion through this interface
- */
- virtual ~MaterialDataProvider()
- {
- }
-};
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // DALI_INTERNAL_SCENE_GRAPH_MATERIAL_DATA_PROVIDER_H
{
RenderDataProvider::RenderDataProvider()
-: mMaterialDataProvider( NULL ),
- mUniformMapDataProvider( NULL ),
+: mUniformMapDataProvider( NULL ),
mShader( NULL )
{
}
{
}
-void RenderDataProvider::SetMaterial( const MaterialDataProvider& materialDataProvider )
-{
- mMaterialDataProvider = &materialDataProvider;
-}
-
-const MaterialDataProvider& RenderDataProvider::GetMaterial() const
-{
- return *mMaterialDataProvider;
-}
void RenderDataProvider::SetUniformMap(const UniformMapDataProvider& uniformMapDataProvider)
{
*
*/
-#include <dali/internal/render/data-providers/material-data-provider.h>
#include <dali/internal/render/data-providers/node-data-provider.h>
#include <dali/internal/render/data-providers/property-buffer-data-provider.h>
#include <dali/internal/render/data-providers/uniform-map-data-provider.h>
#include <dali/internal/render/renderers/render-texture.h>
+#include <dali/devel-api/rendering/renderer.h>
+
namespace Dali
{
namespace Internal
{
+
+struct BlendingOptions;
+
namespace SceneGraph
{
class PropertyBuffer;
public:
/**
- * Set the material data provider
- * @param[in] materialDataProvider The material data provider
- */
- void SetMaterial( const MaterialDataProvider& materialDataProvider );
-
- /**
- * Get the material data provider
- * @return the material data provider
- */
- const MaterialDataProvider& GetMaterial() const;
-
- /**
* Set the uniform map data provider
* @param[in] uniformMapDataProvider The uniform map data provider
*/
Textures& GetTextures();
private:
- const MaterialDataProvider* mMaterialDataProvider;
- const UniformMapDataProvider* mUniformMapDataProvider;
- Shader* mShader;
- Textures mTextures;
-// Give Renderer access to our private data to reduce copying vectors on construction.
+ const UniformMapDataProvider* mUniformMapDataProvider;
+ Shader* mShader;
+ Textures mTextures;
+
+ // Give Renderer access to our private data to reduce copying vectors on construction.
friend class Renderer;
};
mBlendEquationSeparateModeAlpha( GL_FUNC_ADD ),
mMaxTextureSize(0),
mClearColor(Color::WHITE), // initial color, never used until it's been set by the user
- mCullFaceMode( Dali::Material::NONE ),
+ mCullFaceMode( Dali::Renderer::NONE ),
mViewPort( 0, 0, 0, 0 )
{
}
mBlendEquationSeparateModeRGB = GL_FUNC_ADD;
mBlendEquationSeparateModeAlpha = GL_FUNC_ADD;
- mCullFaceMode = Dali::Material::NONE; //By default cullface is disabled, front face is set to CCW and cull face is set to back
+ mCullFaceMode = Dali::Renderer::NONE; //By default cullface is disabled, front face is set to CCW and cull face is set to back
// get maximum texture size
mGlAbstraction.GetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
#include <dali/integration-api/debug.h>
#include <dali/integration-api/gl-abstraction.h>
#include <dali/integration-api/gl-defines.h>
-#include <dali/devel-api/rendering/material.h>
+#include <dali/devel-api/rendering/renderer.h>
#include <dali/internal/render/common/performance-monitor.h>
#include <dali/internal/render/gl-resources/texture-units.h>
#include <dali/internal/render/gl-resources/frame-buffer-state-cache.h>
* enables GL_CULL_FACE if in any of the face culling modes
* otherwise disables GL_CULL_FACE
*/
- void CullFace( Dali::Material::FaceCullingMode mode )
+ void CullFace( Dali::Renderer::FaceCullingMode mode )
{
// Avoid unnecessary calls to gl
if(mCullFaceMode != mode)
mCullFaceMode = mode;
switch(mode)
{
- case Dali::Material::NONE:
+ case Dali::Renderer::NONE:
{
LOG_GL("Disable GL_CULL_FACE\n");
CHECK_GL( mGlAbstraction, mGlAbstraction.Disable(GL_CULL_FACE) );
break;
}
- case Dali::Material::CULL_FRONT:
+ case Dali::Renderer::CULL_FRONT:
{
LOG_GL("Enable GL_CULL_FACE\n");
CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
break;
}
- case Dali::Material::CULL_BACK:
+ case Dali::Renderer::CULL_BACK:
{
LOG_GL("Enable GL_CULL_FACE\n");
CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
break;
}
- case Dali::Material::CULL_BACK_AND_FRONT:
+ case Dali::Renderer::CULL_BACK_AND_FRONT:
{
LOG_GL("Enable GL_CULL_FACE\n");
CHECK_GL( mGlAbstraction, mGlAbstraction.Enable(GL_CULL_FACE) );
Vector4 mClearColor; ///< clear color
// Face culling mode
- Dali::Material::FaceCullingMode mCullFaceMode;
+ Dali::Renderer::FaceCullingMode mCullFaceMode;
// cached viewport size
Rect< int > mViewPort;
{
Renderer* Renderer::New( SceneGraph::RenderDataProvider* dataProvider,
- SceneGraph::RenderGeometry* renderGeometry )
+ SceneGraph::RenderGeometry* renderGeometry,
+ unsigned int blendingBitmask,
+ const Vector4* blendColor,
+ Dali::Renderer::FaceCullingMode faceCullingMode,
+ bool preMultipliedAlphaEnabled )
{
- return new Renderer( dataProvider, renderGeometry);
+ return new Renderer( dataProvider, renderGeometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled );
}
Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
- SceneGraph::RenderGeometry* renderGeometry )
+ SceneGraph::RenderGeometry* renderGeometry,
+ unsigned int blendingBitmask,
+ const Vector4* blendColor,
+ Dali::Renderer::FaceCullingMode faceCullingMode,
+ bool preMultipliedAlphaEnabled)
: mRenderDataProvider( dataProvider ),
mContext(NULL),
mTextureCache( NULL ),
mRenderGeometry( renderGeometry ),
mUniformIndexMap(),
mAttributesLocation(),
+ mBlendingOptions(),
+ mFaceCullingMode( faceCullingMode ),
mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ),
mUpdateAttributesLocation( true ),
- mCullFaceMode( Dali::Material::NONE )
+ mPremultipledAlphaEnabled( preMultipliedAlphaEnabled )
{
+ if( blendingBitmask != 0u )
+ {
+ mBlendingOptions.SetBitmask( blendingBitmask );
+ }
+
+ if( blendColor )
+ {
+ mBlendingOptions.SetBlendColor( *blendColor );
+ }
}
void Renderer::Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache )
context.SetBlend( blend );
if( blend )
{
- const SceneGraph::MaterialDataProvider& material = mRenderDataProvider->GetMaterial();
-
// Blend color is optional and rarely used
- Vector4* blendColor = material.GetBlendColor();
+ const Vector4* blendColor = mBlendingOptions.GetBlendColor();
if( blendColor )
{
context.SetCustomBlendColor( *blendColor );
context.SetDefaultBlendColor();
}
- const BlendingOptions& blending = material.GetBlendingOptions();
// Set blend source & destination factors
- context.BlendFuncSeparate( blending.GetBlendSrcFactorRgb(),
- blending.GetBlendDestFactorRgb(),
- blending.GetBlendSrcFactorAlpha(),
- blending.GetBlendDestFactorAlpha() );
+ context.BlendFuncSeparate( mBlendingOptions.GetBlendSrcFactorRgb(),
+ mBlendingOptions.GetBlendDestFactorRgb(),
+ mBlendingOptions.GetBlendSrcFactorAlpha(),
+ mBlendingOptions.GetBlendDestFactorAlpha() );
// Set blend equations
- context.BlendEquationSeparate( blending.GetBlendEquationRgb(),
- blending.GetBlendEquationAlpha() );
+ context.BlendEquationSeparate( mBlendingOptions.GetBlendEquationRgb(),
+ mBlendingOptions.GetBlendEquationAlpha() );
}
}
}
}
-void Renderer::SetCullFace( Dali::Material::FaceCullingMode mode )
+void Renderer::SetFaceCullingMode( Dali::Renderer::FaceCullingMode mode )
+{
+ mFaceCullingMode = mode;
+}
+
+void Renderer::SetBlendingBitMask( unsigned int bitmask )
+{
+ mBlendingOptions.SetBitmask( bitmask );
+}
+
+void Renderer::SetBlendColor( const Vector4* color )
+{
+ mBlendingOptions.SetBlendColor( *color );
+}
+
+void Renderer::EnablePreMultipliedAlpha( bool enable )
{
- DALI_ASSERT_DEBUG( mode >= Dali::Material::NONE && mode <= Dali::Material::CULL_BACK_AND_FRONT );
- mCullFaceMode = mode;
+ mPremultipledAlphaEnabled = enable;
}
void Renderer::SetSampler( unsigned int samplerBitfield )
}
//Set cull face mode
- context.CullFace( mRenderDataProvider->GetMaterial().GetFaceCullingMode() );
+ context.CullFace( mFaceCullingMode );
//Set blending mode
SetBlending( context, blend );
if( Program::UNIFORM_UNKNOWN != loc )
{
const Vector4& color = node.GetRenderColor( bufferIndex );
- program->SetUniform4f( loc, color.r, color.g, color.b, color.a );
+ if( mPremultipledAlphaEnabled )
+ {
+ program->SetUniform4f( loc, color.r*color.a, color.g*color.a, color.b*color.a, color.a );
+ }
+ else
+ {
+ program->SetUniform4f( loc, color.r, color.g, color.b, color.a );
+ }
}
//Bind textures
* Create a new renderer instance
* @param[in] dataProviders The data providers for the renderer
* @param[in] renderGeometry The geometry for the renderer
+ * @param[in] blendingBitmask A bitmask of blending options.
+ * @param[in] blendColor The blend color to pass to GL
+ * @param[in] faceCullingMode The face-culling mode.
+ * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
*/
- static Renderer* New( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
+ static Renderer* New( SceneGraph::RenderDataProvider* dataProviders,
+ SceneGraph::RenderGeometry* renderGeometry,
+ unsigned int blendingBitmask,
+ const Vector4* blendColor,
+ Dali::Renderer::FaceCullingMode faceCullingMode,
+ bool preMultipliedAlphaEnabled);
/**
* Constructor.
* @param[in] dataProviders The data providers for the renderer
* @param[in] renderGeometry The geometry for the renderer
+ * @param[in] blendingBitmask A bitmask of blending options.
+ * @param[in] blendColor The blend color to pass to GL
+ * @param[in] faceCullingMode The face-culling mode.
+ * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
*/
- Renderer( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
+ Renderer( SceneGraph::RenderDataProvider* dataProviders,
+ SceneGraph::RenderGeometry* renderGeometry,
+ unsigned int blendingBitmask,
+ const Vector4* blendColor,
+ Dali::Renderer::FaceCullingMode faceCullingMode,
+ bool preMultipliedAlphaEnabled);
/**
* Change the data providers of the renderer
* Set the face-culling mode.
* @param[in] mode The face-culling mode.
*/
- void SetCullFace( Dali::Material::FaceCullingMode mode );
+ void SetFaceCullingMode( Dali::Renderer::FaceCullingMode mode );
+
+ /**
+ * Set the bitmask for blending options
+ * @param[in] bitmask A bitmask of blending options.
+ */
+ void SetBlendingBitMask( unsigned int bitmask );
+
+ /**
+ * Set the blend color for blending options
+ * @param[in] blendColor The blend color to pass to GL
+ */
+ void SetBlendColor( const Vector4* color );
+
+ /**
+ * @brief Set whether the Pre-multiplied Alpha Blending is required
+ *
+ * @param[in] preMultipled whether alpha is pre-multiplied.
+ */
+ void EnablePreMultipliedAlpha( bool preMultipled );
/**
* Set the sampler used to render the set texture.
Vector<GLint> mAttributesLocation;
+ BlendingOptions mBlendingOptions; /// Blending options including blend color, blend func and blend equation
+ Dali::Renderer::FaceCullingMode mFaceCullingMode; /// Mode of face culling
+
unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed
- Dali::Material::FaceCullingMode mCullFaceMode:2; ///< cullface enum, 3 bits is enough
+ bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
};
} // namespace SceneGraph
class RenderItem;
class Shader;
class RenderGeometry;
-class MaterialDataProvider;
/**
* Structure to store information for sorting the renderers.
Material::Material()
: mShader( NULL ),
- mBlendColor( NULL ),
mSamplers(),
mTextureId(),
mUniformName(),
mConnectionObservers(),
- mFaceCullingMode( Dali::Material::NONE ),
- mBlendingMode( Dali::BlendingMode::AUTO ),
- mBlendingOptions(), // initializes to defaults
- mBlendPolicy( OPAQUE ),
mResourcesReady( false ),
mFinishedResourceAcquisition( false ),
mMaterialChanged( true )
}
}
}
- mBlendPolicy = OPAQUE;
- switch( mBlendingMode )
- {
- case BlendingMode::OFF:
- {
- mBlendPolicy = OPAQUE;
- break;
- }
- case BlendingMode::ON:
- {
- mBlendPolicy = TRANSLUCENT;
- break;
- }
- case BlendingMode::AUTO:
- {
- // @todo: 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( ( opaqueCount != textureCount ) ||
- ( mShader && mShader->GeometryHintEnabled( Dali::ShaderEffect::HINT_BLENDING ) ) )
- {
- mBlendPolicy = Material::TRANSLUCENT;
- }
- else
- {
- mBlendPolicy = Material::USE_ACTOR_COLOR;
- }
- }
- }
+ // whether the textures or the shader require the opacity to be translucent
+ mIsTranslucent = ( opaqueCount != textureCount ) || ( mShader && mShader->GeometryHintEnabled( Dali::ShaderEffect::HINT_BLENDING ) );
// ready for rendering when all textures are either successfully loaded or they are FBOs
mResourcesReady = (completeCount + frameBufferCount >= textureCount);
return mShader;
}
-void Material::SetFaceCullingMode( unsigned int faceCullingMode )
-{
- mFaceCullingMode = static_cast< Dali::Material::FaceCullingMode >( faceCullingMode );
-}
-
-void Material::SetBlendingMode( unsigned int blendingMode )
-{
- mBlendingMode = static_cast< BlendingMode::Type >( blendingMode );
-}
-
-Material::BlendPolicy Material::GetBlendPolicy() const
-{
- return mBlendPolicy;
-}
-
-void Material::SetBlendingOptions( unsigned int options )
-{
- mBlendingOptions.SetBitmask( options );
-}
-
-void Material::SetBlendColor( const Vector4& blendColor )
-{
- if( mBlendColor )
- {
- *mBlendColor = blendColor;
- }
- else
- {
- mBlendColor = new Vector4( blendColor );
- }
-}
-
-Vector4* Material::GetBlendColor() const
-{
- return mBlendColor;
-}
-
-const BlendingOptions& Material::GetBlendingOptions() const
-{
- return mBlendingOptions;
-}
-
-Dali::Material::FaceCullingMode Material::GetFaceCullingMode() const
+bool Material::IsTranslucent() const
{
- return mFaceCullingMode;
+ return mIsTranslucent;
}
void Material::AddTexture( const std::string& name, ResourceId id, Render::Sampler* sampler )
// INTERNAL INCLUDES
#include <dali/devel-api/rendering/material.h>
#include <dali/internal/common/buffer-index.h>
-#include <dali/internal/common/blending-options.h>
#include <dali/internal/event/common/event-thread-services.h>
#include <dali/internal/update/common/animatable-property.h>
#include <dali/internal/update/common/property-owner.h>
#include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
#include <dali/internal/update/common/uniform-map.h>
-#include <dali/internal/render/data-providers/material-data-provider.h>
#include <dali/internal/update/resources/resource-manager-declarations.h>
namespace Dali
class ConnectionObserver;
class SceneController;
-class Material : public PropertyOwner, public MaterialDataProvider, public UniformMap::Observer, public ConnectionChangePropagator::Observer
+class Material : public PropertyOwner, public UniformMap::Observer, public ConnectionChangePropagator::Observer
{
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 never use blending
- TRANSLUCENT, ///< If the renderer should always be use blending
- USE_ACTOR_COLOR ///< If the renderer should determine opacity using the actor color
- };
/**
* Construct a new Material.
Shader* GetShader() const;
/**
- * Set the face culling mode
- * @param[in] faceCullingMode to use
- */
- void SetFaceCullingMode( unsigned int faceCullingMode );
-
- /**
- * Set the blending mode
- * @param[in] blendingMode to use
- */
- void SetBlendingMode( unsigned int blendingMode );
-
- /**
- * 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
- */
- BlendPolicy GetBlendPolicy() const;
-
- /**
- * Set the blending options. This should only be called from the update thread.
- * @param[in] options A bitmask of blending options.
- */
- void SetBlendingOptions( unsigned int options );
-
- /**
- * Set the blend color for blending operation
- * @param blendColor to pass to GL
- */
- void SetBlendColor( const Vector4& blendColor );
-
- /**
* Adds a new texture to be used by the material
* @param[in] image The image used by the texture
* @param[in] uniformName The uniform name of the texture
void SetTextureUniformName( size_t index, const std::string& uniformName );
/**
+ * Return whether the textures or the shader require the opacity to be translucent
+ * @return The material's blend policy
+ */
+ bool IsTranslucent() const;
+
+ /**
* Get the material resource status
* Note, we need two values as it's possible that some resource failed to load
* in which case resourcesReady is false (the material is not good to be rendered)
*/
void GetResourcesStatus( bool& resourcesReady, bool& finishedResourceAcquisition );
-public: // Implementation of MaterialDataProvider
-
- /**
- * @copydoc MaterialDataProvider::GetBlendColor
- */
- virtual Vector4* GetBlendColor() const;
-
- /**
- * @copydoc MaterialDataProvider::GetBlendingOptions
- */
- virtual const BlendingOptions& GetBlendingOptions() const;
-
- /**
- * @copydoc MaterialDataProvider::GetFaceCullingMode
- */
- virtual Dali::Material::FaceCullingMode GetFaceCullingMode() const;
-
public: // Implementation of ObjectOwnerContainer template methods
private: // Data
Shader* mShader;
- Vector4* mBlendColor; // not double buffered as its not animateable and not frequently changed
Vector< Render::Sampler* > mSamplers; // Not owned
Vector< ResourceId > mTextureId;
std::vector< std::string > mUniformName;
ConnectionChangePropagator mConnectionObservers;
- Dali::Material::FaceCullingMode mFaceCullingMode; // not double buffered as its not animateable and not frequently changed
- BlendingMode::Type mBlendingMode; // not double buffered as its not animateable and not frequently changed
- BlendingOptions mBlendingOptions; // not double buffered as its not animateable and not frequently changed
- BlendPolicy mBlendPolicy; ///< The blend policy as determined by PrepareRender
bool mResourcesReady; ///< if the material is ready to be rendered
bool mFinishedResourceAcquisition; ///< if resource loading is completed
bool mMaterialChanged; ///< if the material has changed since the last frame
+ bool mIsTranslucent; ///< if the textures or the shader require the opacity to be translucent
};
inline void SetShaderMessage( EventThreadServices& eventThreadServices, const Material& material, Shader& shader )
new (slot) LocalType( &material, &Material::SetShader, &shader );
}
-inline void SetFaceCullingModeMessage( EventThreadServices& eventThreadServices, const Material& material, Dali::Material::FaceCullingMode faceCullingMode )
-{
- typedef MessageValue1< Material, unsigned int > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- new (slot) LocalType( &material, &Material::SetFaceCullingMode, faceCullingMode );
-}
-
-inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const Material& material, BlendingMode::Type blendingMode )
-{
- typedef MessageValue1< Material, unsigned int > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- new (slot) LocalType( &material, &Material::SetBlendingMode, blendingMode );
-}
-
-inline void SetBlendingOptionsMessage( EventThreadServices& eventThreadServices, const Material& material, unsigned int options )
-{
- typedef MessageValue1< 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 );
-}
-
-inline void SetBlendColorMessage( EventThreadServices& eventThreadServices, const Material& material, const Vector4& blendColor )
-{
- typedef MessageValue1< Material, Vector4 > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- new (slot) LocalType( &material, &Material::SetBlendColor, blendColor );
-}
-
inline void AddTextureMessage( EventThreadServices& eventThreadServices, const Material& material, const std::string& uniformName, ResourceId id, Render::Sampler* sampler )
{
typedef MessageValue3< Material, std::string, ResourceId, Render::Sampler* > LocalType;
//@todo MESH_REWORK Use memcpy to copy ptrs from one array to the other
}
}
+
+// flags for resending data to renderer
+enum Flags
+{
+ RESEND_DATA_PROVIDER = 1,
+ RESEND_GEOMETRY = 1 << 1,
+ RESEND_FACE_CULLING_MODE = 1 << 2,
+ RESEND_BLEND_COLOR = 1 << 3,
+ RESEND_BLEND_BIT_MASK = 1 << 4,
+ RESEND_PREMULTIPLIED_ALPHA = 1 << 5
+};
+
}
namespace Dali
mRenderer(NULL),
mMaterial(NULL),
mGeometry(NULL),
+ mBlendColor(NULL),
+ mBlendBitmask(0u),
+ mFaceCullingMode( Dali::Renderer::NONE ),
+ mBlendingMode( Dali::BlendingMode::AUTO ),
mReferenceCount(0),
mRegenerateUniformMap(0),
- mResendDataProviders(false),
- mResendGeometry(false),
+ mResendFlag(0),
mResourcesReady(false),
mFinishedResourceAcquisition(false),
mDepthIndex(0)
mRegenerateUniformMap--;
}
- if( mResendDataProviders )
+ if( mResendFlag == 0 )
+ {
+ return;
+ }
+
+ if( mResendFlag & RESEND_DATA_PROVIDER )
{
RenderDataProvider* dataProvider = NewRenderDataProvider();
typedef MessageValue1< Render::Renderer, OwnerPointer<RenderDataProvider> > DerivedType;
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
new (slot) DerivedType( mRenderer, &Render::Renderer::SetRenderDataProvider, dataProvider );
- mResendDataProviders = false;
+ mResendFlag &= ~RESEND_DATA_PROVIDER;
}
- if( mResendGeometry )
+ if( mResendFlag & RESEND_GEOMETRY )
{
// The first call to GetRenderGeometry() creates the geometry and sends it in a message
RenderGeometry* geometry = mGeometry->GetRenderGeometry( mSceneController );
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
new (slot) DerivedType( mRenderer, &Render::Renderer::SetGeometry, geometry );
- mResendGeometry = false;
+ mResendFlag &= ~RESEND_GEOMETRY;
+ }
+
+ if( mResendFlag & RESEND_FACE_CULLING_MODE )
+ {
+ typedef MessageValue1< Render::Renderer, Dali::Renderer::FaceCullingMode > DerivedType;
+ unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
+ new (slot) DerivedType( mRenderer, &Render::Renderer::SetFaceCullingMode, mFaceCullingMode );
+ mResendFlag &= ~RESEND_FACE_CULLING_MODE;
+ }
+
+ if( mResendFlag & RESEND_BLEND_BIT_MASK )
+ {
+ typedef MessageValue1< Render::Renderer, unsigned int > DerivedType;
+ unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
+ new (slot) DerivedType( mRenderer, &Render::Renderer::SetBlendingBitMask, mBlendBitmask );
+ mResendFlag &= ~RESEND_BLEND_BIT_MASK;
+ }
+
+ if( mResendFlag & RESEND_BLEND_COLOR )
+ {
+ typedef MessageValue1< Render::Renderer, const Vector4* > DerivedType;
+ unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
+ new (slot) DerivedType( mRenderer, &Render::Renderer::SetBlendColor, mBlendColor );
+ mResendFlag &= ~RESEND_BLEND_COLOR;
+ }
+
+ if( mResendFlag & RESEND_PREMULTIPLIED_ALPHA )
+ {
+ typedef MessageValue1< Render::Renderer, bool > DerivedType;
+ unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
+ new (slot) DerivedType( mRenderer, &Render::Renderer::EnablePreMultipliedAlpha, mPremultipledAlphaEnabled );
+ mResendFlag &= ~RESEND_PREMULTIPLIED_ALPHA;
}
}
mMaterial->AddConnectionObserver( *this );
mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
- mResendDataProviders = true;
+ mResendFlag |= RESEND_DATA_PROVIDER;
}
void Renderer::SetGeometry( BufferIndex bufferIndex, Geometry* geometry)
if( mRenderer )
{
- mResendGeometry = true;
+ mResendFlag |= RESEND_GEOMETRY;
}
}
mDepthIndex = depthIndex;
}
+void Renderer::SetFaceCullingMode( unsigned int faceCullingMode )
+{
+ mFaceCullingMode = static_cast<Dali::Renderer::FaceCullingMode>(faceCullingMode);
+ mResendFlag |= RESEND_FACE_CULLING_MODE;
+}
+
+void Renderer::SetBlendingMode( unsigned int blendingMode )
+{
+ mBlendingMode = static_cast< BlendingMode::Type >( blendingMode );
+}
+
+void Renderer::SetBlendingOptions( unsigned int options )
+{
+ if( mBlendBitmask != options)
+ {
+ mBlendBitmask = options;
+ mResendFlag |= RESEND_BLEND_BIT_MASK;
+ }
+}
+
+void Renderer::SetBlendColor( const Vector4& blendColor )
+{
+ if( !mBlendColor )
+ {
+ mBlendColor = new Vector4( blendColor );
+ }
+ else
+ {
+ *mBlendColor = blendColor;
+ }
+
+ mResendFlag |= RESEND_BLEND_COLOR;
+}
+
+void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
+{
+ mPremultipledAlphaEnabled = preMultipled;
+ mResendFlag |= RESEND_PREMULTIPLIED_ALPHA;
+}
+
//Called when a node with this renderer is added to the stage
void Renderer::OnStageConnect()
{
RenderDataProvider* dataProvider = NewRenderDataProvider();
RenderGeometry* renderGeometry = mGeometry->GetRenderGeometry(mSceneController);
- mRenderer = Render::Renderer::New( dataProvider, renderGeometry );
+ mRenderer = Render::Renderer::New( dataProvider, renderGeometry,
+ mBlendBitmask, mBlendColor,
+ static_cast< Dali::Renderer::FaceCullingMode >( mFaceCullingMode ),
+ mPremultipledAlphaEnabled );
mSceneController->GetRenderMessageDispatcher().AddRenderer( *mRenderer );
- mResendDataProviders = false;
- mResendGeometry = false;
+ mResendFlag = 0;
}
}
{
RenderDataProvider* dataProvider = new RenderDataProvider();
- dataProvider->mMaterialDataProvider = mMaterial;
dataProvider->mUniformMapDataProvider = this;
dataProvider->mShader = mMaterial->GetShader();
if( mMaterial )
{
- if( mMaterial->GetBlendPolicy() == Material::TRANSLUCENT )
- {
- opacity = Renderer::TRANSLUCENT;
- }
- else if( mMaterial->GetBlendPolicy() == Material::USE_ACTOR_COLOR )
+ switch( mBlendingMode )
{
- float alpha = node.GetWorldColor( updateBufferIndex ).a;
- if( alpha <= FULLY_TRANSPARENT )
+ case BlendingMode::ON: // If the renderer should always be use blending
{
- opacity = TRANSPARENT;
+ opacity = Renderer::TRANSLUCENT;
+ break;
+ }
+ case BlendingMode::AUTO:
+ {
+ if(mMaterial->IsTranslucent() ) // If the renderer should determine opacity using the material
+ {
+ opacity = Renderer::TRANSLUCENT;
+ }
+ else // renderer should determine opacity using the actor color
+ {
+ float alpha = node.GetWorldColor( updateBufferIndex ).a;
+ if( alpha <= FULLY_TRANSPARENT )
+ {
+ opacity = TRANSPARENT;
+ }
+ else if( alpha <= FULLY_OPAQUE )
+ {
+ opacity = TRANSLUCENT;
+ }
+ }
+ break;
}
- else if( alpha <= FULLY_OPAQUE )
+ case BlendingMode::OFF: // the renderer should never use blending
+ default:
{
- opacity = TRANSLUCENT;
+ opacity = Renderer::OPAQUE;
+ break;
}
}
}
mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
// Ensure the child object pointers get re-sent to the renderer
- mResendDataProviders = true;
+ mResendFlag |= RESEND_DATA_PROVIDER;
}
void Renderer::ConnectedUniformMapChanged()
#include <dali/devel-api/rendering/geometry.h>
+#include <dali/devel-api/rendering/renderer.h> // Dali::Renderer
+#include <dali/internal/common/blending-options.h>
#include <dali/internal/event/common/event-thread-services.h>
#include <dali/internal/update/common/property-owner.h>
#include <dali/internal/update/common/uniform-map.h>
}
/**
+ * Set the face culling mode
+ * @param[in] faceCullingMode to use
+ */
+ void SetFaceCullingMode( unsigned int faceCullingMode );
+
+ /**
+ * Set the blending mode
+ * @param[in] blendingMode to use
+ */
+ void SetBlendingMode( unsigned int blendingMode );
+
+ /**
+ * Set the blending options. This should only be called from the update thread.
+ * @param[in] options A bitmask of blending options.
+ */
+ void SetBlendingOptions( unsigned int options );
+
+ /**
+ * Set the blend color for blending operation
+ * @param blendColor to pass to GL
+ */
+ void SetBlendColor( const Vector4& blendColor );
+
+ /**
+ * @brief Set whether the Pre-multiplied Alpha Blending is required
+ *
+ * @param[in] preMultipled whether alpha is pre-multiplied.
+ */
+ void EnablePreMultipliedAlpha( bool preMultipled );
+
+ /**
* Called when an actor with this renderer is added to the stage
*/
void OnStageConnect();
*/
RenderDataProvider* NewRenderDataProvider();
+private:
+
SceneController* mSceneController; ///< Used for initializing renderers whilst attached
Render::Renderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
- Material* mMaterial; ///< The material this renderer uses. (Not owned)
- Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
+ Material* mMaterial; ///< The material this renderer uses. (Not owned)
+ Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
+
+ Vector4* mBlendColor; ///< The blend color for blending operation
+ unsigned int mBlendBitmask; ///< The bitmask of blending options
+ Dali::Renderer::FaceCullingMode mFaceCullingMode; ///< The mode of face culling
+ BlendingMode::Type mBlendingMode; ///< The mode of blending
CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
+ unsigned char mResendFlag; ///< Indicate whether data should be resent to the renderer
bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
- bool mResendDataProviders; ///< True if the data providers should be resent to the renderer
- bool mResendGeometry; ///< True if geometry should be resent to the renderer
bool mResourcesReady; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
+ bool mPremultipledAlphaEnabled; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
public:
int mDepthIndex; ///< Used only in PrepareRenderInstructions
new (slot) LocalType( &attachment, &Renderer::SetDepthIndex, depthIndex );
}
+inline void SetFaceCullingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, Dali::Renderer::FaceCullingMode faceCullingMode )
+{
+ typedef MessageValue1< Renderer, unsigned int > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ new (slot) LocalType( &renderer, &Renderer::SetFaceCullingMode, faceCullingMode );
+}
+
+inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, BlendingMode::Type blendingMode )
+{
+ typedef MessageValue1< Renderer, unsigned int > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ new (slot) LocalType( &renderer, &Renderer::SetBlendingMode, blendingMode );
+}
+
+inline void SetBlendingOptionsMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, unsigned int options )
+{
+ typedef MessageValue1< Renderer, unsigned int > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ new (slot) LocalType( &renderer, &Renderer::SetBlendingOptions, options );
+}
+
+inline void SetBlendColorMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Vector4& blendColor )
+{
+ typedef MessageValue1< Renderer, Vector4 > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ new (slot) LocalType( &renderer, &Renderer::SetBlendColor, blendColor );
+}
+
+inline void SetEnablePreMultipliedAlphaMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, bool preMultiplied )
+{
+ typedef MessageValue1< Renderer, bool > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ new (slot) LocalType( &renderer, &Renderer::EnablePreMultipliedAlpha, preMultiplied );
+}
+
inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
{
typedef Message< Renderer > LocalType;