controlRenderer.SetOnStage( actor );
DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+ DALI_TEST_EQUALS( actor.GetRendererAt(0).GetMaterial().GetBlendMode(), BlendingMode::ON, TEST_LOCATION );
TestGlAbstraction& gl = application.GetGlAbstraction();
RendererFactory factory = RendererFactory::Get();
DALI_TEST_CHECK( factory );
- Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
+ Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
float testSize = 5.f;
- ControlRenderer controlRenderer = factory.GetControlRenderer(testSize, testColor);
+ ControlRenderer controlRenderer = factory.GetControlRenderer(testSize, testColor );
DALI_TEST_CHECK( controlRenderer );
Actor actor = Actor::New();
application.SendNotification();
application.Render(0);
+ DALI_TEST_EQUALS( actor.GetRendererAt(0).GetMaterial().GetBlendMode(), BlendingMode::AUTO, TEST_LOCATION );
+
Vector4 actualColor(Vector4::ZERO);
DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
+ controlRenderer.SetOffStage( actor );
+
+ // enable the anti-aliasing
+ controlRenderer = factory.GetControlRenderer(testSize, testColor, true );
+ controlRenderer.SetOnStage( actor );
+
+ application.SendNotification();
+ application.Render(0);
+ DALI_TEST_EQUALS( actor.GetRendererAt(0).GetMaterial().GetBlendMode(), BlendingMode::ON, TEST_LOCATION );
+
+
END_TEST;
}
-
int UtcDaliRendererFactoryGetLinearGradientRenderer(void)
{
ToolkitTestApplication application;
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");
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
+);
}
BorderRenderer::BorderRenderer( RendererFactoryCache& factoryCache )
mBorderColor( Color::TRANSPARENT ),
mBorderSize( 0.f ),
mBorderColorIndex( Property::INVALID_INDEX ),
- mBorderSizeIndex( Property::INVALID_INDEX )
+ mBorderSizeIndex( Property::INVALID_INDEX ),
+ mAntiAliasing( false )
{
}
{
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<int>& clipRect )
InitializeRenderer();
mBorderColorIndex = (mImpl->mRenderer).RegisterProperty( COLOR_NAME, mBorderColor );
- if( mBorderColor.a < 1.f )
+ if( mBorderColor.a < 1.f || mAntiAliasing)
{
(mImpl->mRenderer).GetMaterial().SetBlendMode( BlendingMode::ON );
}
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::BORDER_SHADER, shader );
- }
-
- Material material = Material::New( shader );
+ Material material = Material::New( GetBorderShader() );
mImpl->mRenderer = Renderer::New( geometry, material );
}
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 );
}
}
}
+void BorderRenderer::RequireAntiAliasing( bool antiAliasing )
+{
+ if( mAntiAliasing != antiAliasing )
+ {
+ mAntiAliasing = antiAliasing;
+ if( mImpl->mRenderer )
+ {
+ Material material = mImpl->mRenderer.GetMaterial();
+ Shader shader = GetBorderShader();
+ material.SetShader( shader );
+ if( mAntiAliasing )
+ {
+ material.SetBlendMode( 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
* |\ | |\ |
* | \| | \|
borderVertices.SetData(borderVertexData);
// 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 );