bool IsSampler(GLenum type)
{
- return type == GL_SAMPLER_2D || type == GL_SAMPLER_3D;
+ return type == GL_SAMPLER_2D || type == GL_SAMPLER_3D || type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES;
}
-bool SortByLocation(Dali::Graphics::UniformInfo a, Dali::Graphics::UniformInfo b)
+bool SortUniformInfoByLocation(Dali::Graphics::UniformInfo a, Dali::Graphics::UniformInfo b)
+{
+ return a.location < b.location;
+}
+
+bool SortUniformExtraInfoByLocation(Dali::Graphics::GLES::Reflection::UniformExtraInfo a, Dali::Graphics::GLES::Reflection::UniformExtraInfo b)
{
return a.location < b.location;
}
name = new char[maxLen];
- using UniformLocationSizePair = std::pair<uint32_t, uint32_t>;
- std::vector<UniformLocationSizePair> uniformSizes;
-
- uniformSizes.reserve(numUniforms);
+ mStandaloneUniformExtraInfos.clear();
for(int i = 0; i < numUniforms; ++i)
{
int written;
gl->GetActiveUniform(glProgram, i, maxLen, &written, &size, &type, name);
int location = gl->GetUniformLocation(glProgram, name);
- uniformSizes.push_back(std::make_pair(location, GetGLDataTypeSize(type)));
Dali::Graphics::UniformInfo uniformInfo;
uniformInfo.name = name;
else
{
mDefaultUniformBlock.members.push_back(uniformInfo);
+ mStandaloneUniformExtraInfos.push_back(UniformExtraInfo(location, GetGLDataTypeSize(type), type));
}
}
// Re-order according to uniform locations.
if(mDefaultUniformBlock.members.size() > 1)
{
- std::sort(mDefaultUniformBlock.members.begin(), mDefaultUniformBlock.members.end(), SortByLocation);
+ std::sort(mDefaultUniformBlock.members.begin(), mDefaultUniformBlock.members.end(), SortUniformInfoByLocation);
}
if(mUniformOpaques.size() > 1)
{
- std::sort(mUniformOpaques.begin(), mUniformOpaques.end(), SortByLocation);
+ std::sort(mUniformOpaques.begin(), mUniformOpaques.end(), SortUniformInfoByLocation);
}
// Calculate the uniform offset
else
{
uint32_t previousUniformLocation = mDefaultUniformBlock.members[i - 1].location;
- auto previousUniform = std::find_if(uniformSizes.begin(), uniformSizes.end(), [&previousUniformLocation](const UniformLocationSizePair& iter) { return iter.first == previousUniformLocation; });
- mDefaultUniformBlock.members[i].offset = mDefaultUniformBlock.members[i - 1].offset + previousUniform->second;
+ auto previousUniform = std::find_if(mStandaloneUniformExtraInfos.begin(), mStandaloneUniformExtraInfos.end(), [&previousUniformLocation](const UniformExtraInfo& iter) { return iter.location == previousUniformLocation; });
+ mDefaultUniformBlock.members[i].offset = mDefaultUniformBlock.members[i - 1].offset + previousUniform->size;
}
}
+
if(mDefaultUniformBlock.members.size() > 0)
{
- uint32_t lastUniformLocation = mDefaultUniformBlock.members.back().location;
- auto lastUniform = std::find_if(uniformSizes.begin(), uniformSizes.end(), [&lastUniformLocation](const UniformLocationSizePair& iter) { return iter.first == lastUniformLocation; });
- mDefaultUniformBlock.size = mDefaultUniformBlock.members.back().offset + lastUniform->second;
+ uint32_t lastUniformLocation = mDefaultUniformBlock.members.back().location;
+ auto lastUniform = std::find_if(mStandaloneUniformExtraInfos.begin(), mStandaloneUniformExtraInfos.end(), [&lastUniformLocation](const UniformExtraInfo& iter) { return iter.location == lastUniformLocation; });
+ mDefaultUniformBlock.size = mDefaultUniformBlock.members.back().offset + lastUniform->size;
+
+ mUniformBlocks.push_back(mDefaultUniformBlock);
}
else
{
mDefaultUniformBlock.size = 0;
}
- mUniformBlocks.push_back(mDefaultUniformBlock);
+ // Re-order according to uniform locations.
+ if(mStandaloneUniformExtraInfos.size() > 1)
+ {
+ std::sort(mStandaloneUniformExtraInfos.begin(), mStandaloneUniformExtraInfos.end(), SortUniformExtraInfoByLocation);
+ }
delete[] name;
}
return false;
}
+std::vector<GLenum> Reflection::GetStandaloneUniformTypes() const
+{
+ std::vector<GLenum> retval{};
+ for(auto&& uniform : mStandaloneUniformExtraInfos)
+ {
+ retval.emplace_back(uniform.type);
+ }
+ return retval;
+}
+
std::vector<Dali::Graphics::UniformInfo> Reflection::GetSamplers() const
{
return mUniformOpaques;
*/
[[nodiscard]] bool GetNamedUniform(const std::string& name, Dali::Graphics::UniformInfo& out) const override;
+ /**
+ * @brief Gets the types of all the standalone uniforms within the default uniform block.
+ *
+ * @return A vector of uniform types sorted in the same order as the uniforms in the default uniform block.
+ */
+ [[nodiscard]] std::vector<GLenum> GetStandaloneUniformTypes() const;
+
// Sampler
/**
public:
/**
+ * @brief Extra information of uniform
+ */
+ struct UniformExtraInfo
+ {
+ UniformExtraInfo(uint32_t location, uint32_t size, GLenum type)
+ : location(location),
+ size(size),
+ type(type){};
+
+ uint32_t location; ///< Location of uniform
+ uint32_t size; ///< size of uniform
+ GLenum type; ///< type of uniform
+ };
+
+ /**
* @brief Build the reflection of vertex attributes
*/
void BuildVertexAttributeReflection();
Dali::Graphics::VertexInputAttributeFormat format{};
};
- std::vector<AttributeInfo> mVertexInputAttributes; ///< List of vertex attributes
- Graphics::UniformBlockInfo mDefaultUniformBlock{}; ///< The emulated UBO containing all the standalone uniforms
- std::vector<Graphics::UniformInfo> mUniformOpaques{}; ///< List of opaque uniforms (i.e. samplers)
- std::vector<Graphics::UniformBlockInfo> mUniformBlocks{}; ///< List of uniform blocks
+ std::vector<AttributeInfo> mVertexInputAttributes; ///< List of vertex attributes
+ Graphics::UniformBlockInfo mDefaultUniformBlock{}; ///< The emulated UBO containing all the standalone uniforms
+ std::vector<Graphics::UniformInfo> mUniformOpaques{}; ///< List of opaque uniforms (i.e. samplers)
+ std::vector<Graphics::UniformBlockInfo> mUniformBlocks{}; ///< List of uniform blocks
+ std::vector<UniformExtraInfo> mStandaloneUniformExtraInfos; ///< List of extra information for standalone uniforms
};
} // namespace GLES