summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-08-06 11:06:34 +0200
committerPaul Lemire <paul.lemire@kdab.com>2015-08-07 14:32:28 +0000
commitf402973ff7180b861ba18c4433c31aa591a64c45 (patch)
treedc1848767985eaf1cd45a62f9a15f1e5265b67f9
parent72c35f5e3e270d786f25d88f7fcee0a47ca9fefb (diff)
Renderer: fix properly compute geometry draw count
Change-Id: I77e0e319a45e91acb1312d1616b030285f215393 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/backend/renderer.cpp25
-rw-r--r--src/render/backend/renderer_p.h2
2 files changed, 14 insertions, 13 deletions
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp
index cd2d2e17e..79184b801 100644
--- a/src/render/backend/renderer.cpp
+++ b/src/render/backend/renderer.cpp
@@ -855,7 +855,7 @@ void Renderer::executeCommands(const QVector<RenderCommand *> &commands)
RenderAttribute *indexAttribute = Q_NULLPTR;
bool specified = false;
const bool requiresVAOUpdate = (!vao || !vao->isCreated()) || (rGeometry->isDirty() || rGeometryRenderer->isDirty());
- GLuint primitiveCount = rGeometryRenderer->primitiveCount();
+ GLsizei primitiveCount = rGeometryRenderer->primitiveCount();
// Append dirty Geometry to temporary vector
// so that its dirtiness can be unset later
@@ -928,6 +928,10 @@ void Renderer::executeCommands(const QVector<RenderCommand *> &commands)
if (err)
qCWarning(Rendering) << "GL error after drawing mesh:" << QString::number(err, 16);
+
+ // Maybe we could cache the VAO and release it only at the end of the exectute frame
+ // in case we are always reusing the same one ?
+
if (vao && vao->isCreated())
vao->release();
@@ -952,9 +956,10 @@ void Renderer::executeCommands(const QVector<RenderCommand *> &commands)
m_dirtyGeometry.clear();
}
-RenderAttribute *Renderer::updateBuffersAndAttributes(RenderGeometry *geometry, RenderCommand *command, GLuint &count, bool forceUpdate)
+RenderAttribute *Renderer::updateBuffersAndAttributes(RenderGeometry *geometry, RenderCommand *command, GLsizei &count, bool forceUpdate)
{
RenderAttribute *indexAttribute = Q_NULLPTR;
+ uint estimatedCount = 0;
Q_FOREACH (const QNodeId &attributeId, geometry->attributes()) {
// TO DO: Improvement we could store handles and use the non locking policy on the attributeManager
@@ -977,29 +982,20 @@ RenderAttribute *Renderer::updateBuffersAndAttributes(RenderGeometry *geometry,
buffer->unsetDirty();
}
- int estimatedCount = 0;
-
// Update attribute and create buffer if needed
// Index Attribute
if (attribute->attributeType() == QAttribute::IndexAttribute) {
if (attribute->isDirty() || forceUpdate)
m_graphicsContext->specifyIndices(buffer);
- estimatedCount = attribute->count();
indexAttribute = attribute;
// Vertex Attribute
} else if (command->m_parameterAttributeToShaderNames.contains(attribute->name())) {
if (attribute->isDirty() || forceUpdate)
m_graphicsContext->specifyAttribute(attribute, buffer);
- if (estimatedCount == 0)
- estimatedCount = attribute->count();
+ estimatedCount = qMax(attribute->count(), estimatedCount);
}
- // If the count was not specified by the geometry renderer
- // we set it to what we estimated it to be
- if (count == 0)
- count = estimatedCount;
-
// Append attribute to temporary vector so that its dirtiness
// can be cleared at the end of the frame
m_dirtyAttributes.push_back(attribute);
@@ -1010,6 +1006,11 @@ RenderAttribute *Renderer::updateBuffersAndAttributes(RenderGeometry *geometry,
// should remain dirty so that VAO for these commands are properly
// updated
}
+
+ // If the count was not specified by the geometry renderer
+ // we set it to what we estimated it to be
+ if (count == 0)
+ count = indexAttribute ? indexAttribute->count() : estimatedCount;
return indexAttribute;
}
diff --git a/src/render/backend/renderer_p.h b/src/render/backend/renderer_p.h
index 48a3e6309..9e1ba5b63 100644
--- a/src/render/backend/renderer_p.h
+++ b/src/render/backend/renderer_p.h
@@ -153,7 +153,7 @@ public:
QVector<QAspectJobPtr> createRenderBufferJobs();
QAspectJobPtr createRenderViewJob(FrameGraphNode *node, int submitOrderIndex);
void executeCommands(const QVector<RenderCommand *> &commands);
- RenderAttribute *updateBuffersAndAttributes(RenderGeometry *geometry, RenderCommand *command, GLuint &count, bool forceUpdate);
+ RenderAttribute *updateBuffersAndAttributes(RenderGeometry *geometry, RenderCommand *command, GLsizei &count, bool forceUpdate);
void addAllocator(QFrameAllocator *allocator);
inline MeshDataManager *meshDataManager() const { return m_meshDataManager; }