Merge "Fixes the change of style when the text-field grabs the keyboard focus." into...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / alpha-discard-effect.h
1 #ifndef __DALI_TOOLKIT_ALPHA_DISCARD_EFFECT_H__
2 #define __DALI_TOOLKIT_ALPHA_DISCARD_EFFECT_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/shader-effects/shader-effect.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 /**
31  * @brief Creates a new Alpha discard effect
32  *
33  * Alpha discard effect is used to discard fragments when the alpha colour value is below a threshold.
34  * This is useful for stenciling.
35  *
36  * Usage example:
37  *
38  *   ImageActor actor = ImageActor::New( Image( EXAMPLE_IMAGE_PATH ) );
39  *   ShaderEffect alphaDiscardEffect = CreateAlphaDiscardEffect();
40  *   actor.SetShaderEffect( alphaDiscardEffect );
41  *
42  * @return A handle to a newly allocated ShaderEffect.
43  */
44 inline ShaderEffect CreateAlphaDiscardEffect()
45 {
46   const char* ALPHA_DISCARD_FRAGMENT_SHADER_SOURCE =
47       "void main()                                                    \n"
48       "{                                                              \n"
49       "  mediump vec4 color = texture2D( sTexture, vTexCoord );       \n"
50       "  if(color.a <= 0.0001)                                        \n"
51       "  {                                                            \n"
52       "    discard;                                                   \n"
53       "  }                                                            \n"
54       "  gl_FragColor = color * uColor;                               \n"
55       "}                                                              \n";
56
57   return ShaderEffect::New( "", // Use default
58                             ALPHA_DISCARD_FRAGMENT_SHADER_SOURCE );
59 }
60
61 } // namespace Toolkit
62
63 } // namespace Dali
64
65 #endif // __DALI_TOOLKIT_ALPHA_DISCARD_EFFECT_H__