mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 04:08:32 +09:00
[Feat] (MG_State/Program): refractor UBO handling
This commit is contained in:
@@ -203,13 +203,11 @@ namespace MobileGL {
|
||||
|
||||
// ---------- UBO ----------
|
||||
int uboCount = m_program->getNumUniformBlocks();
|
||||
m_uniformBlockIndexInTProgram.resize(uboCount, -1);
|
||||
m_uniformBlockBinding.resize(uboCount, 0);
|
||||
m_uniformBlockBinding.resize(uboCount, -1);
|
||||
for (int i = 0; i < uboCount; i++) {
|
||||
auto& ubo = m_program->getUniformBlock(i);
|
||||
m_uniformBlockNameMaxLength = std::max(m_uniformBlockNameMaxLength, (Int)ubo.name.length());
|
||||
m_uniformBlockIndex[ubo.name] = ubo.getBinding();
|
||||
m_uniformBlockIndexInTProgram[ubo.getBinding()] = i;
|
||||
m_uniformBlockIndexByName[ubo.name] = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,30 +76,29 @@ namespace MobileGL {
|
||||
Int GetActiveAttributesMaxLength() const { return m_attribInNameMaxLength; }
|
||||
Int GetActiveUniformBlocksMaxNameLength() const { return m_uniformBlockNameMaxLength; }
|
||||
Uint GetUniformBlockIndex(const char* name) const {
|
||||
auto it = m_uniformBlockIndex.find(name);
|
||||
if (it != m_uniformBlockIndex.end())
|
||||
auto it = m_uniformBlockIndexByName.find(name);
|
||||
if (it != m_uniformBlockIndexByName.end())
|
||||
return it->second;
|
||||
return 0xFFFFFFFFu; // GL_INVALID_INDEX
|
||||
}
|
||||
Bool IsActiveUniformBlock(Uint index) const {
|
||||
if (index >= GetActiveUniformBlocksCount())
|
||||
return false;
|
||||
if (m_uniformBlockIndexInTProgram[index] == -1)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
Uint GetUBOSizeAt(Uint index) const {
|
||||
if (!IsActiveUniformBlock(index))
|
||||
return 0;
|
||||
return m_program->getUniformBlock(m_uniformBlockIndexInTProgram[index]).size;
|
||||
return m_program->getUniformBlock(index).size;
|
||||
}
|
||||
|
||||
|
||||
const String& GetUniformBlockName(Uint index) const {
|
||||
auto& ubo = m_program->getUniform(m_uniformBlockIndexInTProgram[index]);
|
||||
auto& ubo = m_program->getUniform(index);
|
||||
return ubo.name;
|
||||
}
|
||||
|
||||
// Set by glUniformBlockBinding
|
||||
void SetUniformBlockBinding(Uint index, Uint binding) {
|
||||
m_uniformBlockBinding[index] = binding;
|
||||
}
|
||||
@@ -137,10 +136,13 @@ namespace MobileGL {
|
||||
// ditto. Will be set at glUniform1i
|
||||
Vector<Int> m_uniformSamplerOrImageUnitIndex;
|
||||
|
||||
UnorderedMap<String, Uint> m_uniformBlockIndex;
|
||||
|
||||
// Ordered by block index
|
||||
Vector<Int> m_uniformBlockIndexInTProgram;
|
||||
// Ordered by uniform block index
|
||||
// index is DIFFERENT from binding!!!
|
||||
//
|
||||
// Let's define UniformBlockIndex == the order at glslang getUniformBlock()
|
||||
// aka `i = glGetUniformBlockIndex(prog, "BlockName")` implies:
|
||||
// `prog->getUniformBlock(i) == "BlockName"`
|
||||
UnorderedMap<String, Uint> m_uniformBlockIndexByName;
|
||||
Vector<Int> m_uniformBlockBinding;
|
||||
|
||||
// Need to be reflected after linking of SPIR-V binary
|
||||
|
||||
Reference in New Issue
Block a user