1 #ifndef DALI_GRAPHICS_GLES_REFLECTION_H
2 #define DALI_GRAPHICS_GLES_REFLECTION_H
5 * Copyright (c) 2023 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.
21 #include <dali/graphics-api/graphics-reflection.h>
22 #include <dali/graphics-api/graphics-types.h>
23 #include <dali/integration-api/gl-abstraction.h>
25 namespace Dali::Graphics
27 class EglGraphicsController;
32 constexpr uint32_t ERROR_ATTRIBUTE_NOT_FOUND(-1u);
35 * Reflection object represents a single full graphics reflection state.
37 * The state involves compiled and linked shaders as well as state parameters
38 * like blending, stencil, scissors, viewport etc.
40 * Some of the parameters can be modified by issuing commands but
41 * the Reflection must mark those states
45 class Reflection : public Dali::Graphics::Reflection
48 explicit Reflection(GLES::ProgramImpl& program, Graphics::EglGraphicsController& controller);
50 ~Reflection() override;
53 Reflection(const Reflection&) = delete;
54 Reflection& operator=(const Reflection&) = delete;
57 * @brief Gets the location of a vertex attribute.
59 * @param [in] name The name of vertex attribute
60 * @return The index of the vertex attribute in the shader
62 [[nodiscard]] uint32_t GetVertexAttributeLocation(const std::string& name) const override;
65 * @brief Gets the format of a vertex attribute.
67 * @param [in] location The location of vertex attribute
68 * @return The format of a vertex attribute
70 [[nodiscard]] Dali::Graphics::VertexInputAttributeFormat GetVertexAttributeFormat(uint32_t location) const override;
73 * @brief Gets the name of a vertex attribute.
75 * @param [in] location The location of vertex attribute
76 * @return The name of the vertex attribute
78 [[nodiscard]] std::string GetVertexAttributeName(uint32_t location) const override;
81 * @brief Gets the locations of all the vertex attribute in the shader.
83 * @return A vector of the locations of all the vertex attributes in the shader
85 [[nodiscard]] std::vector<uint32_t> GetVertexAttributeLocations() const override;
90 * @brief Gets the number of uniform blocks in the shader
92 * @return The number of uniform blocks
94 [[nodiscard]] uint32_t GetUniformBlockCount() const override;
97 * @brief Gets the binding point to which the uniform block with the given index is binded.
99 * @param [in] index The index of the uniform block
100 * @return The binding point
102 [[nodiscard]] uint32_t GetUniformBlockBinding(uint32_t index) const override;
105 * @brief Gets the size of the uniform block with the given index.
107 * @param [in] index The index of the uniform block
108 * @return The size of the uniform block
110 [[nodiscard]] uint32_t GetUniformBlockSize(uint32_t index) const override;
113 * @brief Retrieves the information of the uniform block with the given index.
115 * The information includes the name, binding point, size, uniforms inside the uniform block, etc.
117 * @param [in] index The index of the uniform block
118 * @param [out] out A structure that contains the information of the uniform block
119 * @return Whether the uniform block exists or not
121 bool GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInfo& out) const override;
124 * @brief Gets the binding points of all the uniform blocks in the shader.
126 * @return A vector of binding points
128 [[nodiscard]] std::vector<uint32_t> GetUniformBlockLocations() const override;
131 * @brief Gets the name of uniform block with the given index.
133 * @param [in] blockIndex The index of the uniform block
134 * @return The name of the uniform block
136 [[nodiscard]] std::string GetUniformBlockName(uint32_t blockIndex) const override;
139 * @brief Gets the number of uniforms in the uniform block with the given index.
141 * @param [in] blockIndex The index of the uniform block
142 * @return The number of uniforms in the uniform block
144 [[nodiscard]] uint32_t GetUniformBlockMemberCount(uint32_t blockIndex) const override;
147 * @brief Gets the name of the uniform in the given location within the uniform block.
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 name of the uniform
153 [[nodiscard]] std::string GetUniformBlockMemberName(uint32_t blockIndex, uint32_t memberLocation) const override;
156 * @brief Gets the byte offset of the uniform in the given location within the uniform block.
158 * @param [in] blockIndex The index of the uniform block
159 * @param [in] memberLocation The location of the uniform within the uniform block
160 * @return The byte offset of the uniform
162 [[nodiscard]] uint32_t GetUniformBlockMemberOffset(uint32_t blockIndex, uint32_t memberLocation) const override;
167 * @brief Gets the information of the uniform by its name.
169 * @param [in] name The name of the uniform
170 * @param [out] out The information of the uniform
171 * @return Whether the uniform exists or not
173 [[nodiscard]] bool GetNamedUniform(const std::string& name, Dali::Graphics::UniformInfo& out) const override;
176 * @brief Gets the types of all the standalone uniforms within the default uniform block.
178 * @return A vector of uniform types sorted in the same order as the uniforms in the default uniform block.
180 [[nodiscard]] std::vector<GLenum> GetStandaloneUniformTypes() const;
185 * @brief Gets all the sampler uniforms
187 * @return A vector of the sampler uniforms
189 const std::vector<Dali::Graphics::UniformInfo>& GetSamplers() const override;
194 * @brief Retrieves the language of the shader
196 * @return The language of the shader
198 [[nodiscard]] Graphics::ShaderLanguage GetLanguage() const override;
202 * @brief Extra information of uniform
204 struct UniformExtraInfo
206 UniformExtraInfo() = default;
207 UniformExtraInfo(uint32_t location, uint32_t size, uint32_t offset, uint32_t arraySize, GLenum type)
208 : location(location),
211 arraySize(arraySize),
214 uint32_t location; ///< Location of uniform
215 uint32_t size; ///< size of uniform
216 uint32_t offset; ///< offset of uniform within UBO
217 uint32_t arraySize; ///< number of array elements (1 for non-arrays)
218 GLenum type; ///< type of uniform
222 * @brief Returns array of additional info about standalone uniforms
224 * @return Array of internal uniform data
226 [[nodiscard]] const std::vector<UniformExtraInfo>& GetStandaloneUniformExtraInfo() const;
229 * @brief Build the reflection of vertex attributes
231 void BuildVertexAttributeReflection();
234 * @brief Build the reflection of uniforms
236 void BuildUniformReflection();
239 * @brief Build the reflection of uniform blocks
241 void BuildUniformBlockReflection();
244 * Sort the samplers by their lexical location in the frag shader source code.
249 Reflection(Reflection&&) = default;
250 Reflection& operator=(Reflection&&) = default;
253 Graphics::EglGraphicsController& mController; ///< The Graphics controller
254 GLES::ProgramImpl& mProgram; ///< The Program object
258 uint32_t location{ERROR_ATTRIBUTE_NOT_FOUND};
260 Dali::Graphics::VertexInputAttributeFormat format{};
263 std::vector<AttributeInfo> mVertexInputAttributes; ///< List of vertex attributes
264 std::vector<Graphics::UniformInfo> mUniformOpaques{}; ///< List of opaque uniforms (i.e. samplers)
265 std::vector<Graphics::UniformBlockInfo> mUniformBlocks{}; ///< List of uniform blocks (First is for standalone uniforms)
266 std::vector<UniformExtraInfo> mStandaloneUniformExtraInfos; ///< List of extra information for standalone uniforms
270 } // namespace Dali::Graphics
272 #endif // DALI_GRAPHICS_GLES_REFLECTION_H