Update comment and remove an unused variable
[platform/core/uifw/dali-core.git] / dali / public-api / rendering / shader.h
1 #ifndef DALI_SHADER_H
2 #define DALI_SHADER_H
3
4 /*
5  * Copyright (c) 2018 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 <string> // std::string
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/handle.h>                // Dali::Handle
26 #include <dali/public-api/object/property-index-ranges.h> // DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX
27
28 /**
29  * @brief DALI_COMPOSE_SHADER macro provides a convenient way to write shader source code.
30  *
31  * We normally use double quotation marks to write a string such as "Hello World".
32  * However many symbols are needed to add multiple lines of string.
33  * We don't need to write quotation marks using this macro at every line.
34  *
35  * [An example of double quotation marks usage]
36  * <pre>
37  * const string FRAGMENT_SHADER_SOURCE = \
38  * "  void main()\n"
39  * "  {\n"
40  * "    gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n"
41  * "  }\n";
42  * </pre><br/>
43  * [An example of DALI_COMPOSE_SHADER usage]
44  * <pre>
45  * const string VERTEX_SHADER_SOURCE = DALI_COMPOSE_SHADER (
46  *   void main()
47  *   {
48  *     gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);
49  *     vTexCoord = aTexCoord;
50  *   }
51  * );
52  * </pre>
53  *
54  * @SINCE_1_1.43
55  */
56 #define DALI_COMPOSE_SHADER(STR) #STR
57
58 namespace Dali
59 {
60
61 namespace Internal DALI_INTERNAL
62 {
63 class Shader;
64 }
65
66 /**
67  * @brief Shaders allows custom vertex and color transformations in the GPU.
68  *
69  * @SINCE_1_1.43
70  */
71 class DALI_CORE_API Shader : public Handle
72 {
73 public:
74
75   /**
76    * @brief Hints for rendering.
77    * @SINCE_1_1.45
78    */
79   struct Hint
80   {
81     /**
82      * @brief Enumeration for the hint value.
83      * @SINCE_1_1.45
84      */
85     enum Value
86     {
87       NONE                     = 0x00, ///< No hints                                                                          @SINCE_1_1.45
88       OUTPUT_IS_TRANSPARENT    = 0x01, ///< Might generate transparent alpha from opaque inputs                               @SINCE_1_1.45
89       MODIFIES_GEOMETRY        = 0x02, ///< Might change position of vertices, this option disables any culling optimizations @SINCE_1_1.45
90     };
91   };
92
93   /**
94    * @brief Enumeration for instances of properties belonging to the Shader class.
95    * @SINCE_1_1.43
96    */
97   struct Property
98   {
99     /**
100      * @brief Enumeration for instances of properties belonging to the Shader class.
101      * @SINCE_1_1.43
102      */
103     enum
104     {
105       /**
106        * @brief Name: "program", Type: MAP.
107        * @note The default value is empty.
108        * @note Format: {"vertex":"","fragment":"",hints:""}
109        * @SINCE_1_1.43
110        */
111       PROGRAM = DEFAULT_OBJECT_PROPERTY_START_INDEX
112     };
113   };
114
115   /**
116    * @brief Creates Shader.
117    *
118    * @SINCE_1_1.43
119    * @param[in] vertexShader Vertex shader code for the effect.
120    * @param[in] fragmentShader Fragment Shader code for the effect.
121    * @param[in] hints Hints to define the geometry of the rendered object
122    * @return A handle to a shader effect
123    */
124   static Shader New( const std::string& vertexShader,
125                      const std::string& fragmentShader,
126                      Hint::Value hints = Hint::NONE );
127
128   /**
129    * @brief Default constructor, creates an empty handle.
130    *
131    * @SINCE_1_1.43
132    */
133   Shader();
134
135   /**
136    * @brief Destructor.
137    * This is non-virtual since derived Handle types must not contain data or virtual methods.
138    *
139    * @SINCE_1_1.43
140    */
141   ~Shader();
142
143   /**
144    * @brief Copy constructor.
145    *
146    * @SINCE_1_1.43
147    * @param[in] handle A handle to a Shader object
148    */
149   Shader( const Shader& handle );
150
151   /**
152    * @brief Downcasts to a shader handle.
153    * If not, a shader the returned shader handle is left uninitialized.
154    *
155    * @SINCE_1_1.43
156    * @param[in] handle Handle to an object
157    * @return Shader handle or an uninitialized handle
158    */
159   static Shader DownCast( BaseHandle handle );
160
161   /**
162    * @brief Assignment operator, changes this handle to point at the same object.
163    *
164    * @SINCE_1_1.43
165    * @param[in] handle Handle to an object
166    * @return Reference to the assigned object
167    */
168   Shader& operator=( const Shader& handle );
169
170 public:
171
172   /**
173    * @brief This constructor is used by Dali New() methods.
174    * @note  Not intended for application developers.
175    * @SINCE_1_1.43
176    * @param[in] effect A pointer to a newly allocated Dali resource.
177    */
178   explicit DALI_INTERNAL Shader( Internal::Shader* effect );
179 };
180
181 } // namespace Dali
182
183 #endif // DALI_SHADER_H