From: Heeyong Song Date: Fri, 9 Feb 2018 09:43:38 +0000 (+0900) Subject: Add OPACITY property to Renderer X-Git-Tag: dali_1.3.17~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F14%2F169814%2F12;p=platform%2Fcore%2Fuifw%2Fdali-core.git Add OPACITY property to Renderer Change-Id: Ie7da7d60e2a97e289014ae83cadb0be8157af353 --- diff --git a/automated-tests/src/dali/utc-Dali-Renderer.cpp b/automated-tests/src/dali/utc-Dali-Renderer.cpp index 021349f..b5c1add 100644 --- a/automated-tests/src/dali/utc-Dali-Renderer.cpp +++ b/automated-tests/src/dali/utc-Dali-Renderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -17,6 +17,7 @@ // EXTERNAL INCLUDES #include +#include #include #include @@ -259,15 +260,21 @@ int UtcDaliRendererSetGetDepthIndex(void) renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 ); + DALI_TEST_EQUALS( renderer.GetProperty(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION ); + DALI_TEST_EQUALS( renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION ); + application.SendNotification(); application.Render(0); - DALI_TEST_EQUALS( renderer.GetProperty(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION ); + DALI_TEST_EQUALS( renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION ); renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 ); + DALI_TEST_EQUALS( renderer.GetProperty(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION ); + DALI_TEST_EQUALS( renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION ); + application.SendNotification(); application.Render(0); - DALI_TEST_EQUALS( renderer.GetProperty(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION ); + DALI_TEST_EQUALS( renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION ); END_TEST; } @@ -550,6 +557,41 @@ int UtcDaliRendererSetBlendMode01(void) END_TEST; } +int UtcDaliRendererSetBlendMode01b(void) +{ + TestApplication application; + + tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled"); + + Geometry geometry = CreateQuadGeometry(); + Shader shader = CreateShader(); + Renderer renderer = Renderer::New( geometry, shader ); + + Actor actor = Actor::New(); + actor.SetOpacity( 0.0f ); + actor.AddRenderer(renderer); + actor.SetSize(400, 400); + Stage::GetCurrent().Add(actor); + + renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON); + + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + glAbstraction.EnableEnableDisableCallTrace(true); + glAbstraction.EnableDrawCallTrace( true ); + + application.SendNotification(); + application.Render(); + + TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace(); + std::ostringstream blendStr; + blendStr << GL_BLEND; + DALI_TEST_CHECK( !glEnableStack.FindMethod( "Enable" ) ); + + DALI_TEST_CHECK( !glAbstraction.GetDrawTrace().FindMethod( "DrawElements" ) ); + + END_TEST; +} + int UtcDaliRendererSetBlendMode02(void) { TestApplication application; @@ -856,13 +898,23 @@ int UtcDaliRendererSetBlendColor(void) TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT ); + application.SendNotification(); application.Render(); + + DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION ); + DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION ); DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION ); renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA ); + + DALI_TEST_EQUALS( renderer.GetProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION ); + DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION ); + application.SendNotification(); application.Render(); + + DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION ); DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION ); Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f ); @@ -948,6 +1000,10 @@ int UtcDaliRendererPreMultipledAlpha(void) DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) ); DALI_TEST_CHECK( preMultipliedAlpha ); + value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA ); + DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) ); + DALI_TEST_CHECK( preMultipliedAlpha ); + srcFactorRgb = renderer.GetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB ); destFactorRgb = renderer.GetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB ); srcFactorAlpha = renderer.GetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA ); @@ -1836,6 +1892,24 @@ int UtcDaliRendererSetIndexRange(void) renderer.SetIndexRange( 0, 5 ); application.SendNotification(); application.Render(); + + Property::Value value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_FIRST ); + int convertedValue; + DALI_TEST_CHECK( value.Get( convertedValue ) ); + DALI_TEST_CHECK( convertedValue == 0 ); + + value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_FIRST ); + DALI_TEST_CHECK( value.Get( convertedValue ) ); + DALI_TEST_CHECK( convertedValue == 0 ); + + value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_COUNT ); + DALI_TEST_CHECK( value.Get( convertedValue ) ); + DALI_TEST_CHECK( convertedValue == 5 ); + + value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_COUNT ); + DALI_TEST_CHECK( value.Get( convertedValue ) ); + DALI_TEST_CHECK( convertedValue == 5 ); + sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT ); bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer ); DALI_TEST_CHECK( result ); @@ -2034,15 +2108,31 @@ int UtcDaliRendererSetDepthFunction(void) * - Check it was set. */ template< typename T > -void CheckEnumerationProperty( Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString ) +void CheckEnumerationProperty( TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString ) { + application.SendNotification(); + application.Render(); + DALI_TEST_CHECK( renderer.GetProperty( propertyIndex ) == static_cast( initialValue ) ); DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast( initialValue ) ); renderer.SetProperty( propertyIndex, firstCheckEnumeration ); DALI_TEST_CHECK( renderer.GetProperty( propertyIndex ) == static_cast( firstCheckEnumeration ) ); + DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast( firstCheckEnumeration ) ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK( renderer.GetProperty( propertyIndex ) == static_cast( firstCheckEnumeration ) ); DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast( firstCheckEnumeration ) ); + renderer.SetProperty( propertyIndex, secondCheckString ); DALI_TEST_CHECK( renderer.GetProperty( propertyIndex ) == static_cast( secondCheckEnumeration ) ); + DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast( secondCheckEnumeration ) ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK( renderer.GetProperty( propertyIndex ) == static_cast( secondCheckEnumeration ) ); DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast( secondCheckEnumeration ) ); } @@ -2055,27 +2145,32 @@ int UtcDaliRendererEnumProperties(void) Shader shader = CreateShader(); Renderer renderer = Renderer::New( geometry, shader ); + Actor actor = Actor::New(); + actor.AddRenderer(renderer); + actor.SetSize(400, 400); + Stage::GetCurrent().Add(actor); + /* * Here we use a templatized function to perform several checks on each enumeration property. * @see CheckEnumerationProperty for details of the checks performed. */ - CheckEnumerationProperty< FaceCullingMode::Type >( renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" ); - CheckEnumerationProperty< BlendMode::Type >( renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" ); - CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" ); - CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" ); - CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" ); - CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" ); - CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" ); - CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" ); - CheckEnumerationProperty< DepthWriteMode::Type >( renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" ); - CheckEnumerationProperty< DepthFunction::Type >( renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" ); - CheckEnumerationProperty< DepthTestMode::Type >( renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" ); - CheckEnumerationProperty< StencilFunction::Type >( renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" ); - CheckEnumerationProperty< RenderMode::Type >( renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" ); - CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" ); - CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" ); - CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" ); + CheckEnumerationProperty< FaceCullingMode::Type >( application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" ); + CheckEnumerationProperty< BlendMode::Type >( application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" ); + CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" ); + CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" ); + CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" ); + CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" ); + CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" ); + CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" ); + CheckEnumerationProperty< DepthWriteMode::Type >( application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" ); + CheckEnumerationProperty< DepthFunction::Type >( application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" ); + CheckEnumerationProperty< DepthTestMode::Type >( application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" ); + CheckEnumerationProperty< StencilFunction::Type >( application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" ); + CheckEnumerationProperty< RenderMode::Type >( application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" ); + CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" ); + CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" ); + CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" ); END_TEST; } @@ -2390,6 +2485,8 @@ int UtcDaliRendererSetStencilFunction(void) ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack ); + DALI_TEST_EQUALS( static_cast( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get() ), testValueReference, TEST_LOCATION ); + std::stringstream parameterStream; parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255"; @@ -2405,6 +2502,8 @@ int UtcDaliRendererSetStencilFunction(void) ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack ); + DALI_TEST_EQUALS( static_cast( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get() ), testValueMask, TEST_LOCATION ); + // Clear the stringstream. parameterStream.str( std::string() ); parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask; @@ -2532,6 +2631,8 @@ int UtcDaliRendererSetStencilMask(void) ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack ); + DALI_TEST_EQUALS( static_cast( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get() ), 0x00, TEST_LOCATION ); + std::string methodString( "StencilMask" ); std::string parameterString = "0"; @@ -2546,6 +2647,8 @@ int UtcDaliRendererSetStencilMask(void) ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack ); + DALI_TEST_EQUALS( static_cast( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get() ), 0xFF, TEST_LOCATION ); + parameterString = "255"; // Check the function was called and the parameters were correct. @@ -2603,3 +2706,129 @@ int UtcDaliRendererWrongNumberOfTextures(void) END_TEST; } + +int UtcDaliRendererOpacity(void) +{ + TestApplication application; + + tet_infoline( "Test OPACITY property" ); + + Geometry geometry = CreateQuadGeometry(); + Shader shader = Shader::New( "vertexSrc", "fragmentSrc" ); + Renderer renderer = Renderer::New( geometry, shader ); + + Actor actor = Actor::New(); + actor.AddRenderer( renderer ); + actor.SetSize( 400, 400 ); + actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) ); + Stage::GetCurrent().Add( actor ); + + Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY ); + float opacity; + DALI_TEST_CHECK( value.Get( opacity ) ); + DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + Vector4 actualValue; + TestGlAbstraction& gl = application.GetGlAbstraction(); + DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) ); + DALI_TEST_EQUALS( actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION ); + + renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.5f ); + + application.SendNotification(); + application.Render(); + + value = renderer.GetProperty( DevelRenderer::Property::OPACITY ); + DALI_TEST_CHECK( value.Get( opacity ) ); + DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION ); + + value = renderer.GetCurrentProperty( DevelRenderer::Property::OPACITY ); + DALI_TEST_CHECK( value.Get( opacity ) ); + DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION ); + + DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) ); + DALI_TEST_EQUALS( actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliRendererOpacityAnimation(void) +{ + TestApplication application; + + tet_infoline( "Test OPACITY property animation" ); + + Geometry geometry = CreateQuadGeometry(); + Shader shader = Shader::New( "vertexSrc", "fragmentSrc" ); + Renderer renderer = Renderer::New( geometry, shader ); + + Actor actor = Actor::New(); + actor.AddRenderer( renderer ); + actor.SetSize( 400, 400 ); + actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) ); + Stage::GetCurrent().Add( actor ); + + application.SendNotification(); + application.Render(0); + + Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY ); + float opacity; + DALI_TEST_CHECK( value.Get( opacity ) ); + DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION ); + + Animation animation = Animation::New( 1.0f ); + animation.AnimateTo( Property( renderer, DevelRenderer::Property::OPACITY ), 0.0f ); + animation.Play(); + + application.SendNotification(); + application.Render( 1000 ); + + value = renderer.GetProperty( DevelRenderer::Property::OPACITY ); + DALI_TEST_CHECK( value.Get( opacity ) ); + DALI_TEST_EQUALS( opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION ); + + renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.1f ); + + animation.Clear(); + animation.AnimateBy( Property( renderer, DevelRenderer::Property::OPACITY ), 0.5f ); + animation.Play(); + + application.SendNotification(); + application.Render( 1000 ); + + value = renderer.GetProperty( DevelRenderer::Property::OPACITY ); + DALI_TEST_CHECK( value.Get( opacity ) ); + DALI_TEST_EQUALS( opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliRendererInvalidProperty(void) +{ + TestApplication application; + + tet_infoline( "Test invalid property" ); + + Geometry geometry = CreateQuadGeometry(); + Shader shader = Shader::New( "vertexSrc", "fragmentSrc" ); + Renderer renderer = Renderer::New( geometry, shader ); + + Actor actor = Actor::New(); + actor.AddRenderer( renderer ); + actor.SetSize( 400, 400 ); + Stage::GetCurrent().Add( actor ); + + application.SendNotification(); + application.Render(0); + + Property::Value value = renderer.GetProperty( Renderer::Property::DEPTH_INDEX + 100 ); + DALI_TEST_CHECK( value.GetType() == Property::Type::NONE ); + + value = renderer.GetCurrentProperty( Renderer::Property::DEPTH_INDEX + 100 ); + DALI_TEST_CHECK( value.GetType() == Property::Type::NONE ); + + END_TEST; +} diff --git a/dali/devel-api/rendering/renderer-devel.h b/dali/devel-api/rendering/renderer-devel.h index e43ff2f..8b4013c 100644 --- a/dali/devel-api/rendering/renderer-devel.h +++ b/dali/devel-api/rendering/renderer-devel.h @@ -2,7 +2,7 @@ #define DALI_RENDERER_DEVEL_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -56,6 +56,12 @@ namespace Property STENCIL_OPERATION_ON_FAIL = Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL, STENCIL_OPERATION_ON_Z_FAIL = Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, STENCIL_OPERATION_ON_Z_PASS = Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, + + /** + * @brief The opacity of the renderer. + * @details Name "opacity", type Property::FLOAT. + */ + OPACITY = STENCIL_OPERATION_ON_Z_PASS + 1, }; } // namespace Property diff --git a/dali/internal/event/common/object-impl-helper.h b/dali/internal/event/common/object-impl-helper.h index 595baee..44ac750 100644 --- a/dali/internal/event/common/object-impl-helper.h +++ b/dali/internal/event/common/object-impl-helper.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_OBJECT_IMPL_HELPER_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -67,6 +67,7 @@ template struct ObjectImplHelper { const PropertyDetails* DEFAULT_PROPERTY_DETAILS; + const int DEFAULT_PROPERTY_START_INDEX; unsigned int GetDefaultPropertyCount() const { @@ -79,7 +80,7 @@ struct ObjectImplHelper for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i ) { - indices.PushBack( DEFAULT_OBJECT_PROPERTY_START_INDEX + i ); + indices.PushBack( DEFAULT_PROPERTY_START_INDEX + i ); } } @@ -87,9 +88,9 @@ struct ObjectImplHelper { const char* name = NULL; - if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT ) + if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT ) { - name = DEFAULT_PROPERTY_DETAILS[index].name; + name = DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].name; } return name; @@ -117,9 +118,9 @@ struct ObjectImplHelper { bool isWritable = false; - if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT ) + if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT ) { - isWritable = DEFAULT_PROPERTY_DETAILS[index].writable; + isWritable = DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].writable; } return isWritable; @@ -129,9 +130,9 @@ struct ObjectImplHelper { bool isAnimatable = false; - if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT ) + if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT ) { - isAnimatable = DEFAULT_PROPERTY_DETAILS[index].animatable; + isAnimatable = DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].animatable; } return isAnimatable; @@ -141,9 +142,9 @@ struct ObjectImplHelper { bool isConstraintInput = false; - if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT ) + if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT ) { - isConstraintInput = DEFAULT_PROPERTY_DETAILS[index].constraintInput; + isConstraintInput = DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].constraintInput; } return isConstraintInput; @@ -153,9 +154,9 @@ struct ObjectImplHelper { Property::Type type = Property::NONE; - if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT ) + if( index >= DEFAULT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_START_INDEX + DEFAULT_PROPERTY_MAX_COUNT ) { - type = DEFAULT_PROPERTY_DETAILS[index].type; + type = DEFAULT_PROPERTY_DETAILS[index - DEFAULT_PROPERTY_START_INDEX].type; } return type; diff --git a/dali/internal/event/rendering/renderer-impl.cpp b/dali/internal/event/rendering/renderer-impl.cpp index 35431d5..346c83b 100644 --- a/dali/internal/event/rendering/renderer-impl.cpp +++ b/dali/internal/event/rendering/renderer-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -65,6 +65,7 @@ DALI_PROPERTY( "stencilMask", INTEGER, true, false, false DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL ) DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ) DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ) +DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY ) DALI_PROPERTY_TABLE_END( DEFAULT_RENDERER_PROPERTY_START_INDEX ) // Property string to enumeration tables: @@ -159,7 +160,7 @@ DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INCREMENT_WRAP ) DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, DECREMENT_WRAP ) DALI_ENUM_TO_STRING_TABLE_END( STENCIL_OPERATION ) -const ObjectImplHelper RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS }; +const ObjectImplHelper RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS, DEFAULT_RENDERER_PROPERTY_START_INDEX }; BaseHandle Create() { @@ -624,6 +625,19 @@ void Renderer::SetDefaultProperty( Property::Index index, } break; } + case Dali::DevelRenderer::Property::OPACITY: + { + float opacity; + if( propertyValue.Get( opacity ) ) + { + if( !Equals( mOpacity, opacity ) ) + { + mOpacity = opacity; + BakeOpacityMessage( GetEventThreadServices(), *mSceneObject, mOpacity ); + } + } + break; + } } } @@ -638,6 +652,174 @@ void Renderer::SetSceneGraphProperty( Property::Index index, Property::Value Renderer::GetDefaultProperty( Property::Index index ) const { Property::Value value; + + if( ! GetCachedPropertyValue( index, value ) ) + { + // If property value is not stored in the event-side, then it must be a scene-graph only property + GetCurrentPropertyValue( index, value ); + } + + return value; +} + +Property::Value Renderer::GetDefaultPropertyCurrentValue( Property::Index index ) const +{ + Property::Value value; + + if( ! GetCurrentPropertyValue( index, value ) ) + { + // If unable to retrieve scene-graph property value, then it must be an event-side only property + GetCachedPropertyValue( index, value ); + } + + return value; +} + +void Renderer::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType ) +{ + switch( animationType ) + { + case Animation::TO: + case Animation::BETWEEN: + { + switch( index ) + { + case Dali::DevelRenderer::Property::OPACITY: + { + value.Get( mOpacity ); + break; + } + } + break; + } + + case Animation::BY: + { + switch( index ) + { + case Dali::DevelRenderer::Property::OPACITY: + { + AdjustValue< float >( mOpacity, value ); + break; + } + } + break; + } + } +} + +const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const +{ + return mSceneObject; +} + +const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const +{ + return mSceneObject; +} + +const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const +{ + DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" ); + const SceneGraph::PropertyBase* property = NULL; + + property = RENDERER_IMPL.GetRegisteredSceneGraphProperty( + this, + &Renderer::FindAnimatableProperty, + &Renderer::FindCustomProperty, + index ); + + if( !property ) + { + if( index == DevelRenderer::Property::OPACITY ) + { + property = &mSceneObject->mOpacity; + } + } + + return property; +} + +const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const +{ + const PropertyInputImpl* property = NULL; + + const SceneGraph::PropertyBase* baseProperty = + RENDERER_IMPL.GetRegisteredSceneGraphProperty( this, + &Renderer::FindAnimatableProperty, + &Renderer::FindCustomProperty, + index ); + property = static_cast( baseProperty ); + + return property; +} + +int Renderer::GetPropertyComponentIndex( Property::Index index ) const +{ + return Property::INVALID_COMPONENT_INDEX; +} + +Renderer::Renderer() +: mSceneObject(NULL ), + mDepthIndex( 0 ), + mIndexedDrawFirstElement( 0 ), + mIndexedDrawElementCount( 0 ), + mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ), + mBlendingOptions(), + mOpacity( 1.0f ), + mDepthFunction( DepthFunction::LESS ), + mFaceCullingMode( FaceCullingMode::NONE ), + mBlendMode( BlendMode::AUTO ), + mDepthWriteMode( DepthWriteMode::AUTO ), + mDepthTestMode( DepthTestMode::AUTO ), + mPremultipledAlphaEnabled( false ) +{ +} + +void Renderer::Initialize() +{ + EventThreadServices& eventThreadServices = GetEventThreadServices(); + SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager(); + + mSceneObject = SceneGraph::Renderer::New(); + OwnerPointer< SceneGraph::Renderer > transferOwnership( mSceneObject ); + AddRendererMessage( updateManager, transferOwnership ); + + eventThreadServices.RegisterObject( this ); +} + +void Renderer::SetBlendColor( const Vector4& blendColor ) +{ + mBlendingOptions.SetBlendColor( blendColor ); + SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, GetBlendColor() ); +} + +const Vector4& Renderer::GetBlendColor() const +{ + const Vector4* blendColor = mBlendingOptions.GetBlendColor(); + if( blendColor ) + { + return *blendColor; + } + return Color::TRANSPARENT; // GL default +} + +Renderer::~Renderer() +{ + if( EventThreadServices::IsCoreRunning() ) + { + EventThreadServices& eventThreadServices = GetEventThreadServices(); + SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager(); + RemoveRendererMessage( updateManager, *mSceneObject ); + + eventThreadServices.UnregisterObject( this ); + } +} + +bool Renderer::GetCachedPropertyValue( Property::Index index, Property::Value& value ) const +{ + bool valueSet = true; + switch( index ) { case Dali::Renderer::Property::DEPTH_INDEX: @@ -780,112 +962,188 @@ Property::Value Renderer::GetDefaultProperty( Property::Index index ) const value = mStencilParameters.stencilOperationOnZPass; break; } + case Dali::DevelRenderer::Property::OPACITY: + { + value = mOpacity; + break; + } + default: + { + // Must be a scene-graph only property + valueSet = false; + break; + } } - return value; -} - -Property::Value Renderer::GetDefaultPropertyCurrentValue( Property::Index index ) const -{ - return GetDefaultProperty( index ); // Event-side only properties -} - -const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const -{ - return mSceneObject; -} -const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const -{ - return mSceneObject; + return valueSet; } -const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const +bool Renderer::GetCurrentPropertyValue( Property::Index index, Property::Value& value ) const { - DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" ); - const SceneGraph::PropertyBase* property = NULL; + bool valueSet = true; - property = RENDERER_IMPL.GetRegisteredSceneGraphProperty( - this, - &Renderer::FindAnimatableProperty, - &Renderer::FindCustomProperty, - index ); - - return property; -} - -const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const -{ - const PropertyInputImpl* property = NULL; - - const SceneGraph::PropertyBase* baseProperty = - RENDERER_IMPL.GetRegisteredSceneGraphProperty( this, - &Renderer::FindAnimatableProperty, - &Renderer::FindCustomProperty, - index ); - property = static_cast( baseProperty ); - - return property; -} - -int Renderer::GetPropertyComponentIndex( Property::Index index ) const -{ - return Property::INVALID_COMPONENT_INDEX; -} - -Renderer::Renderer() -: mSceneObject(NULL ), - mDepthIndex( 0 ), - mIndexedDrawFirstElement( 0 ), - mIndexedDrawElementCount( 0 ), - mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ), - mBlendingOptions(), - mDepthFunction( DepthFunction::LESS ), - mFaceCullingMode( FaceCullingMode::NONE ), - mBlendMode( BlendMode::AUTO ), - mDepthWriteMode( DepthWriteMode::AUTO ), - mDepthTestMode( DepthTestMode::AUTO ), - mPremultipledAlphaEnabled( false ) -{ -} - -void Renderer::Initialize() -{ - EventThreadServices& eventThreadServices = GetEventThreadServices(); - SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager(); - - mSceneObject = SceneGraph::Renderer::New(); - OwnerPointer< SceneGraph::Renderer > transferOwnership( mSceneObject ); - AddRendererMessage( updateManager, transferOwnership ); - - eventThreadServices.RegisterObject( this ); -} - -void Renderer::SetBlendColor( const Vector4& blendColor ) -{ - mBlendingOptions.SetBlendColor( blendColor ); - SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, GetBlendColor() ); -} - -const Vector4& Renderer::GetBlendColor() const -{ - const Vector4* blendColor = mBlendingOptions.GetBlendColor(); - if( blendColor ) + switch( index ) { - return *blendColor; + case Dali::Renderer::Property::DEPTH_INDEX: + { + value = mSceneObject->GetDepthIndex(); + break; + } + case Dali::Renderer::Property::FACE_CULLING_MODE: + { + value = mSceneObject->GetFaceCullingMode(); + break; + } + case Dali::Renderer::Property::BLEND_MODE: + { + value = mSceneObject->GetBlendMode(); + break; + } + case Dali::Renderer::Property::BLEND_EQUATION_RGB: + { + unsigned int bitMask = mSceneObject->GetBlendingOptions(); + BlendingOptions blendingOptions; + blendingOptions.SetBitmask( bitMask ); + value = static_cast( blendingOptions.GetBlendEquationRgb() ); + break; + } + case Dali::Renderer::Property::BLEND_EQUATION_ALPHA: + { + unsigned int bitMask = mSceneObject->GetBlendingOptions(); + BlendingOptions blendingOptions; + blendingOptions.SetBitmask( bitMask ); + value = static_cast( blendingOptions.GetBlendEquationAlpha() ); + break; + } + case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB: + { + unsigned int bitMask = mSceneObject->GetBlendingOptions(); + BlendingOptions blendingOptions; + blendingOptions.SetBitmask( bitMask ); + value = static_cast( blendingOptions.GetBlendSrcFactorRgb() ); + break; + } + case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB: + { + unsigned int bitMask = mSceneObject->GetBlendingOptions(); + BlendingOptions blendingOptions; + blendingOptions.SetBitmask( bitMask ); + value = static_cast( blendingOptions.GetBlendDestFactorRgb() ); + break; + } + case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA: + { + unsigned int bitMask = mSceneObject->GetBlendingOptions(); + BlendingOptions blendingOptions; + blendingOptions.SetBitmask( bitMask ); + value = static_cast( blendingOptions.GetBlendSrcFactorAlpha() ); + break; + } + case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA: + { + unsigned int bitMask = mSceneObject->GetBlendingOptions(); + BlendingOptions blendingOptions; + blendingOptions.SetBitmask( bitMask ); + value = static_cast( blendingOptions.GetBlendDestFactorAlpha() ); + break; + } + case Dali::Renderer::Property::BLEND_COLOR: + { + value = mSceneObject->GetBlendColor(); + break; + } + case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA: + { + value = mSceneObject->IsPreMultipliedAlphaEnabled(); + break; + } + case Dali::Renderer::Property::INDEX_RANGE_FIRST: + { + value = static_cast( mSceneObject->GetIndexedDrawFirstElement() ); + break; + } + case Dali::Renderer::Property::INDEX_RANGE_COUNT: + { + value = static_cast( mSceneObject->GetIndexedDrawElementsCount() ); + break; + } + case Dali::Renderer::Property::DEPTH_WRITE_MODE: + { + value = mSceneObject->GetDepthWriteMode(); + break; + } + case Dali::Renderer::Property::DEPTH_FUNCTION: + { + value = mSceneObject->GetDepthFunction(); + break; + } + case Dali::Renderer::Property::DEPTH_TEST_MODE: + { + value = mSceneObject->GetDepthTestMode(); + break; + } + case Dali::Renderer::Property::STENCIL_FUNCTION: + { + Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters(); + value = stencilParameters.stencilFunction; + break; + } + case Dali::Renderer::Property::STENCIL_FUNCTION_MASK: + { + Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters(); + value = stencilParameters.stencilFunctionMask; + break; + } + case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE: + { + Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters(); + value = stencilParameters.stencilFunctionReference; + break; + } + case Dali::Renderer::Property::STENCIL_MASK: + { + Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters(); + value = stencilParameters.stencilMask; + break; + } + case Dali::Renderer::Property::RENDER_MODE: + { + Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters(); + value = stencilParameters.renderMode; + break; + } + case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL: + { + Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters(); + value = stencilParameters.stencilOperationOnFail; + break; + } + case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL: + { + Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters(); + value = stencilParameters.stencilOperationOnZFail; + break; + } + case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS: + { + Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters(); + value = stencilParameters.stencilOperationOnZPass; + break; + } + case Dali::DevelRenderer::Property::OPACITY: + { + value = mSceneObject->GetOpacity( GetEventThreadServices().GetEventBufferIndex() ); + break; + } + default: + { + // Must be an event-side only property + valueSet = false; + break; + } } - return Color::TRANSPARENT; // GL default -} -Renderer::~Renderer() -{ - if( EventThreadServices::IsCoreRunning() ) - { - EventThreadServices& eventThreadServices = GetEventThreadServices(); - SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager(); - RemoveRendererMessage( updateManager, *mSceneObject ); - - eventThreadServices.UnregisterObject( this ); - } + return valueSet; } } // namespace Internal diff --git a/dali/internal/event/rendering/renderer-impl.h b/dali/internal/event/rendering/renderer-impl.h index ad487d3..e4911a2 100644 --- a/dali/internal/event/rendering/renderer-impl.h +++ b/dali/internal/event/rendering/renderer-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_RENDERER_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -229,6 +229,11 @@ public: // Default property extensions from Object */ virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const; + /** + * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation() + */ + virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType ); + /** * @copydoc Dali::Internal::Object::GetPropertyOwner() */ @@ -278,6 +283,22 @@ private: // implementation */ const Vector4& GetBlendColor() const; + /** + * @brief Retrieves the cached event side value of a default property. + * @param[in] index The index of the property + * @param[out] value Is set with the cached value of the property if found. + * @return True if value set, false otherwise. + */ + bool GetCachedPropertyValue( Property::Index index, Property::Value& value ) const; + + /** + * @brief Retrieves the current value of a default property from the scene-graph. + * @param[in] index The index of the property + * @param[out] value Is set with the current scene-graph value of the property + * @return True if value set, false otherwise. + */ + bool GetCurrentPropertyValue( Property::Index index, Property::Value& value ) const; + protected: /** * A reference counted object may only be deleted by calling Unreference() @@ -302,6 +323,8 @@ private: // data Render::Renderer::StencilParameters mStencilParameters; ///< Struct containing all stencil related options BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask + float mOpacity; ///< Local copy of the opacity + DepthFunction::Type mDepthFunction:3; ///< Local copy of the depth function FaceCullingMode::Type mFaceCullingMode:2; ///< Local copy of the mode of face culling BlendMode::Type mBlendMode:2; ///< Local copy of the mode of blending diff --git a/dali/internal/event/rendering/shader-impl.cpp b/dali/internal/event/rendering/shader-impl.cpp index 962514e..c9da228 100644 --- a/dali/internal/event/rendering/shader-impl.cpp +++ b/dali/internal/event/rendering/shader-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -42,7 +42,7 @@ DALI_PROPERTY_TABLE_BEGIN DALI_PROPERTY( "program", MAP, true, false, false, Dali::Shader::Property::PROGRAM ) DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX ) -const ObjectImplHelper SHADER_IMPL = { DEFAULT_PROPERTY_DETAILS }; +const ObjectImplHelper SHADER_IMPL = { DEFAULT_PROPERTY_DETAILS, DEFAULT_ACTOR_PROPERTY_START_INDEX }; Dali::Scripting::StringEnum ShaderHintsTable[] = { { "NONE", Dali::Shader::Hint::NONE}, diff --git a/dali/internal/render/data-providers/render-data-provider.cpp b/dali/internal/render/data-providers/render-data-provider.cpp index 037e9c7..f6bde71 100644 --- a/dali/internal/render/data-providers/render-data-provider.cpp +++ b/dali/internal/render/data-providers/render-data-provider.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -24,9 +24,10 @@ namespace Internal namespace SceneGraph { -RenderDataProvider::RenderDataProvider() +RenderDataProvider::RenderDataProvider( AnimatableProperty< float >& opacity ) : mUniformMapDataProvider( NULL ), - mShader( NULL ) + mShader( NULL ), + mOpacity( opacity ) { } @@ -64,6 +65,11 @@ std::vector& RenderDataProvider::GetTextures() return mTextures; } +float RenderDataProvider::GetOpacity( BufferIndex bufferIndex ) +{ + return mOpacity[bufferIndex]; +} + } // SceneGraph } // Internal } // Dali diff --git a/dali/internal/render/data-providers/render-data-provider.h b/dali/internal/render/data-providers/render-data-provider.h index 596b72e..478718e 100644 --- a/dali/internal/render/data-providers/render-data-provider.h +++ b/dali/internal/render/data-providers/render-data-provider.h @@ -2,7 +2,7 @@ #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_DATA_PROVIDER_H__ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -25,6 +25,7 @@ #include #include #include +#include namespace Dali { @@ -56,7 +57,7 @@ public: * The RendererAttachment that creates this object will initialize the members * directly. */ - RenderDataProvider(); + RenderDataProvider( AnimatableProperty< float >& opacity ); /** * Destructor @@ -100,12 +101,19 @@ public: */ std::vector& GetTextures(); + /** + * Get the opacity + * @return The opacity + */ + float GetOpacity( BufferIndex bufferIndex ); + private: - const UniformMapDataProvider* mUniformMapDataProvider; - Shader* mShader; + const UniformMapDataProvider* mUniformMapDataProvider; + Shader* mShader; std::vector mTextures; - Samplers mSamplers; + Samplers mSamplers; + AnimatableProperty< float >& mOpacity; // Give Renderer access to our private data to reduce copying vectors on construction. friend class Renderer; diff --git a/dali/internal/render/renderers/render-renderer.cpp b/dali/internal/render/renderers/render-renderer.cpp index 1d2328d..ca9724e 100644 --- a/dali/internal/render/renderers/render-renderer.cpp +++ b/dali/internal/render/renderers/render-renderer.cpp @@ -164,22 +164,6 @@ Renderer::~Renderer() { } -void Renderer::SetRenderDataProvider( OwnerPointer& dataProvider ) -{ - mRenderDataProvider = dataProvider; - mUpdateAttributesLocation = true; - - // Check that the number of textures match the number of samplers in the shader - size_t textureCount = mRenderDataProvider->GetTextures().size(); - Program* program = mRenderDataProvider->GetShader().GetProgram(); - if( program && program->GetActiveSamplerCount() != textureCount ) - { - DALI_LOG_WARNING("The number of active samplers in the shader(%lu) does not match the number of textures in the TextureSet(%lu)\n", - program->GetActiveSamplerCount(), - textureCount ); - } -} - void Renderer::SetGeometry( Render::Geometry* geometry ) { mGeometry = geometry; @@ -563,11 +547,12 @@ void Renderer::Render( Context& context, const Vector4& color = node.GetRenderColor( bufferIndex ); if( mPremultipledAlphaEnabled ) { - program->SetUniform4f( loc, color.r*color.a, color.g*color.a, color.b*color.a, color.a ); + float alpha = color.a * mRenderDataProvider->GetOpacity( bufferIndex ); + program->SetUniform4f( loc, color.r * alpha, color.g * alpha, color.b * alpha, alpha ); } else { - program->SetUniform4f( loc, color.r, color.g, color.b, color.a ); + program->SetUniform4f( loc, color.r, color.g, color.b, color.a * mRenderDataProvider->GetOpacity( bufferIndex ) ); } } diff --git a/dali/internal/render/renderers/render-renderer.h b/dali/internal/render/renderers/render-renderer.h index 1aaf046..6e1a1f7 100644 --- a/dali/internal/render/renderers/render-renderer.h +++ b/dali/internal/render/renderers/render-renderer.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_RENDER_RENDERER_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -148,12 +148,6 @@ public: StencilParameters& stencilParameters ); /** - * Change the data providers of the renderer - * @param[in] dataProviders The data providers - */ - void SetRenderDataProvider( OwnerPointer& dataProviders ); - - /** * Change the geometry used by the renderer * @param[in] geometry The new geometry */ diff --git a/dali/internal/update/manager/render-instruction-processor.cpp b/dali/internal/update/manager/render-instruction-processor.cpp index b95706f..e94a910 100644 --- a/dali/internal/update/manager/render-instruction-processor.cpp +++ b/dali/internal/update/manager/render-instruction-processor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -171,14 +171,14 @@ inline void AddRendererToRenderList( BufferIndex updateBufferIndex, if( inside ) { - Renderer::Opacity opacity = renderable.mRenderer ? renderable.mRenderer->GetOpacity( updateBufferIndex, *renderable.mNode ) : Renderer::OPAQUE; - if( opacity != Renderer::TRANSPARENT ) + Renderer::OpacityType opacityType = renderable.mRenderer ? renderable.mRenderer->GetOpacityType( updateBufferIndex, *renderable.mNode ) : Renderer::OPAQUE; + if( opacityType != Renderer::TRANSPARENT || node->GetClippingMode() == ClippingMode::CLIP_CHILDREN ) { // Get the next free RenderItem. RenderItem& item = renderList.GetNextFreeItem(); item.mNode = renderable.mNode; - item.mIsOpaque = ( opacity == Renderer::OPAQUE ); + item.mIsOpaque = ( opacityType == Renderer::OPAQUE ); if( !isLayer3d ) { item.mDepthIndex = renderable.mNode->GetDepthIndex(); diff --git a/dali/internal/update/rendering/scene-graph-renderer.cpp b/dali/internal/update/rendering/scene-graph-renderer.cpp index 5127be3..6c93f9c 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.cpp +++ b/dali/internal/update/rendering/scene-graph-renderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -88,26 +88,25 @@ void AddMappings( Dali::Internal::SceneGraph::CollectedUniformMap& localMap, con // Flags for re-sending data to renderer. enum Flags { - RESEND_DATA_PROVIDER = 1 << 0, - 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, - RESEND_INDEXED_DRAW_FIRST_ELEMENT = 1 << 6, - RESEND_INDEXED_DRAW_ELEMENTS_COUNT = 1 << 7, - RESEND_DEPTH_WRITE_MODE = 1 << 8, - RESEND_DEPTH_TEST_MODE = 1 << 9, - RESEND_DEPTH_FUNCTION = 1 << 10, - RESEND_RENDER_MODE = 1 << 11, - RESEND_STENCIL_FUNCTION = 1 << 12, - RESEND_STENCIL_FUNCTION_MASK = 1 << 13, - RESEND_STENCIL_FUNCTION_REFERENCE = 1 << 14, - RESEND_STENCIL_MASK = 1 << 15, - RESEND_STENCIL_OPERATION_ON_FAIL = 1 << 16, - RESEND_STENCIL_OPERATION_ON_Z_FAIL = 1 << 17, - RESEND_STENCIL_OPERATION_ON_Z_PASS = 1 << 18, - RESEND_WRITE_TO_COLOR_BUFFER = 1 << 19, + RESEND_GEOMETRY = 1 << 0, + RESEND_FACE_CULLING_MODE = 1 << 1, + RESEND_BLEND_COLOR = 1 << 2, + RESEND_BLEND_BIT_MASK = 1 << 3, + RESEND_PREMULTIPLIED_ALPHA = 1 << 4, + RESEND_INDEXED_DRAW_FIRST_ELEMENT = 1 << 5, + RESEND_INDEXED_DRAW_ELEMENTS_COUNT = 1 << 6, + RESEND_DEPTH_WRITE_MODE = 1 << 7, + RESEND_DEPTH_TEST_MODE = 1 << 8, + RESEND_DEPTH_FUNCTION = 1 << 9, + RESEND_RENDER_MODE = 1 << 10, + RESEND_STENCIL_FUNCTION = 1 << 11, + RESEND_STENCIL_FUNCTION_MASK = 1 << 12, + RESEND_STENCIL_FUNCTION_REFERENCE = 1 << 13, + RESEND_STENCIL_MASK = 1 << 14, + RESEND_STENCIL_OPERATION_ON_FAIL = 1 << 15, + RESEND_STENCIL_OPERATION_ON_Z_FAIL = 1 << 16, + RESEND_STENCIL_OPERATION_ON_Z_PASS = 1 << 17, + RESEND_WRITE_TO_COLOR_BUFFER = 1 << 18 }; } // Anonymous namespace @@ -130,6 +129,7 @@ Renderer::Renderer() mTextureSet( NULL ), mGeometry( NULL ), mShader( NULL ), + mRenderDataProvider( NULL ), mBlendColor( NULL ), mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ), mIndexedDrawFirstElement( 0u ), @@ -143,6 +143,7 @@ Renderer::Renderer() mDepthWriteMode( DepthWriteMode::AUTO ), mDepthTestMode( DepthTestMode::AUTO ), mPremultipledAlphaEnabled( false ), + mOpacity( 1.0f ), mDepthIndex( 0 ) { mUniformMapChanged[0] = false; @@ -214,15 +215,6 @@ void Renderer::PrepareRender( BufferIndex updateBufferIndex ) if( mResendFlag != 0 ) { - if( mResendFlag & RESEND_DATA_PROVIDER ) - { - OwnerPointer dataProvider = NewRenderDataProvider(); - - typedef MessageValue1< Render::Renderer, OwnerPointer > DerivedType; - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - new (slot) DerivedType( mRenderer, &Render::Renderer::SetRenderDataProvider, dataProvider ); - } - if( mResendFlag & RESEND_GEOMETRY ) { typedef MessageValue1< Render::Renderer, Render::Geometry* > DerivedType; @@ -365,7 +357,8 @@ void Renderer::SetTextures( TextureSet* textureSet ) mTextureSet = textureSet; mTextureSet->AddObserver( this ); mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; - mResendFlag |= RESEND_DATA_PROVIDER; + + UpdateTextureSet(); } void Renderer::SetShader( Shader* shader ) @@ -380,7 +373,11 @@ void Renderer::SetShader( Shader* shader ) mShader = shader; mShader->AddConnectionObserver( *this ); mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; - mResendFlag |= RESEND_DATA_PROVIDER; + + if( mRenderDataProvider ) + { + mRenderDataProvider->mShader = mShader; + } } void Renderer::SetGeometry( Render::Geometry* geometry ) @@ -405,11 +402,21 @@ void Renderer::SetFaceCullingMode( FaceCullingMode::Type faceCullingMode ) mResendFlag |= RESEND_FACE_CULLING_MODE; } +FaceCullingMode::Type Renderer::GetFaceCullingMode() const +{ + return mFaceCullingMode; +} + void Renderer::SetBlendMode( BlendMode::Type blendingMode ) { mBlendMode = blendingMode; } +BlendMode::Type Renderer::GetBlendMode() const +{ + return mBlendMode; +} + void Renderer::SetBlendingOptions( unsigned int options ) { if( mBlendBitmask != options) @@ -419,6 +426,11 @@ void Renderer::SetBlendingOptions( unsigned int options ) } } +unsigned int Renderer::GetBlendingOptions() const +{ + return mBlendBitmask; +} + void Renderer::SetBlendColor( const Vector4& blendColor ) { if( blendColor == Color::TRANSPARENT ) @@ -440,42 +452,81 @@ void Renderer::SetBlendColor( const Vector4& blendColor ) mResendFlag |= RESEND_BLEND_COLOR; } +Vector4 Renderer::GetBlendColor() const +{ + if( mBlendColor ) + { + return *mBlendColor; + } + return Color::TRANSPARENT; +} + void Renderer::SetIndexedDrawFirstElement( size_t firstElement ) { mIndexedDrawFirstElement = firstElement; mResendFlag |= RESEND_INDEXED_DRAW_FIRST_ELEMENT; } +size_t Renderer::GetIndexedDrawFirstElement() const +{ + return mIndexedDrawFirstElement; +} + void Renderer::SetIndexedDrawElementsCount( size_t elementsCount ) { mIndexedDrawElementsCount = elementsCount; mResendFlag |= RESEND_INDEXED_DRAW_ELEMENTS_COUNT; } +size_t Renderer::GetIndexedDrawElementsCount() const +{ + return mIndexedDrawElementsCount; +} + void Renderer::EnablePreMultipliedAlpha( bool preMultipled ) { mPremultipledAlphaEnabled = preMultipled; mResendFlag |= RESEND_PREMULTIPLIED_ALPHA; } +bool Renderer::IsPreMultipliedAlphaEnabled() const +{ + return mPremultipledAlphaEnabled; +} + void Renderer::SetDepthWriteMode( DepthWriteMode::Type depthWriteMode ) { mDepthWriteMode = depthWriteMode; mResendFlag |= RESEND_DEPTH_WRITE_MODE; } +DepthWriteMode::Type Renderer::GetDepthWriteMode() const +{ + return mDepthWriteMode; +} + void Renderer::SetDepthTestMode( DepthTestMode::Type depthTestMode ) { mDepthTestMode = depthTestMode; mResendFlag |= RESEND_DEPTH_TEST_MODE; } +DepthTestMode::Type Renderer::GetDepthTestMode() const +{ + return mDepthTestMode; +} + void Renderer::SetDepthFunction( DepthFunction::Type depthFunction ) { mDepthFunction = depthFunction; mResendFlag |= RESEND_DEPTH_FUNCTION; } +DepthFunction::Type Renderer::GetDepthFunction() const +{ + return mDepthFunction; +} + void Renderer::SetRenderMode( RenderMode::Type mode ) { mStencilParameters.renderMode = mode; @@ -524,14 +575,31 @@ void Renderer::SetStencilOperationOnZPass( StencilOperation::Type stencilOperati mResendFlag |= RESEND_STENCIL_OPERATION_ON_Z_PASS; } +const Render::Renderer::StencilParameters& Renderer::GetStencilParameters() const +{ + return mStencilParameters; +} + +void Renderer::BakeOpacity( BufferIndex updateBufferIndex, float opacity ) +{ + mOpacity.Bake( updateBufferIndex, opacity ); +} + +float Renderer::GetOpacity( BufferIndex updateBufferIndex ) const +{ + return mOpacity[updateBufferIndex]; +} + //Called when SceneGraph::Renderer is added to update manager ( that happens when an "event-thread renderer" is created ) void Renderer::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex ) { mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; mSceneController = &sceneController; - RenderDataProvider* dataProvider = NewRenderDataProvider(); - mRenderer = Render::Renderer::New( dataProvider, mGeometry, mBlendBitmask, GetBlendColor(), static_cast< FaceCullingMode::Type >( mFaceCullingMode ), + mRenderDataProvider = new RenderDataProvider( mOpacity ); + mRenderDataProvider->mUniformMapDataProvider = this; + + mRenderer = Render::Renderer::New( mRenderDataProvider, mGeometry, mBlendBitmask, GetBlendColor(), static_cast< FaceCullingMode::Type >( mFaceCullingMode ), mPremultipledAlphaEnabled, mDepthWriteMode, mDepthTestMode, mDepthFunction, mStencilParameters ); OwnerPointer< Render::Renderer > transferOwnership( mRenderer ); @@ -548,37 +616,30 @@ void Renderer::DisconnectFromSceneGraph( SceneController& sceneController, Buffe mRenderer = NULL; } mSceneController = NULL; + mRenderDataProvider = NULL; } -RenderDataProvider* Renderer::NewRenderDataProvider() +void Renderer::UpdateTextureSet() { - RenderDataProvider* dataProvider = new RenderDataProvider(); - - dataProvider->mUniformMapDataProvider = this; - dataProvider->mShader = mShader; - - if( mTextureSet ) + if( mRenderDataProvider ) { - size_t textureCount = mTextureSet->GetTextureCount(); - dataProvider->mTextures.resize( textureCount ); - dataProvider->mSamplers.resize( textureCount ); - for( unsigned int i(0); imTextures[i] = mTextureSet->GetTexture(i); - dataProvider->mSamplers[i] = mTextureSet->GetTextureSampler(i); + size_t textureCount = mTextureSet->GetTextureCount(); + mRenderDataProvider->mTextures.resize( textureCount ); + mRenderDataProvider->mSamplers.resize( textureCount ); + for( unsigned int i(0); imTextures[i] = mTextureSet->GetTexture(i); + mRenderDataProvider->mSamplers[i] = mTextureSet->GetTextureSampler(i); + } + } + else + { + mRenderDataProvider->mTextures.clear(); + mRenderDataProvider->mSamplers.clear(); } } - - return dataProvider; -} - -const Vector4& Renderer::GetBlendColor() const -{ - if( mBlendColor ) - { - return *mBlendColor; - } - return Color::TRANSPARENT; } Render::Renderer& Renderer::GetRenderer() @@ -591,15 +652,23 @@ const CollectedUniformMap& Renderer::GetUniformMap( BufferIndex bufferIndex ) co return mCollectedUniformMap[bufferIndex]; } -Renderer::Opacity Renderer::GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const +Renderer::OpacityType Renderer::GetOpacityType( BufferIndex updateBufferIndex, const Node& node ) const { - Renderer::Opacity opacity = Renderer::OPAQUE; + Renderer::OpacityType opacityType = Renderer::OPAQUE; switch( mBlendMode ) { case BlendMode::ON: // If the renderer should always be use blending { - opacity = Renderer::TRANSLUCENT; + float alpha = node.GetWorldColor( updateBufferIndex ).a * mOpacity[updateBufferIndex]; + if( alpha <= FULLY_TRANSPARENT ) + { + opacityType = Renderer::TRANSPARENT; + } + else + { + opacityType = Renderer::TRANSLUCENT; + } break; } case BlendMode::AUTO: @@ -607,37 +676,37 @@ Renderer::Opacity Renderer::GetOpacity( BufferIndex updateBufferIndex, const Nod bool shaderRequiresBlending( mShader->HintEnabled( Dali::Shader::Hint::OUTPUT_IS_TRANSPARENT ) ); if( shaderRequiresBlending || ( mTextureSet && mTextureSet->HasAlpha() ) ) { - opacity = Renderer::TRANSLUCENT; + opacityType = Renderer::TRANSLUCENT; } - else // renderer should determine opacity using the actor color + + // renderer should determine opacity using the actor color + float alpha = node.GetWorldColor( updateBufferIndex ).a * mOpacity[updateBufferIndex]; + if( alpha <= FULLY_TRANSPARENT ) { - float alpha = node.GetWorldColor( updateBufferIndex ).a; - if( alpha <= FULLY_TRANSPARENT ) - { - opacity = TRANSPARENT; - } - else if( alpha <= FULLY_OPAQUE ) - { - opacity = TRANSLUCENT; - } + opacityType = Renderer::TRANSPARENT; + } + else if( alpha <= FULLY_OPAQUE ) + { + opacityType = Renderer::TRANSLUCENT; } break; } case BlendMode::OFF: // the renderer should never use blending default: { - opacity = Renderer::OPAQUE; + opacityType = Renderer::OPAQUE; break; } } - return opacity; + return opacityType; } void Renderer::TextureSetChanged() { mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; - mResendFlag |= RESEND_DATA_PROVIDER; + + UpdateTextureSet(); } void Renderer::TextureSetDeleted() @@ -645,16 +714,15 @@ void Renderer::TextureSetDeleted() mTextureSet = NULL; mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; - mResendFlag |= RESEND_DATA_PROVIDER; + + UpdateTextureSet(); } + void Renderer::ConnectionsChanged( PropertyOwner& object ) { // One of our child objects has changed it's connections. Ensure the uniform // map gets regenerated during PrepareRender mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; - - // Ensure the child object pointers get re-sent to the renderer - mResendFlag |= RESEND_DATA_PROVIDER; } void Renderer::ConnectedUniformMapChanged() diff --git a/dali/internal/update/rendering/scene-graph-renderer.h b/dali/internal/update/rendering/scene-graph-renderer.h index ee6762d..f1ef2a7 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.h +++ b/dali/internal/update/rendering/scene-graph-renderer.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_RENDERER_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -59,7 +60,7 @@ class Renderer : public PropertyOwner, { public: - enum Opacity + enum OpacityType { OPAQUE, TRANSPARENT, @@ -140,60 +141,120 @@ public: void SetFaceCullingMode( FaceCullingMode::Type faceCullingMode ); /** + * Get face culling mode + * @return The face culling mode + */ + FaceCullingMode::Type GetFaceCullingMode() const; + + /** * Set the blending mode * @param[in] blendingMode to use */ void SetBlendMode( BlendMode::Type blendingMode ); /** + * Get the blending mode + * @return The the blending mode + */ + BlendMode::Type GetBlendMode() 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 ); /** + * Get the blending options + * @return The the blending mode + */ + unsigned int GetBlendingOptions() const; + + /** * Set the blend color for blending operation * @param blendColor to pass to GL */ void SetBlendColor( const Vector4& blendColor ); /** + * Get the blending color + * @return The blend color + */ + Vector4 GetBlendColor() const; + + /** * Set the index of first element for indexed draw * @param[in] firstElement index of first element to draw */ void SetIndexedDrawFirstElement( size_t firstElement ); /** + * Get the index of first element for indexed draw + * @return The index of first element for indexed draw + */ + size_t GetIndexedDrawFirstElement() const; + + /** * Set the number of elements to draw by indexed draw * @param[in] elementsCount number of elements to draw */ void SetIndexedDrawElementsCount( size_t elementsCount ); /** + * Get the number of elements to draw by indexed draw + * @return The number of elements to draw by indexed draw + */ + size_t GetIndexedDrawElementsCount() 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; + + /** * Sets the depth buffer write mode * @param[in] depthWriteMode The depth buffer write mode */ void SetDepthWriteMode( DepthWriteMode::Type depthWriteMode ); /** + * Get the depth buffer write mode + * @return The depth buffer write mode + */ + DepthWriteMode::Type GetDepthWriteMode() const; + + /** * Sets the depth buffer test mode * @param[in] depthTestMode The depth buffer test mode */ void SetDepthTestMode( DepthTestMode::Type depthTestMode ); /** + * Get the depth buffer test mode + * @return The depth buffer test mode + */ + DepthTestMode::Type GetDepthTestMode() const; + + /** * Sets the depth function * @param[in] depthFunction The depth function */ void SetDepthFunction( DepthFunction::Type depthFunction ); /** + * Get the depth function + * @return The depth function + */ + DepthFunction::Type GetDepthFunction() const; + + /** * Sets the render mode * @param[in] mode The render mode */ @@ -242,13 +303,33 @@ public: void SetStencilOperationOnZPass( StencilOperation::Type stencilOperationOnZPass ); /** + * Gets the stencil parameters + * @return The stencil parameters + */ + const Render::Renderer::StencilParameters& GetStencilParameters() const; + + /** + * Bakes the opacity + * @param[in] updateBufferIndex The current update buffer index. + * @param[in] opacity The opacity + */ + void BakeOpacity( BufferIndex updateBufferIndex, float opacity ); + + /** + * Gets the opacity + * @param[in] bufferIndex The buffer to read from. + * @return The opacity + */ + float GetOpacity( BufferIndex updateBufferIndex ) const; + + /** * Prepare the object for rendering. * This is called by the UpdateManager when an object is due to be rendered in the current frame. * @param[in] updateBufferIndex The current update buffer index. */ void PrepareRender( BufferIndex updateBufferIndex ); - /* + /** * Retrieve the Render thread renderer * @return The associated render thread renderer */ @@ -259,7 +340,7 @@ public: * @param[in] updateBufferIndex The current update buffer index. * @return OPAQUE if fully opaque, TRANSPARENT if fully transparent and TRANSLUCENT if in between */ - Opacity GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const; + OpacityType GetOpacityType( BufferIndex updateBufferIndex, const Node& node ) const; /** * Called by the TextureSet to notify to the renderer that it has changed @@ -346,25 +427,20 @@ private: Renderer(); /** - * Helper function to create a new render data provider - * @return the new (initialized) data provider + * Update texture set to the render data provider */ - RenderDataProvider* NewRenderDataProvider(); - - /** - * Helper function to retrieve the blend color. - * @return The blend color. - */ - const Vector4& GetBlendColor() const; + void UpdateTextureSet(); private: CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer + SceneController* mSceneController; ///< Used for initializing renderers Render::Renderer* mRenderer; ///< Raw pointer to the renderer (that's owned by RenderManager) TextureSet* mTextureSet; ///< The texture set this renderer uses. (Not owned) Render::Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned) Shader* mShader; ///< The shader this renderer uses. (Not owned) + RenderDataProvider* mRenderDataProvider; ///< The render data provider OwnerPointer< Vector4 > mBlendColor; ///< The blend color for blending operation Dali::Internal::Render::Renderer::StencilParameters mStencilParameters; ///< Struct containing all stencil related options @@ -386,6 +462,7 @@ private: public: + AnimatableProperty< float > mOpacity; ///< The opacity value int mDepthIndex; ///< Used only in PrepareRenderInstructions }; @@ -616,6 +693,16 @@ inline void SetStencilOperationOnZPassMessage( EventThreadServices& eventThreadS new (slot) LocalType( &renderer, &Renderer::SetStencilOperationOnZPass, stencilOperation ); } +inline void BakeOpacityMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, float opacity ) +{ + typedef MessageDoubleBuffered1< Renderer, float > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + + new (slot) LocalType( &renderer, &Renderer::BakeOpacity, opacity ); +} + } // namespace SceneGraph } // namespace Internal } // namespace Dali