(ImageActor) resize the geometry in shader
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / image-actor-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/actors/image-actor-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/animation/constraints.h> // for EqualToConstraint
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/devel-api/scripting/scripting.h>
28 #include <dali/internal/event/animation/constraint-impl.h>
29 #include <dali/internal/event/common/property-helper.h>
30 #include <dali/internal/event/effects/shader-effect-impl.h>
31 #include <dali/internal/event/images/image-connector.h>
32 #include <dali/internal/event/images/nine-patch-image-impl.h>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39
40 namespace
41 {
42
43 // Properties
44
45 //              Name           Type   writable animatable constraint-input  enum for index-checking
46 DALI_PROPERTY_TABLE_BEGIN
47 DALI_PROPERTY( "pixelArea",    RECTANGLE, true,    false,   true,    Dali::ImageActor::Property::PIXEL_AREA )
48 DALI_PROPERTY( "style",        STRING,    true,    false,   true,    Dali::ImageActor::Property::STYLE      )
49 DALI_PROPERTY( "border",       VECTOR4,   true,    false,   true,    Dali::ImageActor::Property::BORDER     )
50 DALI_PROPERTY( "image",        MAP,       true,    false,   false,   Dali::ImageActor::Property::IMAGE      )
51 DALI_PROPERTY_TABLE_END( DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX )
52
53 BaseHandle Create()
54 {
55   return Dali::ImageActor::New();
56 }
57
58 TypeRegistration mType( typeid( Dali::ImageActor ), typeid( Dali::Actor ), Create );
59
60 struct GridVertex
61 {
62   Vector3 mPosition;
63   Vector2 mTextureCoord;
64 };
65
66 GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight )
67 {
68   // Create vertices
69   std::vector< Vector2 > vertices;
70   vertices.reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) );
71
72   for( unsigned int y = 0u; y < gridHeight + 1; ++y )
73   {
74     float yPos = (float)y / gridHeight;
75     for( unsigned int x = 0u; x < gridWidth + 1; ++x )
76     {
77       float xPos = (float)x / gridWidth;
78       vertices.push_back( Vector2( xPos - 0.5f, yPos - 0.5f ) );
79     }
80   }
81
82   // Create indices
83   Vector< unsigned int > indices;
84   indices.Reserve( ( gridWidth + 2 ) * gridHeight * 2 - 2);
85
86   for( unsigned int row = 0u; row < gridHeight; ++row )
87   {
88     unsigned int rowStartIndex = row*(gridWidth+1u);
89     unsigned int nextRowStartIndex = rowStartIndex + gridWidth +1u;
90
91     if( row != 0u ) // degenerate index on non-first row
92     {
93       indices.PushBack( rowStartIndex );
94     }
95
96     for( unsigned int column = 0u; column < gridWidth+1u; column++) // main strip
97     {
98       indices.PushBack( rowStartIndex + column);
99       indices.PushBack( nextRowStartIndex + column);
100     }
101
102     if( row != gridHeight-1u ) // degenerate index on non-last row
103     {
104       indices.PushBack( nextRowStartIndex + gridWidth );
105     }
106   }
107
108
109   Property::Map vertexFormat;
110   vertexFormat[ "aPosition" ] = Property::VECTOR2;
111   PropertyBufferPtr vertexPropertyBuffer = PropertyBuffer::New();
112   vertexPropertyBuffer->SetFormat( vertexFormat );
113   vertexPropertyBuffer->SetSize( vertices.size() );
114   if( vertices.size() > 0 )
115   {
116     vertexPropertyBuffer->SetData( &vertices[ 0 ] );
117   }
118
119   Property::Map indexFormat;
120   indexFormat[ "indices" ] = Property::INTEGER;
121   PropertyBufferPtr indexPropertyBuffer = PropertyBuffer::New();
122   indexPropertyBuffer->SetFormat( indexFormat );
123   indexPropertyBuffer->SetSize( indices.Size() );
124   if( indices.Size() > 0 )
125   {
126     indexPropertyBuffer->SetData( &indices[ 0 ] );
127   }
128
129   // Create the geometry object
130   GeometryPtr geometry = Geometry::New();
131   geometry->AddVertexBuffer( *vertexPropertyBuffer );
132   geometry->SetIndexBuffer( *indexPropertyBuffer );
133   geometry->SetGeometryType( Dali::Geometry::TRIANGLE_STRIP );
134
135   return geometry;
136
137 }
138
139 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
140   attribute mediump vec2 aPosition;\n
141   varying mediump vec2 vTexCoord;\n
142   uniform mediump mat4 uMvpMatrix;\n
143   uniform mediump vec3 uSize;\n
144   uniform mediump vec4 uTextureRect;\n
145   \n
146   void main()\n
147   {\n
148     gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0);\n
149     vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5));\n
150   }\n
151 );
152
153 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
154   varying mediump vec2 vTexCoord;\n
155   uniform sampler2D sTexture;\n
156   uniform lowp vec4 uColor;\n
157   \n
158   void main()\n
159   {\n
160     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
161   }\n
162 );
163
164 const size_t INVALID_TEXTURE_ID = (size_t)-1;
165 const int INVALID_RENDERER_ID = -1;
166 const uint16_t MAXIMUM_GRID_SIZE = 2048;
167 }
168
169 ImageActorPtr ImageActor::New()
170 {
171   ImageActorPtr actor( new ImageActor );
172
173   // Second-phase construction of base class
174   actor->Initialize();
175
176   //Create the renderer
177   actor->mRenderer = Renderer::New();
178
179   GeometryPtr quad  = CreateGeometry( 1u, 1u );
180   actor->mRenderer->SetGeometry( *quad );
181
182   ShaderPtr shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, Dali::Shader::HINT_NONE );
183   MaterialPtr material = Material::New();
184   material->SetShader( *shader );
185   actor->mRenderer->SetMaterial( *material );
186
187   return actor;
188 }
189
190 void ImageActor::OnInitialize()
191 {
192   // TODO: Remove this, at the moment its needed for size negotiation to work
193   SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
194 }
195
196 void ImageActor::SetImage( ImagePtr& image )
197 {
198   if( !image )
199   {
200     if( mRendererIndex != INVALID_RENDERER_ID )
201     {
202       RemoveRenderer( mRendererIndex );
203       mRendererIndex = INVALID_RENDERER_ID;
204     }
205   }
206   else
207   {
208     SamplerPtr sampler = Sampler::New();
209     sampler->SetFilterMode( mMinFilter, mMagFilter );
210
211     mTextureIndex = mRenderer->GetMaterial()->AddTexture( image, "sTexture", sampler );
212
213     if( mRendererIndex == INVALID_RENDERER_ID )
214     {
215       mRendererIndex = AddRenderer( *mRenderer );
216     }
217
218     if( !mIsPixelAreaSet )
219     {
220       mPixelArea = PixelArea( 0, 0, image->GetWidth(), image->GetHeight() );
221     }
222
223     RelayoutRequest();
224     UpdateTexureRect();
225   }
226 }
227
228 ImagePtr ImageActor::GetImage() const
229 {
230   return mRenderer->GetMaterial()->GetTexture( mTextureIndex );
231 }
232
233 void ImageActor::SetPixelArea( const PixelArea& pixelArea )
234 {
235   mPixelArea = pixelArea;
236   mIsPixelAreaSet = true;
237
238   RelayoutRequest();
239   UpdateTexureRect();
240 }
241
242 const ImageActor::PixelArea& ImageActor::GetPixelArea() const
243 {
244   return mPixelArea;
245 }
246
247 bool ImageActor::IsPixelAreaSet() const
248 {
249   return mIsPixelAreaSet;
250 }
251
252 void ImageActor::ClearPixelArea()
253 {
254   mIsPixelAreaSet = false;
255
256   int imageWidth = 0;
257   int imageHeight = 0;
258   ImagePtr image = GetImage();
259   if( image )
260   {
261     imageWidth = image->GetWidth();
262     imageHeight = image->GetHeight();
263   }
264
265   mPixelArea = PixelArea( 0, 0, imageWidth, imageHeight );
266
267   RelayoutRequest();
268   UpdateTexureRect();
269 }
270
271 ImageActor::ImageActor()
272 : Actor( Actor::BASIC ),
273   mGridSize( 1u, 1u ),
274   mRendererIndex( INVALID_RENDERER_ID ),
275   mTextureIndex( INVALID_TEXTURE_ID ),
276   mEffectTextureIndex( INVALID_TEXTURE_ID ),
277   mMinFilter( FilterMode::DEFAULT ),
278   mMagFilter( FilterMode::DEFAULT ),
279   mIsPixelAreaSet( false )
280 {
281 }
282
283 ImageActor::~ImageActor()
284 {
285 }
286
287 Vector3 ImageActor::GetNaturalSize() const
288 {
289   Vector2 naturalSize( CalculateNaturalSize() );
290   return Vector3( naturalSize.width, naturalSize.height, 0.f );
291 }
292
293 Vector2 ImageActor::CalculateNaturalSize() const
294 {
295   // if no image then natural size is 0
296   Vector2 size( 0.0f, 0.0f );
297
298   ImagePtr image = GetImage();
299   if( image )
300   {
301     if( IsPixelAreaSet() )
302     {
303       PixelArea area(GetPixelArea());
304       size.width = area.width;
305       size.height = area.height;
306     }
307     else
308     {
309       size = image->GetNaturalSize();
310     }
311   }
312
313   return size;
314 }
315
316 void ImageActor::UpdateGeometry()
317 {
318   uint16_t gridWidth = 1u;
319   uint16_t gridHeight = 1u;
320
321   if( mShaderEffect )
322   {
323     Vector2 gridSize = mShaderEffect->GetGridSize( Vector2(mPixelArea.width, mPixelArea.height) );
324
325     //limit the grid size
326     gridWidth = std::min( MAXIMUM_GRID_SIZE, static_cast<uint16_t>(gridSize.width) );
327     gridHeight = std::min( MAXIMUM_GRID_SIZE, static_cast<uint16_t>(gridSize.height) );
328   }
329
330   if( gridWidth != mGridSize.GetWidth() || gridHeight != mGridSize.GetHeight() )
331   {
332     mGridSize.SetWidth( gridWidth );
333     mGridSize.SetHeight( gridHeight );
334
335     GeometryPtr geometry = CreateGeometry( gridWidth, gridHeight );
336     mRenderer->SetGeometry( *geometry );
337   }
338 }
339 void ImageActor::UpdateTexureRect()
340 {
341   Vector4 textureRect( 0.f, 0.f, 1.f, 1.f );
342
343   ImagePtr image = GetImage();
344   if( mIsPixelAreaSet && image )
345   {
346     const float uScale = 1.0f / float(image->GetWidth());
347     const float vScale = 1.0f / float(image->GetHeight());
348     // bottom left
349     textureRect.x = uScale * float(mPixelArea.x);
350     textureRect.y = vScale * float(mPixelArea.y);
351     // top right
352     textureRect.z  = uScale * float(mPixelArea.x + mPixelArea.width);
353     textureRect.w = vScale * float(mPixelArea.y + mPixelArea.height);
354   }
355
356   Material* material = mRenderer->GetMaterial();
357   material->RegisterProperty( "uTextureRect", textureRect );
358 }
359
360 unsigned int ImageActor::GetDefaultPropertyCount() const
361 {
362   return Actor::GetDefaultPropertyCount() + DEFAULT_PROPERTY_COUNT;
363 }
364
365 void ImageActor::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
366 {
367   Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
368
369   indices.Reserve( indices.Size() + DEFAULT_PROPERTY_COUNT );
370
371   int index = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
372   for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i, ++index )
373   {
374     indices.PushBack( index );
375   }
376 }
377
378 bool ImageActor::IsDefaultPropertyWritable( Property::Index index ) const
379 {
380   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
381   {
382     return Actor::IsDefaultPropertyWritable(index);
383   }
384
385   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
386   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
387   {
388     return DEFAULT_PROPERTY_DETAILS[ index ].writable;
389   }
390
391   return false;
392 }
393
394 bool ImageActor::IsDefaultPropertyAnimatable( Property::Index index ) const
395 {
396   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
397   {
398     return Actor::IsDefaultPropertyAnimatable( index );
399   }
400
401   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
402   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
403   {
404     return DEFAULT_PROPERTY_DETAILS[ index ].animatable;
405   }
406
407   return false;
408 }
409
410 bool ImageActor::IsDefaultPropertyAConstraintInput( Property::Index index ) const
411 {
412   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
413   {
414     return Actor::IsDefaultPropertyAConstraintInput( index );
415   }
416
417   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
418   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
419   {
420     return DEFAULT_PROPERTY_DETAILS[ index ].constraintInput;
421   }
422
423   return false;
424 }
425
426 Property::Type ImageActor::GetDefaultPropertyType( Property::Index index ) const
427 {
428   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
429   {
430     return Actor::GetDefaultPropertyType( index );
431   }
432
433   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
434   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
435   {
436     return DEFAULT_PROPERTY_DETAILS[index].type;
437   }
438
439   // index out-of-bounds
440   return Property::NONE;
441 }
442
443 const char* ImageActor::GetDefaultPropertyName( Property::Index index ) const
444 {
445   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
446   {
447     return Actor::GetDefaultPropertyName(index);
448   }
449
450   index -= DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
451   if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
452   {
453     return DEFAULT_PROPERTY_DETAILS[index].name;
454   }
455
456   // index out-of-bounds
457   return NULL;
458 }
459
460 Property::Index ImageActor::GetDefaultPropertyIndex(const std::string& name) const
461 {
462   Property::Index index = Property::INVALID_INDEX;
463
464   // Look for name in default properties
465   for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
466   {
467     const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
468     if( 0 == strcmp( name.c_str(), property->name ) ) // Don't want to convert rhs to string
469     {
470       index = i + DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX;
471       break;
472     }
473   }
474
475   // If not found, check in base class
476   if( Property::INVALID_INDEX == index )
477   {
478     index = Actor::GetDefaultPropertyIndex( name );
479   }
480   return index;
481 }
482
483 void ImageActor::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
484 {
485   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
486   {
487     Actor::SetDefaultProperty( index, propertyValue );
488   }
489   else
490   {
491     switch(index)
492     {
493       case Dali::ImageActor::Property::PIXEL_AREA:
494       {
495         SetPixelArea(propertyValue.Get<Rect<int> >());
496         break;
497       }
498       case Dali::ImageActor::Property::STYLE:
499       {
500         //not supported
501         break;
502       }
503       case Dali::ImageActor::Property::BORDER:
504       {
505         //not supported
506         break;
507       }
508       case Dali::ImageActor::Property::IMAGE:
509       {
510         Dali::Image img = Scripting::NewImage( propertyValue );
511         if(img)
512         {
513           ImagePtr image( &GetImplementation(img) );
514           SetImage( image );
515         }
516         else
517         {
518           DALI_LOG_WARNING("Cannot create image from property value\n");
519         }
520         break;
521       }
522       default:
523       {
524         DALI_LOG_WARNING("Unknown property (%d)\n", index);
525         break;
526       }
527     } // switch(index)
528
529   } // else
530 }
531
532 Property::Value ImageActor::GetDefaultProperty( Property::Index index ) const
533 {
534   Property::Value ret;
535   if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
536   {
537     ret = Actor::GetDefaultProperty( index );
538   }
539   else
540   {
541     switch( index )
542     {
543       case Dali::ImageActor::Property::PIXEL_AREA:
544       {
545         Rect<int> r = GetPixelArea();
546         ret = r;
547         break;
548       }
549       case Dali::ImageActor::Property::STYLE:
550       {
551         //not supported
552         break;
553       }
554       case Dali::ImageActor::Property::BORDER:
555       {
556         //not supported
557         break;
558       }
559       case Dali::ImageActor::Property::IMAGE:
560       {
561         Property::Map map;
562         Scripting::CreatePropertyMap( Dali::Image( GetImage().Get() ), map );
563         ret = Property::Value( map );
564         break;
565       }
566       default:
567       {
568         DALI_LOG_WARNING( "Unknown property (%d)\n", index );
569         break;
570       }
571     } // switch(index)
572   }
573
574   return ret;
575 }
576
577 void ImageActor::SetSortModifier(float modifier)
578 {
579   mRenderer->SetDepthIndex( modifier );
580 }
581
582 float ImageActor::GetSortModifier() const
583 {
584   return mRenderer->GetDepthIndex();
585 }
586
587 void ImageActor::SetCullFace(CullFaceMode mode)
588 {
589   mRenderer->GetMaterial()->SetFaceCullingMode( static_cast< Dali::Material::FaceCullingMode >( mode ) );
590 }
591
592 CullFaceMode ImageActor::GetCullFace() const
593 {
594   return static_cast< CullFaceMode >( mRenderer->GetMaterial()->GetFaceCullingMode() );
595 }
596
597 void ImageActor::SetBlendMode( BlendingMode::Type mode )
598 {
599   mRenderer->GetMaterial()->SetBlendMode( mode );
600 }
601
602 BlendingMode::Type ImageActor::GetBlendMode() const
603 {
604   return mRenderer->GetMaterial()->GetBlendMode();
605 }
606
607 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba,   BlendingFactor::Type destFactorRgba )
608 {
609   mRenderer->GetMaterial()->SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
610 }
611
612 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
613                                BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
614 {
615   mRenderer->GetMaterial()->SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
616 }
617
618 void ImageActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
619                                BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
620 {
621   mRenderer->GetMaterial()->GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
622 }
623
624 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgba )
625 {
626   mRenderer->GetMaterial()->SetBlendEquation( equationRgba, equationRgba );
627 }
628
629 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
630 {
631   mRenderer->GetMaterial()->SetBlendEquation( equationRgb, equationAlpha );
632 }
633
634 void ImageActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
635 {
636   mRenderer->GetMaterial()->GetBlendEquation( equationRgb, equationAlpha );
637 }
638
639 void ImageActor::SetBlendColor( const Vector4& color )
640 {
641   mBlendColor = color;
642   mRenderer->GetMaterial()->SetBlendColor( mBlendColor );
643 }
644
645 const Vector4& ImageActor::GetBlendColor() const
646 {
647   return mBlendColor;
648 }
649
650 void ImageActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
651 {
652   mMinFilter = minFilter;
653   mMagFilter = magFilter;
654
655   if( mTextureIndex != INVALID_TEXTURE_ID )
656   {
657     SamplerPtr sampler = Sampler::New();
658     sampler->SetFilterMode( minFilter, magFilter );
659
660     mRenderer->GetMaterial()->SetTextureSampler( mTextureIndex, sampler.Get() );
661   }
662 }
663
664 void ImageActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
665 {
666   minFilter = mMinFilter;
667   magFilter = mMagFilter;
668 }
669
670 void ImageActor::SetShaderEffect( ShaderEffect& effect )
671 {
672   if( mShaderEffect )
673   {
674     mShaderEffect->Disconnect( this );
675   }
676
677   mShaderEffect = ShaderEffectPtr( &effect );
678   effect.Connect( this );
679
680   ShaderPtr shader = mShaderEffect->GetShader();
681   mRenderer->GetMaterial()->SetShader( *shader );
682
683   EffectImageUpdated();
684
685   UpdateGeometry();
686 }
687
688 ShaderEffectPtr ImageActor::GetShaderEffect() const
689 {
690   return mShaderEffect;
691 }
692
693 void ImageActor::RemoveShaderEffect()
694 {
695   if( mShaderEffect )
696   {
697     mShaderEffect->Disconnect( this );
698     // change to the standard shader and quad geometry
699     ShaderPtr shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, Dali::Shader::HINT_NONE );
700     mRenderer->GetMaterial()->SetShader( *shader );
701     mShaderEffect.Reset();
702
703     UpdateGeometry();
704   }
705 }
706
707 void ImageActor::EffectImageUpdated()
708 {
709   if( mShaderEffect )
710   {
711     Dali::Image effectImage = mShaderEffect->GetEffectImage();
712     if( effectImage )
713     {
714       Image& effectImageImpl = GetImplementation( effectImage );
715
716       if( mEffectTextureIndex == INVALID_TEXTURE_ID )
717       {
718         mEffectTextureIndex = mRenderer->GetMaterial()->AddTexture( &effectImageImpl, "sEffect", NULL );
719       }
720       else
721       {
722         mRenderer->GetMaterial()->SetTextureImage( mEffectTextureIndex, &effectImageImpl );
723       }
724     }
725     else
726     {
727       if( mEffectTextureIndex != INVALID_TEXTURE_ID )
728       {
729         mRenderer->GetMaterial()->RemoveTexture( mEffectTextureIndex );
730       }
731       mEffectTextureIndex = INVALID_TEXTURE_ID;
732     }
733
734   }
735 }
736
737 } // namespace Internal
738
739 } // namespace Dali