const char HTTPS_URL[] = "https://";
const char * const RENDERER_TYPE("rendererType");
-const char * const RENDERER_TYPE_VALUE("imageRenderer");
+const char * const RENDERER_TYPE_VALUE("image");
// property names
const char * const IMAGE_URL_NAME( "imageUrl" );
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";
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
);
-
-Geometry GenerateGeometry( const Vector< Vector2 >& vertices, const Vector< unsigned int >& indices )
-{
- Property::Map vertexFormat;
- vertexFormat[ "aPosition" ] = Property::VECTOR2;
- PropertyBuffer vertexPropertyBuffer = PropertyBuffer::New( vertexFormat, vertices.Size() );
- if( vertices.Size() > 0 )
- {
- vertexPropertyBuffer.SetData( &vertices[ 0 ] );
- }
-
- Property::Map indexFormat;
- indexFormat[ "indices" ] = Property::INTEGER;
- PropertyBuffer indexPropertyBuffer = PropertyBuffer::New( indexFormat, indices.Size() );
- if( indices.Size() > 0 )
- {
- indexPropertyBuffer.SetData( &indices[ 0 ] );
- }
-
- // Create the geometry object
- Geometry geometry = Geometry::New();
- geometry.AddVertexBuffer( vertexPropertyBuffer );
- geometry.SetIndexBuffer( indexPropertyBuffer );
- geometry.SetGeometryType( Geometry::TRIANGLE_STRIP );
-
- return geometry;
-}
-
Geometry CreateGeometry( RendererFactoryCache& factoryCache, ImageDimensions gridSize )
{
Geometry geometry;
geometry = factoryCache.GetGeometry( RendererFactoryCache::QUAD_GEOMETRY );
if( !geometry )
{
- geometry = factoryCache.CreateQuadGeometry();
+ geometry = RendererFactoryCache::CreateQuadGeometry();
factoryCache.SaveGeometry( RendererFactoryCache::QUAD_GEOMETRY, geometry );
}
}
else
{
- uint16_t gridWidth = gridSize.GetWidth();
- uint16_t gridHeight = gridSize.GetHeight();
-
- // Create vertices
- Vector< Vector2 > vertices;
- vertices.Reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) );
-
- for( int y = 0; y < gridHeight + 1; ++y )
- {
- for( int x = 0; x < gridWidth + 1; ++x )
- {
- vertices.PushBack( Vector2( (float)x/gridWidth - 0.5f, (float)y/gridHeight - 0.5f) );
- }
- }
-
- // Create indices
- Vector< unsigned int > indices;
- indices.Reserve( (gridWidth+2)*gridHeight*2 - 2);
-
- for( unsigned int row = 0u; row < gridHeight; ++row )
- {
- unsigned int rowStartIndex = row*(gridWidth+1u);
- unsigned int nextRowStartIndex = rowStartIndex + gridWidth +1u;
-
- if( row != 0u ) // degenerate index on non-first row
- {
- indices.PushBack( rowStartIndex );
- }
-
- for( unsigned int column = 0u; column < gridWidth+1u; column++) // main strip
- {
- indices.PushBack( rowStartIndex + column);
- indices.PushBack( nextRowStartIndex + column);
- }
-
- if( row != gridHeight-1u ) // degenerate index on non-last row
- {
- indices.PushBack( nextRowStartIndex + gridWidth );
- }
- }
-
- return GenerateGeometry( vertices, indices );
+ geometry = RendererFactoryCache::CreateGridGeometry( gridSize );
}
return geometry;
mDesiredSize(),
mFittingMode( FittingMode::DEFAULT ),
mSamplingMode( SamplingMode::DEFAULT ),
- mIsAlphaPreMultiplied( false ),
mNativeFragmentShaderCode( ),
mNativeImageFlag( false )
{
{
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 );
}
}
}
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
{
{
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 );
}
}
}
InitializeRenderer( mImage );
}
- EnablePreMultipliedAlpha( mIsAlphaPreMultiplied );
}
void ImageRenderer::DoSetOffStage( Actor& actor )
{
actor.RemoveRenderer( mImpl->mRenderer );
CleanCache(mImageUrl);
-
mImage.Reset();
}
else
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;
}
}
}
-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 );
- }
- }
- }
-}
-
void ImageRenderer::ApplyImageToSampler( const Image& image )
{
if( image )