1 #ifndef DALI_GRAPHICS_GLES_REFLECTION_H
2 #define DALI_GRAPHICS_GLES_REFLECTION_H
5 * Copyright (c) 2021 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;
178 * @brief Gets all the sampler uniforms
180 * @return A vector of the sampler uniforms
182 [[nodiscard]] std::vector<Dali::Graphics::UniformInfo> GetSamplers() const override;
187 * @brief Retrieves the language of the shader
189 * @return The language of the shader
191 [[nodiscard]] Graphics::ShaderLanguage GetLanguage() const override;
195 * @brief Build the reflection of vertex attributes
197 void BuildVertexAttributeReflection();
200 * @brief Build the reflection of uniforms
202 void BuildUniformReflection();
205 * @brief Build the reflection of uniform blocks
207 void BuildUniformBlockReflection();
210 Reflection(Reflection&&) = default;
211 Reflection& operator=(Reflection&&) = default;
214 Graphics::EglGraphicsController& mController; ///< The Graphics controller
215 GLES::ProgramImpl& mProgram; ///< The Program object
221 Dali::Graphics::VertexInputAttributeFormat format{};
224 std::vector<AttributeInfo> mVertexInputAttributes; ///< List of vertex attributes
225 Graphics::UniformBlockInfo mDefaultUniformBlock{}; ///< The emulated UBO containing all the standalone uniforms
226 std::vector<Graphics::UniformInfo> mUniformOpaques{}; ///< List of opaque uniforms (i.e. samplers)
227 std::vector<Graphics::UniformBlockInfo> mUniformBlocks{}; ///< List of uniform blocks
231 } // namespace Dali::Graphics
233 #endif // DALI_GRAPHICS_GLES_REFLECTION_H