Access the object uniforms relative to gl_InstanceIndex

This commit is contained in:
Mathias Agopian
2022-07-06 15:51:41 -07:00
committed by Mathias Agopian
parent 9ce797eee8
commit 6bc0e032fc
5 changed files with 15 additions and 3 deletions
+1 -1
View File
@@ -557,7 +557,7 @@ void FView::prepare(FEngine& engine, DriverApi& driver, ArenaScope& arena,
const size_t count = std::max(size_t(16u), (4u * merged.size() + 2u) / 3u);
mRenderableUBOSize = uint32_t(count * sizeof(PerRenderableData));
driver.destroyBufferObject(mRenderableUbh);
mRenderableUbh = driver.createBufferObject(mRenderableUBOSize,
mRenderableUbh = driver.createBufferObject(mRenderableUBOSize + sizeof(PerRenderableUib),
BufferObjectBinding::UNIFORM, BufferUsage::DYNAMIC);
} else {
// TODO: should we shrink the underlying UBO at some point?
@@ -211,7 +211,7 @@ static_assert(sizeof(PerRenderableData) == 256,
struct alignas(256) PerRenderableUib { // NOLINT(cppcoreguidelines-pro-type-member-init)
static constexpr utils::StaticString _name{ "ObjectUniforms" };
PerRenderableData data[1];
PerRenderableData data[64];
};
// PerRenderableUib must have an alignment of 256 to be compatible with all versions of GLES.
static_assert(sizeof(PerRenderableUib) <= 16384,
+1 -1
View File
@@ -149,7 +149,7 @@ UniformInterfaceBlock const& UibGenerator::getPerViewUib() noexcept {
UniformInterfaceBlock const& UibGenerator::getPerRenderableUib() noexcept {
static UniformInterfaceBlock uib = UniformInterfaceBlock::Builder()
.name(PerRenderableUib::_name)
.add("data", 1, "PerRenderableData", sizeof(PerRenderableData))
.add("data", 64, "PerRenderableData", sizeof(PerRenderableData))
.build();
return uib;
}
+6
View File
@@ -141,5 +141,11 @@ highp vec4 getCascadeLightSpacePosition(uint cascade) {
#endif
PerRenderableData getObjectUniforms() {
#if defined(MATERIAL_HAS_INSTANCES)
// the material manages instancing, all instances share the same uniform block.
return objectUniforms.data[0];
#else
// automatic instancing was used, each instance has its own uniform block.
return objectUniforms.data[instance_index];
#endif
}
+6
View File
@@ -18,7 +18,13 @@ mat4 getLightFromWorldMatrix() {
}
PerRenderableData getObjectUniforms() {
#if defined(MATERIAL_HAS_INSTANCES)
// the material manages instancing, all instances share the same uniform block.
return objectUniforms.data[0];
#else
// automatic instancing was used, each instance has its own uniform block.
return objectUniforms.data[instance_index];
#endif
}
/** @public-api */