diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2019-11-29 12:01:11 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2019-12-03 07:02:41 +0100 |
commit | a83d7847eae1c67ae5eb35e62b1d7549c90fae3a (patch) | |
tree | 1a4b1e28b06466bc8ffc463ac404d6a14c99da9c /src/render/renderers/opengl | |
parent | 5fb374d64c788ed830cc1473cb0b2c855e48e2dc (diff) |
Fill as much as what we can when building the RC
Avoids repeating that process over and over again in
the submission phase.
Change-Id: Ie2fa36842cd7280f7c966381238e90dd2dbaa821
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/renderers/opengl')
-rw-r--r-- | src/render/renderers/opengl/renderer/renderer.cpp | 68 | ||||
-rw-r--r-- | src/render/renderers/opengl/renderer/renderview.cpp | 76 |
2 files changed, 75 insertions, 69 deletions
diff --git a/src/render/renderers/opengl/renderer/renderer.cpp b/src/render/renderers/opengl/renderer/renderer.cpp index a530c26b0..d79750726 100644 --- a/src/render/renderers/opengl/renderer/renderer.cpp +++ b/src/render/renderers/opengl/renderer/renderer.cpp @@ -1019,74 +1019,6 @@ void Renderer::prepareCommandsSubmission(const QVector<RenderView *> &renderView // Prepare the ShaderParameterPack based on the active uniforms of the shader shader->prepareUniforms(command.m_parameterPack); - { // Scoped to show extent - command.m_isValid = !command.m_activeAttributes.empty(); - if (!command.m_isValid) - continue; - - // Update the draw command with what's going to be needed for the drawing - uint primitiveCount = rGeometryRenderer->vertexCount(); - uint estimatedCount = 0; - Attribute *indexAttribute = nullptr; - Attribute *indirectAttribute = nullptr; - - const QVector<Qt3DCore::QNodeId> attributeIds = rGeometry->attributes(); - for (Qt3DCore::QNodeId attributeId : attributeIds) { - Attribute *attribute = m_nodesManager->attributeManager()->lookupResource(attributeId); - switch (attribute->attributeType()) { - case QAttribute::IndexAttribute: - indexAttribute = attribute; - break; - case QAttribute::DrawIndirectAttribute: - indirectAttribute = attribute; - break; - case QAttribute::VertexAttribute: { - if (command.m_activeAttributes.contains(attribute->nameId())) - estimatedCount = qMax(attribute->count(), estimatedCount); - break; - } - default: - Q_UNREACHABLE(); - break; - } - } - - command.m_drawIndexed = (indexAttribute != nullptr); - command.m_drawIndirect = (indirectAttribute != nullptr); - - // Update the draw command with all the information required for the drawing - if (command.m_drawIndexed) { - command.m_indexAttributeDataType = GraphicsContext::glDataTypeFromAttributeDataType(indexAttribute->vertexBaseType()); - command.m_indexAttributeByteOffset = indexAttribute->byteOffset() + rGeometryRenderer->indexBufferByteOffset(); - } - - // Note: we only care about the primitiveCount when using direct draw calls - // For indirect draw calls it is assumed the buffer was properly set already - if (command.m_drawIndirect) { - command.m_indirectAttributeByteOffset = indirectAttribute->byteOffset(); - command.m_indirectDrawBuffer = m_nodesManager->bufferManager()->lookupHandle(indirectAttribute->bufferId()); - } else { - // Use the count specified by the GeometryRender - // If not specify use the indexAttribute count if present - // Otherwise tries to use the count from the attribute with the highest count - if (primitiveCount == 0) { - if (indexAttribute) - primitiveCount = indexAttribute->count(); - else - primitiveCount = estimatedCount; - } - } - - command.m_primitiveCount = primitiveCount; - command.m_primitiveType = rGeometryRenderer->primitiveType(); - command.m_primitiveRestartEnabled = rGeometryRenderer->primitiveRestartEnabled(); - command.m_restartIndexValue = rGeometryRenderer->restartIndexValue(); - command.m_firstInstance = rGeometryRenderer->firstInstance(); - command.m_instanceCount = rGeometryRenderer->instanceCount(); - command.m_firstVertex = rGeometryRenderer->firstVertex(); - command.m_indexOffset = rGeometryRenderer->indexOffset(); - command.m_verticesPerPatch = rGeometryRenderer->verticesPerPatch(); - } // scope } else if (command.m_type == RenderCommand::Compute) { Shader *shader = m_nodesManager->data<Shader, ShaderManager>(command.m_shader); Q_ASSERT(shader); diff --git a/src/render/renderers/opengl/renderer/renderview.cpp b/src/render/renderers/opengl/renderer/renderview.cpp index 2eabec4ea..042b60163 100644 --- a/src/render/renderers/opengl/renderer/renderview.cpp +++ b/src/render/renderers/opengl/renderer/renderview.cpp @@ -643,12 +643,15 @@ EntityRenderCommandData RenderView::buildDrawRenderCommands(const QVector<Entity const HMaterial materialHandle = entity->componentHandle<Material>(); const QVector<RenderPassParameterData> renderPassData = m_parameters.value(materialComponentId); + HGeometry geometryHandle = m_manager->geometryManager()->lookupHandle(geometryRenderer->geometryId()); + Geometry *geometry = m_manager->geometryManager()->data(geometryHandle); + // 1 RenderCommand per RenderPass pass on an Entity with a Mesh for (const RenderPassParameterData &passData : renderPassData) { // Add the RenderPass Parameters RenderCommand command = {}; command.m_geometryRenderer = geometryRendererHandle; - command.m_geometry = m_manager->geometryManager()->lookupHandle(geometryRenderer->geometryId()); + command.m_geometry = geometryHandle; command.m_material = materialHandle; // For RenderPass based states we use the globally set RenderState @@ -665,6 +668,73 @@ EntityRenderCommandData RenderView::buildDrawRenderCommands(const QVector<Entity } command.m_shader = m_manager->lookupHandle<Shader, ShaderManager, HShader>(pass->shaderProgram()); + { // Scoped to show extent + + // Update the draw command with what's going to be needed for the drawing + int primitiveCount = geometryRenderer->vertexCount(); + int estimatedCount = 0; + Attribute *indexAttribute = nullptr; + Attribute *indirectAttribute = nullptr; + + const QVector<Qt3DCore::QNodeId> attributeIds = geometry->attributes(); + for (Qt3DCore::QNodeId attributeId : attributeIds) { + Attribute *attribute = m_manager->attributeManager()->lookupResource(attributeId); + switch (attribute->attributeType()) { + case QAttribute::IndexAttribute: + indexAttribute = attribute; + break; + case QAttribute::DrawIndirectAttribute: + indirectAttribute = attribute; + break; + case QAttribute::VertexAttribute: { + if (command.m_activeAttributes.contains(attribute->nameId())) + estimatedCount = std::max(int(attribute->count()), estimatedCount); + break; + } + default: + Q_UNREACHABLE(); + break; + } + } + + command.m_drawIndexed = (indexAttribute != nullptr); + command.m_drawIndirect = (indirectAttribute != nullptr); + + // Update the draw command with all the information required for the drawing + if (command.m_drawIndexed) { + command.m_indexAttributeDataType = GraphicsContext::glDataTypeFromAttributeDataType(indexAttribute->vertexBaseType()); + command.m_indexAttributeByteOffset = indexAttribute->byteOffset() + geometryRenderer->indexBufferByteOffset(); + } + + // Note: we only care about the primitiveCount when using direct draw calls + // For indirect draw calls it is assumed the buffer was properly set already + if (command.m_drawIndirect) { + command.m_indirectAttributeByteOffset = indirectAttribute->byteOffset(); + command.m_indirectDrawBuffer = m_manager->bufferManager()->lookupHandle(indirectAttribute->bufferId()); + } else { + // Use the count specified by the GeometryRender + // If not specify use the indexAttribute count if present + // Otherwise tries to use the count from the attribute with the highest count + if (primitiveCount == 0) { + if (indexAttribute) + primitiveCount = indexAttribute->count(); + else + primitiveCount = estimatedCount; + } + } + + command.m_primitiveCount = primitiveCount; + command.m_primitiveType = geometryRenderer->primitiveType(); + command.m_primitiveRestartEnabled = geometryRenderer->primitiveRestartEnabled(); + command.m_restartIndexValue = geometryRenderer->restartIndexValue(); + command.m_firstInstance = geometryRenderer->firstInstance(); + command.m_instanceCount = geometryRenderer->instanceCount(); + command.m_firstVertex = geometryRenderer->firstVertex(); + command.m_indexOffset = geometryRenderer->indexOffset(); + command.m_verticesPerPatch = geometryRenderer->verticesPerPatch(); + } // scope + + commands.push_back(entity, std::move(command), std::move(passData)); @@ -986,6 +1056,10 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, // Set default attributes command->m_activeAttributes = attributeNamesIds; + // At this point we know whether the command is a valid draw command or not + // We still need to process the uniforms as the command could be a compute command + command->m_isValid = !command->m_activeAttributes.empty(); + // Parameters remaining could be // -> uniform scalar / vector // -> uniform struct / arrays |