2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
17 #include <dali-toolkit/public-api/shader-effects/shear-effect.h>
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" );
34 ShearEffect::ShearEffect()
38 //Call the Parent copy constructor to add reference to the implementation for this object
39 ShearEffect::ShearEffect(ShaderEffect handle)
44 ShearEffect::~ShearEffect()
49 ShearEffect ShearEffect::New()
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"
59 "mediump vec4 world = uModelView * vec4(aPosition,1.0);\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"
64 "gl_Position = uProjection * world;\n"
66 "vTexCoord = aTexCoord;\n"
69 // Create the implementation, temporarily owned on stack,
70 ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New(
73 GeometryType( GEOMETRY_TYPE_IMAGE | GEOMETRY_TYPE_TEXT ),
74 GeometryHints( HINT_GRID ));
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 );
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);
87 void ShearEffect::SetCenter( const Vector2& center )
89 SetUniform( CENTER_PROPERTY_NAME, center, COORDINATE_TYPE_VIEWPORT_POSITION );
92 void ShearEffect::SetAngleXAxis( float angle )
94 SetUniform( ANGLE_X_AXIS_PROPERTY_NAME, angle );
97 void ShearEffect::SetAngleYAxis( float angle )
99 SetUniform( ANGLE_Y_AXIS_PROPERTY_NAME, angle );
102 const std::string& ShearEffect::GetCenterPropertyName() const
104 return CENTER_PROPERTY_NAME;
107 const std::string& ShearEffect::GetAngleXAxisPropertyName() const
109 return ANGLE_X_AXIS_PROPERTY_NAME;
112 const std::string& ShearEffect::GetAngleYAxisPropertyName() const
114 return ANGLE_Y_AXIS_PROPERTY_NAME;
117 } // namespace Toolkit