2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-toolkit/public-api/shader-effects/shear-effect.h>
29 const std::string CENTER_PROPERTY_NAME( "uCenter" );
30 const std::string ANGLE_X_AXIS_PROPERTY_NAME( "uAngleXAxis" );
31 const std::string ANGLE_Y_AXIS_PROPERTY_NAME( "uAngleYAxis" );
35 ShearEffect::ShearEffect()
39 //Call the Parent copy constructor to add reference to the implementation for this object
40 ShearEffect::ShearEffect(ShaderEffect handle)
45 ShearEffect::~ShearEffect()
50 ShearEffect ShearEffect::New()
52 // append the default version
53 std::string vertexShader(
54 "uniform mediump vec2 uCenter;\n"
55 "uniform mediump float uAngleXAxis;\n"
56 "uniform mediump float uAngleYAxis;\n"
60 "mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
62 "world.x = world.x + tan(radians(uAngleXAxis)) * (world.y - uCenter.y * world.w);\n"
63 "world.y = world.y + tan(radians(uAngleYAxis)) * (world.x - uCenter.x * world.w);\n"
65 "gl_Position = uProjection * world;\n"
67 "vTexCoord = aTexCoord;\n"
70 // Create the implementation, temporarily owned on stack,
71 ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New(
74 GeometryType( GEOMETRY_TYPE_IMAGE | GEOMETRY_TYPE_TEXT ),
75 GeometryHints( HINT_GRID ));
77 // Pass ownership to ShearEffect through overloaded constructor, So that it now has access to the
78 // Dali::ShaderEffect implementation
79 Dali::Toolkit::ShearEffect handle( shaderEffectCustom );
81 handle.SetUniform( CENTER_PROPERTY_NAME, Vector2(0.0f, 0.0f), COORDINATE_TYPE_VIEWPORT_POSITION );
82 handle.SetUniform( ANGLE_X_AXIS_PROPERTY_NAME, 0.0f);
83 handle.SetUniform( ANGLE_Y_AXIS_PROPERTY_NAME, 0.0f);
88 void ShearEffect::SetCenter( const Vector2& center )
90 SetUniform( CENTER_PROPERTY_NAME, center, COORDINATE_TYPE_VIEWPORT_POSITION );
93 void ShearEffect::SetAngleXAxis( float angle )
95 SetUniform( ANGLE_X_AXIS_PROPERTY_NAME, angle );
98 void ShearEffect::SetAngleYAxis( float angle )
100 SetUniform( ANGLE_Y_AXIS_PROPERTY_NAME, angle );
103 const std::string& ShearEffect::GetCenterPropertyName() const
105 return CENTER_PROPERTY_NAME;
108 const std::string& ShearEffect::GetAngleXAxisPropertyName() const
110 return ANGLE_X_AXIS_PROPERTY_NAME;
113 const std::string& ShearEffect::GetAngleYAxisPropertyName() const
115 return ANGLE_Y_AXIS_PROPERTY_NAME;
118 } // namespace Toolkit