Add 'ExclusiveArch: armv7l' limit build to arm architecture
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / shader-effects / square-dissolve-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/square-dissolve-effect.h>
18
19 namespace Dali
20 {
21
22 namespace Toolkit
23 {
24
25 namespace
26 {
27
28 const std::string STEP_PROPERTY_NAME( "uStep" );
29 const std::string ROWS_PROPERTY_NAME( "uRows" );
30 const std::string COLUMNS_PROPERTY_NAME( "uColumns" );
31 const std::string TEXSIZE_PROPERTY_NAME( "texSize" );
32
33 } // namespace
34
35 SquareDissolveEffect::SquareDissolveEffect()
36 {
37 }
38
39 //Call the Parent copy constructor to add reference to the implementation for this object
40 SquareDissolveEffect::SquareDissolveEffect(ShaderEffect handle)
41 :ShaderEffect(handle)
42 {
43 }
44
45 SquareDissolveEffect::~SquareDissolveEffect()
46 {
47 }
48
49 SquareDissolveEffect SquareDissolveEffect::New()
50 {
51   // variable "uStep" range scope : [0.0, 1.0]
52   std::string fragmentShader(
53       "uniform  vec2   texSize;                   \n"
54       "uniform  float  uStep;                     \n"
55       "uniform  float  uRows;                     \n"
56       "uniform  float  uColumns;                  \n"
57       "void main()                                \n"
58       "{                                          \n"
59       "  vec2 mosaicSize = vec2(1.0 / uRows, 1.0 / uColumns);                               \n"
60       "  vec2 intXY = vec2(vTexCoord.x * texSize.x, vTexCoord.y * texSize.y);               \n"
61       "  vec2 XYMosaic = vec2(floor(intXY.x / mosaicSize.x) * mosaicSize.x, floor(intXY.y / mosaicSize.y) * mosaicSize.y); \n"
62       "  vec2 UVMosaic = vec2(XYMosaic.x /texSize.x, XYMosaic.y / texSize.y);               \n"
63       "  vec4 noiseVec = texture2D(sEffect, UVMosaic);                                      \n"
64       "  float intensity = (noiseVec[0] + noiseVec[1] + noiseVec[2] + noiseVec[3]) / 4.0;   \n"
65       "  if(intensity < uStep)                                                              \n"
66       "    gl_FragColor = vec4(0.1, 0.1, 0.1, 1.0);                                         \n"
67       "  else                                                                               \n"
68       "    gl_FragColor = texture2D(sTexture, vTexCoord);                                   \n"
69       "  gl_FragColor *= uColor;                                                            \n"
70       "}                                                                                    \n" );
71
72   // Create the implementation, temporarily owned on stack
73   Dali::ShaderEffect shaderEffectCustom =  Dali::ShaderEffect::New(
74       "",
75       fragmentShader,
76       GeometryType( GEOMETRY_TYPE_IMAGE ),
77       ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
78
79   /* Pass ownership to SquareDissolveEffect through overloaded constructor, So that it now has access to the
80      Dali::ShaderEffect implementation */
81   Dali::Toolkit::SquareDissolveEffect handle( shaderEffectCustom );
82
83   handle.SetUniform( TEXSIZE_PROPERTY_NAME, Vector2(1.0f, 1.0f) );//COORDINATE_TYPE_DEFAULT
84   handle.SetUniform( STEP_PROPERTY_NAME, 0.1f);
85   handle.SetUniform( ROWS_PROPERTY_NAME, 25.0f);
86   handle.SetUniform( COLUMNS_PROPERTY_NAME, 25.0f);
87   return handle;
88 }
89
90 void SquareDissolveEffect::SetStep( float step )
91 {
92   SetUniform( STEP_PROPERTY_NAME, step );
93 }
94
95 void SquareDissolveEffect::SetRows(float rows)
96 {
97   SetUniform(ROWS_PROPERTY_NAME, rows);
98 }
99
100 void SquareDissolveEffect::SetColumns(float columns)
101 {
102   SetUniform(COLUMNS_PROPERTY_NAME, columns);
103 }
104
105 void SquareDissolveEffect::SetTextureSize(const Vector2& textureSize)
106 {
107   SetUniform(TEXSIZE_PROPERTY_NAME, textureSize);
108 }
109
110 const std::string& SquareDissolveEffect::GetStepPropertyName() const
111 {
112   return STEP_PROPERTY_NAME;
113 }
114
115 const std::string& SquareDissolveEffect::GetRowsPropertyName() const
116 {
117   return ROWS_PROPERTY_NAME;
118 }
119
120 const std::string& SquareDissolveEffect::GetColumnsPropertyName() const
121 {
122   return COLUMNS_PROPERTY_NAME;
123 }
124
125 const std::string& SquareDissolveEffect::GetTexSizePropertyName() const
126 {
127   return TEXSIZE_PROPERTY_NAME;
128 }
129
130 } // namespace Toolkit
131
132 } // namespace Dali