5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <string> // std::string
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
29 * @brief DALI_COMPOSE_SHADER macro provides a convenient way to write shader source code.
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.
35 * [An example of double quotation marks usage]
37 * const string FRAGMENT_SHADER_SOURCE = \
40 * " gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n"
43 * [An example of DALI_COMPOSE_SHADER usage]
45 * const string VERTEX_SHADER_SOURCE = DALI_COMPOSE_SHADER (
48 * gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);
49 * vTexCoord = aTexCoord;
54 #define DALI_COMPOSE_SHADER(STR) #STR
59 namespace Internal DALI_INTERNAL
65 * @brief Shaders allows custom vertex and color transformations in the GPU
67 class DALI_IMPORT_API Shader : public Handle
71 * @brief Hints for rendering/subdividing geometry.
75 HINT_NONE = 0x00, ///< no hints
76 HINT_REQUIRES_SELF_DEPTH_TEST = 0x01, ///< Expects depth testing enabled
77 HINT_OUTPUT_IS_TRANSPARENT = 0x02, ///< Might generate transparent alpha from opaque inputs
78 HINT_OUTPUT_IS_OPAQUE = 0x04, ///< Outputs opaque colors even if the inputs are transparent
79 HINT_MODIFIES_GEOMETRY = 0x08, ///< Might change position of vertices,
80 ///< this option disables any culling optimizations
84 * @brief An enumeration of properties belonging to the Shader class.
90 PROGRAM = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "program", type MAP; {"vertex-prefix":"","fragment-prefix":"","vertex":"","fragment":""}
91 SHADER_HINTS, ///< name "shader-hints", type UNSIGNED_INTEGER; (bitfield) values from enum Shader::Hints
96 * @brief Create Shader.
98 * @param vertexShader code for the effect. If you pass in an empty string, the default version will be used
99 * @param fragmentShader code for the effect. If you pass in an empty string, the default version will be used
100 * @param hints GeometryHints to define the geometry of the rendered object
101 * @return A handle to a shader effect
103 static Shader New( const std::string& vertexShader,
104 const std::string& fragmentShader,
105 ShaderHints hints = ShaderHints(HINT_NONE) );
108 * @brief Default constructor, creates an empty handle
115 * This is non-virtual since derived Handle types must not contain data or virtual methods.
120 * @brief Copy constructor
122 * @param handle A handle to a Shader object
124 Shader( const Shader& handle );
127 * @brief Downcast to a shader handle.
129 * If not a shader the returned shader handle is left uninitialized.
130 * @param[in] handle to an object
131 * @return shader handle or an uninitialized handle
133 static Shader DownCast( BaseHandle handle );
136 * @brief Assignment operator, changes this handle to point at the same object
138 * @param[in] handle Handle to an object
139 * @return Reference to the assigned object
141 Shader& operator=( const Shader& handle );
143 public: // Not intended for application developers
145 * @brief This constructor is used by Dali New() methods.
146 * @param [in] effect A pointer to a newly allocated Dali resource.
148 explicit DALI_INTERNAL Shader( Internal::Shader* effect );
153 #endif // DALI_SHADER_H