[Qt3D] Using a SSBO in Qt3D
-
Hello,
I can't get a SSBO working using Qt3D. I'm also unable to find a single example displaying how it is supposed to be done.
Here are the main parts of my code:Buffer init:
QByteArray ssboData; ssboData.resize(1000); ssboData.fill(0); mySSBOBuffer = new Qt3DRender::QBuffer(this); mySSBOBuffer->setUsage(Qt3DRender::QBuffer::DynamicRead); mySSBOBuffer->setAccessType(Qt3DRender::QBuffer::AccessType::ReadWrite); mySSBOBuffer->setData(ssboData); QByteArray atomicCounterData; atomicCounterData.resize(4); atomicCounterData.fill(0); myAtomicCounterBuffer = new Qt3DRender::QBuffer(this); myAtomicCounterBuffer->setUsage(Qt3DRender::QBuffer::DynamicRead); myAtomicCounterBuffer->setAccessType(Qt3DRender::QBuffer::AccessType::ReadWrite); myAtomicCounterBuffer->setData(atomicCounterData);
Passing the buffers as QParameters to the shader.
myMaterial->addParameter(new Qt3DRender::QParameter("acCountFrags", QVariant::fromValue(myAtomicCounterBuffer->id()), myMaterial)); myMaterial->addParameter(new Qt3DRender::QParameter("ssboBuffer", QVariant::fromValue(mySSBOBuffer->id()), myMaterial));
I also tried
myMaterial->addParameter(new Qt3DRender::QParameter("acCountFrags", QVariant::fromValue(myAtomicCounterBuffer), myMaterial)); myMaterial->addParameter(new Qt3DRender::QParameter("ssboBuffer", QVariant::fromValue(mySSBOBuffer), myMaterial));
Fragment Shader (color has no use, just to check shader is working):
#version 430 core layout(binding = 0, offset = 0) uniform atomic_uint acCountFrags; layout (std430) buffer ssboBuffer { uint fragIds[]; }; out vec4 color; void main() { uint index = atomicCounterIncrement(acCountFrags); fragIds[index] = 5; color = vec4(0.2, 0.2, 0.2, 1.0); }
In all of my tries, nothing is written to the buffers after rendering. They are still full of 0 like after init.
Does anybody know if i'm doing something wrong ? Or somewhere I could find a working example ?Thank you.
-
Hi,
I just got SSBO working with Qt3D. This might be too late for you, but it might help somebody else. Change you shader to something like:
#version 430 core layout(binding = 0, offset = 0) uniform atomic_uint acCountFrags; layout (std430) buffer ssboBuffer { uint fragIds[]; } myssbo; out vec4 color; void main() { uint index = atomicCounterIncrement(acCountFrags); myssbo.fragIds[index] = 5; color = vec4(0.2, 0.2, 0.2, 1.0); }
I have had success passing data from compute shaders into vertex and fragment shaders.
Best regards,
Øystein