X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fimage%2Fimage-visual.cpp;h=22a54e636659941914f2698f6a57ae9734c0070a;hp=6f3231d2131bddc721e657ea1bd9a8d24e9c5bce;hb=798ef5fa1591aa78851e9e3d08fe37411192176a;hpb=dea624eb348a4926d8761c8a1364f03f9f71acf5 diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index 6f3231d..22a54e6 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -40,7 +42,6 @@ #include #include #include -#include namespace Dali { @@ -512,52 +513,31 @@ void ImageVisual::GetNaturalSize( Vector2& naturalSize ) void ImageVisual::CreateRenderer( TextureSet& textureSet ) { Geometry geometry; - Shader shader; - if( !mImpl->mCustomShader ) + // Get the geometry + if( mImpl->mCustomShader ) + { + geometry = CreateGeometry( mFactoryCache, mImpl->mCustomShader->mGridSize ); + } + else // Get any geometry associated with the texture { TextureManager& textureManager = mFactoryCache.GetTextureManager(); - uint32_t opaqueElementsCount {0u}; - uint32_t transparentElementsCount {0u}; - geometry = textureManager.GetRenderGeometry(mTextureId, opaqueElementsCount, transparentElementsCount); - if(!opaqueElementsCount && !transparentElementsCount) - { - geometry = CreateGeometry( mFactoryCache, ImageDimensions( 1, 1 ) ); - } + uint32_t firstElementCount {0u}; + uint32_t secondElementCount {0u}; + geometry = textureManager.GetRenderGeometry(mTextureId, firstElementCount, secondElementCount); - shader = mImageVisualShaderFactory.GetShader( mFactoryCache, - mImpl->mFlags & Impl::IS_ATLASING_APPLIED, - mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE, - IsRoundedCornerRequired() ); - } - else - { - geometry = CreateGeometry( mFactoryCache, mImpl->mCustomShader->mGridSize ); - if( mImpl->mCustomShader->mVertexShader.empty() && mImpl->mCustomShader->mFragmentShader.empty() ) - { - // Use custom hints - shader = Shader::New( mImageVisualShaderFactory.GetVertexShaderSource(), mImageVisualShaderFactory.GetFragmentShaderSource(), mImpl->mCustomShader->mHints ); - shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); - } - else + if(!firstElementCount && !secondElementCount) // Otherwise use quad { - shader = Shader::New( mImpl->mCustomShader->mVertexShader.empty() ? mImageVisualShaderFactory.GetVertexShaderSource() : mImpl->mCustomShader->mVertexShader, - mImpl->mCustomShader->mFragmentShader.empty() ? mImageVisualShaderFactory.GetFragmentShaderSource() : mImpl->mCustomShader->mFragmentShader, - mImpl->mCustomShader->mHints ); - if( mImpl->mCustomShader->mVertexShader.empty() ) - { - shader.RegisterProperty( PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT ); - } + geometry = CreateGeometry( mFactoryCache, ImageDimensions( 1, 1 ) ); } } - // Set pixel align off as default. - // ToDo: Pixel align causes issues such as rattling image animation. - // We should trun it off until issues are resolved - shader.RegisterProperty( PIXEL_ALIGNED_UNIFORM_NAME, PIXEL_ALIGN_OFF ); + Shader shader = GetShader(); + // Create the renderer mImpl->mRenderer = Renderer::New( geometry, shader ); + if( textureSet ) { mImpl->mRenderer.SetTextures( textureSet ); @@ -570,6 +550,7 @@ void ImageVisual::CreateRenderer( TextureSet& textureSet ) EnablePreMultipliedAlpha( IsPreMultipliedAlphaEnabled() ); } + void ImageVisual::LoadTexture( bool& atlasing, Vector4& atlasRect, TextureSet& textures, bool orientationCorrection, TextureManager::ReloadPolicy forceReload ) { @@ -788,6 +769,15 @@ bool ImageVisual::IsResourceReady() const mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::FAILED ); } +void ImageVisual::UpdateShader() +{ + if(mImpl->mRenderer) + { + Shader shader = GetShader(); + mImpl->mRenderer.SetShader(shader); + } +} + // From existing atlas manager void ImageVisual::UploadCompleted() { @@ -863,28 +853,28 @@ void ImageVisual::UploadComplete( bool loadingSuccess, int32_t textureId, Textur // use geometry if needed if( loadingSuccess ) { - uint32_t opaqueElements{0u}; - uint32_t transparentElements{0u}; - auto geometry = mFactoryCache.GetTextureManager().GetRenderGeometry(mTextureId, opaqueElements, transparentElements); + uint32_t firstElementCount{0u}; + uint32_t secondElementCount{0u}; + auto geometry = mFactoryCache.GetTextureManager().GetRenderGeometry(mTextureId, firstElementCount, secondElementCount); if (mImpl->mRenderer && geometry) { mImpl->mRenderer.SetGeometry(geometry); Dali::DevelRenderer::DrawCommand drawCommand{}; drawCommand.drawType = DevelRenderer::DrawType::INDEXED; - if (opaqueElements) + if (firstElementCount) { drawCommand.firstIndex = 0; - drawCommand.elementCount = opaqueElements; - drawCommand.queue = 0; + drawCommand.elementCount = firstElementCount; + drawCommand.queue = DevelRenderer::RENDER_QUEUE_OPAQUE; DevelRenderer::AddDrawCommand(mImpl->mRenderer, drawCommand); } - if (transparentElements) + if (secondElementCount) { - drawCommand.firstIndex = opaqueElements; - drawCommand.elementCount = transparentElements; - drawCommand.queue = 1; + drawCommand.firstIndex = firstElementCount; + drawCommand.elementCount = secondElementCount; + drawCommand.queue = DevelRenderer::RENDER_QUEUE_TRANSPARENT; DevelRenderer::AddDrawCommand(mImpl->mRenderer, drawCommand); } } @@ -922,6 +912,73 @@ void ImageVisual::RemoveTexture() } } +Shader ImageVisual::GetShader() +{ + Shader shader; + + std::string vertexShader; + bool usesWholeTexture = true; + if(mImpl->mCustomShader && !mImpl->mCustomShader->mVertexShader.empty()) + { + vertexShader = mImpl->mCustomShader->mVertexShader; + usesWholeTexture = false; // Impossible to tell. + } + else + { + vertexShader = mImageVisualShaderFactory.GetVertexShaderSource().data(); + } + + std::string fragmentShader; + if(mImpl->mCustomShader && !mImpl->mCustomShader->mFragmentShader.empty()) + { + fragmentShader = mImpl->mCustomShader->mFragmentShader; + } + else + { + fragmentShader = mImageVisualShaderFactory.GetFragmentShaderSource().data(); + } + + // If the texture is native, we may need to change prefix and sampler in + // the fragment shader + bool modifiedFragmentShader = false; + if(mTextures && DevelTexture::IsNative(mTextures.GetTexture(0))) + { + Texture nativeTexture = mTextures.GetTexture(0); + modifiedFragmentShader = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragmentShader); + } + + const bool useStandardShader = !mImpl->mCustomShader && !modifiedFragmentShader; + if(useStandardShader) + { + // Create and cache the standard shader + shader = mImageVisualShaderFactory.GetShader( + mFactoryCache, + mImpl->mFlags & Impl::IS_ATLASING_APPLIED, + mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE, + IsRoundedCornerRequired()); + } + else if(mImpl->mCustomShader) + { + shader = Shader::New(vertexShader, fragmentShader, mImpl->mCustomShader->mHints); + } + else + { + shader = Shader::New(vertexShader, fragmentShader); + } + + if(usesWholeTexture) + { + shader.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, FULL_TEXTURE_RECT); + } + + // Set pixel align off as default. + // ToDo: Pixel align causes issues such as rattling image animation. + // We should trun it off until issues are resolved + shader.RegisterProperty(PIXEL_ALIGNED_UNIFORM_NAME, PIXEL_ALIGN_OFF); + + return shader; +} + } // namespace Internal } // namespace Toolkit