// temporary static set of binding slots (thread local)
static const auto MAX_UNIFORM_BUFFER_BINDINGS = 64; // TODO: this should be read from introspection
- // TODO: could use vector?
- static thread_local UniformBufferBindingDescriptor sTempBindings[MAX_UNIFORM_BUFFER_BINDINGS];
+ static const UniformBufferBindingDescriptor NULL_DESCRIPTOR{nullptr, 0, 0, 0, 0, false};
+ static thread_local std::vector<UniformBufferBindingDescriptor> sTempBindings(MAX_UNIFORM_BUFFER_BINDINGS, NULL_DESCRIPTOR);
// reset temp bindings
- memset(sTempBindings, 0, sizeof(UniformBufferBindingDescriptor) * MAX_UNIFORM_BUFFER_BINDINGS);
+ std::fill_n(sTempBindings.begin(), MAX_UNIFORM_BUFFER_BINDINGS, NULL_DESCRIPTOR);
- auto maxBinding = 0u;
- bool hasBindings = false;
+ memset(&bindCmd.standaloneUniformsBufferBinding, 0, sizeof(UniformBufferBindingDescriptor));
// find max binding and standalone UBO
- memset(&bindCmd.standaloneUniformsBufferBinding, 0, sizeof(UniformBufferBindingDescriptor));
+ auto maxBinding = 0u;
+ bool hasBindings = false;
for(const auto& binding : bindings)
{
if(binding.buffer)
if(glesBuffer->IsCPUAllocated()) // standalone uniforms
{
bindCmd.standaloneUniformsBufferBinding.buffer = glesBuffer;
- bindCmd.standaloneUniformsBufferBinding.offset = binding.offset;
bindCmd.standaloneUniformsBufferBinding.binding = binding.binding;
+ bindCmd.standaloneUniformsBufferBinding.offset = binding.offset;
bindCmd.standaloneUniformsBufferBinding.emulated = true;
}
else // Bind regular UBO
{
- auto& slot = sTempBindings[binding.binding];
+ auto& slot = sTempBindings[binding.binding];
+
slot.buffer = glesBuffer;
- slot.offset = binding.offset;
slot.binding = binding.binding;
- slot.blockIndex = 0;
- slot.binding = binding.binding; // implicitly
+ slot.offset = binding.offset;
slot.dataSize = binding.dataSize;
+ slot.blockIndex = 0;
slot.emulated = false;
- maxBinding = std::max(maxBinding, binding.binding);
- hasBindings = true;
+
+ maxBinding = std::max(maxBinding, binding.binding);
+ hasBindings = true;
}
}
}
auto size = sizeof(UniformBufferBindingDescriptor) * (maxBinding + 1);
if(!(size % sizeof(intptr_t)))
{
- auto* srcPtr = reinterpret_cast<intptr_t*>(sTempBindings);
+ auto* srcPtr = reinterpret_cast<intptr_t*>(&sTempBindings[0]);
auto* dstPtr = reinterpret_cast<intptr_t*>(destBindings.Ptr());
for(auto i = 0u; i < size / sizeof(intptr_t); ++i)
{
}
else
{
- memcpy(destBindings.Ptr(), sTempBindings, size);
+ memcpy(destBindings.Ptr(), &sTempBindings[0], size);
}
bindCmd.uniformBufferBindings = destBindings;
bindCmd.uniformBufferBindingsCount = maxBinding + 1;
auto activeUniformOffset = getActiveUniformParams(GL_UNIFORM_OFFSET);
// Extract only uniform blocks and collect data
- std::string uniformName;
-
// collect samplers into separate array
std::vector<UniformInfo> samplers;
gl->GetActiveUniform(glProgram, i, maxUniformNameLength, &written, &elementCount, &type, name);
auto location = gl->GetUniformLocation(glProgram, name);
- uniformName = name;
UniformInfo* uniformInfo{nullptr};
if(IsSampler(activeUniformType[i]))
uniformInfo->location = location; // location must be set later and sorted by offset
uniformInfo->name = name;
+
// Strip off array index from name, use element count instead
if(elementCount > 1)
{
- auto iter = std::string(uniformName).find('[', 0);
+ std::string uniformName = name;
+ auto iter = uniformName.find('[', 0);
if(iter != std::string::npos)
{
- uniformInfo->name = std::string(name).substr(0, iter);
+ uniformInfo->name = uniformName.substr(0, iter);
uniformInfo->elementCount = elementCount;
}
}
}
+ delete[] name;
// Sort by offset
uint32_t blockIndex = 0;