[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-graphics-reflection.h
1 #ifndef DALI_TEST_GRAPHICS_REFLECTION_H
2 #define DALI_TEST_GRAPHICS_REFLECTION_H
3
4 /*
5  * Copyright (c) 2023 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 #include <dali/graphics-api/graphics-program-create-info.h>
21 #include <dali/graphics-api/graphics-reflection.h>
22 #include "test-gl-abstraction.h"
23
24 namespace Dali
25 {
26 class TestGraphicsController;
27
28 class TestGraphicsReflection : public Graphics::Reflection
29 {
30 public:
31   class TestUniformBlockInfo;
32
33   TestGraphicsReflection(TestGraphicsController& controller, TestGlAbstraction& gl, uint32_t program_id, Property::Array& vertexFormats, const Graphics::ProgramCreateInfo& createInfo, std::vector<UniformData>& customUniforms, std::vector<TestUniformBlockInfo>& customUniformBlocks);
34
35   uint32_t                                        GetVertexAttributeLocation(const std::string& name) const override;
36   Dali::Graphics::VertexInputAttributeFormat      GetVertexAttributeFormat(uint32_t location) const override;
37   std::string                                     GetVertexAttributeName(uint32_t location) const override;
38   std::vector<uint32_t>                           GetVertexAttributeLocations() const override;
39   uint32_t                                        GetUniformBlockCount() const override;
40   uint32_t                                        GetUniformBlockBinding(uint32_t index) const override;
41   uint32_t                                        GetUniformBlockSize(uint32_t index) const override;
42   bool                                            GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInfo& out) const override;
43   std::vector<uint32_t>                           GetUniformBlockLocations() const override;
44   std::string                                     GetUniformBlockName(uint32_t blockIndex) const override;
45   uint32_t                                        GetUniformBlockMemberCount(uint32_t blockIndex) const override;
46   std::string                                     GetUniformBlockMemberName(uint32_t blockIndex, uint32_t memberLocation) const override;
47   uint32_t                                        GetUniformBlockMemberOffset(uint32_t blockIndex, uint32_t memberLocation) const override;
48   bool                                            GetNamedUniform(const std::string& name, Dali::Graphics::UniformInfo& out) const override;
49   const std::vector<Dali::Graphics::UniformInfo>& GetSamplers() const override;
50   Graphics::ShaderLanguage                        GetLanguage() const override;
51
52 public: // Test methods
53   struct TestUniformInfo
54   {
55     std::string            name{""}; // baseName in the case of arrays
56     Graphics::UniformClass uniformClass{Graphics::UniformClass::UNDEFINED};
57     uint32_t               binding{0u};
58     uint32_t               bufferIndex{0u};
59     std::vector<uint32_t>  offsets{};
60     std::vector<uint32_t>  locations{};
61     uint32_t               numElements{0u}; // 0 elements means this isn't an array; 1 element means this is an array of size 1
62     Property::Type         type;
63   };
64
65   struct TestUniformBlockInfo
66   {
67     std::string                  name{""};
68     uint32_t                     descriptorSet{0u};
69     uint32_t                     binding{0u};
70     uint32_t                     size{0u};
71     std::vector<TestUniformInfo> members{};
72   };
73
74   void SetAttributes(std::vector<std::string> locations)
75   {
76     mAttributes.clear();
77     mAttributes.resize(locations.size());
78     for(auto& location : locations)
79     {
80       mAttributes.push_back(location);
81     }
82   }
83
84   const TestUniformBlockInfo& GetTestUniformBlock(uint32_t index) const
85   {
86     return mUniformBlocks[index];
87   }
88
89   TestGraphicsController&          mController;
90   TestGlAbstraction&               mGl;
91   mutable std::vector<std::string> mAttributes;
92   std::vector<UniformData>         mCustomUniforms;
93
94   TestUniformBlockInfo              mDefaultUniformBlock{}; ///< The emulated UBO containing all the standalone uniforms
95   std::vector<TestUniformBlockInfo> mUniformBlocks{};       ///< List of uniform blocks
96 };
97
98 } // namespace Dali
99
100 #endif //DALI_TEST_GRAPHICS_REFLECTION_H