[3.0] Ensure the use of ShaderEffect in ImageActor is backwards-compatible 42/59742/2 accepted/tizen/ivi/20160219.012716 accepted/tizen/mobile/20160218.111040 accepted/tizen/tv/20160218.111102 accepted/tizen/wearable/20160218.111125 submit/tizen/20160218.103925 submit/tizen_common/20160218.142243
authorXiangyin Ma <x1.ma@samsung.com>
Thu, 11 Feb 2016 16:49:55 +0000 (16:49 +0000)
committerTaeyoon Lee <taeyoon0.lee@samsung.com>
Thu, 18 Feb 2016 05:56:38 +0000 (21:56 -0800)
Change-Id: If517adfd7b1dca2478df14747bba18518e016824

dali/internal/event/actors/image-actor-impl.cpp
dali/internal/event/actors/image-actor-impl.h
dali/internal/render/shader-source/image.txt
dali/internal/render/shaders/program.cpp
dali/public-api/shader-effects/shader-effect.h

index 19f6cd2..b952c50 100644 (file)
@@ -59,14 +59,20 @@ TypeRegistration mType( typeid( Dali::ImageActor ), typeid( Dali::Actor ), Creat
 
 struct GridVertex
 {
+  GridVertex( float positionX, float positionY, const Vector2& size )
+  : mPosition( positionX*size.x, positionY*size.y, 0.f ),
+    mTextureCoord( positionX+0.5f, positionY+0.5f )
+  {
+  }
+
   Vector3 mPosition;
   Vector2 mTextureCoord;
 };
 
-GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight )
+GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight, const Vector2& size )
 {
   // Create vertices
-  std::vector< Vector2 > vertices;
+  std::vector< GridVertex > vertices;
   vertices.reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) );
 
   for( unsigned int y = 0u; y < gridHeight + 1; ++y )
@@ -75,7 +81,7 @@ GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight )
     for( unsigned int x = 0u; x < gridWidth + 1; ++x )
     {
       float xPos = (float)x / gridWidth;
-      vertices.push_back( Vector2( xPos - 0.5f, yPos - 0.5f ) );
+      vertices.push_back( GridVertex( xPos - 0.5f, yPos - 0.5f, size ) );
     }
   }
 
@@ -107,7 +113,8 @@ GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight )
 
 
   Property::Map vertexFormat;
-  vertexFormat[ "aPosition" ] = Property::VECTOR2;
+  vertexFormat[ "aPosition" ] = Property::VECTOR3;
+  vertexFormat[ "aTexCoord" ] = Property::VECTOR2;
   PropertyBufferPtr vertexPropertyBuffer = PropertyBuffer::New();
   vertexPropertyBuffer->SetFormat( vertexFormat );
   vertexPropertyBuffer->SetSize( vertices.size() );
@@ -137,16 +144,17 @@ GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight )
 }
 
 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
+  attribute mediump vec3 aPosition;\n
+  attribute mediump vec2 aTexCoord;\n
   varying mediump vec2 vTexCoord;\n
   uniform mediump mat4 uMvpMatrix;\n
   uniform mediump vec3 uSize;\n
-  uniform mediump vec4 uTextureRect;\n
+  uniform mediump vec4 sTextureRect;\n
   \n
   void main()\n
   {\n
-    gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0);\n
-    vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5));\n
+    gl_Position = uMvpMatrix * vec4(aPosition, 1.0);\n
+    vTexCoord = aTexCoord;\n
   }\n
 );
 
@@ -161,6 +169,8 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
   }\n
 );
 
+const char * const TEXTURE_RECT_UNIFORM_NAME( "sTextureRect" );
+
 const size_t INVALID_TEXTURE_ID = (size_t)-1;
 const int INVALID_RENDERER_ID = -1;
 const uint16_t MAXIMUM_GRID_SIZE = 2048;
@@ -176,7 +186,7 @@ ImageActorPtr ImageActor::New()
   //Create the renderer
   actor->mRenderer = Renderer::New();
 
-  GeometryPtr quad  = CreateGeometry( 1u, 1u );
+  GeometryPtr quad  = CreateGeometry( 1u, 1u, Vector2::ONE );
   actor->mRenderer->SetGeometry( *quad );
 
   ShaderPtr shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, Dali::Shader::HINT_NONE );
@@ -294,6 +304,7 @@ Vector4 ImageActor::GetNinePatchBorder() const
 
 ImageActor::ImageActor()
 : Actor( Actor::BASIC ),
+  mActorSize( Vector2::ZERO ),
   mGridSize( 1u, 1u ),
   mRendererIndex( INVALID_RENDERER_ID ),
   mTextureIndex( INVALID_TEXTURE_ID ),
@@ -352,14 +363,11 @@ void ImageActor::UpdateGeometry()
     gridHeight = std::min( MAXIMUM_GRID_SIZE, static_cast<uint16_t>(gridSize.height) );
   }
 
-  if( gridWidth != mGridSize.GetWidth() || gridHeight != mGridSize.GetHeight() )
-  {
-    mGridSize.SetWidth( gridWidth );
-    mGridSize.SetHeight( gridHeight );
+  mGridSize.SetWidth( gridWidth );
+  mGridSize.SetHeight( gridHeight );
 
-    GeometryPtr geometry = CreateGeometry( gridWidth, gridHeight );
-    mRenderer->SetGeometry( *geometry );
-  }
+  GeometryPtr geometry = CreateGeometry( gridWidth, gridHeight, mActorSize );
+  mRenderer->SetGeometry( *geometry );
 }
 void ImageActor::UpdateTexureRect()
 {
@@ -379,7 +387,7 @@ void ImageActor::UpdateTexureRect()
   }
 
   Material* material = mRenderer->GetMaterial();
-  material->RegisterProperty( "uTextureRect", textureRect );
+  material->RegisterProperty( TEXTURE_RECT_UNIFORM_NAME, textureRect );
 }
 
 unsigned int ImageActor::GetDefaultPropertyCount() const
@@ -759,6 +767,25 @@ void ImageActor::EffectImageUpdated()
   }
 }
 
+void ImageActor::OnRelayout( const Vector2& size, RelayoutContainer& container )
+{
+  if( mActorSize != size )
+  {
+    mActorSize = size;
+    UpdateGeometry();
+  }
+}
+
+void ImageActor::OnSizeSet( const Vector3& targetSize )
+{
+  Vector2 size( targetSize.x, targetSize.y );
+  if( mActorSize != size )
+  {
+    mActorSize = size;
+    UpdateGeometry();
+  }
+}
+
 } // namespace Internal
 
 } // namespace Dali
index a9e2f6f..be5fa46 100644 (file)
@@ -222,6 +222,18 @@ public:
    */
   virtual void RemoveShaderEffect();
 
+private:
+
+  /**
+   * @copydoc Actor::OnRelayout
+   */
+  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
+
+  /**
+   * @copydoc Actor::OnSizeSet
+   */
+  virtual void OnSizeSet( const Vector3& targetSize );
+
 public: // Default property extensions from Object
 
   /**
@@ -319,6 +331,7 @@ private:
   PixelArea               mPixelArea;               ///< The pixel area of the image to render
   Vector4                 mBlendColor;              ///< The blend color for this ImageActor
   Vector4                 mNinePatchBorder;         ///< Nine-patch not supported, but this is used to store what is set so it can be returned for backwards compatibility.
+  Vector2                 mActorSize;               ///< The actor size
   Uint16Pair              mGridSize;                ///< The geometry grid size
   int                     mRendererIndex;           ///< The index location of mRenderer
   size_t                  mTextureIndex;            ///< The texture index for this ImageActor's texture
index 3705da8..6ad19f8 100644 (file)
@@ -1,6 +1,7 @@
 <VertexShader>
 
-attribute mediump vec2  aPosition;
+attribute mediump vec3  aPosition;
+attribute mediump vec2  aTexCoord;
 
 uniform   mediump mat4  uModelView;
 uniform   mediump mat4  uProjection;
@@ -14,12 +15,12 @@ uniform   mediump vec3  uSize;
 
 varying   mediump vec2  vTexCoord;
 
-uniform   mediump vec4  uTextureRect;
+uniform   mediump vec4  sTextureRect;
 
 void main()
 {
-  gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0);
-  vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );
+  gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+  vTexCoord = aTexCoord;
 }
 
 </VertexShader>
@@ -29,7 +30,7 @@ void main()
 uniform sampler2D sTexture;
 uniform sampler2D sEffect;
 
-uniform mediump vec4 uTextureRect;
+uniform mediump vec4 sTextureRect;
 uniform mediump vec4 uColor;
 
 varying mediump vec2 vTexCoord;
index e1dbe8a..a2367f6 100644 (file)
@@ -92,7 +92,7 @@ const char* gStdUniforms[ Program::UNIFORM_TYPE_LAST ] =
   "uNormalMatrix",        // UNIFORM_NORMAL_MATRIX
   "uColor",               // UNIFORM_COLOR
   "sTexture",             // UNIFORM_SAMPLER
-  "uTextureRect",         // UNIFORM_SAMPLER_RECT
+  "sTextureRect",         // UNIFORM_SAMPLER_RECT
   "sEffect",              // UNIFORM_EFFECT_SAMPLER
   "uSize"                 // UNIFORM_SIZE
 };
index 401e3e7..f4d2823 100644 (file)
@@ -47,8 +47,8 @@ namespace Dali
  * const string VERTEX_SHADER_SOURCE = DALI_COMPOSE_SHADER (
  *   void main()
  *   {
- *     gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0);
- *     vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );
+ *     gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+ *     vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord) );
  *   }
  * );
  */
@@ -90,8 +90,8 @@ class ShaderEffect;
  * <pre>
  * void main()
  * {
- *     gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0);
- *     vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );
+ *     gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
+ *     vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );
  * }
  * </pre>
  * For fragment shader the default part for images contains the following code: