From cdaca7ee697b4debd987d7d03bbbb0c959d9de6a Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 5 Aug 2017 15:26:55 +0100 Subject: Ensure integer attributes get configured properly For joint indices. Change-Id: If3de9c6e7053a5f445604e776f73e2ff843b0be8 Reviewed-by: Paul Lemire Reviewed-by: Sean Harmer --- src/render/backend/renderer.cpp | 8 ++++---- src/render/graphicshelpers/graphicscontext.cpp | 24 ++++++++++++++++-------- src/render/graphicshelpers/graphicscontext_p.h | 5 ++++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp index df8664f3e..bf34842d1 100644 --- a/src/render/backend/renderer.cpp +++ b/src/render/backend/renderer.cpp @@ -1820,16 +1820,16 @@ bool Renderer::updateVAOWithAttributes(Geometry *geometry, if ((attributeWasDirty = attribute->isDirty()) == true || forceUpdate) { // Find the location for the attribute const QVector shaderAttributes = shader->attributes(); - int attributeLocation = -1; + const ShaderAttribute *attributeDescription = nullptr; for (const ShaderAttribute &shaderAttribute : shaderAttributes) { if (shaderAttribute.m_nameId == attribute->nameId()) { - attributeLocation = shaderAttribute.m_location; + attributeDescription = &shaderAttribute; break; } } - if (attributeLocation < 0) + if (!attributeDescription || attributeDescription->m_location < 0) return false; - m_graphicsContext->specifyAttribute(attribute, buffer, attributeLocation); + m_graphicsContext->specifyAttribute(attribute, buffer, attributeDescription); } } diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp index e480d0aa7..7910c828a 100644 --- a/src/render/graphicshelpers/graphicscontext.cpp +++ b/src/render/graphicshelpers/graphicscontext.cpp @@ -1272,13 +1272,17 @@ void GraphicsContext::enableAttribute(const VAOVertexAttribute &attr) Q_ASSERT(buf); bindGLBuffer(buf, attr.bufferType); - QOpenGLShaderProgram *prog = activeShader(); - prog->enableAttributeArray(attr.location); - prog->setAttributeBuffer(attr.location, - attr.dataType, - attr.byteOffset, - attr.vertexSize, - attr.byteStride); + // Don't use QOpenGLShaderProgram::setAttributeBuffer() because of QTBUG-43199. + // Use the introspection data and set the attribute explicitly + m_glHelper->enableVertexAttributeArray(attr.location); + m_glHelper->vertexAttributePointer(attr.shaderDataType, + attr.location, + attr.vertexSize, + attr.dataType, + GL_TRUE, // TODO: Support normalization property on QAttribute + attr.byteStride, + reinterpret_cast(qintptr(attr.byteOffset))); + // Done by the helper if it supports it if (attr.divisor != 0) @@ -1403,8 +1407,11 @@ void GraphicsContext::applyUniform(const ShaderUniform &description, const Unifo } // Note: needs to be called while VAO is bound -void GraphicsContext::specifyAttribute(const Attribute *attribute, Buffer *buffer, int location) +void GraphicsContext::specifyAttribute(const Attribute *attribute, + Buffer *buffer, + const ShaderAttribute *attributeDescription) { + const int location = attributeDescription->m_location; if (location < 0) { qCWarning(Backend) << "failed to resolve location for attribute:" << attribute->name(); return; @@ -1440,6 +1447,7 @@ void GraphicsContext::specifyAttribute(const Attribute *attribute, Buffer *buffe attr.vertexSize = attribute->vertexSize() / attrCount; attr.byteStride = attribute->byteStride() + (attrCount * attrCount * typeSize); attr.divisor = attribute->divisor(); + attr.shaderDataType = attributeDescription->m_type; enableAttribute(attr); diff --git a/src/render/graphicshelpers/graphicscontext_p.h b/src/render/graphicshelpers/graphicscontext_p.h index f1dc176f8..9252bb467 100644 --- a/src/render/graphicshelpers/graphicscontext_p.h +++ b/src/render/graphicshelpers/graphicscontext_p.h @@ -157,7 +157,9 @@ public: void setRenderer(Renderer *renderer); - void specifyAttribute(const Attribute *attribute, Buffer *buffer, int attributeLocation); + void specifyAttribute(const Attribute *attribute, + Buffer *buffer, + const ShaderAttribute *attributeDescription); void specifyIndices(Buffer *buffer); void updateBuffer(Buffer *buffer); QByteArray downloadBufferContent(Buffer *buffer); @@ -324,6 +326,7 @@ private: uint vertexSize; uint byteStride; uint divisor; + GLenum shaderDataType; }; using VAOIndexAttribute = HGLBuffer; -- cgit v1.2.3