X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Frenderers%2Fborder%2Fborder-renderer.cpp;h=9ae46a162d829ac522e7e4a4cb4050aeefc625a7;hp=8e0d0948d7630ddddd9f18f73036765d04541831;hb=a2de9cf491172cd5da9dc9ed60b17683dab6d7bc;hpb=8991dd870badfb20693aa0eb1acf0aedbe88f99f diff --git a/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp b/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp index 8e0d094..9ae46a1 100644 --- a/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/border/border-renderer.cpp @@ -37,13 +37,12 @@ namespace Internal namespace { -const char * const RENDERER_TYPE("renderer-type"); -const char * const RENDERER_TYPE_VALUE("border-renderer"); +const char * const RENDERER_TYPE("rendererType"); +const char * const RENDERER_TYPE_VALUE("border"); -const char * const COLOR_NAME("border-color"); -const char * const COLOR_UNIFORM_NAME("uBorderColor"); -const char * const SIZE_NAME("border-size"); -const char * const SIZE_UNIFORM_NAME("uBorderSize"); +const char * const COLOR_NAME("borderColor"); +const char * const SIZE_NAME("borderSize"); +const char * const ANTI_ALIASING("antiAliasing"); const char * const POSITION_ATTRIBUTE_NAME("aPosition"); const char * const DRIFT_ATTRIBUTE_NAME("aDrift"); @@ -55,22 +54,51 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aDrift;\n uniform mediump mat4 uMvpMatrix;\n uniform mediump vec3 uSize;\n - uniform mediump float uBorderSize;\n + uniform mediump float borderSize;\n \n void main()\n {\n - vec2 position = aPosition*uSize.xy + aDrift*uBorderSize;\n + vec2 position = aPosition*uSize.xy + aDrift*borderSize;\n gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n }\n ); const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( uniform lowp vec4 uColor;\n - uniform lowp vec4 uBorderColor;\n + uniform lowp vec4 borderColor;\n \n void main()\n {\n - gl_FragColor = uBorderColor*uColor;\n + gl_FragColor = borderColor*uColor;\n + }\n +); + +const char* VERTEX_SHADER_ANTI_ALIASING = DALI_COMPOSE_SHADER( + attribute mediump vec2 aPosition;\n + attribute mediump vec2 aDrift;\n + uniform mediump mat4 uMvpMatrix;\n + uniform mediump vec3 uSize;\n + uniform mediump float borderSize;\n + varying mediump float vAlpha;\n + \n + void main()\n + {\n + vec2 position = aPosition*(uSize.xy+vec2(0.75)) + aDrift*(borderSize+1.5);\n + gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n + vAlpha = min( abs(aDrift.x), abs(aDrift.y) )*(borderSize+1.5); + }\n +); + +const char* FRAGMENT_SHADER_ANTI_ALIASING = DALI_COMPOSE_SHADER( + uniform lowp vec4 uColor;\n + uniform lowp vec4 borderColor;\n + uniform mediump float borderSize;\n + varying mediump float vAlpha;\n + \n + void main()\n + {\n + gl_FragColor = borderColor*uColor;\n + gl_FragColor.a *= smoothstep(0.0, 1.5, vAlpha)*smoothstep( borderSize+1.5, borderSize, vAlpha );\n }\n ); } @@ -80,7 +108,8 @@ BorderRenderer::BorderRenderer( RendererFactoryCache& factoryCache ) mBorderColor( Color::TRANSPARENT ), mBorderSize( 0.f ), mBorderColorIndex( Property::INVALID_INDEX ), - mBorderSizeIndex( Property::INVALID_INDEX ) + mBorderSizeIndex( Property::INVALID_INDEX ), + mAntiAliasing( false ) { } @@ -101,6 +130,12 @@ void BorderRenderer::DoInitialize( Actor& actor, const Property::Map& propertyMa { DALI_LOG_ERROR( "Fail to provide a border size to the BorderRenderer object" ); } + + Property::Value* antiAliasing = propertyMap.Find( ANTI_ALIASING ); + if( antiAliasing ) + { + antiAliasing->Get( mAntiAliasing ); + } } void BorderRenderer::SetClipRect( const Rect& clipRect ) @@ -114,12 +149,12 @@ void BorderRenderer::DoSetOnStage( Actor& actor ) { InitializeRenderer(); - mBorderColorIndex = (mImpl->mRenderer).RegisterProperty( COLOR_UNIFORM_NAME, mBorderColor ); - if( mBorderColor.a < 1.f ) + 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_UNIFORM_NAME, mBorderSize ); + mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( SIZE_NAME, mBorderSize ); } void BorderRenderer::DoCreatePropertyMap( Property::Map& map ) const @@ -136,18 +171,13 @@ void BorderRenderer::InitializeRenderer() if( !geometry ) { geometry = CreateBorderGeometry(); - mFactoryCache.SaveGeometry( RendererFactoryCache::QUAD_GEOMETRY, geometry ); + mFactoryCache.SaveGeometry( RendererFactoryCache::BORDER_GEOMETRY, geometry ); } - Shader shader = mFactoryCache.GetShader( RendererFactoryCache::BORDER_SHADER ); - if( !shader ) - { - shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); - mFactoryCache.SaveShader( RendererFactoryCache::COLOR_SHADER, shader ); - } - Material material = Material::New( shader ); - mImpl->mRenderer = Renderer::New( geometry, material ); + Shader shader = GetBorderShader(); + mImpl->mRenderer = Renderer::New( geometry, shader ); + } void BorderRenderer::SetBorderColor(const Vector4& color) @@ -157,9 +187,9 @@ void BorderRenderer::SetBorderColor(const Vector4& color) if( mImpl->mRenderer ) { (mImpl->mRenderer).SetProperty( mBorderColorIndex, 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 ); } } } @@ -174,14 +204,56 @@ void BorderRenderer::SetBorderSize( float size ) } } +void BorderRenderer::RequireAntiAliasing( bool antiAliasing ) +{ + if( mAntiAliasing != antiAliasing ) + { + mAntiAliasing = antiAliasing; + if( mImpl->mRenderer ) + { + Shader borderShader( GetBorderShader() ); + mImpl->mRenderer.SetShader( borderShader ); + if( mAntiAliasing ) + { + mImpl->mRenderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON ); + } + } + } +} + +Shader BorderRenderer::GetBorderShader() +{ + Shader shader; + if( mAntiAliasing ) + { + shader = mFactoryCache.GetShader( RendererFactoryCache::BORDER_SHADER_ANTI_ALIASING ); + if( !shader ) + { + shader = Shader::New( VERTEX_SHADER_ANTI_ALIASING, FRAGMENT_SHADER_ANTI_ALIASING ); + mFactoryCache.SaveShader( RendererFactoryCache::BORDER_SHADER_ANTI_ALIASING, shader ); + } + } + else + { + shader = mFactoryCache.GetShader( RendererFactoryCache::BORDER_SHADER ); + if( !shader ) + { + shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); + mFactoryCache.SaveShader( RendererFactoryCache::BORDER_SHADER, shader ); + } + } + + return shader; +} + /** * Vertices and triangles of the border geometry: * * vertex position = aPosition*uSize.xy + aDrift*uBorderSize; * * 0--1--2--3 - * | /| /| /| - * |/ |/ |/ | + * |\ | /| /| + * | \|/ |/ | * 4--5--6--7 * |\ | |\ | * | \| | \| @@ -221,15 +293,15 @@ Geometry BorderRenderer::CreateBorderGeometry() Property::Map borderVertexFormat; borderVertexFormat[POSITION_ATTRIBUTE_NAME] = Property::VECTOR2; borderVertexFormat[DRIFT_ATTRIBUTE_NAME] = Property::VECTOR2; - PropertyBuffer borderVertices = PropertyBuffer::New( borderVertexFormat, 16 ); - borderVertices.SetData(borderVertexData); + PropertyBuffer borderVertices = PropertyBuffer::New( borderVertexFormat ); + borderVertices.SetData( borderVertexData, 16 ); // Create indices - unsigned int indexData[24] = { 0,4,1,5,2,6,3,7,7,6,11,10,15,14,14,10,13,9,12,8,8,9,4,5 }; + unsigned int indexData[24] = { 1,5,2,6,3,7,7,6,11,10,15,14,14,10,13,9,12,8,8,9,4,5,0,1}; Property::Map indexFormat; indexFormat[INDEX_NAME] = Property::INTEGER; - PropertyBuffer indices = PropertyBuffer::New( indexFormat, 24 ); - indices.SetData(indexData); + PropertyBuffer indices = PropertyBuffer::New( indexFormat ); + indices.SetData( indexData, 24 ); // Create the geometry object Geometry geometry = Geometry::New();