Merge "Add ApplyCustomFragmentPrefix" into devel/master
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-reflection.h
1 #ifndef DALI_GRAPHICS_REFLECTION_H
2 #define DALI_GRAPHICS_REFLECTION_H
3
4 /*
5  * Copyright (c) 2021 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 // INTERNAL INCLUDES
22 #include "graphics-types.h"
23
24 namespace Dali
25 {
26 namespace Graphics
27 {
28 /**
29  * @brief The Reflection class represents a single shader that can be bound
30  * to the specific stage of pipeline (vertex, fragment, compute etc.).
31  *
32  * Reflections are linked together when pipeline is created.
33  *
34  */
35 class Reflection
36 {
37 public:
38   Reflection()          = default;
39   virtual ~Reflection() = default;
40
41   // not copyable
42   Reflection(const Reflection&) = delete;
43   Reflection& operator=(const Reflection&) = delete;
44
45   // Vertex attributes
46
47   /**
48    * @brief Gets the location of a vertex attribute.
49    *
50    * @param [in] name The name of vertex attribute
51    * @return The index of the vertex attribute in the shader
52    */
53   virtual uint32_t GetVertexAttributeLocation(const std::string& name) const = 0;
54
55   /**
56    * @brief Gets the format of a vertex attribute.
57    *
58    * @param [in] location The location of vertex attribute
59    * @return The format of a vertex attribute
60    */
61   virtual Dali::Graphics::VertexInputAttributeFormat GetVertexAttributeFormat(uint32_t location) const = 0;
62
63   /**
64    * @brief Gets the name of a vertex attribute.
65    *
66    * @param [in] location The location of vertex attribute
67    * @return The name of the vertex attribute
68    */
69   virtual std::string GetVertexAttributeName(uint32_t location) const = 0;
70
71   /**
72    * @brief Gets the locations of all the vertex attribute in the shader.
73    *
74    * @return A vector of the locations of all the vertex attributes in the shader
75    */
76   virtual std::vector<uint32_t> GetVertexAttributeLocations() const = 0;
77
78   // Uniform blocks
79
80   /**
81    * @brief Gets the number of uniform blocks in the shader
82    *
83    * @return The number of uniform blocks
84    */
85   virtual uint32_t GetUniformBlockCount() const = 0;
86
87   /**
88    * @brief Gets the binding point to which the uniform block with the given index is binded.
89    *
90    * @param [in] index The index of the uniform block
91    * @return The binding point
92    */
93   virtual uint32_t GetUniformBlockBinding(uint32_t index) const = 0;
94
95   /**
96    * @brief Gets the size of the uniform block with the given index.
97    *
98    * @param [in] index The index of the uniform block
99    * @return The size of the uniform block
100    */
101   virtual uint32_t GetUniformBlockSize(uint32_t index) const = 0;
102
103   /**
104    * @brief Retrieves the information of the uniform block with the given index.
105    *
106    * The information includes the name, binding point, size, uniforms inside the uniform block, etc.
107    *
108    * @param [in] index The index of the uniform block
109    * @param [out] out A structure that contains the information of the uniform block
110    * @return Whether the uniform block exists or not
111    */
112   virtual bool GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInfo& out) const = 0;
113
114   /**
115    * @brief Gets the binding points of all the uniform blocks in the shader.
116    *
117    * @return A vector of binding points
118    */
119   virtual std::vector<uint32_t> GetUniformBlockLocations() const = 0;
120
121   /**
122    * @brief Gets the name of uniform block with the given index.
123    *
124    * @param [in] blockIndex The index of the uniform block
125    * @return The name of the uniform block
126    */
127   virtual std::string GetUniformBlockName(uint32_t blockIndex) const = 0;
128
129   /**
130    * @brief Gets the number of uniforms in the uniform block with the given index.
131    *
132    * @param [in] blockIndex The index of the uniform block
133    * @return The number of uniforms in the uniform block
134    */
135   virtual uint32_t GetUniformBlockMemberCount(uint32_t blockIndex) const = 0;
136
137   /**
138    * @brief Gets the name of the uniform in the given location within the uniform block.
139    *
140    * @param [in] blockIndex The index of the uniform block
141    * @param [in] memberLocation The location of the uniform within the uniform block
142    * @return The name of the uniform
143    */
144   virtual std::string GetUniformBlockMemberName(uint32_t blockIndex, uint32_t memberLocation) const = 0;
145
146   /**
147    * @brief Gets the byte offset of the uniform in the given location within the uniform block.
148    *
149    * @param [in] blockIndex The index of the uniform block
150    * @param [in] memberLocation The location of the uniform within the uniform block
151    * @return The byte offset of the uniform
152    */
153   virtual uint32_t GetUniformBlockMemberOffset(uint32_t blockIndex, uint32_t memberLocation) const = 0;
154
155   // Named uniforms
156
157   /**
158    * @brief Gets the information of the uniform by its name.
159    *
160    * @param [in] name The name of the uniform
161    * @param [out] out The information of the uniform
162    * @return Whether the uniform exists or not
163    */
164   virtual bool GetNamedUniform(const std::string& name, Dali::Graphics::UniformInfo& out) const = 0;
165
166   // Sampler
167
168   /**
169    * @brief Gets all the sampler uniforms
170    *
171    * @return A vector of the sampler uniforms
172    */
173   virtual const std::vector<Dali::Graphics::UniformInfo>& GetSamplers() const = 0;
174
175   // Language
176
177   /**
178    * @brief Retrieves the language of the shader
179    *
180    * @return The language of the shader
181    */
182   virtual Graphics::ShaderLanguage GetLanguage() const = 0;
183
184 protected:
185   Reflection(Reflection&&) = default;
186   Reflection& operator=(Reflection&&) = default;
187 };
188
189 } // Namespace Graphics
190 } // Namespace Dali
191
192 #endif // DALI_GRAPHICS_REFLECTION_H