diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2020-08-10 09:50:32 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2020-08-10 16:57:38 +0200 |
commit | 46e56c81ee20324e77cc91e3eca76fe946368804 (patch) | |
tree | e1524eb5b6f79c53207922cda1d456c0447564ee /src | |
parent | b146ebf6ebbe805f0ba84b314a2b2581713a7751 (diff) |
rhi: compute correct attribute stride if set to 0
OpenGL works with a stride of 0 where it assumes tight packing. Other
graphics APIs don't accept that.
Change-Id: I0f7a94c41543271300a8f0eff4a32b97aa3d297d
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/renderers/rhi/renderer/renderer.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/plugins/renderers/rhi/renderer/renderer.cpp b/src/plugins/renderers/rhi/renderer/renderer.cpp index b2fdc2a08..480c1d5fc 100644 --- a/src/plugins/renderers/rhi/renderer/renderer.cpp +++ b/src/plugins/renderers/rhi/renderer/renderer.cpp @@ -1639,7 +1639,32 @@ bool Renderer::prepareGeometryInputBindings(const Geometry *geometry, const RHIS const QRhiVertexInputBinding::Classification classification = isPerInstanceAttr ? QRhiVertexInputBinding::PerInstance : QRhiVertexInputBinding::PerVertex; - const BufferBinding binding = { attrib->bufferId(), attrib->byteStride(), + + auto getAttributeByteSize = [] (const QAttribute::VertexBaseType type) { + switch (type) { + case QAttribute::Byte: + case QAttribute::UnsignedByte: + return 1; + case QAttribute::Short: + case QAttribute::UnsignedShort: + case QAttribute::HalfFloat: + return 2; + case QAttribute::Int: + case QAttribute::UnsignedInt: + case QAttribute::Float: + return 4; + case QAttribute::Double: + return 8; + } + }; + + uint byteStride = attrib->byteStride(); + // in GL 0 means tighly packed, we therefore assume a tighly packed + // attribute and compute the stride if that happens + if (byteStride == 0) + byteStride = attrib->vertexSize() * getAttributeByteSize(attrib->vertexBaseType()); + + const BufferBinding binding = { attrib->bufferId(), byteStride, classification, isPerInstanceAttr ? attrib->divisor() : 1U }; |