Add support for Animation::EndAction::BakeFinal to builder
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / shader-effects / shear-effect.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include <dali-toolkit/public-api/shader-effects/shear-effect.h>
18
19 namespace Dali
20 {
21
22 namespace Toolkit
23 {
24
25 namespace
26 {
27
28 const std::string CENTER_PROPERTY_NAME( "uCenter" );
29 const std::string ANGLE_X_AXIS_PROPERTY_NAME( "uAngleXAxis" );
30 const std::string ANGLE_Y_AXIS_PROPERTY_NAME( "uAngleYAxis" );
31
32 } // namespace
33
34 ShearEffect::ShearEffect()
35 {
36 }
37
38 //Call the Parent copy constructor to add reference to the implementation for this object
39 ShearEffect::ShearEffect(ShaderEffect handle)
40 :ShaderEffect(handle)
41 {
42 }
43
44 ShearEffect::~ShearEffect()
45 {
46 }
47
48
49 ShearEffect ShearEffect::New()
50 {
51   // append the default version
52   std::string vertexShader(
53               "uniform mediump  vec2  uCenter;\n"
54               "uniform mediump  float uAngleXAxis;\n"
55               "uniform mediump  float uAngleYAxis;\n"
56               "\n"
57               "void main()\n"
58               "{\n"
59                   "mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
60                   "\n"
61                   "world.x = world.x + tan(radians(uAngleXAxis)) * (world.y - uCenter.y * world.w);\n"
62                   "world.y = world.y + tan(radians(uAngleYAxis)) * (world.x - uCenter.x * world.w);\n"
63                   "\n"
64                   "gl_Position = uProjection * world;\n"
65                   "\n"
66                   "vTexCoord = aTexCoord;\n"
67               "}" );
68
69   // Create the implementation, temporarily owned on stack,
70   ShaderEffect shaderEffectCustom =  Dali::ShaderEffect::New(
71       vertexShader,
72       "",
73       GeometryType( GEOMETRY_TYPE_IMAGE | GEOMETRY_TYPE_TEXT ),
74       GeometryHints( HINT_GRID ));
75
76   // Pass ownership to ShearEffect through overloaded constructor, So that it now has access to the
77   // Dali::ShaderEffect implementation
78   Dali::Toolkit::ShearEffect handle( shaderEffectCustom );
79
80   handle.SetUniform( CENTER_PROPERTY_NAME, Vector2(0.0f, 0.0f), COORDINATE_TYPE_VIEWPORT_POSITION );
81   handle.SetUniform( ANGLE_X_AXIS_PROPERTY_NAME, 0.0f);
82   handle.SetUniform( ANGLE_Y_AXIS_PROPERTY_NAME, 0.0f);
83
84   return handle;
85 }
86
87 void ShearEffect::SetCenter( const Vector2& center )
88 {
89   SetUniform( CENTER_PROPERTY_NAME, center, COORDINATE_TYPE_VIEWPORT_POSITION );
90 }
91
92 void ShearEffect::SetAngleXAxis( float angle )
93 {
94   SetUniform( ANGLE_X_AXIS_PROPERTY_NAME, angle );
95 };
96
97 void ShearEffect::SetAngleYAxis( float angle )
98 {
99   SetUniform( ANGLE_Y_AXIS_PROPERTY_NAME, angle );
100 };
101
102 const std::string& ShearEffect::GetCenterPropertyName() const
103 {
104   return CENTER_PROPERTY_NAME;
105 }
106
107 const std::string& ShearEffect::GetAngleXAxisPropertyName() const
108 {
109   return ANGLE_X_AXIS_PROPERTY_NAME;
110 }
111
112 const std::string& ShearEffect::GetAngleYAxisPropertyName() const
113 {
114   return ANGLE_Y_AXIS_PROPERTY_NAME;
115 }
116
117 } // namespace Toolkit
118
119 } // namespace Dali