Merge "Move glyphy shaders into separate files" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / vector-based / glyphy-shader / glyphy-shader.cpp
1 /*
2  * Copyright (c) 2021 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 // CLASS HEADER
19 #include <dali-toolkit/internal/text/rendering/vector-based/glyphy-shader/glyphy-shader.h>
20
21 // EXTERNAL HEADERS
22 #include <sstream>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
26
27 using namespace Dali;
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Text
34 {
35 GlyphyShader::GlyphyShader()
36 {
37 }
38
39 GlyphyShader::GlyphyShader(Shader handle)
40 : Shader(handle)
41 {
42 }
43
44 GlyphyShader::~GlyphyShader()
45 {
46 }
47
48 GlyphyShader GlyphyShader::New(const Dali::Vector4& atlasInfo)
49 {
50   std::ostringstream vertexShaderStringStream;
51   std::ostringstream fragmentShaderStringStream;
52
53   vertexShaderStringStream << SHADER_GLYPHY_SHADER_EXTENTION_PREFIX_DEF.data() << SHADER_GLYPHY_SHADER_MAIN_VERT.data();
54
55   fragmentShaderStringStream << SHADER_GLYPHY_SHADER_EXTENTION_PREFIX_DEF.data()
56                              << SHADER_GLYPHY_SHADER_FRAGMENT_PREFIX_FRAG.data()
57                              << SHADER_GLYPHY_COMMON_GLSL_SHADER_DEF.data()
58                              << "#define GLYPHY_SDF_PSEUDO_DISTANCE 1\n"
59                              << SHADER_GLYPHY_SDF_GLSL_SHADER_DEF.data()
60                              << SHADER_GLYPHY_SHADER_MAIN_FRAG.data();
61
62   Shader shaderEffectCustom = Shader::New(vertexShaderStringStream.str(),
63                                           fragmentShaderStringStream.str(),
64                                           Shader::Hint::OUTPUT_IS_TRANSPARENT);
65
66   GlyphyShader handle(shaderEffectCustom);
67
68   handle.RegisterProperty("u_atlas_info", atlasInfo);
69   handle.RegisterProperty("u_contrast", 1.f);
70   handle.RegisterProperty("u_gamma_adjust", 1.f);
71   handle.RegisterProperty("u_outline_thickness", 1.f);
72   handle.RegisterProperty("u_outline", 1.f);
73   handle.RegisterProperty("u_boldness", 0.f);
74
75   return handle;
76 }
77
78 } // namespace Text
79
80 } // namespace Toolkit
81
82 } // namespace Dali