Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-demo.git] / examples / metaball-explosion / metaball-explosion-example.cpp
index 1c76add..39519b8 100644 (file)
@@ -31,14 +31,14 @@ using namespace Dali::Toolkit;
 
 namespace
 {
-const char * const BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-2.jpg" );
-const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
+const char * const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-2.jpg" );
+const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
 
 const float GRAVITY_X(0);
 const float GRAVITY_Y(-0.09);
 }
 
-#define METABALL_NUMBER 12
+#define METABALL_NUMBER 6
 
 
 const char*const METABALL_VERTEX_SHADER = DALI_COMPOSE_SHADER (
@@ -299,7 +299,7 @@ private:
 
 //-----------------------------------------------------------------------------------------------
 //
-//     IMPLEMENTATION
+//  IMPLEMENTATION
 //
 //----------------
 
@@ -373,34 +373,29 @@ Geometry MetaballExplosionController::CreateGeometry()
     { Vector2(1.0f, 1.0f * aspect) }
   };
 
-  int indices[] = { 0, 3, 1, 0, 2, 3 };
-
   unsigned int numberOfVertices = sizeof(vertices)/sizeof(VertexPosition);
 
   //Vertices
   Property::Map positionVertexFormat;
   positionVertexFormat["aPosition"] = Property::VECTOR2;
-  PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat, numberOfVertices );
-  positionVertices.SetData(vertices);
+  PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat );
+  positionVertices.SetData( vertices, numberOfVertices );
 
   //Textures
   Property::Map textureVertexFormat;
   textureVertexFormat["aTexture"] = Property::VECTOR2;
-  PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat, numberOfVertices );
-  textureVertices.SetData(textures);
+  PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat );
+  textureVertices.SetData( textures, numberOfVertices );
 
   //Indices
-  Property::Map indicesVertexFormat;
-  indicesVertexFormat["aIndices"] = Property::INTEGER;
-  PropertyBuffer indicesToVertices = PropertyBuffer::New( indicesVertexFormat, 6 );
-  indicesToVertices.SetData(indices);
+  unsigned short indices[] = { 0, 3, 1, 0, 2, 3 };
 
   // Create the geometry object
   Geometry texturedQuadGeometry = Geometry::New();
   texturedQuadGeometry.AddVertexBuffer( positionVertices );
   texturedQuadGeometry.AddVertexBuffer( textureVertices );
 
-  texturedQuadGeometry.SetIndexBuffer ( indicesToVertices );
+  texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) );
 
   return texturedQuadGeometry;
 }
@@ -431,34 +426,29 @@ Geometry MetaballExplosionController::CreateGeometryComposition()
     { Vector2(1.0f, 1.0f) }
   };
 
-  int indices[] = { 0, 3, 1, 0, 2, 3 };
-
   unsigned int numberOfVertices = sizeof(vertices)/sizeof(VertexPosition);
 
   //Vertices
   Property::Map positionVertexFormat;
   positionVertexFormat["aPosition"] = Property::VECTOR2;
-  PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat, numberOfVertices );
-  positionVertices.SetData(vertices);
+  PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat );
+  positionVertices.SetData( vertices, numberOfVertices );
 
   //Textures
   Property::Map textureVertexFormat;
   textureVertexFormat["aTexture"] = Property::VECTOR2;
-  PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat, numberOfVertices );
-  textureVertices.SetData(textures);
+  PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat );
+  textureVertices.SetData( textures, numberOfVertices );
 
   //Indices
-  Property::Map indicesVertexFormat;
-  indicesVertexFormat["aIndices"] = Property::INTEGER;
-  PropertyBuffer indicesToVertices = PropertyBuffer::New( indicesVertexFormat, 6 );
-  indicesToVertices.SetData(indices);
+  unsigned short indices[] = { 0, 3, 1, 0, 2, 3 };
 
   // Create the geometry object
   Geometry texturedQuadGeometry = Geometry::New();
   texturedQuadGeometry.AddVertexBuffer( positionVertices );
   texturedQuadGeometry.AddVertexBuffer( textureVertices );
 
-  texturedQuadGeometry.SetIndexBuffer ( indicesToVertices );
+  texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) );
 
   return texturedQuadGeometry;
 }
@@ -474,24 +464,20 @@ void MetaballExplosionController::CreateMetaballActors()
   //Create the shader for the metaballs
   Shader shader = Shader::New( METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER );
 
-  Material material = Material::New( shader );
-  material.SetBlendMode(BlendingMode::ON );
-  material.SetBlendFunc(BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE);
-
   Geometry metaballGeom = CreateGeometry();
-
+  Renderer renderer = Renderer::New( metaballGeom, shader );
+  renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON );
+  renderer.SetBlendFunc(BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE);
   //Initialization of each of the metaballs
   for( int i = 0; i < METABALL_NUMBER; i++ )
   {
     mMetaballs[i].position = Vector2(0.0f, 0.0f);
-    mMetaballs[i].radius = mMetaballs[i].initRadius = randomNumber(0.025f,0.035f);
+    mMetaballs[i].radius = mMetaballs[i].initRadius = randomNumber(0.05f,0.07f);
 
     mMetaballs[i].actor = Actor::New( );
     mMetaballs[i].actor.SetName("Metaball");
     mMetaballs[i].actor.SetScale( 1.0f );
     mMetaballs[i].actor.SetParentOrigin( ParentOrigin::CENTER );
-
-    Renderer renderer = Renderer::New( metaballGeom, material );
     mMetaballs[i].actor.AddRenderer( renderer );
 
     mMetaballs[i].positionIndex = mMetaballs[i].actor.RegisterProperty( "uPositionMetaball", mMetaballs[i].position );
@@ -557,17 +543,17 @@ void MetaballExplosionController::AddRefractionImage()
 
   //Create new shader
   Shader shader = Shader::New( METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER );
-  //Create new material
-  Material material = Material::New( shader );
 
-  //Add Textures
-  material.AddTexture(mBackImage, "sTexture");
-  material.AddTexture(fbo, "sEffect");
+  //Create new texture set
+  TextureSet textureSet = TextureSet::New();
+  textureSet.SetImage( 0u, mBackImage );
+  textureSet.SetImage( 1u, fbo );
 
   //Create geometry
   Geometry metaballGeom = CreateGeometryComposition();
 
-  Renderer mRenderer = Renderer::New( metaballGeom, material );
+  Renderer mRenderer = Renderer::New( metaballGeom, shader );
+  mRenderer.SetTextures( textureSet );
 
   mCompositionActor = Actor::New( );
   mCompositionActor.SetParentOrigin(ParentOrigin::CENTER);
@@ -753,7 +739,7 @@ void RunTest( Application& application )
 
 // Entry point for Linux & Tizen applications
 //
-int main( int argc, char **argv )
+int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv );