std::string fragmentShader;
const char* fragmentPreFix = nativeImage.GetCustomFragmentPreFix();
const char* customSamplerTypename = nativeImage.GetCustomSamplerTypename();
+
if( fragmentPreFix )
{
fragmentShader = fragmentPreFix;
fragmentShader += "\n";
}
+
if( mImpl->mCustomShader && !mImpl->mCustomShader->mFragmentShader.empty() )
{
fragmentShader += mImpl->mCustomShader->mFragmentShader;
{
fragmentShader += FRAGMENT_SHADER_NO_ATLAS;
}
+
if( customSamplerTypename )
{
fragmentShader.replace( fragmentShader.find( DEFAULT_SAMPLER_TYPENAME ), strlen( DEFAULT_SAMPLER_TYPENAME ), customSamplerTypename );
( strncasecmp( imageUrl.c_str(), HTTPS_URL, sizeof(HTTPS_URL) -1 ) != 0 ) )
{
bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
- bool defaultTransform = mImpl->mTransform.mSize == Vector2::ONE &&
- mImpl->mTransform.mOffset == Vector2::ZERO &&
- mImpl->mTransform.mOffsetSizeMode == Vector4::ZERO &&
- mImpl->mTransform.mOrigin == Toolkit::Align::CENTER &&
- mImpl->mTransform.mAnchorPoint == Toolkit::Align::CENTER;
-
- bool cacheable = defaultWrapMode && defaultTransform && mPixelArea == FULL_TEXTURE_RECT;
+ Vector4 atlasRect;
+ // texture set has to be created first as we need to know if atlasing succeeded or not
+ // when selecting the shader
+ TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), true );
+ CreateRenderer( textures );
- mImpl->mFlags &= ~Impl::IS_FROM_CACHE;
- if( cacheable ) // fetch the renderer from cache if exist
- {
- mImpl->mRenderer = mFactoryCache.GetRenderer( imageUrl );
- mImpl->mFlags |= Impl::IS_FROM_CACHE;
- }
-
- if( !mImpl->mRenderer ) // new renderer is needed
+ if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED ) // the texture is packed inside atlas
{
- Vector4 atlasRect;
- // texture set has to be created first as we need to know if atlasing succeeded or not
- // when selecting the shader
- TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), true );
- CreateRenderer( textures );
-
- if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED ) // the texture is packed inside atlas
+ mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, atlasRect );
+ if( !defaultWrapMode ) // custom wrap mode, renderer is not cached.
{
- mImpl->mRenderer.RegisterProperty( ATLAS_RECT_UNIFORM_NAME, atlasRect );
- if( !defaultWrapMode ) // custom wrap mode, renderer is not cached.
- {
- Vector2 wrapMode(mWrapModeU-WrapMode::CLAMP_TO_EDGE, mWrapModeV-WrapMode::CLAMP_TO_EDGE);
- wrapMode.Clamp( Vector2::ZERO, Vector2( 2.f, 2.f ) );
- mImpl->mRenderer.RegisterProperty( WRAP_MODE_UNIFORM_NAME, wrapMode );
- }
- }
-
- // save the renderer to cache only when default wrap mode and default pixel area is used
- if( cacheable )
- {
- mFactoryCache.SaveRenderer( imageUrl, mImpl->mRenderer );
+ Vector2 wrapMode(mWrapModeU-WrapMode::CLAMP_TO_EDGE, mWrapModeV-WrapMode::CLAMP_TO_EDGE);
+ wrapMode.Clamp( Vector2::ZERO, Vector2( 2.f, 2.f ) );
+ mImpl->mRenderer.RegisterProperty( WRAP_MODE_UNIFORM_NAME, wrapMode );
}
}
}
else
{
- // for custom shader or remote image, renderer is not cached and atlas is not applied
- mImpl->mFlags &= ~Impl::IS_FROM_CACHE;
+ // for custom shader or remote image, atlas is not applied
Vector4 atlasRect; // ignored in this case
TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), false );
CreateRenderer( textures );
void ImageVisual::InitializeRenderer( const Image& image )
{
- mImpl->mFlags &= ~Impl::IS_FROM_CACHE;
-
// don't reuse CreateTextureSet
TextureSet textures = TextureSet::New();
+
// Renderer can't be shared if mImage is NativeImage
NativeImage nativeImage = NativeImage::DownCast( image );
if( nativeImage )
actor.RemoveRenderer( mImpl->mRenderer);
if( !mImageUrl.empty() )
{
- CleanCache(mImageUrl);
+ RemoveFromAtlas(mImageUrl);
mImage.Reset();
}
}
}
-void ImageVisual::CleanCache(const std::string& url)
+void ImageVisual::RemoveFromAtlas(const std::string& url)
{
- if( IsFromCache() )
+ Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f );
+ Property::Index index = mImpl->mRenderer.GetPropertyIndex( ATLAS_RECT_UNIFORM_NAME );
+ if( index != Property::INVALID_INDEX )
{
- Vector4 atlasRect( 0.f, 0.f, 1.f, 1.f );
- Property::Index index = mImpl->mRenderer.GetPropertyIndex( ATLAS_RECT_UNIFORM_NAME );
- if( index != Property::INVALID_INDEX )
- {
- Property::Value atlasRectValue = mImpl->mRenderer.GetProperty( index );
- atlasRectValue.Get( atlasRect );
- }
+ Property::Value atlasRectValue = mImpl->mRenderer.GetProperty( index );
+ atlasRectValue.Get( atlasRect );
+ }
- TextureSet textureSet = mImpl->mRenderer.GetTextures();
- mImpl->mRenderer.Reset();
- if( mFactoryCache.CleanRendererCache( url ) && index != Property::INVALID_INDEX )
- {
- mFactoryCache.GetAtlasManager()->Remove( textureSet, atlasRect );
- }
+ TextureSet textureSet = mImpl->mRenderer.GetTextures();
+ mImpl->mRenderer.Reset();
+
+ if( index != Property::INVALID_INDEX )
+ {
+ mFactoryCache.GetAtlasManager()->Remove( textureSet, atlasRect );
}
}