From f9e62d3ce9fbe30aabcf89914f479059c6a4ec16 Mon Sep 17 00:00:00 2001 From: "dongsug.song" Date: Tue, 23 Feb 2016 21:53:23 +0900 Subject: [PATCH] Revert "[3.0] Ensure the use of ShaderEffect in ImageActor is backwards-compatible" This reverts commit 9ef925cf1da2d99130aae7026c88055611666950. Change-Id: I7d7a942dbf44423f03c97d74053a5744d8307df0 --- dali/internal/event/actors/image-actor-impl.cpp | 61 +++++++------------------ dali/internal/event/actors/image-actor-impl.h | 13 ------ dali/internal/render/shader-source/image.txt | 11 ++--- dali/internal/render/shaders/program.cpp | 2 +- dali/public-api/shader-effects/shader-effect.h | 8 ++-- 5 files changed, 27 insertions(+), 68 deletions(-) diff --git a/dali/internal/event/actors/image-actor-impl.cpp b/dali/internal/event/actors/image-actor-impl.cpp index b952c50..19f6cd2 100644 --- a/dali/internal/event/actors/image-actor-impl.cpp +++ b/dali/internal/event/actors/image-actor-impl.cpp @@ -59,20 +59,14 @@ 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, const Vector2& size ) +GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight ) { // Create vertices - std::vector< GridVertex > vertices; + std::vector< Vector2 > vertices; vertices.reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) ); for( unsigned int y = 0u; y < gridHeight + 1; ++y ) @@ -81,7 +75,7 @@ GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight, con for( unsigned int x = 0u; x < gridWidth + 1; ++x ) { float xPos = (float)x / gridWidth; - vertices.push_back( GridVertex( xPos - 0.5f, yPos - 0.5f, size ) ); + vertices.push_back( Vector2( xPos - 0.5f, yPos - 0.5f ) ); } } @@ -113,8 +107,7 @@ GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight, con Property::Map vertexFormat; - vertexFormat[ "aPosition" ] = Property::VECTOR3; - vertexFormat[ "aTexCoord" ] = Property::VECTOR2; + vertexFormat[ "aPosition" ] = Property::VECTOR2; PropertyBufferPtr vertexPropertyBuffer = PropertyBuffer::New(); vertexPropertyBuffer->SetFormat( vertexFormat ); vertexPropertyBuffer->SetSize( vertices.size() ); @@ -144,17 +137,16 @@ GeometryPtr CreateGeometry( unsigned int gridWidth, unsigned int gridHeight, con } const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( - attribute mediump vec3 aPosition;\n - attribute mediump vec2 aTexCoord;\n + attribute mediump vec2 aPosition;\n varying mediump vec2 vTexCoord;\n uniform mediump mat4 uMvpMatrix;\n uniform mediump vec3 uSize;\n - uniform mediump vec4 sTextureRect;\n + uniform mediump vec4 uTextureRect;\n \n void main()\n {\n - gl_Position = uMvpMatrix * vec4(aPosition, 1.0);\n - vTexCoord = aTexCoord;\n + gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0);\n + vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5));\n }\n ); @@ -169,8 +161,6 @@ 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; @@ -186,7 +176,7 @@ ImageActorPtr ImageActor::New() //Create the renderer actor->mRenderer = Renderer::New(); - GeometryPtr quad = CreateGeometry( 1u, 1u, Vector2::ONE ); + GeometryPtr quad = CreateGeometry( 1u, 1u ); actor->mRenderer->SetGeometry( *quad ); ShaderPtr shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, Dali::Shader::HINT_NONE ); @@ -304,7 +294,6 @@ Vector4 ImageActor::GetNinePatchBorder() const ImageActor::ImageActor() : Actor( Actor::BASIC ), - mActorSize( Vector2::ZERO ), mGridSize( 1u, 1u ), mRendererIndex( INVALID_RENDERER_ID ), mTextureIndex( INVALID_TEXTURE_ID ), @@ -363,11 +352,14 @@ void ImageActor::UpdateGeometry() gridHeight = std::min( MAXIMUM_GRID_SIZE, static_cast(gridSize.height) ); } - mGridSize.SetWidth( gridWidth ); - mGridSize.SetHeight( gridHeight ); + if( gridWidth != mGridSize.GetWidth() || gridHeight != mGridSize.GetHeight() ) + { + mGridSize.SetWidth( gridWidth ); + mGridSize.SetHeight( gridHeight ); - GeometryPtr geometry = CreateGeometry( gridWidth, gridHeight, mActorSize ); - mRenderer->SetGeometry( *geometry ); + GeometryPtr geometry = CreateGeometry( gridWidth, gridHeight ); + mRenderer->SetGeometry( *geometry ); + } } void ImageActor::UpdateTexureRect() { @@ -387,7 +379,7 @@ void ImageActor::UpdateTexureRect() } Material* material = mRenderer->GetMaterial(); - material->RegisterProperty( TEXTURE_RECT_UNIFORM_NAME, textureRect ); + material->RegisterProperty( "uTextureRect", textureRect ); } unsigned int ImageActor::GetDefaultPropertyCount() const @@ -767,25 +759,6 @@ 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 diff --git a/dali/internal/event/actors/image-actor-impl.h b/dali/internal/event/actors/image-actor-impl.h index be5fa46..a9e2f6f 100644 --- a/dali/internal/event/actors/image-actor-impl.h +++ b/dali/internal/event/actors/image-actor-impl.h @@ -222,18 +222,6 @@ 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 /** @@ -331,7 +319,6 @@ 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 diff --git a/dali/internal/render/shader-source/image.txt b/dali/internal/render/shader-source/image.txt index 6ad19f8..3705da8 100644 --- a/dali/internal/render/shader-source/image.txt +++ b/dali/internal/render/shader-source/image.txt @@ -1,7 +1,6 @@ -attribute mediump vec3 aPosition; -attribute mediump vec2 aTexCoord; +attribute mediump vec2 aPosition; uniform mediump mat4 uModelView; uniform mediump mat4 uProjection; @@ -15,12 +14,12 @@ uniform mediump vec3 uSize; varying mediump vec2 vTexCoord; -uniform mediump vec4 sTextureRect; +uniform mediump vec4 uTextureRect; void main() { - gl_Position = uMvpMatrix * vec4(aPosition, 1.0); - vTexCoord = aTexCoord; + gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0); + vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) ); } @@ -30,7 +29,7 @@ void main() uniform sampler2D sTexture; uniform sampler2D sEffect; -uniform mediump vec4 sTextureRect; +uniform mediump vec4 uTextureRect; uniform mediump vec4 uColor; varying mediump vec2 vTexCoord; diff --git a/dali/internal/render/shaders/program.cpp b/dali/internal/render/shaders/program.cpp index a2367f6..e1dbe8a 100644 --- a/dali/internal/render/shaders/program.cpp +++ b/dali/internal/render/shaders/program.cpp @@ -92,7 +92,7 @@ const char* gStdUniforms[ Program::UNIFORM_TYPE_LAST ] = "uNormalMatrix", // UNIFORM_NORMAL_MATRIX "uColor", // UNIFORM_COLOR "sTexture", // UNIFORM_SAMPLER - "sTextureRect", // UNIFORM_SAMPLER_RECT + "uTextureRect", // UNIFORM_SAMPLER_RECT "sEffect", // UNIFORM_EFFECT_SAMPLER "uSize" // UNIFORM_SIZE }; diff --git a/dali/public-api/shader-effects/shader-effect.h b/dali/public-api/shader-effects/shader-effect.h index f4d2823..401e3e7 100644 --- a/dali/public-api/shader-effects/shader-effect.h +++ b/dali/public-api/shader-effects/shader-effect.h @@ -47,8 +47,8 @@ namespace Dali * const string VERTEX_SHADER_SOURCE = DALI_COMPOSE_SHADER ( * void main() * { - * gl_Position = uMvpMatrix * vec4(aPosition, 1.0); - * vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord) ); + * gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0); + * vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) ); * } * ); */ @@ -90,8 +90,8 @@ class ShaderEffect; *
  * void main()
  * {
- *     gl_Position = uMvpMatrix * vec4(aPosition, 1.0);
- *     vTexCoord = mix( sTextureRect.xy, sTextureRect.zw, aTexCoord );
+ *     gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0);
+ *     vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );
  * }
  * 
* For fragment shader the default part for images contains the following code: -- 2.7.4