-const char * const BORDER_ONLY( "borderOnly" );
-const char * const BORDER( "border" );
-const char * const AUXILIARY_IMAGE_NAME( "auxiliaryImage" );
-const char * const AUXILIARY_IMAGE_ALPHA_NAME( "auxiliaryImageAlpha" );
-
-const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vMaskTexCoord;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump vec3 uSize;\n
- uniform mediump vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];\n
- uniform mediump vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];\n
- \n
-
- // Visual size and offset
- uniform mediump vec2 offset;\n
- uniform mediump vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
-
- void main()\n
- {\n
- mediump vec2 fixedFactor = vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );\n
- mediump vec2 stretch = vec2( uNinePatchFactorsX[ int( ( aPosition.x ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y ) * 0.5 ) ].y );\n
- \n
- mediump vec2 fixedTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );\n
- mediump vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );\n
- \n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- \n
- mediump vec4 gridPosition = vec4( fixedFactor + ( visualSize.xy - fixedTotal ) * stretch / stretchTotal, 0.0, 1.0 );\n
- mediump vec4 vertexPosition = gridPosition;\n
- vertexPosition.xy -= visualSize.xy * vec2( 0.5, 0.5 );\n
- vertexPosition.xy += anchorPoint*visualSize + (visualOffset + origin)*uSize.xy;\n
- vertexPosition = uMvpMatrix * vertexPosition;\n
- \n
- vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );\n
- vMaskTexCoord = gridPosition.xy / visualSize;\n
- \n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* VERTEX_SHADER_3X3 = DALI_COMPOSE_SHADER(
- attribute mediump vec2 aPosition;\n
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vMaskTexCoord;\n
- uniform mediump mat4 uModelMatrix;\n
- uniform mediump mat4 uMvpMatrix;\n
- uniform mediump vec3 uSize;\n
- uniform mediump vec2 uFixed[ 3 ];\n
- uniform mediump vec2 uStretchTotal;\n
- \n
- //Visual size and offset
- uniform mediump vec2 offset;\n
- uniform mediump vec2 size;\n
- uniform mediump vec4 offsetSizeMode;\n
- uniform mediump vec2 origin;\n
- uniform mediump vec2 anchorPoint;\n
- \n
- void main()\n
- {\n
- vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
- vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
- \n
- mediump vec2 size = visualSize.xy;\n
- \n
- mediump vec2 fixedFactor = vec2( uFixed[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uFixed[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].y );\n
- mediump vec2 stretch = floor( aPosition * 0.5 );\n
- mediump vec2 fixedTotal = uFixed[ 2 ];\n
- \n
- mediump vec4 gridPosition = vec4( fixedFactor + ( size - fixedTotal ) * stretch, 0.0, 1.0 );\n
- mediump vec4 vertexPosition = gridPosition;\n
- vertexPosition.xy -= size * vec2( 0.5, 0.5 );\n
- vertexPosition.xy += anchorPoint*size + (visualOffset + origin)*uSize.xy;\n
- \n
- vertexPosition = uMvpMatrix * vertexPosition;\n
- \n
- vTexCoord = ( fixedFactor + stretch * uStretchTotal ) / ( fixedTotal + uStretchTotal );\n
- \n
- vMaskTexCoord = gridPosition.xy / size;\n
- gl_Position = vertexPosition;\n
- }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- uniform lowp float opacity;\n
- uniform lowp float preMultipliedAlpha;\n
- lowp vec4 visualMixColor()\n
- {\n
- return vec4( mixColor * mix( 1.0, opacity, preMultipliedAlpha ), opacity );\n
- }\n
- void main()\n
- {\n
- gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * visualMixColor();\n
- }\n
-);
-
-const char* FRAGMENT_MASK_SHADER = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;\n
- varying mediump vec2 vMaskTexCoord;\n
- uniform sampler2D sTexture;\n
- uniform sampler2D sMask;\n
- uniform lowp vec4 uColor;\n
- uniform lowp vec3 mixColor;\n
- uniform lowp float opacity;\n
- uniform lowp float preMultipliedAlpha;\n
- uniform mediump float auxiliaryImageAlpha;\n
- lowp vec4 visualMixColor()\n
- {\n
- return vec4( mixColor * mix( 1.0, opacity, preMultipliedAlpha ), opacity );\n
- }\n
- void main()\n
- {\n
- // Where mask image is transparent, all of background image must show through.
- // where mask image is opaque, only mask should be shown
- // where mask is translucent, less of background should be shown.
- // auxiliaryImageAlpha controls how much of mask is visible
-
- mediump vec4 color = texture2D( sTexture, vTexCoord );\n
- mediump vec4 mask = texture2D( sMask, vMaskTexCoord );\n
-
- mediump vec3 mixedColor = color.rgb * mix( 1.0-mask.a, 1.0, 1.0-auxiliaryImageAlpha)
- + mask.rgb*mask.a * auxiliaryImageAlpha;\n
- gl_FragColor = vec4(mixedColor,1.0) * uColor * visualMixColor();\n
- }\n
-);
-
-/**
- * @brief Creates the geometry formed from the vertices and indices
- *
- * @param[in] vertices The vertices to generate the geometry from
- * @param[in] indices The indices to generate the geometry from
- * @return The geometry formed from the vertices and indices
- */
-Geometry GenerateGeometry( const Vector< Vector2 >& vertices, const Vector< unsigned short >& indices )
-{
- Property::Map vertexFormat;
- vertexFormat[ "aPosition" ] = Property::VECTOR2;
- PropertyBuffer vertexPropertyBuffer = PropertyBuffer::New( vertexFormat );
- if( vertices.Size() > 0 )
- {
- vertexPropertyBuffer.SetData( &vertices[ 0 ], vertices.Size() );
- }
-
- // Create the geometry object
- Geometry geometry = Geometry::New();
- geometry.AddVertexBuffer( vertexPropertyBuffer );
- if( indices.Size() > 0 )
- {
- geometry.SetIndexBuffer( &indices[ 0 ], indices.Size() );
- }
-
-
- return geometry;
-}
-
-/**
- * @brief Adds the indices to form a quad composed off two triangles where the indices are organised in a grid
- *
- * @param[out] indices The indices to add to
- * @param[in] rowIdx The row index to start the quad
- * @param[in] nextRowIdx The index to the next row
- */
-void AddQuadIndices( Vector< unsigned short >& indices, unsigned int rowIdx, unsigned int nextRowIdx )
-{
- indices.PushBack( rowIdx );
- indices.PushBack( nextRowIdx + 1 );
- indices.PushBack( rowIdx + 1 );
-
- indices.PushBack( rowIdx );
- indices.PushBack( nextRowIdx );
- indices.PushBack( nextRowIdx + 1 );
-}
-
-void AddVertex( Vector< Vector2 >& vertices, unsigned int x, unsigned int y )
-{
- vertices.PushBack( Vector2( x, y ) );
-}
-
-void RegisterStretchProperties( Renderer& renderer, const char * uniformName, const NinePatchImage::StretchRanges& stretchPixels, uint16_t imageExtent)
-{
- uint16_t prevEnd = 0;
- uint16_t prevFix = 0;
- uint16_t prevStretch = 0;
- unsigned int i = 1;
- for( NinePatchImage::StretchRanges::ConstIterator it = stretchPixels.Begin(); it != stretchPixels.End(); ++it, ++i )
- {
- uint16_t start = it->GetX();
- uint16_t end = it->GetY();
-
- uint16_t fix = prevFix + start - prevEnd;
- uint16_t stretch = prevStretch + end - start;
-
- std::stringstream uniform;
- uniform << uniformName << "[" << i << "]";
- renderer.RegisterProperty( uniform.str(), Vector2( fix, stretch ) );
-
- prevEnd = end;
- prevFix = fix;
- prevStretch = stretch;
- }
-
- {
- prevFix += imageExtent - prevEnd;
- std::stringstream uniform;
- uniform << uniformName << "[" << i << "]";
- renderer.RegisterProperty( uniform.str(), Vector2( prevFix, prevStretch ) );
- }