/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
*/
#include <dali/dali.h>
-#include <dali/devel-api/rendering/renderer.h>
+#include <dali/devel-api/images/texture-set-image.h>
+#include <dali/public-api/rendering/renderer.h>
#include <dali-toolkit/dali-toolkit.h>
#include <cstdio>
#include <string>
+#include "shared/utility.h"
using namespace Dali;
using namespace Dali::Toolkit;
~MetaballRefracController();
void Create( Application& app );
- bool OnTouch( Actor actor, const TouchEvent& touch );
+ bool OnTouch( Actor actor, const TouchData& touch );
void OnKeyEvent(const KeyEvent& event);
void SetGravity(const Vector2 & gravity);
Actor mCompositionActor;
//Motion
- bool mExitClick;
Vector2 mCurrentTouchPosition;
Vector2 mMetaballPosVariation;
Vector2 mMetaballPosVariationFrom;
Vector2 mGravityVar;
Renderer mRendererRefraction;
- Material mMaterialRefraction;
- Material mMaterialNormal;
+ TextureSet mTextureSetRefraction;
+ Shader mShaderRefraction;
+ TextureSet mTextureSetNormal;
+ Shader mShaderNormal;
//Animations
Animation mGravityAnimation[METABALL_NUMBER];
stage.SetBackgroundColor(Color::BLACK);
//Set background image for the view
- mBackImage = ResourceImage::New( BACKGROUND_IMAGE );
+ mBackImage = DemoHelper::LoadImage( BACKGROUND_IMAGE );
mGravity = Vector2(GRAVITY_X,GRAVITY_Y);
mGravityVar = Vector2(0,0);
CreateAnimations();
// Connect the callback to the touch signal on the mesh actor
- stage.GetRootLayer().TouchedSignal().Connect( this, &MetaballRefracController::OnTouch );
+ stage.GetRootLayer().TouchSignal().Connect( this, &MetaballRefracController::OnTouch );
}
/**
{ Vector3(0.0f, 0.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 );
//Normals
Property::Map normalVertexFormat;
normalVertexFormat["aNormal"] = Property::VECTOR3;
- PropertyBuffer normalVertices = PropertyBuffer::New( normalVertexFormat, numberOfVertices );
- normalVertices.SetData(normals);
+ PropertyBuffer normalVertices = PropertyBuffer::New( normalVertexFormat );
+ normalVertices.SetData( normals, 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( textureVertices );
texturedQuadGeometry.AddVertexBuffer( normalVertices );
- texturedQuadGeometry.SetIndexBuffer ( indicesToVertices );
+ texturedQuadGeometry.SetIndexBuffer ( &indices[0], 6 );
return texturedQuadGeometry;
}
{ Vector3(0.0f, 0.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 );
//Normals
Property::Map normalVertexFormat;
normalVertexFormat["aNormal"] = Property::VECTOR3;
- PropertyBuffer normalVertices = PropertyBuffer::New( normalVertexFormat, numberOfVertices );
- normalVertices.SetData(normals);
+ PropertyBuffer normalVertices = PropertyBuffer::New( normalVertexFormat );
+ normalVertices.SetData( normals, 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( textureVertices );
texturedQuadGeometry.AddVertexBuffer( normalVertices );
- texturedQuadGeometry.SetIndexBuffer ( indicesToVertices );
+ texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) );
return texturedQuadGeometry;
}
//With MeshData Textured
float aspect = (float)mScreenSize.y / (float)mScreenSize.x;
- //Create the shader for the metaballs
-
+ //Create the renderer for the metaballs
Shader shader = Shader::New( METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER );
-
- Material material = Material::New( shader );
-
Geometry metaballGeom = CreateGeometry();
+ Renderer renderer = Renderer::New( metaballGeom, shader );
+ renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
+ renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE );
+ renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE );
+ renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE );
+ renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE );
//Each metaball has a different radius
mMetaballs[0].radius = mMetaballs[0].initRadius = 0.0145f;
mMetaballs[i].actor.SetScale( 1.0f );
mMetaballs[i].actor.SetParentOrigin( ParentOrigin::CENTER );
- Renderer renderer = Renderer::New( metaballGeom, material );
- renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON );
- renderer.SetBlendFunc(BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE);
+
mMetaballs[i].actor.AddRenderer( renderer );
mMetaballs[i].positionIndex = mMetaballs[i].actor.RegisterProperty( "uPositionMetaball", mMetaballs[i].position );
Geometry metaballGeom = CreateGeometryComposition();
//Create Refraction shader and renderer
- Shader shader = Shader::New( METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER );
- //Create new material
- mMaterialRefraction = Material::New( shader );
+ mShaderRefraction = Shader::New( METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER );
- //Add Textures
- mMaterialRefraction.AddTexture(mBackImage, "sTexture");
- mMaterialRefraction.AddTexture(mMetaballFBO, "sEffect");
+ //Create new texture set
+ mTextureSetRefraction = TextureSet::New();
+ TextureSetImage( mTextureSetRefraction, 0u, mBackImage );
+ TextureSetImage( mTextureSetRefraction, 1u, mMetaballFBO );
//Create normal shader
- Shader shaderNormal = Shader::New( METABALL_VERTEX_SHADER, FRAG_SHADER );
- //Create new material
- mMaterialNormal = Material::New( shaderNormal );
-
- //Add samplers
- mMaterialNormal.AddTexture(mBackImage, "sTexture");
+ mShaderNormal = Shader::New( METABALL_VERTEX_SHADER, FRAG_SHADER );
+ //Create new texture set
+ mTextureSetNormal = TextureSet::New();
+ TextureSetImage( mTextureSetNormal, 0u, mBackImage );
//Create actor
mCompositionActor = Actor::New( );
mCompositionActor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
mCompositionActor.SetSize(mScreenSize.x, mScreenSize.y);
-
- mRendererRefraction = Renderer::New( metaballGeom, mMaterialNormal );
+ mRendererRefraction = Renderer::New( metaballGeom, mShaderNormal );
+ mRendererRefraction.SetTextures( mTextureSetNormal );
mCompositionActor.AddRenderer( mRendererRefraction );
Stage stage = Stage::GetCurrent();
*/
void MetaballRefracController::ResetMetaballsState()
{
- mRendererRefraction.SetMaterial(mMaterialNormal);
+ mRendererRefraction.SetTextures(mTextureSetNormal);
+ mRendererRefraction.SetShader( mShaderNormal );
for (int i = 0 ; i < METABALL_NUMBER ; i++)
{
}
}
-bool MetaballRefracController::OnTouch( Actor actor, const TouchEvent& touch )
+bool MetaballRefracController::OnTouch( Actor actor, const TouchData& touch )
{
- const TouchPoint &point = touch.GetPoint(0);
float aspectR = mScreenSize.y / mScreenSize.x;
- switch(point.state)
+ switch( touch.GetState( 0 ) )
{
- case TouchPoint::Down:
+ case PointState::DOWN:
{
StopAfterClickAnimations();
for (int i = 0 ; i < METABALL_NUMBER ; i++)
mRadiusVarAnimation[3].Play();
//We draw with the refraction-composition shader
- mRendererRefraction.SetMaterial(mMaterialRefraction);
-
- mCurrentTouchPosition = point.screen;
+ mRendererRefraction.SetTextures(mTextureSetRefraction);
+ mRendererRefraction.SetShader( mShaderRefraction );
+ mCurrentTouchPosition = touch.GetScreenPosition( 0 );
//we use the click position for the metaballs
- Vector2 metaballCenter = Vector2((point.screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - point.screen.y) / mScreenSize.y) - 0.5) * 2.0;
+ Vector2 metaballCenter = Vector2((mCurrentTouchPosition.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - mCurrentTouchPosition.y) / mScreenSize.y) - 0.5) * 2.0;
SetPositionToMetaballs(metaballCenter);
break;
}
- case TouchPoint::Motion:
+ case PointState::MOTION:
{
- Vector2 displacement = point.screen - mCurrentTouchPosition;
- mCurrentTouchPosition = point.screen;
+ Vector2 screen = touch.GetScreenPosition( 0 );
+ Vector2 displacement = screen - mCurrentTouchPosition;
+ mCurrentTouchPosition = screen;
mMetaballPosVariationTo.x += (displacement.x / mScreenSize.x) * 2.2;
mMetaballPosVariationTo.y += (- displacement.y / mScreenSize.y) * 2.2;
mPositionVarAnimation[1].Play();
//we use the click position for the metaballs
- Vector2 metaballCenter = Vector2((point.screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - point.screen.y) / mScreenSize.y) - 0.5) * 2.0;
+ Vector2 metaballCenter = Vector2((screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5) * 2.0;
SetPositionToMetaballs(metaballCenter);
break;
}
- case TouchPoint::Up:
- case TouchPoint::Leave:
- case TouchPoint::Interrupted:
+ case PointState::UP:
+ case PointState::LEAVE:
+ case PointState::INTERRUPTED:
{
//Stop click animations
StopClickAnimations();
// 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 );