Move more public-api headers to devel-api. PART 3
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / blind-effect.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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
18 #include <dali-toolkit/devel-api/shader-effects/blind-effect.h>
19
20 namespace Dali
21 {
22
23 namespace Toolkit
24 {
25
26 namespace
27 {
28
29 const std::string STEP_PROPERTY_NAME( "uStep" );
30
31 } // namespace
32
33 BlindEffect::BlindEffect()
34 {
35 }
36
37 //Call the Parent copy constructor to add reference to the implementation for this object
38 BlindEffect::BlindEffect(ShaderEffect handle)
39 :ShaderEffect(handle)
40 {
41 }
42
43 BlindEffect::~BlindEffect()
44 {
45 }
46
47
48 BlindEffect BlindEffect::New()
49 {
50   std::string fragmentShader(
51     "uniform mediump float uStep;                                                        \n"
52     "void main()                                                                         \n"
53     "{                                                                                   \n"
54     "    mediump vec4 alphaColor;                                                        \n"
55     "    mediump vec4 baseColor;                                                         \n"
56     "    baseColor = texture2D( sTexture, vTexCoord);                                    \n"
57     "    alphaColor = vec4(0.1,0.1,0.1,1.0);                                             \n"
58     "    lowp float index = 0.0;                                                         \n"
59     "    index = floor(vTexCoord.y/0.1);                                                 \n"
60     "    if((vTexCoord.y < (index * 0.1 + uStep * 0.005)) && (vTexCoord.y > index * 0.1))\n"
61     "    {                                                                               \n"
62     "      gl_FragColor = alphaColor;                                                    \n"
63     "    }                                                                               \n"
64     "    else                                                                            \n"
65     "    {                                                                               \n"
66     "      gl_FragColor = baseColor;                                                     \n"
67     "    }                                                                               \n"
68     "    gl_FragColor*=uColor;                                                           \n"
69     "}                                                                                   \n"
70   );
71
72   Dali::ShaderEffect shaderEffectCustom =  Dali::ShaderEffect::New(
73       "",
74       fragmentShader,
75       Dali::GeometryType( GEOMETRY_TYPE_IMAGE ),
76       ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING | ShaderEffect::HINT_GRID ));
77
78   Dali::Toolkit::BlindEffect handle( shaderEffectCustom );
79
80   handle.SetUniform( STEP_PROPERTY_NAME, 0.0f );
81
82   return handle;
83 }
84
85 void BlindEffect::SetStep(float step)
86 {
87   SetUniform( STEP_PROPERTY_NAME, step );
88 }
89
90 const std::string& BlindEffect::GetStepPropertyName() const
91 {
92   return STEP_PROPERTY_NAME;
93 }
94
95 } // namespace Toolkit
96
97 } // namespace Dali