From 2a8f032f9d3e1a78a31986a95ea72964a5b515b0 Mon Sep 17 00:00:00 2001 From: Xiangyin Ma Date: Fri, 29 Jan 2016 16:31:30 +0000 Subject: [PATCH] Update following the changes of blending&culling options Change-Id: I2a48b7d440b31f93ac2d8478f0ffe10ca417099d --- .../src/dali-toolkit/utc-Dali-BubbleEmitter.cpp | 38 ---- .../src/dali-toolkit/utc-Dali-ControlRenderer.cpp | 6 +- .../src/dali-toolkit/utc-Dali-ImageView.cpp | 21 +- .../src/dali-toolkit/utc-Dali-RendererFactory.cpp | 10 +- .../controls/bubble-effect/bubble-emitter.cpp | 5 - .../controls/bubble-effect/bubble-emitter.h | 7 - .../controls/bubble-effect/bubble-emitter-impl.cpp | 16 -- .../controls/bubble-effect/bubble-emitter-impl.h | 5 - .../controls/model3d-view/model3d-view-impl.cpp | 3 +- .../controls/renderers/border/border-renderer.cpp | 6 +- .../controls/renderers/color/color-renderer.cpp | 6 +- .../controls/renderers/control-renderer-impl.cpp | 4 +- .../controls/renderers/image/image-renderer.cpp | 36 +-- .../internal/text/decorator/text-decorator.cpp | 2 +- .../rendering/atlas/atlas-glyph-manager-impl.cpp | 1 - .../text/rendering/atlas/text-atlas-renderer.cpp | 6 +- .../cube-transition-effect-impl.cpp | 5 +- .../src/constants/constants-wrapper.cpp | 10 +- .../dali-script-v8/src/rendering/material-api.cpp | 247 --------------------- .../dali-script-v8/src/rendering/material-api.h | 7 - .../src/rendering/material-wrapper.cpp | 7 - .../dali-script-v8/src/rendering/renderer-api.cpp | 156 +++++++++++++ .../dali-script-v8/src/rendering/renderer-api.h | 4 + .../src/rendering/renderer-wrapper.cpp | 4 + 24 files changed, 209 insertions(+), 403 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-BubbleEmitter.cpp b/automated-tests/src/dali-toolkit/utc-Dali-BubbleEmitter.cpp index 2140f2a..f17e30e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-BubbleEmitter.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-BubbleEmitter.cpp @@ -284,44 +284,6 @@ int UtcDaliBubbleEmitterSetBubbleDensity02(void) END_TEST; } -int UtcDaliBubbleEmitterSetBlendMode(void) -{ - ToolkitTestApplication application; - tet_infoline( " UtcDaliBubbleEmitterSetBlendMode " ); - - Image shapeImage = CreateSolidColorImage( application, Color::GREEN, 5, 5 ); - BubbleEmitter emitter = BubbleEmitter::New( Vector2(50.f,50.f),shapeImage, 150, Vector2( 5.f, 10.f )); - DALI_TEST_CHECK(emitter); - Actor root = emitter.GetRootActor(); - Stage::GetCurrent().Add( root ); - root.SetPosition( Vector3::ZERO ); - root.SetParentOrigin( ParentOrigin::CENTER ); - root.SetAnchorPoint( AnchorPoint::CENTER ); - - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - Wait(application); - DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION ); - - emitter.SetBlendMode( true ); - Wait(application); - DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ZERO, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION ); - - emitter.SetBlendMode( false ); - Wait(application); - DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION ); - - END_TEST; -} - int UtcDaliBubbleEmitterEmitBubble(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ControlRenderer.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ControlRenderer.cpp index fbcbcee..da69b02 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ControlRenderer.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ControlRenderer.cpp @@ -92,11 +92,13 @@ int UtcDaliControlRendererSetGetDepthIndex(void) Stage::GetCurrent().Add( actor ); controlRenderer.SetOnStage( actor ); - DALI_TEST_EQUALS( actor.GetRendererAt(0u).GetDepthIndex(), 1, TEST_LOCATION ); + int depthIndex = actor.GetRendererAt(0u).GetProperty( Renderer::Property::DEPTH_INDEX ); + DALI_TEST_EQUALS( depthIndex, 1, TEST_LOCATION ); DALI_TEST_EQUALS( controlRenderer.GetDepthIndex(), 1.f, TEST_LOCATION ); controlRenderer.SetDepthIndex( -1.f ); - DALI_TEST_EQUALS( actor.GetRendererAt(0u).GetDepthIndex(), -1, TEST_LOCATION ); + depthIndex = actor.GetRendererAt(0u).GetProperty( Renderer::Property::DEPTH_INDEX ); + DALI_TEST_EQUALS( depthIndex, -1, TEST_LOCATION ); DALI_TEST_EQUALS( controlRenderer.GetDepthIndex(), -1.f, TEST_LOCATION ); END_TEST; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp index 32d987f..864d7eb 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -330,36 +329,36 @@ int UtcDaliImageViewSetGetProperty03(void) application.Render(); // conventional alpha blending - Material material = imageView.GetRendererAt( 0 ).GetMaterial(); + Renderer renderer = imageView.GetRendererAt( 0 ); BlendingFactor::Type srcFactorRgb; BlendingFactor::Type destFactorRgb; BlendingFactor::Type srcFactorAlpha; BlendingFactor::Type destFactorAlpha; - material.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha); + renderer.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha); DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA ); DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA ); DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE ); DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA ); - TestGlAbstraction& gl = application.GetGlAbstraction(); - - float alphaBlendingUniform; - DALI_TEST_CHECK( gl.GetUniformValue( "uAlphaBlending", alphaBlendingUniform ) ); - DALI_TEST_EQUALS( alphaBlendingUniform, 1.f, TEST_LOCATION ); + Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA ); + bool enable; + DALI_TEST_CHECK( value.Get( enable ) ); + DALI_TEST_CHECK( !enable ); // pre-multiplied alpha blending imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true ); application.SendNotification(); application.Render(); - material.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha); + renderer.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha); DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::ONE ); DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA ); DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE ); DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE ); - DALI_TEST_CHECK( gl.GetUniformValue( "uAlphaBlending", alphaBlendingUniform ) ); - DALI_TEST_EQUALS( alphaBlendingUniform, 0.f, TEST_LOCATION ); + value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA ); + DALI_TEST_CHECK( value.Get( enable ) ); + DALI_TEST_CHECK( enable ); END_TEST; } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-RendererFactory.cpp b/automated-tests/src/dali-toolkit/utc-Dali-RendererFactory.cpp index 9a66d4b..c9a87e3 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-RendererFactory.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-RendererFactory.cpp @@ -354,7 +354,8 @@ int UtcDaliRendererFactoryGetBorderRenderer1(void) controlRenderer.SetOnStage( actor ); DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); - DALI_TEST_EQUALS( actor.GetRendererAt(0).GetMaterial().GetBlendMode(), BlendingMode::ON, TEST_LOCATION ); + int blendMode = actor.GetRendererAt(0u).GetProperty( Renderer::Property::BLENDING_MODE ); + DALI_TEST_EQUALS( static_cast(blendMode), BlendingMode::ON, TEST_LOCATION ); TestGlAbstraction& gl = application.GetGlAbstraction(); @@ -402,7 +403,8 @@ int UtcDaliRendererFactoryGetBorderRenderer2(void) application.SendNotification(); application.Render(0); - DALI_TEST_EQUALS( actor.GetRendererAt(0).GetMaterial().GetBlendMode(), BlendingMode::AUTO, TEST_LOCATION ); + int blendMode = actor.GetRendererAt(0u).GetProperty( Renderer::Property::BLENDING_MODE ); + DALI_TEST_EQUALS( static_cast(blendMode), BlendingMode::AUTO, TEST_LOCATION ); Vector4 actualColor(Vector4::ZERO); DALI_TEST_CHECK( gl.GetUniformValue( "borderColor", actualColor ) ); @@ -420,8 +422,8 @@ int UtcDaliRendererFactoryGetBorderRenderer2(void) application.SendNotification(); application.Render(0); - DALI_TEST_EQUALS( actor.GetRendererAt(0).GetMaterial().GetBlendMode(), BlendingMode::ON, TEST_LOCATION ); - + blendMode = actor.GetRendererAt(0u).GetProperty( Renderer::Property::BLENDING_MODE ); + DALI_TEST_EQUALS( static_cast(blendMode), BlendingMode::ON, TEST_LOCATION ); END_TEST; } diff --git a/dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.cpp b/dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.cpp index da3a099..16faba4 100644 --- a/dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.cpp +++ b/dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.cpp @@ -99,11 +99,6 @@ void BubbleEmitter::SetBubbleDensity( unsigned int density ) GetImpl(*this).SetBubbleDensity( density ); } -void BubbleEmitter::SetBlendMode( bool enable ) -{ - GetImpl(*this).SetBlendMode( enable ); -} - void BubbleEmitter::EmitBubble( Animation& animation, const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement ) { GetImpl(*this).EmitBubble( animation, emitPosition, direction, displacement ); diff --git a/dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h b/dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h index 5140144..8408fcc 100644 --- a/dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h +++ b/dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h @@ -140,13 +140,6 @@ public: void SetBubbleDensity( unsigned int density ); /** - * @brief Enable different blending mode for rendering. - * - * @param[in] enable If false, the default blending function if ImageActor is used. - */ - void SetBlendMode( bool enable ); - - /** * @brief Add a bubble movement to the animation. * * @param[in] animation The animation reference. diff --git a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp index 8b248ce..26f6798 100644 --- a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp +++ b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp @@ -226,22 +226,6 @@ void BubbleEmitter::SetBubbleDensity( unsigned int density ) } } -void BubbleEmitter::SetBlendMode( bool enable ) -{ - if(enable) - { - // linear overlay - mMaterial.SetBlendFunc(BlendingFactor::SRC_ALPHA, BlendingFactor::ONE, - BlendingFactor::ZERO, BlendingFactor::ONE); - } - else - { - // using default blend func - mMaterial.SetBlendFunc( BlendingFactor::SRC_ALPHA, BlendingFactor::ONE_MINUS_SRC_ALPHA, - BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA ); - } -} - // clear the resources created for the off screen rendering void BubbleEmitter::OnRenderFinished(RenderTask& source) { diff --git a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.h b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.h index 08185a0..37cbbb9 100644 --- a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.h +++ b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.h @@ -92,11 +92,6 @@ public: void SetBubbleDensity( unsigned int density ); /** - * @copydoc Toolkit::BubbleEmitter::SetBlendMode - */ - void SetBlendMode( bool enable ); - - /** * @copydoc Toolkit::BubbleEmitter::EmitBubble */ void EmitBubble( Animation& animation, const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement ); diff --git a/dali-toolkit/internal/controls/model3d-view/model3d-view-impl.cpp b/dali-toolkit/internal/controls/model3d-view/model3d-view-impl.cpp index 2c27f85..ce4169f 100644 --- a/dali-toolkit/internal/controls/model3d-view/model3d-view-impl.cpp +++ b/dali-toolkit/internal/controls/model3d-view/model3d-view-impl.cpp @@ -606,11 +606,10 @@ void Model3dView::CreateMaterial() mMaterial = Material::New( mShader ); - mMaterial.SetFaceCullingMode(Material::NONE); - if( mRenderer ) { mRenderer.SetMaterial( mMaterial ); + mRenderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, Renderer::NONE); } UpdateShaderUniforms(); diff --git a/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp b/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp index 396d02c..dd02796 100644 --- a/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp @@ -152,7 +152,7 @@ void BorderRenderer::DoSetOnStage( Actor& actor ) mBorderColorIndex = (mImpl->mRenderer).RegisterProperty( COLOR_NAME, mBorderColor ); if( mBorderColor.a < 1.f || mAntiAliasing) { - (mImpl->mRenderer).GetMaterial().SetBlendMode( BlendingMode::ON ); + mImpl->mRenderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON ); } mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( SIZE_NAME, mBorderSize ); } @@ -187,7 +187,7 @@ void BorderRenderer::SetBorderColor(const Vector4& color) (mImpl->mRenderer).SetProperty( mBorderColorIndex, color ); if( color.a < 1.f ) { - (mImpl->mRenderer).GetMaterial().SetBlendMode( BlendingMode::ON ); + mImpl->mRenderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON ); } } } @@ -214,7 +214,7 @@ void BorderRenderer::RequireAntiAliasing( bool antiAliasing ) material.SetShader( shader ); if( mAntiAliasing ) { - material.SetBlendMode( BlendingMode::ON ); + mImpl->mRenderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON ); } } } diff --git a/dali-toolkit/internal/controls/renderers/color/color-renderer.cpp b/dali-toolkit/internal/controls/renderers/color/color-renderer.cpp index c7e4ed5..2f6f374 100644 --- a/dali-toolkit/internal/controls/renderers/color/color-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/color/color-renderer.cpp @@ -137,7 +137,7 @@ void ColorRenderer::InitializeRenderer() mBlendColorIndex = mImpl->mRenderer.RegisterProperty( COLOR_NAME, mBlendColor ); if( mBlendColor.a < 1.f ) { - mImpl->mRenderer.GetMaterial().SetBlendMode( BlendingMode::ON ); + mImpl->mRenderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON ); } } @@ -148,9 +148,9 @@ void ColorRenderer::SetColor(const Vector4& color) if( mImpl->mRenderer ) { (mImpl->mRenderer).SetProperty( mBlendColorIndex, color ); - if( color.a < 1.f && (mImpl->mRenderer).GetMaterial().GetBlendMode() != BlendingMode::ON) + if( color.a < 1.f ) { - (mImpl->mRenderer).GetMaterial().SetBlendMode( BlendingMode::ON ); + mImpl->mRenderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON ); } } } diff --git a/dali-toolkit/internal/controls/renderers/control-renderer-impl.cpp b/dali-toolkit/internal/controls/renderers/control-renderer-impl.cpp index 7ac2490..307818f 100644 --- a/dali-toolkit/internal/controls/renderers/control-renderer-impl.cpp +++ b/dali-toolkit/internal/controls/renderers/control-renderer-impl.cpp @@ -107,7 +107,7 @@ void ControlRenderer::SetDepthIndex( float index ) mImpl->mDepthIndex = index; if( mImpl->mRenderer ) { - mImpl->mRenderer.SetDepthIndex( mImpl->mDepthIndex ); + mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex ); } } @@ -120,7 +120,7 @@ void ControlRenderer::SetOnStage( Actor& actor ) { DoSetOnStage( actor ); - mImpl->mRenderer.SetDepthIndex( mImpl->mDepthIndex ); + mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex ); actor.AddRenderer( mImpl->mRenderer ); mImpl->mFlags |= Impl::IS_ON_STAGE; } diff --git a/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp b/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp index b9fcec9..2ab916d 100644 --- a/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/image/image-renderer.cpp @@ -75,9 +75,6 @@ const std::string TEXTURE_UNIFORM_NAME = "sTexture"; const std::string ATLAS_RECT_UNIFORM_NAME = "uAtlasRect"; const std::string PIXEL_AREA_UNIFORM_NAME = "pixelArea"; -// Set this uniform to 1.0 for conventional alpha blending; if pre-multiplied alpha blending, set this uniform to 0.0 -const std::string ALPHA_BLENDING_UNIFORM_NAME = "uAlphaBlending"; - const Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D"; @@ -105,11 +102,10 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( varying mediump vec2 vTexCoord;\n uniform sampler2D sTexture;\n uniform lowp vec4 uColor;\n - uniform lowp float uAlphaBlending; // Set to 1.0 for conventional alpha blending; if pre-multiplied alpha blending, set to 0.0 \n void main()\n {\n - gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4( uColor.rgb*max( uAlphaBlending, uColor.a ), uColor.a );\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n }\n ); @@ -429,7 +425,6 @@ Renderer ImageRenderer::CreateRenderer() const { shader.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); - shader.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 1.f ); } } } @@ -450,7 +445,6 @@ Renderer ImageRenderer::CreateNativeImageRenderer() const shader = Shader::New( VERTEX_SHADER, mNativeFragmentShaderCode ); shader.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); - shader.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 1.f ); } else { @@ -468,7 +462,6 @@ Renderer ImageRenderer::CreateNativeImageRenderer() const { shader.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); - shader.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 1.f ); } } } @@ -553,7 +546,7 @@ void ImageRenderer::DoSetOnStage( Actor& actor ) InitializeRenderer( mImage ); } - EnablePreMultipliedAlpha( mIsAlphaPreMultiplied ); + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, mIsAlphaPreMultiplied); } void ImageRenderer::DoSetOffStage( Actor& actor ) @@ -678,7 +671,6 @@ Shader ImageRenderer::GetImageShader( RendererFactoryCache& factoryCache ) factoryCache.SaveShader( RendererFactoryCache::IMAGE_SHADER, shader ); shader.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, FULL_TEXTURE_RECT ); shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); - shader.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 1.f ); } return shader; } @@ -809,29 +801,7 @@ void ImageRenderer::EnablePreMultipliedAlpha( bool preMultipled ) mIsAlphaPreMultiplied = preMultipled; if( mImpl->mRenderer ) { - Material material = mImpl->mRenderer.GetMaterial(); - - if( preMultipled ) - { - material.SetBlendFunc( BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA, - BlendingFactor::ONE, BlendingFactor::ONE ); - if( !mImpl->mCustomShader || mImpl->mCustomShader->mVertexShader.empty()) - { - material.RegisterProperty( ALPHA_BLENDING_UNIFORM_NAME, 0.f ); - } - } - else - { - // using default blend func - material.SetBlendFunc( BlendingFactor::SRC_ALPHA, BlendingFactor::ONE_MINUS_SRC_ALPHA, - BlendingFactor::ONE, BlendingFactor::ONE_MINUS_SRC_ALPHA ); - - Property::Index index = material.GetPropertyIndex( ALPHA_BLENDING_UNIFORM_NAME ); - if( index != Property::INVALID_INDEX ) // only set value when the property already exist on the Material - { - material.SetProperty( index, 1.f ); - } - } + mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, mIsAlphaPreMultiplied); } } diff --git a/dali-toolkit/internal/text/decorator/text-decorator.cpp b/dali-toolkit/internal/text/decorator/text-decorator.cpp index bc27da3..e06ea8b 100644 --- a/dali-toolkit/internal/text/decorator/text-decorator.cpp +++ b/dali-toolkit/internal/text/decorator/text-decorator.cpp @@ -1091,7 +1091,7 @@ struct Decorator::Impl : public ConnectionTracker if( mHighlightRenderer ) { - mHighlightRenderer.SetDepthIndex( mTextDepth - 2u ); // text is rendered at mTextDepth and text's shadow at mTextDepth -1u. + mHighlightRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mTextDepth - 2 ); // text is rendered at mTextDepth and text's shadow at mTextDepth -1u. } } } diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp index c8ea1e2..49dd310 100644 --- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp @@ -101,7 +101,6 @@ void AtlasGlyphManager::Add( const Text::GlyphInfo& glyph, Pixel::Format pixelFormat = mAtlasManager.GetPixelFormat( slot.mAtlasId ); Material material = Material::New( pixelFormat == Pixel::L8 ? mShaderL8 : mShaderRgba ); material.AddTexture( atlas, "sTexture" ); - material.SetBlendMode( BlendingMode::ON ); mAtlasManager.SetMaterial( slot.mAtlasId, material ); } diff --git a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp index 35bb46f..7b82d21 100644 --- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp +++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp @@ -425,7 +425,8 @@ struct AtlasRenderer::Impl if( actor.GetRendererCount() ) { Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) ); - renderer.SetDepthIndex( renderer.GetDepthIndex() - 1 ); + int depthIndex = renderer.GetProperty(Dali::Renderer::Property::DEPTH_INDEX); + renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, depthIndex - 1 ); shadowActor.SetParentOrigin( ParentOrigin::CENTER ); shadowActor.SetSize( actorSize ); containerActor.Add( shadowActor ); @@ -490,7 +491,8 @@ struct AtlasRenderer::Impl Material material = mGlyphManager.GetMaterial( meshRecord.mAtlasId ); Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material ); - renderer.SetDepthIndex( DepthIndex::CONTENT + mDepth ); + renderer.SetProperty( Dali::Renderer::Property::BLENDING_MODE, BlendingMode::ON ); + renderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, DepthIndex::CONTENT + mDepth ); Actor actor = Actor::New(); #if defined(DEBUG_ENABLED) actor.SetName( "Text renderable actor" ); diff --git a/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp b/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp index 757858f..bcd4b07 100644 --- a/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp +++ b/dali-toolkit/internal/transition-effects/cube-transition-effect-impl.cpp @@ -281,7 +281,7 @@ void CubeTransitionEffect::OnStageConnection( int depth ) } mCurrentRenderer = Renderer::New( geometry, material ); - mCurrentRenderer.SetDepthIndex( depth ); + mCurrentRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, depth ); Self().AddRenderer( mCurrentRenderer ); } @@ -394,7 +394,8 @@ void CubeTransitionEffect::StartTransition( Vector2 panPosition, Vector2 panDisp Geometry geometry = mCurrentRenderer.GetGeometry(); mTargetRenderer = Renderer::New( geometry, material ); - mTargetRenderer.SetDepthIndex( mCurrentRenderer.GetDepthIndex() ); + int depthIndex = mCurrentRenderer.GetProperty(Renderer::Property::DEPTH_INDEX); + mTargetRenderer.SetProperty( Dali::Renderer::Property::DEPTH_INDEX, depthIndex ); for( size_t i = 0; i < mBoxes.size(); ++i ) { diff --git a/plugins/dali-script-v8/src/constants/constants-wrapper.cpp b/plugins/dali-script-v8/src/constants/constants-wrapper.cpp index a3a3dd7..1311506 100644 --- a/plugins/dali-script-v8/src/constants/constants-wrapper.cpp +++ b/plugins/dali-script-v8/src/constants/constants-wrapper.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -217,10 +217,10 @@ const IntegerPair EnumTable[] = { "WRAP_MODE_REPEAT", WrapMode::REPEAT }, { "WRAP_MODE_MIRRORED_REPEAT", WrapMode::MIRRORED_REPEAT }, - { "MATERIAL_NONE", Material::NONE }, - { "MATERIAL_CULL_BACK", Material::CULL_BACK }, - { "MATERIAL_CULL_FRONT", Material::CULL_FRONT }, - { "MATERIAL_CULL_BACK_AND_FRONT", Material::CULL_BACK_AND_FRONT }, + { "MATERIAL_NONE", Renderer::NONE }, + { "MATERIAL_CULL_BACK", Renderer::CULL_BACK }, + { "MATERIAL_CULL_FRONT", Renderer::CULL_FRONT }, + { "MATERIAL_CULL_BACK_AND_FRONT", Renderer::CULL_BACK_AND_FRONT }, { "GEOMETRY_POINTS", Geometry::POINTS }, { "GEOMETRY_LINES", Geometry::LINES }, diff --git a/plugins/dali-script-v8/src/rendering/material-api.cpp b/plugins/dali-script-v8/src/rendering/material-api.cpp index cb173fa..b21c376 100644 --- a/plugins/dali-script-v8/src/rendering/material-api.cpp +++ b/plugins/dali-script-v8/src/rendering/material-api.cpp @@ -368,253 +368,6 @@ void MaterialApi::GetNumberOfTextures( const v8::FunctionCallbackInfo< v8::Value args.GetReturnValue().Set( v8::Integer::New( isolate, material.GetNumberOfTextures() ) ); } -/** - * Set the culling mode for this material - * - * @method setFaceCullingMode - * @for Material - * @param {integer} cullingMode The culling mode for this material - * @example - * // face culling mode is one of the following - * dali.MATERIAL_NONE // None of the faces should be culled - * dali.MATERIAL_CULL_BACK // Cull back face, back face should never be shown - * dali.MATERIAL_CULL_FRONT // Cull front face, back face should never be shown - * dali.MATERIAL_CULL_BACK_AND_FRONT // Cull back and front faces, if the geometry is composed of triangles none of the faces will be shown - * - * material.setFaceCullingMode( dali.MATERIAL_NONE ); - */ -void MaterialApi::SetFaceCullingMode( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - - Material material = GetMaterial( isolate, args ); - - bool found( false ); - int mode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0); - if( !found ) - { - DALI_SCRIPT_EXCEPTION( isolate, "invalid cullingMode parameter" ); - } - else - { - material.SetFaceCullingMode( static_cast(mode) ); - } -} - -/** - * Set the blending mode. - * - * If blending is disabled (BLENDING_OFF) fade in and fade out animations do not work. - * - * @for Material - * @method setBlendMode - * @param { integer } mode The blending mode. - * @example - * // blend mode is one of the following - * dali.BLENDING_OFF // Blending is disabled. - * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel. - * dali.BLENDING_ON // Blending is enabled. - * - * material.setBlendMode( dali.BLENDING_AUTO ); - */ -void MaterialApi::SetBlendMode( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - - Material material = GetMaterial( isolate, args ); - - bool found( false ); - int mode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); - if( !found ) - { - DALI_SCRIPT_EXCEPTION( isolate, "invalid blendMode parameter" ); - } - else - { - material.SetBlendMode( static_cast( mode ) ); - } -} - -/** - * Retrieves the blending mode. - * - * @for Material - * @method getBlendMode - * @return { integer } blendMode - * @example returns one of the following: - * - * dali.BLENDING_OFF // Blending is disabled. - * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel. - * dali.BLENDING_ON // Blending is enabled. - */ -void MaterialApi::GetBlendMode( const v8::FunctionCallbackInfo& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - - Material material = GetMaterial( isolate, args ); - - args.GetReturnValue().Set( v8::Integer::New( isolate, material.GetBlendMode() ) ); -} - -/** - * Specify the pixel arithmetic used when the actor is blended. - * - * @for Material - * @method setBlendFunc - * @param {integer} srcFactorRgb Source Blending RGB - * @param {integer} destFactorRgb Destination Blending RGB - * @param {integer} srcFactorAlpha Source Blending Alpha - * @param {integer} destFactorAlpha Destinatino Blending Alpha - * @example - * //blending constants - * dali.BLEND_FACTOR_ZERO - * dali.BLEND_FACTOR_ONE - * dali.BLEND_FACTOR_SRC_COLOR - * dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR - * dali.BLEND_FACTOR_SRC_ALPHA - * dali.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA - * dali.BLEND_FACTOR_DST_ALPHA - * dali.BLEND_FACTOR_ONE_MINUS_DST_ALPHA - * dali.BLEND_FACTOR_DST_COLOR - * dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR - * dali.BLEND_FACTOR_SRC_ALPHA_SATURATE - * dali.BLEND_FACTOR_CONSTANT_COLOR - * dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR - * dali.BLEND_FACTOR_CONSTANT_ALPHA - * dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA - * - * material.setBlendFunc( dali.BLEND_FACTOR_CONSTANT_COLOR, dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR, - * dali.BLEND_FACTOR_CONSTANT_ALPHA, dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA ); - */ -void MaterialApi::SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - - Material material = GetMaterial( isolate, args ); - - int params[4]; - bool foundAllParams(false); - V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 4, args, 0 ); - if( foundAllParams ) - { - material.SetBlendFunc( static_cast< Dali::BlendingFactor::Type>(params[0]), - static_cast< Dali::BlendingFactor::Type>(params[1]), - static_cast< Dali::BlendingFactor::Type>(params[2]), - static_cast< Dali::BlendingFactor::Type>(params[3]) ); - } - else - { - DALI_SCRIPT_EXCEPTION( isolate, "invalid blendFunc parameter"); - } -} - -/** - * Query the pixel arithmetic used when the actor is blended. - * - * @for Material - * @method getBlendFunc - * @return {Object} Blend properties - * @example Blend properties object has 4 fields - * - * blendProperties.sourceRgb // source rgb enum - * blendProperties.destinationRgb // destination rgb enum - * blendProperties.sourceAlpha source // alpha enum - * blendProperties.destinationAlpha // destination alpha enum - */ -void MaterialApi::GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - // Pass by reference doesn't work in Javascript - // For now just return a vector 4... - - BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha; - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - - Material material = GetMaterial( isolate, args ); - - material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); - - v8::Local blendProperties = v8::Object::New( isolate ); - - blendProperties->Set( v8::String::NewFromUtf8( isolate, "sourceRgb" ), v8::Integer::New( isolate, srcFactorRgb) ); - blendProperties->Set( v8::String::NewFromUtf8( isolate, "destinationRgb" ), v8::Integer::New( isolate, destFactorRgb ) ); - blendProperties->Set( v8::String::NewFromUtf8( isolate, "sourceAlpha" ), v8::Integer::New( isolate, srcFactorAlpha ) ); - blendProperties->Set( v8::String::NewFromUtf8( isolate, "destinationAlpha" ), v8::Integer::New( isolate, destFactorAlpha ) ); - - args.GetReturnValue().Set( blendProperties ); -} - -/** - * Specify the equation used when the actor is blended. - * - * @for Material - * @method setBlendEquation - * @param { integer } equationRgb The equation used for combining red, green, and blue components. - * @param { integer } equationAlpha The equation used for combining the alpha component. - * @example - * // blend equation is one of the following - * dali.BLEND_EQUATION_ADD - * dali.BLEND_EQUATION_SUBTRACT - * dali.BLEND_EQUATION_REVERSE_SUBTRACT - * - * material.setBlendEquation( dali.BLEND_EQUATION_ADD, dali.BLEND_EQUATION_REVERSE_SUBTRACT ); - */ -void MaterialApi::SetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - - Material material = GetMaterial( isolate, args ); - - int params[2]; - bool foundAllParams(false); - V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 2, args, 0 ); - if( foundAllParams ) - { - material.SetBlendEquation( static_cast< BlendingEquation::Type>(params[0]), static_cast< BlendingEquation::Type>(params[1]) ); - } - else - { - DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendEquation parameter"); - } -} - -/** - * Query the equation used when the actor is blended. - * - * @for Material - * @method getBlendEquation - * @return {Object} Blend equations - * @example Blend equations object has 2 fields - * - * blendEquations.equationRgb // equation used for combining rgb components - * blendEquations.equationAlpha // equation used for combining alpha components - */ -void MaterialApi::GetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args ) -{ - // Pass by reference doesn't work in Javascript - // For now just return a vector 2... - - BlendingEquation::Type equationRgb, equationAlpha; - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope handleScope( isolate ); - - Material material = GetMaterial( isolate, args ); - - material.GetBlendEquation( equationRgb, equationAlpha ); - - v8::Local blendEquations = v8::Object::New( isolate ); - - blendEquations->Set( v8::String::NewFromUtf8( isolate, "equationRgb" ), v8::Integer::New( isolate, equationRgb) ); - blendEquations->Set( v8::String::NewFromUtf8( isolate, "equationAlpha" ), v8::Integer::New( isolate, equationAlpha ) ); - - args.GetReturnValue().Set( blendEquations ); -} - } // namespace V8Plugin } // namespace Dali diff --git a/plugins/dali-script-v8/src/rendering/material-api.h b/plugins/dali-script-v8/src/rendering/material-api.h index 314ba2a..6cf64a0 100644 --- a/plugins/dali-script-v8/src/rendering/material-api.h +++ b/plugins/dali-script-v8/src/rendering/material-api.h @@ -66,13 +66,6 @@ namespace MaterialApi void SetTextureUniformName( const v8::FunctionCallbackInfo< v8::Value >& args ); void GetTextureIndex( const v8::FunctionCallbackInfo< v8::Value >& args ); void GetNumberOfTextures( const v8::FunctionCallbackInfo< v8::Value >& args ); - void SetFaceCullingMode( const v8::FunctionCallbackInfo< v8::Value >& args ); - void SetBlendMode( const v8::FunctionCallbackInfo< v8::Value >& args ); - void GetBlendMode( const v8::FunctionCallbackInfo< v8::Value >& args ); - void SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ); - void GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ); - void SetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args ); - void GetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args ); }; // namespace MaterialApi diff --git a/plugins/dali-script-v8/src/rendering/material-wrapper.cpp b/plugins/dali-script-v8/src/rendering/material-wrapper.cpp index 2ebdb81..fb69a7e 100644 --- a/plugins/dali-script-v8/src/rendering/material-wrapper.cpp +++ b/plugins/dali-script-v8/src/rendering/material-wrapper.cpp @@ -54,13 +54,6 @@ const ApiFunction MaterialFunctionTable[]= { "SetTextureUniformName" , MaterialApi::SetTextureUniformName }, { "GetTextureIndex" , MaterialApi::GetTextureIndex }, { "GetNumberOfTextures" , MaterialApi::GetNumberOfTextures }, - { "SetFaceCullingMode" , MaterialApi::SetFaceCullingMode }, - { "SetBlendMode" , MaterialApi::SetBlendMode }, - { "GetBlendMode" , MaterialApi::GetBlendMode }, - { "SetBlendFunc" , MaterialApi::SetBlendFunc }, - { "GetBlendFunc" , MaterialApi::GetBlendFunc }, - { "SetBlendEquation" , MaterialApi::SetBlendEquation }, - { "GetBlendEquation" , MaterialApi::GetBlendEquation }, }; const unsigned int MaterialFunctionTableCount = sizeof(MaterialFunctionTable)/sizeof(MaterialFunctionTable[0]); diff --git a/plugins/dali-script-v8/src/rendering/renderer-api.cpp b/plugins/dali-script-v8/src/rendering/renderer-api.cpp index fb2c0a8..2ec736d 100644 --- a/plugins/dali-script-v8/src/rendering/renderer-api.cpp +++ b/plugins/dali-script-v8/src/rendering/renderer-api.cpp @@ -204,6 +204,162 @@ void RendererApi::GetMaterial( const v8::FunctionCallbackInfo& args ) args.GetReturnValue().Set( localObject ); } +/** + * Specify the pixel arithmetic used when the actor is blended. + * + * @for Renderer + * @method setBlendFunc + * @param {integer} srcFactorRgb Source Blending RGB + * @param {integer} destFactorRgb Destination Blending RGB + * @param {integer} srcFactorAlpha Source Blending Alpha + * @param {integer} destFactorAlpha Destination Blending Alpha + * @example + * //blending constants + * dali.BLEND_FACTOR_ZERO + * dali.BLEND_FACTOR_ONE + * dali.BLEND_FACTOR_SRC_COLOR + * dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR + * dali.BLEND_FACTOR_SRC_ALPHA + * dali.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA + * dali.BLEND_FACTOR_DST_ALPHA + * dali.BLEND_FACTOR_ONE_MINUS_DST_ALPHA + * dali.BLEND_FACTOR_DST_COLOR + * dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR + * dali.BLEND_FACTOR_SRC_ALPHA_SATURATE + * dali.BLEND_FACTOR_CONSTANT_COLOR + * dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR + * dali.BLEND_FACTOR_CONSTANT_ALPHA + * dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA + * + * renderer.setBlendFunc( dali.BLEND_FACTOR_CONSTANT_COLOR, dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR, + * dali.BLEND_FACTOR_CONSTANT_ALPHA, dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA ); + */ +void RendererApi::SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Renderer renderer = GetRenderer( isolate, args ); + + int params[4]; + bool foundAllParams(false); + V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 4, args, 0 ); + if( foundAllParams ) + { + renderer.SetBlendFunc( static_cast< Dali::BlendingFactor::Type>(params[0]), + static_cast< Dali::BlendingFactor::Type>(params[1]), + static_cast< Dali::BlendingFactor::Type>(params[2]), + static_cast< Dali::BlendingFactor::Type>(params[3]) ); + } + else + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid blendFunc parameter"); + } +} + +/** + * Query the pixel arithmetic used when the actor is blended. + * + * @for Renderer + * @method getBlendFunc + * @return {Object} Blend properties + * @example Blend properties object has 4 fields + * + * blendProperties.sourceRgb // source rgb enum + * blendProperties.destinationRgb // destination rgb enum + * blendProperties.sourceAlpha source // alpha enum + * blendProperties.destinationAlpha // destination alpha enum + */ +void RendererApi::GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ) +{ + // Pass by reference doesn't work in Javascript + // For now just return a vector 4... + + BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha; + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Renderer renderer = GetRenderer( isolate, args ); + + renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); + + v8::Local blendProperties = v8::Object::New( isolate ); + + blendProperties->Set( v8::String::NewFromUtf8( isolate, "sourceRgb" ), v8::Integer::New( isolate, srcFactorRgb) ); + blendProperties->Set( v8::String::NewFromUtf8( isolate, "destinationRgb" ), v8::Integer::New( isolate, destFactorRgb ) ); + blendProperties->Set( v8::String::NewFromUtf8( isolate, "sourceAlpha" ), v8::Integer::New( isolate, srcFactorAlpha ) ); + blendProperties->Set( v8::String::NewFromUtf8( isolate, "destinationAlpha" ), v8::Integer::New( isolate, destFactorAlpha ) ); + + args.GetReturnValue().Set( blendProperties ); +} + +/** + * Specify the equation used when the actor is blended. + * + * @for Renderer + * @method setBlendEquation + * @param { integer } equationRgb The equation used for combining red, green, and blue components. + * @param { integer } equationAlpha The equation used for combining the alpha component. + * @example + * // blend equation is one of the following + * dali.BLEND_EQUATION_ADD + * dali.BLEND_EQUATION_SUBTRACT + * dali.BLEND_EQUATION_REVERSE_SUBTRACT + * + * renderer.setBlendEquation( dali.BLEND_EQUATION_ADD, dali.BLEND_EQUATION_REVERSE_SUBTRACT ); + */ +void RendererApi::SetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Renderer renderer = GetRenderer( isolate, args ); + + int params[2]; + bool foundAllParams(false); + V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 2, args, 0 ); + if( foundAllParams ) + { + renderer.SetBlendEquation( static_cast< BlendingEquation::Type>(params[0]), static_cast< BlendingEquation::Type>(params[1]) ); + } + else + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendEquation parameter"); + } +} + +/** + * Query the equation used when the actor is blended. + * + * @for Renderer + * @method getBlendEquation + * @return {Object} Blend equations + * @example Blend equations object has 2 fields + * + * blendEquations.equationRgb // equation used for combining rgb components + * blendEquations.equationAlpha // equation used for combining alpha components + */ +void RendererApi::GetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args ) +{ + // Pass by reference doesn't work in Javascript + // For now just return a vector 2... + + BlendingEquation::Type equationRgb, equationAlpha; + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Renderer renderer = GetRenderer( isolate, args ); + + renderer.GetBlendEquation( equationRgb, equationAlpha ); + + v8::Local blendEquations = v8::Object::New( isolate ); + + blendEquations->Set( v8::String::NewFromUtf8( isolate, "equationRgb" ), v8::Integer::New( isolate, equationRgb) ); + blendEquations->Set( v8::String::NewFromUtf8( isolate, "equationAlpha" ), v8::Integer::New( isolate, equationAlpha ) ); + + args.GetReturnValue().Set( blendEquations ); +} + } // namespace V8Plugin } // namespace Dali diff --git a/plugins/dali-script-v8/src/rendering/renderer-api.h b/plugins/dali-script-v8/src/rendering/renderer-api.h index e415e74..50e1874 100644 --- a/plugins/dali-script-v8/src/rendering/renderer-api.h +++ b/plugins/dali-script-v8/src/rendering/renderer-api.h @@ -61,6 +61,10 @@ namespace RendererApi void GetGeometry( const v8::FunctionCallbackInfo< v8::Value >& args ); void SetMaterial( const v8::FunctionCallbackInfo< v8::Value >& args ); void GetMaterial( const v8::FunctionCallbackInfo< v8::Value >& args ); + void SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ); + void GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ); + void SetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args ); + void GetBlendEquation( const v8::FunctionCallbackInfo< v8::Value >& args ); }; // namespace RendererApi diff --git a/plugins/dali-script-v8/src/rendering/renderer-wrapper.cpp b/plugins/dali-script-v8/src/rendering/renderer-wrapper.cpp index ecd6649..3286b10 100644 --- a/plugins/dali-script-v8/src/rendering/renderer-wrapper.cpp +++ b/plugins/dali-script-v8/src/rendering/renderer-wrapper.cpp @@ -49,6 +49,10 @@ const ApiFunction RendererFunctionTable[]= { "GetGeometry" , RendererApi::GetGeometry }, { "SetMaterial" , RendererApi::SetMaterial }, { "GetMaterial" , RendererApi::GetMaterial }, + { "SetBlendFunc" , RendererApi::SetBlendFunc }, + { "GetBlendFunc" , RendererApi::GetBlendFunc }, + { "SetBlendEquation" , RendererApi::SetBlendEquation }, + { "GetBlendEquation" , RendererApi::GetBlendEquation }, }; const unsigned int RendererFunctionTableCount = sizeof(RendererFunctionTable)/sizeof(RendererFunctionTable[0]); -- 2.7.4