summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-08-05 15:26:55 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-08-10 10:41:33 +0000
commitcdaca7ee697b4debd987d7d03bbbb0c959d9de6a (patch)
treebadcc9ee3929efe42e19ee8932383c9da0e51dd3
parent8103be87b5810f7dd30082844549a5192dd6d180 (diff)
Ensure integer attributes get configured properly
For joint indices. Change-Id: If3de9c6e7053a5f445604e776f73e2ff843b0be8 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/backend/renderer.cpp8
-rw-r--r--src/render/graphicshelpers/graphicscontext.cpp24
-rw-r--r--src/render/graphicshelpers/graphicscontext_p.h5
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<ShaderAttribute> 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<const void *>(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;