/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/object/property-map.h>
#include <string>
#include <vector>
+
+extern "C"
+{
+ void tet_infoline(const char* str);
+ void tet_printf(const char* format, ...);
+}
+
namespace Dali
{
namespace
} // namespace
-TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t programId, Property::Array& vfs, const Graphics::ProgramCreateInfo& createInfo, std::vector<UniformData>& customUniforms)
+TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t programId, Property::Array& vfs, const Graphics::ProgramCreateInfo& createInfo, std::vector<UniformData>& customUniforms, std::vector<TestGraphicsReflection::TestUniformBlockInfo>& customUniformBlocks)
: mGl(gl),
mCustomUniforms(customUniforms)
{
for(const auto& data : mCustomUniforms)
{
fprintf(stderr, "\ncustom uniforms: %s\n", data.name.c_str());
- mDefaultUniformBlock.members.emplace_back();
- auto& item = mDefaultUniformBlock.members.back();
auto iter = data.name.find("[", 0);
int numElements = 1;
{
numElements = 1;
}
-
- item.name = baseName;
- item.binding = 0;
- item.bufferIndex = 0;
- item.uniformClass = Graphics::UniformClass::UNIFORM;
- item.type = data.type;
- item.numElements = numElements;
-
- for(int i = 0; i < numElements; ++i)
+ iter = data.name.find("]");
+ std::string suffix;
+ if(iter != std::string::npos && iter + 1 != data.name.length())
{
- std::stringstream elementNameStream;
- elementNameStream << baseName << "[" << i << "]";
+ suffix = data.name.substr(iter + 1); // If there is a suffix, it means it is an element of an array of struct
+ }
- item.locations.push_back(gl.GetUniformLocation(programId, elementNameStream.str().c_str()));
- item.offsets.push_back(offset);
- offset += GetSizeForType(data.type);
+ if(!suffix.empty())
+ {
+ // Write multiple items
+ for(int i = 0; i < numElements; ++i)
+ {
+ std::stringstream elementNameStream;
+ elementNameStream << baseName << "[" << i << "]" << suffix;
+ mDefaultUniformBlock.members.emplace_back();
+ auto& item = mDefaultUniformBlock.members.back();
+ item.name = elementNameStream.str();
+ item.binding = 0;
+ item.offsets.push_back(offset);
+ item.locations.push_back(gl.GetUniformLocation(programId, elementNameStream.str().c_str()));
+ item.bufferIndex = 0;
+ item.uniformClass = Graphics::UniformClass::UNIFORM;
+ item.type = data.type;
+ offset += GetSizeForType(data.type);
+ }
+ }
+ else
+ {
+ // Write 1 item with multiple elements
+ mDefaultUniformBlock.members.emplace_back();
+ auto& item = mDefaultUniformBlock.members.back();
+
+ item.name = baseName;
+ item.binding = 0;
+ item.bufferIndex = 0;
+ item.uniformClass = Graphics::UniformClass::UNIFORM;
+ item.type = data.type;
+ item.numElements = numElements;
+
+ for(int i = 0; i < numElements; ++i)
+ {
+ std::stringstream elementNameStream;
+ elementNameStream << baseName << "[" << i << "]";
+ item.locations.push_back(gl.GetUniformLocation(programId, elementNameStream.str().c_str()));
+ item.offsets.push_back(offset);
+ offset += GetSizeForType(data.type);
+ }
}
}
else
{
+ // Write 1 item with 1 element
+ mDefaultUniformBlock.members.emplace_back();
+ auto& item = mDefaultUniformBlock.members.back();
item.name = data.name;
item.binding = 0;
item.offsets.push_back(offset);
mDefaultUniformBlock.size = offset;
mUniformBlocks.push_back(mDefaultUniformBlock);
+ for(auto& element : customUniformBlocks)
+ {
+ mUniformBlocks.push_back(element);
+ }
}
uint32_t TestGraphicsReflection::GetVertexAttributeLocation(const std::string& name) const
Dali::Graphics::VertexInputAttributeFormat TestGraphicsReflection::GetVertexAttributeFormat(uint32_t location) const
{
+ tet_infoline("Warning, TestGraphicsReflection::GetVertexAttributeFormat is unimplemented\n");
return Dali::Graphics::VertexInputAttributeFormat{};
}
std::string TestGraphicsReflection::GetVertexAttributeName(uint32_t location) const
{
+ tet_infoline("Warning, TestGraphicsReflection::GetVertexAttributeName is unimplemented\n");
return 0u;
}
uint32_t TestGraphicsReflection::GetUniformBlockBinding(uint32_t index) const
{
- return 0u;
+ if(index >= mUniformBlocks.size())
+ {
+ return 0;
+ }
+ return mUniformBlocks[index].binding;
}
uint32_t TestGraphicsReflection::GetUniformBlockSize(uint32_t index) const
std::vector<uint32_t> TestGraphicsReflection::GetUniformBlockLocations() const
{
+ tet_infoline("Warning, TestGraphicsReflection::GetUniformBlockLocations is unimplemented\n");
return std::vector<uint32_t>{};
}
std::string TestGraphicsReflection::GetUniformBlockName(uint32_t blockIndex) const
{
+ tet_infoline("Warning, TestGraphicsReflection::GetUniformBlockName is unimplemented\n");
return std::string{};
}
bool TestGraphicsReflection::GetNamedUniform(const std::string& name, Dali::Graphics::UniformInfo& out) const
{
+ tet_infoline("Warning, TestGraphicsReflection::GetNamedUniform is unimplemented\n");
return true;
}
const std::vector<Dali::Graphics::UniformInfo>& TestGraphicsReflection::GetSamplers() const
{
+ tet_infoline("Warning, TestGraphicsReflection::GetSamplers is unimplemented\n");
static std::vector<Dali::Graphics::UniformInfo> samplers{};
return samplers;
}