mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 04:08:32 +09:00
[Chore] (MG_State/ProgramObject): directly use TProgram for reflection
This commit is contained in:
@@ -91,11 +91,7 @@ namespace MobileGL {
|
||||
// i-th elements refers to uniform at layout(location = i, ...)
|
||||
// Be aware, there could be gaps in between these vectors
|
||||
// Locations can be not sequential
|
||||
m_uniformNames.resize(m_maxUniformLocation + 1);
|
||||
m_uniformTypes.resize(m_maxUniformLocation + 1, GL_ZERO);
|
||||
m_uniformIsOpaqueType.resize(m_maxUniformLocation + 1);
|
||||
m_uniformOffsets.resize(m_maxUniformLocation + 1);
|
||||
m_uniformArraySizes.resize(m_maxUniformLocation + 1);
|
||||
m_uniformIndexInTProgram.resize(m_maxUniformLocation + 1, 4095);
|
||||
|
||||
Vector<int> unallocatedUniformIndex;
|
||||
|
||||
@@ -103,26 +99,21 @@ namespace MobileGL {
|
||||
for (int i = 0; i < m_activeUniformCount; i++) {
|
||||
auto& uniform = m_program->getUniform(i);
|
||||
auto location = uniform.layoutLocation();
|
||||
if (location >= m_uniformNames.size()) {
|
||||
if (m_uniformLocations[uniform.name] == 4095) {
|
||||
unallocatedUniformIndex.emplace_back(i);
|
||||
continue; // will allocate unallocated uniforms later
|
||||
}
|
||||
m_uniformNames[location] = uniform.name;
|
||||
m_uniformTypes[location] = uniform.glDefineType;
|
||||
m_uniformIsOpaqueType[location] = uniform.getType()->isOpaque();
|
||||
m_uniformArraySizes[location] = uniform.size;
|
||||
m_uniformIndexInTProgram[location] = i;
|
||||
}
|
||||
|
||||
SizeT locNeedle = 0;
|
||||
for (auto index : unallocatedUniformIndex) {
|
||||
for (auto index: unallocatedUniformIndex) {
|
||||
auto& uniform = m_program->getUniform(index);
|
||||
for (; locNeedle <= m_maxUniformLocation; locNeedle++) {
|
||||
if (m_uniformTypes[locNeedle] != GL_ZERO) continue;
|
||||
if (m_uniformIndexInTProgram[locNeedle] != 4095)
|
||||
continue;
|
||||
// Found a vacant location at locNeedle
|
||||
m_uniformNames[locNeedle] = uniform.name;
|
||||
m_uniformTypes[locNeedle] = uniform.glDefineType;
|
||||
m_uniformIsOpaqueType[locNeedle] = uniform.getType()->isOpaque();
|
||||
m_uniformArraySizes[locNeedle] = uniform.size;
|
||||
m_uniformIndexInTProgram[locNeedle] = index;
|
||||
m_uniformLocations[uniform.name] = locNeedle;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -25,17 +25,27 @@ namespace MobileGL {
|
||||
Uint GetMaxUniformLocation() const { return m_maxUniformLocation; }
|
||||
Int GetUniformLocation(const String& name) {
|
||||
const auto it = m_uniformLocations.find(name);
|
||||
if (it == m_uniformLocations.end()) return -1;
|
||||
if (it == m_uniformLocations.end())
|
||||
return -1;
|
||||
return (Int)it->second;
|
||||
}
|
||||
GLenum GetUniformType(Uint index) const { return m_uniformTypes[index]; }
|
||||
GLenum GetUniformType(Uint location) const {
|
||||
auto& uniform = m_program->getUniform(m_uniformIndexInTProgram[location]);
|
||||
return uniform.glDefineType;
|
||||
}
|
||||
|
||||
Bool IsUniformOpaqueAtLocation(Uint location) const { return m_uniformIsOpaqueType[location]; }
|
||||
Bool IsUniformOpaqueAtLocation(Uint location) const {
|
||||
auto& uniform = m_program->getUniform(m_uniformIndexInTProgram[location]);
|
||||
return uniform.getType()->isOpaque();
|
||||
}
|
||||
|
||||
const String& GetUniformName(Uint index) const { return m_uniformNames[index]; }
|
||||
const String& GetUniformName(Uint location) const {
|
||||
auto& uniform = m_program->getUniform(m_uniformIndexInTProgram[location]);
|
||||
return uniform.name;
|
||||
}
|
||||
Uint GetUniformOffset(Uint location) const { return m_uniformOffsets[location]; }
|
||||
Uint GetUniformSizesInBytes(Uint location) const {
|
||||
return MG_Util::GetGLTypeSize(m_uniformTypes[location]);
|
||||
return MG_Util::GetGLTypeSize(GetUniformType(location));
|
||||
}
|
||||
|
||||
Int GetAttributeLocation(const String& name) {
|
||||
@@ -79,12 +89,8 @@ namespace MobileGL {
|
||||
|
||||
UnorderedMap<String, Uint> m_uniformLocations;
|
||||
// Ordered by location,
|
||||
// aka. m_uniformNames[loc] == "name at location `loc`"
|
||||
Vector<String> m_uniformNames;
|
||||
// ditto.
|
||||
Vector<GLenum> m_uniformTypes;
|
||||
Vector<Bool> m_uniformIsOpaqueType;
|
||||
Vector<Int> m_uniformArraySizes;
|
||||
// aka. m_uniformIndexInTProgram[loc] == "uniform index of TProgram at location `loc`"
|
||||
Vector<Int> m_uniformIndexInTProgram;
|
||||
|
||||
// Need to be reflected after linking of SPIR-V binary
|
||||
Vector<Uint> m_uniformOffsets;
|
||||
|
||||
Reference in New Issue
Block a user