Using migrated Public Visual API
[platform/core/uifw/dali-demo.git] / examples / mesh-sorting / mesh-sorting-example.cpp
index 248a4c3..35300d5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
  */
 
 // EXTERNAL INCLUDES
-#include <dali/devel-api/rendering/renderer.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <stdio.h>
 #include <sstream>
 
 // INTERNAL INCLUDES
 #include "shared/view.h"
+#include "shared/utility.h"
 
 using namespace Dali;
 
 namespace
 {
 
-const char* MATERIAL_SAMPLES[] =
+const char* IMAGES[] =
 {
-  DALI_IMAGE_DIR "people-medium-1.jpg",
-  DALI_IMAGE_DIR "people-medium-4.jpg",
-  DALI_IMAGE_DIR "people-medium-11.jpg",
-  DALI_IMAGE_DIR "people-small-16.jpg",
-  DALI_IMAGE_DIR "people-medium-15.jpg",
-  DALI_IMAGE_DIR "people-medium-6.jpg",
+  DEMO_IMAGE_DIR "people-medium-1.jpg",
+  DEMO_IMAGE_DIR "people-medium-4.jpg",
+  DEMO_IMAGE_DIR "people-medium-11.jpg",
+  DEMO_IMAGE_DIR "people-small-16.jpg",
+  DEMO_IMAGE_DIR "people-medium-15.jpg",
+  DEMO_IMAGE_DIR "people-medium-6.jpg",
 };
-const unsigned int NUMBER_OF_SAMPLES(sizeof(MATERIAL_SAMPLES)/sizeof(const char*));
+const unsigned int NUMBER_OF_SAMPLES(sizeof(IMAGES)/sizeof(const char*));
 
 
 #define MAKE_SHADER(A)#A
@@ -84,38 +84,6 @@ void main()
 }
 );
 
-Geometry CreateGeometry()
-{
-  // Create vertices
-  const float halfQuadSize = .5f;
-  struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
-  TexturedQuadVertex texturedQuadVertexData[4] = {
-    { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
-    { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
-    { Vector2(-halfQuadSize,  halfQuadSize), Vector2(0.f, 1.f) },
-    { Vector2( halfQuadSize,  halfQuadSize), Vector2(1.f, 1.f) } };
-
-  Property::Map texturedQuadVertexFormat;
-  texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
-  texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2;
-  PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
-  texturedQuadVertices.SetData(texturedQuadVertexData);
-
-  // Create indices
-  unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 };
-  Property::Map indexFormat;
-  indexFormat["indices"] = Property::UNSIGNED_INTEGER;
-  PropertyBuffer indices = PropertyBuffer::New( indexFormat, 6 );
-  indices.SetData(indexData);
-
-  // Create the geometry object
-  Geometry texturedQuadGeometry = Geometry::New();
-  texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
-  texturedQuadGeometry.SetIndexBuffer( indices );
-
-  return texturedQuadGeometry;
-}
-
 } // anonymous namespace
 
 // This example shows how to use a simple mesh
@@ -162,26 +130,26 @@ public:
     application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
 
     mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
-    mGeometry = CreateGeometry();
+    mGeometry = DemoHelper::CreateTexturedQuad();
 
-    Material firstMat;
+    TextureSet firstTextureSet;
 
     for( unsigned i=0; i<NUMBER_OF_SAMPLES; ++i)
     {
-      Image image = ResourceImage::New( MATERIAL_SAMPLES[i] );
-      Sampler sampler = Sampler::New(image, "sTexture");
-      Material material = Material::New( mShader );
-      material.AddSampler( sampler );
-      if( i==0 ) { firstMat = material; }
+      Texture texture = DemoHelper::LoadTexture( IMAGES[i] );
+      TextureSet textureSet = TextureSet::New();
+      textureSet.SetTexture( 0u, texture );
+      if( i==0 ) { firstTextureSet = textureSet; }
 
-      Renderer renderer = Renderer::New( mGeometry, material );
+      Renderer renderer = Renderer::New( mGeometry, mShader );
+      renderer.SetTextures( textureSet );
       Actor meshActor = Actor::New();
       mActors[i] = meshActor;
       meshActor.AddRenderer( renderer );
       meshActor.SetSize(175, 175);
       meshActor.RegisterProperty("index", (int)i);
 
-      renderer.SetDepthIndex(0);
+      renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
       // Test with actor alpha
       meshActor.SetParentOrigin( ParentOrigin::CENTER );
       meshActor.SetAnchorPoint( AnchorPoint::CENTER );
@@ -191,16 +159,16 @@ public:
 
       meshActor.RegisterProperty("uHue", i/(float)NUMBER_OF_SAMPLES);
 
-      meshActor.TouchedSignal().Connect(this, &ExampleController::OnTouched);
+      meshActor.TouchSignal().Connect(this, &ExampleController::OnTouched);
       std::ostringstream oss;
       oss << "Mesh Actor " << i;
       meshActor.SetName(oss.str());
       stage.Add( meshActor );
     }
 
-    mActors[NUMBER_OF_SAMPLES-2].GetRendererAt(0).SetMaterial( firstMat );
+    mActors[NUMBER_OF_SAMPLES-2].GetRendererAt(0).SetTextures( firstTextureSet );
 
-    stage.GetRootLayer().TouchedSignal().Connect(this, &ExampleController::OnStageTouched);
+    stage.GetRootLayer().TouchSignal().Connect(this, &ExampleController::OnStageTouched);
   }
 
   void PrintDepths()
@@ -231,9 +199,9 @@ public:
     printf("\n");
   }
 
-  bool OnTouched( Actor actor, const TouchEvent& event )
+  bool OnTouched( Actor actor, const TouchData& event )
   {
-    if( event.GetPoint(0).state == TouchPoint::Finished )
+    if( event.GetState( 0 ) == PointState::UP )
     {
       int index = actor.GetProperty<int>(actor.GetPropertyIndex("index"));
 
@@ -241,16 +209,16 @@ public:
       mDepthIndices[index] = newDepthIndex;
 
       Renderer renderer = actor.GetRendererAt(0);
-      renderer.SetDepthIndex(newDepthIndex);
+      renderer.SetProperty( Renderer::Property::DEPTH_INDEX, newDepthIndex);
 
       PrintDepths();
     }
     return true;
   }
 
-  bool OnStageTouched( Actor rootLayer, const TouchEvent& event )
+  bool OnStageTouched( Actor rootLayer, const TouchData& event )
   {
-    if( event.GetPoint(0).state == TouchPoint::Finished )
+    if( event.GetState( 0 ) == PointState::UP )
     {
       switch( mZMode )
       {
@@ -336,7 +304,7 @@ void RunTest( Application& application )
 
 // Entry point for Linux & SLP applications
 //
-int main( int argc, char **argv )
+int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv );