Merge "Deprecate the public APIs taking Image as input" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / shader-effects / mask-effect.h
1 #ifndef __DALI_TOOLKIT_MASK_EFFECT_H__
2 #define __DALI_TOOLKIT_MASK_EFFECT_H__
3
4 /*
5  * Copyright (c) 2016 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/images/image.h>
23 #include <dali/devel-api/shader-effects/shader-effect.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 /**
32  * @brief Creates a new MaskEffect
33  *
34  * MaskEffect is used to control which parts of an image are visible, using the alpha channel of a separate mask image.
35  *
36  * Typically mask images should be the same size as the main image being viewed, but this isn't essential.
37  *
38  * Usage example:
39  *
40  *   ImageActor actor = ImageActor::New( Image( EXAMPLE_IMAGE_PATH ) );
41  *   ShaderEffect maskEffect = CreateMaskEffect( Image::New( MASK_IMAGE_PATH ) );
42  *   actor.SetShaderEffect( maskEffect );
43  *
44  * @param[in] maskImage The image to use as a mask
45  * @return A handle to a newly allocated ShaderEffect
46  */
47 inline ShaderEffect CreateMaskEffect(Image maskImage)
48 {
49   const char* ALPHA_MASK_FRAGMENT_SHADER_SOURCE =
50       "void main()                                                                    \n"
51       "{                                                                              \n"
52       "  highp vec4 mask = texture2D(sEffect, vTexCoord);                             \n"
53       "  gl_FragColor = texture2D(sTexture, vTexCoord) * uColor * vec4(1,1,1,mask.a); \n"
54       "}                                                                              \n";
55
56   ShaderEffect shaderEffect = ShaderEffect::New(
57       "", // Use default
58       ALPHA_MASK_FRAGMENT_SHADER_SOURCE,
59       ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
60
61   shaderEffect.SetEffectImage( maskImage );
62
63   return shaderEffect;
64 }
65
66 } // namespace Toolkit
67
68 } // namespace Dali
69
70 #endif // __DALI_TOOLKIT_MASK_EFFECT_H__