Commit bb40e8f928d340b380f1eab14f76575b83472794

Authored by Ferran Sole
1 parent 8d2e32de

Modified native image and compressed texture examples to use new texture.

* Clean-up some demos to use utility function to create quad with texture coordinates

Change-Id: I35d71cabc4140bdda298c2975f1f682d72a94176
examples/benchmark/benchmark.cpp
1 1 /*
2   - * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  2 + * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
... ... @@ -15,12 +15,12 @@
15 15 *
16 16 */
17 17  
18   -#include <dali-toolkit/dali-toolkit.h>
  18 +// EXTERNAL INCLUDES
19 19 #include <dali/devel-api/rendering/renderer.h>
20   -#include <dali/public-api/common/dali-common.h>
21   -#include <dali/integration-api/resource-policies.h>
22   -#include <dali/integration-api/debug.h>
23   -#include <iostream>
  20 +#include <dali-toolkit/dali-toolkit.h>
  21 +
  22 +// INTERNAL INCLUDES
  23 +#include "shared/utility.h"
24 24  
25 25 using namespace Dali;
26 26 using namespace Dali::Toolkit;
... ... @@ -183,29 +183,6 @@ const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
183 183 }\n
184 184 );
185 185  
186   -
187   -Geometry& QuadMesh()
188   -{
189   - static Geometry mesh;
190   - if( !mesh )
191   - {
192   - PropertyBuffer vertexBuffer;
193   - Property::Map vertexFormat;
194   - vertexFormat["aPosition"] = Property::VECTOR2;
195   - vertexFormat["aTexCoord"] = Property::VECTOR2;
196   -
197   - //Create a vertex buffer for vertex positions and texture coordinates
198   - vertexBuffer = PropertyBuffer::New( vertexFormat );
199   - vertexBuffer.SetData( gQuadWithTexture, 4u );
200   -
201   - //Create the geometry
202   - mesh = Geometry::New();
203   - mesh.AddVertexBuffer( vertexBuffer );
204   - mesh.SetGeometryType(Geometry::TRIANGLE_STRIP );
205   - }
206   - return mesh;
207   -}
208   -
209 186 bool gUseMesh(false);
210 187 bool gUseImageActor(false);
211 188 bool gNinePatch(false);
... ... @@ -213,33 +190,16 @@ unsigned int gRowsPerPage(25);
213 190 unsigned int gColumnsPerPage( 25 );
214 191 unsigned int gPageCount(13);
215 192  
216   -Renderer CreateRenderer( unsigned int index )
  193 +Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader )
217 194 {
218   -
219   - int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES;
220   - static Renderer* renderers = new Renderer[numImages];
221   - if( !renderers[index] )
222   - {
223   - //Create the renderer
224   - Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
225   -
226   - const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index];
227   - Image image = ResourceImage::New(imagePath);
228   - TextureSet textureSet = TextureSet::New();
229   - textureSet.SetImage( 0u, image );
230   - renderers[index] = Renderer::New( QuadMesh(), shader );
231   - renderers[index].SetTextures( textureSet );
232   - renderers[index].SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
233   - }
234   - return renderers[index];
235   -}
236   -
237   -Actor CreateMeshActor( unsigned int index)
238   -{
239   - Renderer renderer = CreateRenderer(index);
240   - Actor meshActor = Actor::New();
241   - meshActor.AddRenderer( renderer );
242   - return meshActor;
  195 + Renderer renderer = Renderer::New( geometry, shader );
  196 + const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index];
  197 + Texture texture = DemoHelper::LoadTexture( imagePath );
  198 + TextureSet textureSet = TextureSet::New();
  199 + textureSet.SetTexture( 0u, texture );
  200 + renderer.SetTextures( textureSet );
  201 + renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
  202 + return renderer;
243 203 }
244 204  
245 205 }
... ... @@ -348,15 +308,26 @@ public:
348 308  
349 309 void CreateMeshActors()
350 310 {
  311 + unsigned int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES;
  312 +
  313 + //Create all the renderers
  314 + std::vector<Renderer> renderers( numImages );
  315 + Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
  316 + Geometry geometry = DemoHelper::CreateTexturedQuad();
  317 + for( unsigned int i(0); i<numImages; ++i )
  318 + {
  319 + renderers[i] = CreateRenderer( i, geometry, shader );
  320 + }
  321 +
  322 + //Create the actors
351 323 Stage stage = Stage::GetCurrent();
352 324 unsigned int actorCount(mRowsPerPage*mColumnsPerPage * mPageCount);
353 325 mActor.resize(actorCount);
354 326 for( size_t i(0); i<actorCount; ++i )
355 327 {
356   - size_t numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES;
357   - mActor[i] = CreateMeshActor(i % numImages);
  328 + mActor[i] = Actor::New();
  329 + mActor[i].AddRenderer( renderers[i % numImages] );
358 330 mActor[i].SetSize(0.0f,0.0f,0.0f);
359   -
360 331 stage.Add(mActor[i]);
361 332 }
362 333 }
... ...
examples/compressed-texture-formats/compressed-texture-formats-example.cpp
... ... @@ -15,15 +15,74 @@
15 15 *
16 16 */
17 17  
  18 +// EXTERNAL INCLUDES
  19 +#include <dali/dali.h>
  20 +#include <dali/devel-api/rendering/renderer.h>
18 21 #include <dali-toolkit/dali-toolkit.h>
19 22  
  23 +// INTERNAL INCLUDES
  24 +#include "shared/utility.h"
  25 +
20 26 using namespace Dali;
21 27 using Dali::Toolkit::TextLabel;
22 28  
  29 +namespace
  30 +{
  31 +
23 32 const char* IMAGE_FILENAME_ETC = DEMO_IMAGE_DIR "tx-etc1.ktx";
24 33 const char* IMAGE_FILENAME_ASTC_LINEAR = DEMO_IMAGE_DIR "tx-astc-4x4-linear.ktx";
25 34 const char* IMAGE_FILENAME_ASTC_LINEAR_NATIVE = DEMO_IMAGE_DIR "tx-astc-4x4-linear-native.astc";
26 35  
  36 +
  37 +static const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
  38 + attribute mediump vec2 aPosition;\n
  39 + attribute mediump vec2 aTexCoord;\n
  40 + uniform mediump mat4 uMvpMatrix;\n
  41 + uniform mediump vec3 uSize;\n
  42 + varying mediump vec2 vTexCoord;\n
  43 + void main()\n
  44 + {\n
  45 + vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0);\n
  46 + gl_Position = uMvpMatrix * position;\n
  47 + vTexCoord = aTexCoord;\n
  48 + }\n
  49 +);
  50 +
  51 +static const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
  52 + uniform lowp vec4 uColor;\n
  53 + uniform sampler2D sTexture;\n
  54 + varying mediump vec2 vTexCoord;\n
  55 +
  56 + void main()\n
  57 + {\n
  58 + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
  59 + }\n
  60 +);
  61 +
  62 +/**
  63 + * @brief Create a renderer to render an image and adds it to an actor
  64 + * @param[in] imagePath The path where the image file is located
  65 + * @param[in] actor The actor that will be used to render the image
  66 + * @param[in[ geometry The geometry to use
  67 + * @param[in] shader The shader to use
  68 + */
  69 +void AddImage( const char*imagePath, Actor& actor, Geometry& geometry, Shader& shader )
  70 +{
  71 + //Load the texture
  72 + Texture texture = DemoHelper::LoadTexture( imagePath );
  73 + TextureSet textureSet = TextureSet::New();
  74 + textureSet.SetTexture( 0u, texture );
  75 +
  76 + //Create the renderer
  77 + Renderer renderer = Renderer::New( geometry, shader );
  78 + renderer.SetTextures( textureSet );
  79 +
  80 + //Set actor size and add the renderer
  81 + actor.SetSize( texture.GetWidth(), texture.GetHeight() );
  82 + actor.AddRenderer( renderer );
  83 +}
  84 +
  85 +}
27 86 /**
28 87 * @brief This example shows 3 images, each of a different compressed texture type.
29 88 * If built and run on a OpenGL ES 3.1 compatable target, then all 3 images will display.
... ... @@ -89,26 +148,37 @@ public:
89 148 table.AddChild( textLabel, Toolkit::TableView::CellPosition( 2u, 0u ) );
90 149 table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 0u ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
91 150  
92   - // Add images.
93   - Toolkit::ImageView imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ETC ) );
94   - imageView.SetAnchorPoint( AnchorPoint::CENTER );
95   - imageView.SetParentOrigin( ParentOrigin::CENTER );
96   - table.AddChild( imageView, Toolkit::TableView::CellPosition( 0u, 1u ) );
97   -
98   - imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ASTC_LINEAR ) );
99   - imageView.SetAnchorPoint( AnchorPoint::CENTER );
100   - imageView.SetParentOrigin( ParentOrigin::CENTER );
101   - table.AddChild( imageView, Toolkit::TableView::CellPosition( 1u, 1u ) );
  151 + //Create the geometry and the shader renderers will use
  152 + Geometry geometry = DemoHelper::CreateTexturedQuad();
  153 + Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
102 154  
103   - imageView = Toolkit::ImageView::New( ResourceImage::New( IMAGE_FILENAME_ASTC_LINEAR_NATIVE ) );
104   - imageView.SetAnchorPoint( AnchorPoint::CENTER );
105   - imageView.SetParentOrigin( ParentOrigin::CENTER );
106   - table.AddChild( imageView, Toolkit::TableView::CellPosition( 2u, 1u ) );
  155 + // Add images.
  156 + Actor actor = Actor::New();
  157 + actor.SetAnchorPoint( AnchorPoint::CENTER );
  158 + actor.SetParentOrigin( ParentOrigin::CENTER );
  159 + AddImage( IMAGE_FILENAME_ETC, actor, geometry, shader );
  160 + table.AddChild( actor, Toolkit::TableView::CellPosition( 0u, 1u ) );
  161 + table.SetCellAlignment( Toolkit::TableView::CellPosition( 0u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
  162 +
  163 + actor = Actor::New();
  164 + actor.SetAnchorPoint( AnchorPoint::CENTER );
  165 + actor.SetParentOrigin( ParentOrigin::CENTER );
  166 + AddImage( IMAGE_FILENAME_ASTC_LINEAR, actor, geometry, shader );
  167 + table.AddChild( actor, Toolkit::TableView::CellPosition( 1u, 1u ) );
  168 + table.SetCellAlignment( Toolkit::TableView::CellPosition( 1u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
  169 +
  170 + actor = Actor::New();
  171 + actor.SetAnchorPoint( AnchorPoint::CENTER );
  172 + actor.SetParentOrigin( ParentOrigin::CENTER );
  173 + AddImage( IMAGE_FILENAME_ASTC_LINEAR_NATIVE, actor, geometry, shader );
  174 + table.AddChild( actor, Toolkit::TableView::CellPosition( 2u, 1u ) );
  175 + table.SetCellAlignment( Toolkit::TableView::CellPosition( 2u, 1u ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
107 176  
108 177 stage.Add( table );
109 178  
110   - // Respond to a click anywhere on the stage
  179 + // Respond to touch and key signals
111 180 stage.GetRootLayer().TouchSignal().Connect( this, &CompressedTextureFormatsController::OnTouch );
  181 + stage.KeyEventSignal().Connect(this, &CompressedTextureFormatsController::OnKeyEvent);
112 182 }
113 183  
114 184 bool OnTouch( Actor actor, const TouchData& touch )
... ... @@ -118,6 +188,17 @@ public:
118 188 return true;
119 189 }
120 190  
  191 + void OnKeyEvent(const KeyEvent& event)
  192 + {
  193 + if(event.state == KeyEvent::Down)
  194 + {
  195 + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
  196 + {
  197 + mApplication.Quit();
  198 + }
  199 + }
  200 + }
  201 +
121 202 private:
122 203 Application& mApplication;
123 204 };
... ...
examples/mesh-sorting/mesh-sorting-example.cpp
... ... @@ -85,34 +85,6 @@ void main()
85 85 }
86 86 );
87 87  
88   -Geometry CreateGeometry()
89   -{
90   - // Create vertices
91   - const float halfQuadSize = .5f;
92   - struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
93   - TexturedQuadVertex texturedQuadVertexData[4] = {
94   - { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
95   - { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
96   - { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
97   - { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
98   -
99   - Property::Map texturedQuadVertexFormat;
100   - texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
101   - texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2;
102   - PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat );
103   - texturedQuadVertices.SetData( texturedQuadVertexData, 4 );
104   -
105   - // Create indices
106   - unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 };
107   -
108   - // Create the geometry object
109   - Geometry texturedQuadGeometry = Geometry::New();
110   - texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
111   - texturedQuadGeometry.SetIndexBuffer( &indexData[0], sizeof(indexData)/sizeof(unsigned short) );
112   -
113   - return texturedQuadGeometry;
114   -}
115   -
116 88 } // anonymous namespace
117 89  
118 90 // This example shows how to use a simple mesh
... ... @@ -159,7 +131,7 @@ public:
159 131 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
160 132  
161 133 mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
162   - mGeometry = CreateGeometry();
  134 + mGeometry = DemoHelper::CreateTexturedQuad();
163 135  
164 136 TextureSet firstTextureSet;
165 137  
... ...
examples/native-image-source/native-image-source-example.cpp
... ... @@ -15,15 +15,111 @@
15 15 *
16 16 */
17 17  
  18 +// EXTERNAL INCLUDES
18 19 #include <dali/dali.h>
  20 +#include <dali/devel-api/images/native-image-interface-extension.h>
  21 +#include <dali/devel-api/rendering/renderer.h>
  22 +#include <dali/devel-api/rendering/frame-buffer.h>
19 23 #include <dali-toolkit/dali-toolkit.h>
  24 +#include <cstring>
  25 +
  26 +// INTERNAL INCLUDES
  27 +#include "shared/utility.h"
20 28  
21 29 using namespace Dali;
22 30 using namespace Toolkit;
23 31  
24 32 namespace
25 33 {
26   - const std::string JPG_FILENAME = DEMO_IMAGE_DIR "gallery-medium-4.jpg";
  34 +
  35 +/**
  36 + * @brief Creates a shader used to render a native image
  37 + * @param[in] nativeImageInterface The native image interface
  38 + * @return A shader to render the native image
  39 + */
  40 +Shader CreateShader( NativeImageInterface& nativeImageInterface )
  41 +{
  42 + static const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D";
  43 +
  44 + static const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
  45 + attribute mediump vec2 aPosition;\n
  46 + attribute mediump vec2 aTexCoord;\n
  47 + uniform mediump mat4 uMvpMatrix;\n
  48 + uniform mediump vec3 uSize;\n
  49 + varying mediump vec2 vTexCoord;\n
  50 + void main()\n
  51 + {\n
  52 + vec4 position = vec4(aPosition,0.0,1.0)*vec4(uSize,1.0);\n
  53 + gl_Position = uMvpMatrix * position;\n
  54 + vTexCoord = aTexCoord;\n
  55 + }\n
  56 + );
  57 +
  58 + static const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
  59 + uniform lowp vec4 uColor;\n
  60 + uniform sampler2D sTexture;\n
  61 + varying mediump vec2 vTexCoord;\n
  62 +
  63 + void main()\n
  64 + {\n
  65 + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
  66 + }\n
  67 + );
  68 +
  69 + NativeImageInterface::Extension* extension( nativeImageInterface.GetExtension() );
  70 + if( extension )
  71 + {
  72 + std::string fragmentShader;
  73 +
  74 + //Get custom fragment shader prefix
  75 + const char* fragmentPreFix = extension->GetCustomFragmentPreFix();
  76 + if( fragmentPreFix )
  77 + {
  78 + fragmentShader = fragmentPreFix;
  79 + fragmentShader += FRAGMENT_SHADER_TEXTURE;
  80 + }
  81 + else
  82 + {
  83 + fragmentShader = FRAGMENT_SHADER_TEXTURE;
  84 + }
  85 +
  86 + //Get custom sampler type name
  87 + const char* customSamplerTypename = extension->GetCustomSamplerTypename();
  88 + if( customSamplerTypename )
  89 + {
  90 + fragmentShader.replace( fragmentShader.find( DEFAULT_SAMPLER_TYPENAME ), strlen(DEFAULT_SAMPLER_TYPENAME), customSamplerTypename );
  91 + }
  92 +
  93 + return Shader::New( VERTEX_SHADER_TEXTURE, fragmentShader );
  94 + }
  95 + else
  96 + {
  97 + return Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
  98 + }
  99 +}
  100 +
  101 +/**
  102 + * @brief Creates an actor to render a native image
  103 + * @param[in] texture The texture creates from a native image
  104 + * @param[in] nativeImageInterface The native image interface used to create the texture
  105 + * @return An actor that renders the texture
  106 + */
  107 +Actor CreateNativeActor( Texture texture, NativeImageInterface& nativeImageInterface )
  108 +{
  109 + Actor actor = Actor::New();
  110 + Geometry geometry = DemoHelper::CreateTexturedQuad();
  111 + Shader shader = CreateShader(nativeImageInterface);
  112 + Renderer renderer = Renderer::New( geometry, shader );
  113 + TextureSet textureSet = TextureSet::New();
  114 + textureSet.SetTexture( 0u, texture );
  115 + renderer.SetTextures( textureSet );
  116 +
  117 + actor.AddRenderer( renderer );
  118 + actor.SetSize( texture.GetWidth(), texture.GetHeight() );
  119 + return actor;
  120 +}
  121 +
  122 +const std::string JPG_FILENAME = DEMO_IMAGE_DIR "gallery-medium-4.jpg";
27 123 }
28 124  
29 125 // This example shows how to create and use a NativeImageSource as the target of the render task.
... ... @@ -103,7 +199,9 @@ public:
103 199 animation.Play();
104 200  
105 201 // create a offscreen renderer task to render content into the native image source
106   - FrameBufferImage targetBuffer = FrameBufferImage::New( *nativeImageSourcePtr );
  202 + Texture nativeTexture = Texture::New( *nativeImageSourcePtr );
  203 + FrameBuffer targetBuffer = FrameBuffer::New( nativeTexture.GetWidth(), nativeTexture.GetHeight(), FrameBuffer::COLOR );
  204 + targetBuffer.AttachColorTexture( nativeTexture );
107 205  
108 206 CameraActor cameraActor = CameraActor::New(imageSize);
109 207 cameraActor.SetParentOrigin(ParentOrigin::TOP_CENTER);
... ... @@ -118,25 +216,24 @@ public:
118 216 mOffscreenRenderTask.SetClearEnabled(true);
119 217 mOffscreenRenderTask.SetCameraActor(cameraActor);
120 218 mOffscreenRenderTask.GetCameraActor().SetInvertYAxis(true);
121   - mOffscreenRenderTask.SetTargetFrameBuffer( targetBuffer );
  219 + mOffscreenRenderTask.SetFrameBuffer( targetBuffer );
122 220 mOffscreenRenderTask.SetRefreshRate( RenderTask::REFRESH_ALWAYS );
123 221  
124 222 // Display the native image on the screen
125   - NativeImage nativeImage = NativeImage::New( *nativeImageSourcePtr );
126   - ImageView nativeImageView = ImageView::New( nativeImage );
127   - nativeImageView.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
128   - nativeImageView.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
129   - stage.Add( nativeImageView );
  223 + Actor nativeImageActor = CreateNativeActor( nativeTexture, *nativeImageSourcePtr );
  224 + nativeImageActor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
  225 + nativeImageActor.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
  226 + stage.Add( nativeImageActor );
130 227  
131 228 TextLabel textLabel1 = TextLabel::New( "Resource Image" );
132 229 textLabel1.SetParentOrigin( ParentOrigin::TOP_CENTER );
133 230 textLabel1.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
134   - nativeImageView.Add( textLabel1 );
  231 + nativeImageActor.Add( textLabel1 );
135 232  
136 233 TextLabel textLabel2 = TextLabel::New( "Native Image" );
137 234 textLabel2.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
138 235 textLabel2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
139   - nativeImageView.Add( textLabel2 );
  236 + nativeImageActor.Add( textLabel2 );
140 237  
141 238 return false;
142 239 }
... ...
examples/perf-scroll/perf-scroll.cpp
1 1 /*
2   - * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  2 + * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
... ... @@ -15,13 +15,8 @@
15 15 *
16 16 */
17 17  
18   -#include <dali-toolkit/dali-toolkit.h>
19 18 #include <dali/devel-api/rendering/renderer.h>
20   -#include <dali/devel-api/rendering/sampler.h>
21   -#include <dali/public-api/common/dali-common.h>
22   -#include <dali/integration-api/resource-policies.h>
23   -#include <dali/integration-api/debug.h>
24   -#include <iostream>
  19 +#include <dali-toolkit/dali-toolkit.h>
25 20  
26 21 #include "shared/utility.h"
27 22  
... ... @@ -186,29 +181,6 @@ const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
186 181 }\n
187 182 );
188 183  
189   -
190   -Geometry& QuadMesh()
191   -{
192   - static Geometry mesh;
193   - if( !mesh )
194   - {
195   - PropertyBuffer vertexBuffer;
196   - Property::Map vertexFormat;
197   - vertexFormat["aPosition"] = Property::VECTOR2;
198   - vertexFormat["aTexCoord"] = Property::VECTOR2;
199   -
200   - //Create a vertex buffer for vertex positions and texture coordinates
201   - vertexBuffer = PropertyBuffer::New( vertexFormat );
202   - vertexBuffer.SetData( gQuadWithTexture, 4u );
203   -
204   - //Create the geometry
205   - mesh = Geometry::New();
206   - mesh.AddVertexBuffer( vertexBuffer );
207   - mesh.SetGeometryType( Geometry::TRIANGLE_STRIP );
208   - }
209   - return mesh;
210   -}
211   -
212 184 bool gUseMesh(false);
213 185 bool gNinePatch(false);
214 186 unsigned int gRowsPerPage(15);
... ... @@ -216,35 +188,18 @@ unsigned int gColumnsPerPage(15);
216 188 unsigned int gPageCount(10);
217 189 float gDuration(10.0f);
218 190  
219   -Renderer CreateRenderer( unsigned int index )
  191 +Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader )
220 192 {
221   -
222   - int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES;
223   - static Renderer* renderers = new Renderer[numImages];
224   - if( !renderers[index] )
225   - {
226   - //Create the renderer
227   - Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
228   -
229   - const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index];
230   - Texture texture = DemoHelper::LoadTexture( imagePath );
231   -
232   - TextureSet textureSet = TextureSet::New();
233   - textureSet.SetTexture( 0u, texture );
234   - renderers[index] = Renderer::New( QuadMesh(), shader );
235   - renderers[index].SetTextures( textureSet );
236   - renderers[index].SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
237   - }
238   - return renderers[index];
  193 + Renderer renderer = Renderer::New( geometry, shader );
  194 + const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index];
  195 + Texture texture = DemoHelper::LoadTexture( imagePath );
  196 + TextureSet textureSet = TextureSet::New();
  197 + textureSet.SetTexture( 0u, texture );
  198 + renderer.SetTextures( textureSet );
  199 + renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
  200 + return renderer;
239 201 }
240 202  
241   -Actor CreateMeshActor( unsigned int index)
242   -{
243   - Renderer renderer = CreateRenderer( index );
244   - Actor meshActor = Actor::New();
245   - meshActor.AddRenderer( renderer );
246   - return meshActor;
247   -}
248 203  
249 204 }
250 205 // Test application to compare performance between ImageActor and ImageView
... ... @@ -333,18 +288,27 @@ public:
333 288  
334 289 void CreateMeshActors()
335 290 {
336   - Stage stage = Stage::GetCurrent();
  291 + unsigned int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES;
337 292  
338   - unsigned int actorCount( mRowsPerPage * mColumnsPerPage * mPageCount );
339   - mActor.resize( actorCount );
  293 + //Create all the renderers
  294 + std::vector<Renderer> renderers( numImages );
  295 + Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
  296 + Geometry geometry = DemoHelper::CreateTexturedQuad();
  297 + for( unsigned int i(0); i<numImages; ++i )
  298 + {
  299 + renderers[i] = CreateRenderer( i, geometry, shader );
  300 + }
340 301  
  302 + //Create the actors
  303 + Stage stage = Stage::GetCurrent();
  304 + unsigned int actorCount(mRowsPerPage*mColumnsPerPage * mPageCount);
  305 + mActor.resize(actorCount);
341 306 for( size_t i(0); i<actorCount; ++i )
342 307 {
343   - size_t numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES;
344   - mActor[i] = CreateMeshActor( i % numImages );
  308 + mActor[i] = Actor::New();
  309 + mActor[i].AddRenderer( renderers[i % numImages] );
345 310 mActor[i].SetSize(0.0f,0.0f,0.0f);
346   -
347   - mParent.Add( mActor[i] );
  311 + mParent.Add(mActor[i]);
348 312 }
349 313 }
350 314  
... ...
examples/textured-mesh/textured-mesh-example.cpp
... ... @@ -62,34 +62,6 @@ void main()
62 62 }
63 63 );
64 64  
65   -Geometry CreateGeometry()
66   -{
67   - // Create vertices
68   - const float halfQuadSize = .5f;
69   - struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
70   - TexturedQuadVertex texturedQuadVertexData[4] = {
71   - { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
72   - { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
73   - { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) },
74   - { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } };
75   -
76   - Property::Map texturedQuadVertexFormat;
77   - texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
78   - texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2;
79   - PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat );
80   - texturedQuadVertices.SetData( texturedQuadVertexData, 4 );
81   -
82   - // Create indices
83   - unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 };
84   -
85   - // Create the geometry object
86   - Geometry texturedQuadGeometry = Geometry::New();
87   - texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
88   - texturedQuadGeometry.SetIndexBuffer( &indexData[0], sizeof(indexData)/sizeof(indexData[0]) );
89   -
90   - return texturedQuadGeometry;
91   -}
92   -
93 65 /**
94 66 * Sinusoidal curve starting at zero with 2 cycles
95 67 */
... ... @@ -151,7 +123,7 @@ public:
151 123 mTextureSet2 = TextureSet::New();
152 124 mTextureSet2.SetTexture( 0u, texture2 );
153 125  
154   - mGeometry = CreateGeometry();
  126 + mGeometry = DemoHelper::CreateTexturedQuad();
155 127  
156 128 mRenderer = Renderer::New( mGeometry, mShader );
157 129 mRenderer.SetTextures( mTextureSet1 );
... ...
shared/utility.h
... ... @@ -20,6 +20,7 @@
20 20  
21 21 #include <dali/dali.h>
22 22 #include <dali/devel-api/images/atlas.h>
  23 +#include <dali/devel-api/rendering/geometry.h>
23 24 #include <dali/devel-api/rendering/texture.h>
24 25 #include <dali/devel-api/adaptor-framework/bitmap-loader.h>
25 26  
... ... @@ -86,6 +87,35 @@ Dali::Texture LoadStageFillingTexture( const char* imagePath )
86 87 return LoadTexture( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
87 88 }
88 89  
  90 +Dali::Geometry CreateTexturedQuad()
  91 +{
  92 + struct Vertex
  93 + {
  94 + Dali::Vector2 position;
  95 + Dali::Vector2 texCoord;
  96 + };
  97 +
  98 + static const Vertex data[] = {{ Dali::Vector2( -0.5f, -0.5f ), Dali::Vector2( 0.0f, 0.0f ) },
  99 + { Dali::Vector2( 0.5f, -0.5f ), Dali::Vector2( 1.0f, 0.0f ) },
  100 + { Dali::Vector2( -0.5f, 0.5f ), Dali::Vector2( 0.0f, 1.0f ) },
  101 + { Dali::Vector2( 0.5f, 0.5f ), Dali::Vector2( 1.0f, 1.0f ) }};
  102 +
  103 + Dali::PropertyBuffer vertexBuffer;
  104 + Dali::Property::Map vertexFormat;
  105 + vertexFormat["aPosition"] = Dali::Property::VECTOR2;
  106 + vertexFormat["aTexCoord"] = Dali::Property::VECTOR2;
  107 +
  108 + //Create a vertex buffer for vertex positions and texture coordinates
  109 + vertexBuffer = Dali::PropertyBuffer::New( vertexFormat );
  110 + vertexBuffer.SetData( data, 4u );
  111 +
  112 + //Create the geometry
  113 + Dali::Geometry geometry = Dali::Geometry::New();
  114 + geometry.AddVertexBuffer( vertexBuffer );
  115 + geometry.SetGeometryType(Dali::Geometry::TRIANGLE_STRIP );
  116 +
  117 + return geometry;
  118 +}
89 119 } // DemoHelper
90 120  
91 121 #endif // __DALI_DEMO_HELPER_VIEW_H__
... ...