Using migrated Public Visual API
[platform/core/uifw/dali-demo.git] / examples / point-mesh / point-mesh-example.cpp
index 80a6ad0..747f07f 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.
  */
 
 // EXTERNAL INCLUDES
+#include <dali-toolkit/dali-toolkit.h>
 
 // INTERNAL INCLUDES
 #include "shared/view.h"
-
-#include <dali-toolkit/dali-toolkit.h>
+#include "shared/utility.h"
 
 using namespace Dali;
 
 namespace
 {
-const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" );
-const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" );
+const char* MATERIAL_SAMPLE( DEMO_IMAGE_DIR "gallery-small-48.jpg" );
+const char* MATERIAL_SAMPLE2( DEMO_IMAGE_DIR "gallery-medium-19.jpg" );
 
 #define MAKE_SHADER(A)#A
 
@@ -37,6 +37,7 @@ attribute highp   float   aHue;
 varying   mediump vec2    vTexCoord;
 uniform   mediump mat4    uMvpMatrix;
 uniform   mediump vec3    uSize;
+uniform   mediump float   uPointSize;
 uniform   lowp    vec4    uFadeColor;
 varying   mediump vec3    vVertexColor;
 varying   mediump float   vHue;
@@ -51,11 +52,11 @@ vec3 hsv2rgb(vec3 c)
 void main()
 {
   mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
-  vertexPosition.xyz *= uSize;
+  vertexPosition.xyz *= (uSize-uPointSize);
   vertexPosition = uMvpMatrix * vertexPosition;
-  vVertexColor = hsv2rgb( vec3( aHue, 0.6, 0.7 ) );
+  vVertexColor = hsv2rgb( vec3( aHue, 0.7, 1.0 ) );
   vHue = aHue;
-  gl_PointSize = 80.0;
+  gl_PointSize = uPointSize;
   gl_Position = vertexPosition;
 }
 );
@@ -85,10 +86,11 @@ Geometry CreateGeometry()
   Vertex polyhedraVertexData[numSides];
   float angle=0;
   float sectorAngle = 2.0f * Math::PI / (float) numSides;
+
   for(unsigned int i=0; i<numSides; ++i)
   {
-    polyhedraVertexData[i].position.x = sinf(angle);
-    polyhedraVertexData[i].position.y = cosf(angle);
+    polyhedraVertexData[i].position.x = sinf(angle)*0.5f;
+    polyhedraVertexData[i].position.y = cosf(angle)*0.5f;
     polyhedraVertexData[i].hue = angle / ( 2.0f * Math::PI);
     angle += sectorAngle;
   }
@@ -96,13 +98,13 @@ Geometry CreateGeometry()
   Property::Map polyhedraVertexFormat;
   polyhedraVertexFormat["aPosition"] = Property::VECTOR2;
   polyhedraVertexFormat["aHue"] = Property::FLOAT;
-  PropertyBuffer polyhedraVertices = PropertyBuffer::New( PropertyBuffer::STATIC, polyhedraVertexFormat, numSides );
-  polyhedraVertices.SetData(polyhedraVertexData);
+  PropertyBuffer polyhedraVertices = PropertyBuffer::New( polyhedraVertexFormat );
+  polyhedraVertices.SetData( polyhedraVertexData, numSides );
 
   // Create the geometry object
   Geometry polyhedraGeometry = Geometry::New();
   polyhedraGeometry.AddVertexBuffer( polyhedraVertices );
-  polyhedraGeometry.SetGeometryType( Geometry::POINTS );
+  polyhedraGeometry.SetType( Geometry::POINTS );
 
   return polyhedraGeometry;
 }
@@ -150,31 +152,29 @@ public:
     // Hide the indicator bar
     application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
 
-    mImage = ResourceImage::New( MATERIAL_SAMPLE );
-    Image image = ResourceImage::New( MATERIAL_SAMPLE2 );
-    mSampler1 = Sampler::New(mImage, "sTexture1");
-    mSampler2 = Sampler::New(image, "sTexture2");
+    Texture texture0 = DemoHelper::LoadTexture( MATERIAL_SAMPLE );
+    Texture texture1 = DemoHelper::LoadTexture( MATERIAL_SAMPLE2 );
 
-    mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+    Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
 
-    mMaterial = Material::New( mShader );
-    mMaterial.AddSampler( mSampler1 );
-    mMaterial.AddSampler( mSampler2 );
+    TextureSet textureSet = TextureSet::New();
+    textureSet.SetTexture( 0u, texture0 );
+    textureSet.SetTexture( 1u, texture1 );
 
-    mGeometry = CreateGeometry();
+    Geometry geometry = CreateGeometry();
 
-    mRenderer = Renderer::New( mGeometry, mMaterial );
+    mRenderer = Renderer::New( geometry, shader );
+    mRenderer.SetTextures( textureSet );
 
     mMeshActor = Actor::New();
     mMeshActor.AddRenderer( mRenderer );
-    mMeshActor.SetSize(200, 200);
+    mMeshActor.SetSize(400, 400);
 
-    Property::Index fadeColorIndex = mMeshActor.RegisterProperty( "fade-color", Color::GREEN );
-    mMeshActor.AddUniformMapping( fadeColorIndex, std::string("uFadeColor") );
+    mMeshActor.RegisterProperty( "uFadeColor", Color::GREEN );
 
-    fadeColorIndex = mRenderer.RegisterProperty( "fade-color", Color::MAGENTA );
-    mRenderer.AddUniformMapping( fadeColorIndex, std::string("uFadeColor" ) );
-    mRenderer.SetDepthIndex(0);
+    mRenderer.RegisterProperty( "uFadeColor", Color::MAGENTA );
+    mRenderer.RegisterProperty( "uPointSize", 80.0f );
+    mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
 
     mMeshActor.SetParentOrigin( ParentOrigin::CENTER );
     mMeshActor.SetAnchorPoint( AnchorPoint::CENTER );
@@ -185,12 +185,12 @@ public:
     keyFrames.Add(0.0f, Vector4::ZERO);
     keyFrames.Add(1.0f, Vector4( 1.0f, 0.0f, 1.0f, 1.0f ));
 
-    animation.RotateBy( mMeshActor, Degree(360), Vector3::ZAXIS );
+    animation.AnimateBy( Property(mMeshActor, Actor::Property::ORIENTATION), Quaternion(Degree(360), Vector3::ZAXIS) );
 
     animation.SetLooping(true);
     animation.Play();
 
-    stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));;
+    stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));
   }
 
   /**
@@ -220,12 +220,6 @@ private:
   Application&  mApplication;                             ///< Application instance
   Vector3 mStageSize;                                     ///< The size of the stage
 
-  Image    mImage;
-  Sampler  mSampler1;
-  Sampler  mSampler2;
-  Shader   mShader;
-  Material mMaterial;
-  Geometry mGeometry;
   Renderer mRenderer;
   Actor    mMeshActor;
   Renderer mRenderer2;
@@ -242,7 +236,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 );