2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "test-graphics-reflection.h"
18 #include <dali/public-api/object/property-map.h>
30 UniformData( const std::string& name, Property::Type type = Property::Type::NONE)
31 : name(name), type(type)
34 static const std::vector<UniformData> UNIFORMS =
36 UniformData("uRendererColor",Property::Type::FLOAT),
37 UniformData("uCustom", Property::Type::INTEGER),
38 UniformData("uCustom3", Property::Type::VECTOR3),
39 UniformData("uFadeColor", Property::Type::VECTOR4),
40 UniformData("uUniform1", Property::Type::VECTOR4),
41 UniformData("uUniform2", Property::Type::VECTOR4),
42 UniformData("uUniform3", Property::Type::VECTOR4),
43 UniformData("uFadeProgress", Property::Type::FLOAT),
44 UniformData("uANormalMatrix", Property::Type::MATRIX3),
45 UniformData("sEffect", Property::Type::FLOAT),
46 UniformData("sTexture", Property::Type::FLOAT),
47 UniformData("sTextureRect", Property::Type::FLOAT),
48 UniformData("sGloss", Property::Type::FLOAT),
49 UniformData("uColor", Property::Type::VECTOR4),
50 UniformData("uModelMatrix", Property::Type::MATRIX),
51 UniformData("uModelView", Property::Type::MATRIX),
52 UniformData("uMvpMatrix", Property::Type::MATRIX),
53 UniformData("uNormalMatrix", Property::Type::MATRIX3),
54 UniformData("uProjection", Property::Type::MATRIX),
55 UniformData("uSize", Property::Type::VECTOR3),
56 UniformData("uViewMatrix", Property::Type::MATRIX),
57 UniformData("uLightCameraProjectionMatrix", Property::Type::MATRIX),
58 UniformData("uLightCameraViewMatrix", Property::Type::MATRIX),
63 TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vfs)
66 for(Property::Array::SizeType i = 0; i < vfs.Count(); ++i)
68 Property::Map* vertexFormat = vfs[i].GetMap();
71 for(Property::Map::SizeType j = 0; j < vertexFormat->Count(); ++j)
73 auto key = vertexFormat->GetKeyAt(j);
74 if(key.type == Property::Key::STRING)
76 mAttributes.push_back(key.stringKey);
83 uint32_t TestGraphicsReflection::GetVertexAttributeLocation(const std::string& name) const
85 // Automatically assign locations to named attributes when requested
86 auto iter = std::find(mAttributes.begin(), mAttributes.end(), name);
87 if(iter != mAttributes.end())
89 return iter - mAttributes.begin();
93 uint32_t location = mAttributes.size();
94 mAttributes.push_back(name);
100 Dali::Graphics::VertexInputAttributeFormat TestGraphicsReflection::GetVertexAttributeFormat(uint32_t location) const
102 return Dali::Graphics::VertexInputAttributeFormat{};
105 std::string TestGraphicsReflection::GetVertexAttributeName(uint32_t location) const
110 std::vector<uint32_t> TestGraphicsReflection::GetVertexAttributeLocations() const
112 std::vector<uint32_t> locs;
113 for(uint32_t i = 0; i < mAttributes.size(); ++i)
120 uint32_t TestGraphicsReflection::GetUniformBlockCount() const
125 uint32_t TestGraphicsReflection::GetUniformBlockBinding(uint32_t index) const
130 uint32_t TestGraphicsReflection::GetUniformBlockSize(uint32_t index) const
132 // 64 bytes per uniform (64 = 4x4 matrix)
133 // TODO: fix if array will be used
134 return 64 * UNIFORMS.size();
137 bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInfo& out) const
143 info.size = 64 * UNIFORMS.size();
144 info.descriptorSet = 0;
145 info.members.clear();
147 for( const auto& data : UNIFORMS )
149 info.members.emplace_back();
150 auto& item = info.members.back();
151 item.name = data.name;
153 item.offset = loc*64;
154 item.location = loc++;
155 item.bufferIndex = 0;
156 item.uniformClass = Graphics::UniformClass::UNIFORM;
161 std::vector<uint32_t> TestGraphicsReflection::GetUniformBlockLocations() const
163 return std::vector<uint32_t>{};
166 std::string TestGraphicsReflection::GetUniformBlockName(uint32_t blockIndex) const
168 return std::string{};
171 uint32_t TestGraphicsReflection::GetUniformBlockMemberCount(uint32_t blockIndex) const
173 return UNIFORMS.size();
176 std::string TestGraphicsReflection::GetUniformBlockMemberName(uint32_t blockIndex, uint32_t memberLocation) const
178 return UNIFORMS[memberLocation].name;
181 uint32_t TestGraphicsReflection::GetUniformBlockMemberOffset(uint32_t blockIndex, uint32_t memberLocation) const
186 bool TestGraphicsReflection::GetNamedUniform(const std::string& name, Dali::Graphics::UniformInfo& out) const
191 std::vector<Dali::Graphics::UniformInfo> TestGraphicsReflection::GetSamplers() const
193 return std::vector<Dali::Graphics::UniformInfo>{};
196 Graphics::ShaderLanguage TestGraphicsReflection::GetLanguage() const
198 return Graphics::ShaderLanguage::GLSL_3_1;
201 Dali::Property::Type TestGraphicsReflection::GetMemberType( int blockIndex, int location) const
203 return UNIFORMS[location].type;