Merge "Implemented n-patch rendering for NPatchRenderer." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / npatch / npatch-renderer.cpp
1 /*
2  * Copyright (c) 2015 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 "npatch-renderer.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/platform-abstraction.h>
23 #include <dali/public-api/images/buffer-image.h>
24 #include <dali/public-api/images/resource-image.h>
25
26 // INTERNAL IINCLUDES
27 #include <dali-toolkit/internal/controls/renderers/renderer-factory-impl.h>
28 #include <dali-toolkit/internal/controls/renderers/renderer-factory-cache.h>
29 #include <dali-toolkit/internal/controls/renderers/control-renderer-impl.h>
30 #include <dali-toolkit/internal/controls/renderers/control-renderer-data-impl.h>
31
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 namespace
43 {
44 const char * const RENDERER_TYPE("renderer-type");
45 const char * const RENDERER_TYPE_VALUE("n-patch-renderer");
46
47 const char * const IMAGE_URL_NAME("image-url");
48 const char * const BORDER_ONLY("border-only");
49
50 std::string TEXTURE_UNIFORM_NAME = "sTexture";
51
52 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
53   attribute mediump vec2 aPosition;\n
54   varying mediump vec2 vTexCoord;\n
55   uniform mediump mat4 uMvpMatrix;\n
56   uniform mediump vec3 uSize;\n
57   uniform mediump vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];\n
58   uniform mediump vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];\n
59   \n
60   void main()\n
61   {\n
62     mediump vec2 fixedFactor  = vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );\n
63     mediump vec2 stretch      = vec2( uNinePatchFactorsX[ int( ( aPosition.x       ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y       ) * 0.5 ) ].y );\n
64     \n
65     mediump vec2 fixedTotal   = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );\n
66     mediump vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );\n
67     \n
68     mediump vec4 vertexPosition = vec4( ( fixedFactor + ( uSize.xy - fixedTotal ) * stretch / stretchTotal ), 0.0, 1.0 );\n
69     vertexPosition.xy -= uSize.xy * vec2( 0.5, 0.5 );\n
70     vertexPosition = uMvpMatrix * vertexPosition;\n
71     \n
72     vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );\n
73     \n
74     gl_Position = vertexPosition;\n
75   }\n
76 );
77
78 const char* VERTEX_SHADER_3X3 = DALI_COMPOSE_SHADER(
79     attribute mediump vec2 aPosition;\n
80     varying mediump vec2 vTexCoord;\n
81     uniform mediump mat4 uModelMatrix;\n
82     uniform mediump mat4 uMvpMatrix;\n
83     uniform mediump vec3 uSize;\n
84     uniform mediump vec2 uFixed[ 3 ];\n
85     uniform mediump vec2 uStretchTotal;\n
86     \n
87     void main()\n
88     {\n
89       mediump vec2 scale        = vec2( length( uModelMatrix[ 0 ].xyz ), length( uModelMatrix[ 1 ].xyz ) );\n
90       mediump vec2 size         = uSize.xy * scale;\n
91       \n
92       mediump vec2 fixedFactor  = vec2( uFixed[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uFixed[ int( ( aPosition.y  + 1.0 ) * 0.5 ) ].y );\n
93       mediump vec2 stretch      = floor( aPosition * 0.5 );\n
94       mediump vec2 fixedTotal   = uFixed[ 2 ];\n
95       \n
96       mediump vec4 vertexPosition = vec4( fixedFactor + ( size - fixedTotal ) * stretch, 0.0, 1.0 );\n
97       vertexPosition.xy -= size * vec2( 0.5, 0.5 );\n
98       vertexPosition.xy =  vertexPosition.xy / scale;\n
99       \n
100       vertexPosition = uMvpMatrix * vertexPosition;\n
101       \n
102       vTexCoord = ( fixedFactor + stretch * uStretchTotal ) / ( fixedTotal + uStretchTotal );\n
103       \n
104       gl_Position = vertexPosition;\n
105     }\n
106 );
107
108 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
109   varying mediump vec2 vTexCoord;\n
110   uniform sampler2D sTexture;\n
111   uniform lowp vec4 uColor;\n
112   \n
113   void main()\n
114   {\n
115     gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
116   }\n
117 );
118
119 /**
120  * @brief Creates the geometry formed from the vertices and indices
121  *
122  * @param[in]  vertices             The vertices to generate the geometry from
123  * @param[in]  indices              The indices to generate the geometry from
124  * @return The geometry formed from the vertices and indices
125  */
126 Geometry GenerateGeometry( const Vector< Vector2 >& vertices, const Vector< unsigned int >& indices )
127 {
128   Property::Map vertexFormat;
129   vertexFormat[ "aPosition" ] = Property::VECTOR2;
130   PropertyBuffer vertexPropertyBuffer = PropertyBuffer::New( vertexFormat, vertices.Size() );
131   if( vertices.Size() > 0 )
132   {
133     vertexPropertyBuffer.SetData( &vertices[ 0 ] );
134   }
135
136   Property::Map indexFormat;
137   indexFormat[ "indices" ] = Property::INTEGER;
138   PropertyBuffer indexPropertyBuffer = PropertyBuffer::New( indexFormat, indices.Size() );
139   if( indices.Size() > 0 )
140   {
141     indexPropertyBuffer.SetData( &indices[ 0 ] );
142   }
143
144   // Create the geometry object
145   Geometry geometry = Geometry::New();
146   geometry.AddVertexBuffer( vertexPropertyBuffer );
147   geometry.SetIndexBuffer( indexPropertyBuffer );
148
149   return geometry;
150 }
151
152 /**
153  * @brief Adds the indices to form a quad composed off two triangles where the indices are organised in a grid
154  *
155  * @param[out] indices     The indices to add to
156  * @param[in]  rowIdx      The row index to start the quad
157  * @param[in]  nextRowIdx  The index to the next row
158  */
159 void AddQuadIndices( Vector< unsigned int >& indices, unsigned int rowIdx, unsigned int nextRowIdx )
160 {
161   indices.PushBack( rowIdx );
162   indices.PushBack( nextRowIdx + 1 );
163   indices.PushBack( rowIdx + 1 );
164
165   indices.PushBack( rowIdx );
166   indices.PushBack( nextRowIdx );
167   indices.PushBack( nextRowIdx + 1 );
168 }
169
170 void AddVertex( Vector< Vector2 >& vertices, unsigned int x, unsigned int y )
171 {
172   vertices.PushBack( Vector2( x, y ) );
173 }
174
175 void RegisterStretchProperties( Sampler& sampler, const char * uniformName, const NinePatchImage::StretchRanges& stretchPixels, uint16_t imageExtent)
176 {
177   uint16_t prevEnd = 0;
178   uint16_t prevFix = 0;
179   uint16_t prevStretch = 0;
180   unsigned int i = 1;
181   for( NinePatchImage::StretchRanges::ConstIterator it = stretchPixels.Begin(); it != stretchPixels.End(); ++it, ++i )
182   {
183     uint16_t start = it->GetX();
184     uint16_t end = it->GetY();
185
186     uint16_t fix = prevFix + start - prevEnd;
187     uint16_t stretch = prevStretch + end - start;
188
189     std::stringstream uniform;
190     uniform << uniformName << "[" << i << "]";
191     sampler.RegisterProperty( uniform.str(), Vector2( fix, stretch ) );
192
193     prevEnd = end;
194     prevFix = fix;
195     prevStretch = stretch;
196   }
197
198   {
199     prevFix += imageExtent - prevEnd;
200     std::stringstream uniform;
201     uniform << uniformName << "[" << i << "]";
202     sampler.RegisterProperty( uniform.str(), Vector2( prevFix, prevStretch ) );
203   }
204 }
205
206 } //unnamed namespace
207
208 /////////////////NPatchRenderer////////////////
209
210 NPatchRenderer::NPatchRenderer( RendererFactoryCache& factoryCache )
211 : ControlRenderer( factoryCache ),
212   mBorderOnly( false )
213 {
214 }
215
216 NPatchRenderer::~NPatchRenderer()
217 {
218 }
219
220 void NPatchRenderer::DoInitialize( const Property::Map& propertyMap )
221 {
222   Property::Value* imageURLValue = propertyMap.Find( IMAGE_URL_NAME );
223   if( imageURLValue )
224   {
225     //Read the border-only property first since InitialiseFromImage relies on mBorderOnly to be properly set
226     Property::Value* borderOnlyValue = propertyMap.Find( BORDER_ONLY );
227     if( borderOnlyValue )
228     {
229       borderOnlyValue->Get( mBorderOnly );
230     }
231
232     if( imageURLValue->Get( mImageUrl ) )
233     {
234       NinePatchImage nPatch = NinePatchImage::New( mImageUrl );
235       InitialiseFromImage( nPatch );
236     }
237     else
238     {
239       CreateErrorImage();
240       DALI_LOG_ERROR( "The property '%s' is not a string\n", IMAGE_URL_NAME );
241     }
242   }
243 }
244
245 void NPatchRenderer::GetNaturalSize( Vector2& naturalSize ) const
246 {
247   if( mImage )
248   {
249     naturalSize.x = mImage.GetWidth();
250     naturalSize.y = mImage.GetHeight();
251     return;
252   }
253   else if( !mImageUrl.empty() )
254   {
255     ImageDimensions dimentions = ResourceImage::GetImageSize( mImageUrl );
256     naturalSize.x = dimentions.GetWidth();
257     naturalSize.y = dimentions.GetHeight();
258     return;
259   }
260
261   naturalSize = Vector2::ZERO;
262 }
263
264 void NPatchRenderer::SetClipRect( const Rect<int>& clipRect )
265 {
266   ControlRenderer::SetClipRect( clipRect );
267   //ToDo: renderer responds to the clipRect change
268 }
269
270 void NPatchRenderer::SetOffset( const Vector2& offset )
271 {
272   //ToDo: renderer applies the offset
273 }
274
275 void NPatchRenderer::InitializeRenderer( Renderer& renderer )
276 {
277   Geometry geometry;
278   Shader shader;
279   if( mStretchPixelsX.Size() == 1 && mStretchPixelsY.Size() == 1 )
280   {
281     if( !mBorderOnly )
282     {
283       geometry = mFactoryCache.GetGeometry( RendererFactoryCache::NINE_PATCH_GEOMETRY );
284       if( !geometry )
285       {
286         geometry = CreateGeometry( Uint16Pair( 3, 3 ) );
287         mFactoryCache.SaveGeometry( RendererFactoryCache::NINE_PATCH_GEOMETRY, geometry );
288       }
289     }
290     else
291     {
292       geometry = mFactoryCache.GetGeometry( RendererFactoryCache::NINE_PATCH_BORDER_GEOMETRY );
293       if( !geometry )
294       {
295         geometry = CreateGeometryBorder( Uint16Pair( 3, 3 ) );
296         mFactoryCache.SaveGeometry( RendererFactoryCache::NINE_PATCH_BORDER_GEOMETRY, geometry );
297       }
298     }
299
300     shader = mFactoryCache.GetShader( RendererFactoryCache::NINE_PATCH_SHADER );
301     if( !shader )
302     {
303       shader = Shader::New( VERTEX_SHADER_3X3, FRAGMENT_SHADER );
304       mFactoryCache.SaveShader( RendererFactoryCache::NINE_PATCH_SHADER, shader );
305     }
306   }
307   else if( mStretchPixelsX.Size() > 0 || mStretchPixelsY.Size() > 0)
308   {
309     Uint16Pair gridSize( 2 * mStretchPixelsX.Size() + 1,  2 * mStretchPixelsY.Size() + 1 );
310     geometry = !mBorderOnly ? CreateGeometry( gridSize ) : CreateGeometryBorder( gridSize );
311
312     std::stringstream vertexShader;
313     vertexShader << "#define FACTOR_SIZE_X " << mStretchPixelsX.Size() + 2 << "\n"
314                  << "#define FACTOR_SIZE_Y " << mStretchPixelsY.Size() + 2 << "\n"
315                  << VERTEX_SHADER;
316
317     shader = Shader::New( vertexShader.str(), FRAGMENT_SHADER );
318   }
319   else
320   {
321     DALI_LOG_ERROR("The 9 patch image '%s' doesn't have any valid stretch borders and so is not a valid 9 patch image\n", mImageUrl.c_str() );
322     CreateErrorImage();
323   }
324
325   if( !renderer )
326   {
327     Material material = Material::New( shader );
328     renderer = Renderer::New( geometry, material );
329   }
330   else
331   {
332     mImpl->mRenderer.SetGeometry( geometry );
333     Material material = mImpl->mRenderer.GetMaterial();
334     if( material )
335     {
336       material.SetShader( shader );
337     }
338   }
339 }
340
341 void NPatchRenderer::DoSetOnStage( Actor& actor )
342 {
343   if( !mCroppedImage )
344   {
345     if( !mImageUrl.empty() )
346     {
347       NinePatchImage nPatch = NinePatchImage::New( mImageUrl );
348       InitialiseFromImage( nPatch );
349     }
350     else if( mImage )
351     {
352       InitialiseFromImage( mImage );
353     }
354
355     InitializeRenderer( mImpl->mRenderer );
356   }
357
358   if( mCroppedImage )
359   {
360     ApplyImageToSampler();
361   }
362 }
363
364 void NPatchRenderer::DoSetOffStage( Actor& actor )
365 {
366   mCroppedImage.Reset();
367 }
368
369 void NPatchRenderer::DoCreatePropertyMap( Property::Map& map ) const
370 {
371   map.Clear();
372   map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE );
373   if( !mImageUrl.empty() )
374   {
375     map.Insert( IMAGE_URL_NAME, mImageUrl );
376   }
377   else if( mImage )
378   {
379     map.Insert( IMAGE_URL_NAME, mImage.GetUrl() );
380   }
381   map.Insert( BORDER_ONLY, mBorderOnly );
382 }
383
384 void NPatchRenderer::SetImage( const std::string& imageUrl, bool borderOnly )
385 {
386   mBorderOnly = borderOnly;
387   mImage.Reset();
388   if( mImageUrl == imageUrl )
389   {
390     return;
391   }
392
393   mImageUrl = imageUrl;
394   NinePatchImage nPatch = NinePatchImage::New( mImageUrl );
395   InitialiseFromImage( nPatch );
396
397   if( mCroppedImage && mImpl->mIsOnStage )
398   {
399     ApplyImageToSampler();
400   }
401 }
402
403 void NPatchRenderer::SetImage( NinePatchImage image, bool borderOnly )
404 {
405   mBorderOnly = borderOnly;
406   mImageUrl.empty();
407   if( mImage == image )
408   {
409     return;
410   }
411
412   mImage = image;
413   InitialiseFromImage( mImage );
414
415   if( mCroppedImage && mImpl->mIsOnStage )
416   {
417     ApplyImageToSampler();
418   }
419 }
420
421 void NPatchRenderer::InitialiseFromImage( NinePatchImage nPatch )
422 {
423   mCroppedImage = nPatch.CreateCroppedBufferImage();
424   if( !mCroppedImage )
425   {
426     DALI_LOG_ERROR("'%s' specify a valid 9 patch image\n", mImageUrl.c_str() );
427     CreateErrorImage();
428     return;
429   }
430
431   mImageSize = ImageDimensions( mCroppedImage.GetWidth(), mCroppedImage.GetHeight() );
432
433   mStretchPixelsX = nPatch.GetStretchPixelsX();
434   mStretchPixelsY = nPatch.GetStretchPixelsY();
435 }
436
437 void NPatchRenderer::CreateErrorImage()
438 {
439   mImageSize = ImageDimensions( 1, 1 );
440
441   BufferImage bufferImage = BufferImage::New( mImageSize.GetWidth(), mImageSize.GetHeight(), Pixel::RGBA8888 );
442   mCroppedImage = bufferImage;
443   PixelBuffer* pixbuf = bufferImage.GetBuffer();
444
445   for( size_t i = 0; i < mImageSize.GetWidth() * mImageSize.GetHeight() * 4u; )
446   {
447     pixbuf[ i++ ] = 0;
448     pixbuf[ i++ ] = 0;
449     pixbuf[ i++ ] = 0;
450     pixbuf[ i++ ] = 255;
451   }
452
453   mStretchPixelsX.Clear();
454   mStretchPixelsX.PushBack( Uint16Pair( 0, mImageSize.GetWidth() ) );
455   mStretchPixelsY.Clear();
456   mStretchPixelsY.PushBack( Uint16Pair( 0, mImageSize.GetHeight() ) );
457
458 }
459
460 void NPatchRenderer::ApplyImageToSampler()
461 {
462   Material material = mImpl->mRenderer.GetMaterial();
463   if( material )
464   {
465     Sampler sampler;
466     for( std::size_t i = 0; i < material.GetNumberOfSamplers(); ++i )
467     {
468       sampler = material.GetSamplerAt( i );
469       if( sampler.GetUniformName() == TEXTURE_UNIFORM_NAME )
470       {
471         sampler.SetImage( mCroppedImage );
472         break;
473       }
474     }
475     if( !sampler )
476     {
477       sampler = Sampler::New( mCroppedImage, TEXTURE_UNIFORM_NAME );
478       material.AddSampler( sampler );
479     }
480
481     if( mStretchPixelsX.Size() == 1 && mStretchPixelsY.Size() == 1 )
482     {
483       //special case for 9 patch
484       Uint16Pair stretchX = mStretchPixelsX[ 0 ];
485       Uint16Pair stretchY = mStretchPixelsY[ 0 ];
486
487       uint16_t stretchWidth = stretchX.GetY() - stretchX.GetX();
488       uint16_t stretchHeight = stretchY.GetY() - stretchY.GetX();
489
490       sampler.RegisterProperty( "uFixed[0]", Vector2::ZERO );
491       sampler.RegisterProperty( "uFixed[1]", Vector2( stretchX.GetX(), stretchY.GetX()) );
492       sampler.RegisterProperty( "uFixed[2]", Vector2( mImageSize.GetWidth() - stretchWidth, mImageSize.GetHeight() - stretchHeight ) );
493       sampler.RegisterProperty( "uStretchTotal", Vector2( stretchWidth, stretchHeight ) );
494     }
495     else
496     {
497       sampler.RegisterProperty( "uNinePatchFactorsX[0]", Vector2::ZERO );
498       sampler.RegisterProperty( "uNinePatchFactorsY[0]", Vector2::ZERO );
499
500       RegisterStretchProperties( sampler, "uNinePatchFactorsX", mStretchPixelsX, mImageSize.GetWidth() );
501       RegisterStretchProperties( sampler, "uNinePatchFactorsY", mStretchPixelsY, mImageSize.GetHeight() );
502     }
503   }
504 }
505
506 Geometry NPatchRenderer::CreateGeometry( Uint16Pair gridSize )
507 {
508   uint16_t gridWidth = gridSize.GetWidth();
509   uint16_t gridHeight = gridSize.GetHeight();
510
511   // Create vertices
512   Vector< Vector2 > vertices;
513   vertices.Reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) );
514
515   for( int y = 0; y < gridHeight + 1; ++y )
516   {
517     for( int x = 0; x < gridWidth + 1; ++x )
518     {
519       AddVertex( vertices, x, y );
520     }
521   }
522
523   // Create indices
524   //TODO: compare performance with triangle strip when Geometry supports it
525   Vector< unsigned int > indices;
526   indices.Reserve( gridWidth * gridHeight * 6 );
527
528   unsigned int rowIdx     = 0;
529   unsigned int nextRowIdx = gridWidth + 1;
530   for( int y = 0; y < gridHeight; ++y, ++nextRowIdx, ++rowIdx )
531   {
532     for( int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx )
533     {
534       AddQuadIndices( indices, rowIdx, nextRowIdx );
535     }
536   }
537
538   return GenerateGeometry( vertices, indices );
539 }
540
541 Geometry NPatchRenderer::CreateGeometryBorder( Uint16Pair gridSize )
542 {
543   uint16_t gridWidth = gridSize.GetWidth();
544   uint16_t gridHeight = gridSize.GetHeight();
545
546   // Create vertices
547   Vector< Vector2 > vertices;
548   vertices.Reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) );
549
550   //top
551   int y = 0;
552   for(; y < 2; ++y)
553   {
554     for( int x = 0; x < gridWidth + 1; ++x )
555     {
556       AddVertex( vertices, x, y );
557     }
558   }
559
560   for(; y < gridHeight - 1; ++y)
561   {
562     //left
563     AddVertex( vertices, 0, y );
564     AddVertex( vertices, 1, y );
565
566     //right
567     AddVertex( vertices, gridWidth - 1, y );
568     AddVertex( vertices, gridWidth, y );
569   }
570
571   //bottom
572   for(; y < gridHeight + 1; ++y)
573   {
574     for( int x = 0; x < gridWidth + 1; ++x )
575     {
576       AddVertex( vertices, x, y );
577     }
578   }
579
580   // Create indices
581   //TODO: compare performance with triangle strip when Geometry supports it
582   Vector< unsigned int > indices;
583   indices.Reserve( gridWidth * gridHeight * 6 );
584
585   //top
586   unsigned int rowIdx     = 0 ;
587   unsigned int nextRowIdx = gridWidth + 1;
588   for( int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx )
589   {
590     AddQuadIndices( indices, rowIdx, nextRowIdx );
591   }
592
593   if(gridHeight > 2)
594   {
595     rowIdx     = gridWidth + 1;
596     nextRowIdx = ( gridWidth + 1 ) * 2;
597
598     unsigned increment = gridWidth - 1;
599     if(gridHeight > 3)
600     {
601       increment = 2;
602       //second row left
603       AddQuadIndices( indices, rowIdx, nextRowIdx );
604
605       rowIdx     = gridWidth * 2;
606       nextRowIdx = ( gridWidth + 1 ) * 2 + 2;
607       //second row right
608       AddQuadIndices( indices, rowIdx, nextRowIdx );
609
610       //left and right
611       rowIdx     = nextRowIdx - 2;
612       nextRowIdx = rowIdx + 4;
613       for(int y = 2; y < 2*(gridHeight - 3); ++y, rowIdx += 2, nextRowIdx += 2)
614       {
615         AddQuadIndices( indices, rowIdx, nextRowIdx );
616       }
617     }
618
619     //second row left
620     AddQuadIndices( indices, rowIdx, nextRowIdx );
621
622     rowIdx     += increment;
623     nextRowIdx += gridWidth - 1;
624     //second row right
625     AddQuadIndices( indices, rowIdx, nextRowIdx );
626   }
627
628   //bottom
629   rowIdx     = nextRowIdx - gridWidth + 1;
630   nextRowIdx = rowIdx + gridWidth + 1;
631   for( int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx )
632   {
633     AddQuadIndices( indices, rowIdx, nextRowIdx );
634   }
635
636   return GenerateGeometry( vertices, indices );
637 }
638
639 } // namespace Internal
640
641 } // namespace Toolkit
642
643 } // namespace Dali