Access the object uniforms relative to gl_InstanceIndex
This commit is contained in:
committed by
Mathias Agopian
parent
9ce797eee8
commit
6bc0e032fc
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user