From 5a5dfd8fc8714261fb934319321d05a5bd82955f Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 10 Aug 2015 22:30:12 +0200 Subject: Renderer/GLHelpers: handle primitive restart when possible Change-Id: I9270ec5f7909dce84da64a6b539b14afd572a3cc Reviewed-by: Sean Harmer --- src/render/backend/qgraphicscontext.cpp | 12 ++++++++++++ src/render/backend/qgraphicscontext_p.h | 2 ++ src/render/backend/qgraphicshelperes2.cpp | 14 ++++++++------ src/render/backend/qgraphicshelperes2_p.h | 2 ++ src/render/backend/qgraphicshelpergl2.cpp | 12 ++++++++---- src/render/backend/qgraphicshelpergl2_p.h | 2 ++ src/render/backend/qgraphicshelpergl3.cpp | 15 +++++++++++++-- src/render/backend/qgraphicshelpergl3_p.h | 2 ++ src/render/backend/qgraphicshelpergl4.cpp | 11 +++++++++++ src/render/backend/qgraphicshelpergl4_p.h | 2 ++ src/render/backend/qgraphicshelperinterface_p.h | 5 ++++- src/render/backend/renderer.cpp | 5 +++++ 12 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/render/backend/qgraphicscontext.cpp b/src/render/backend/qgraphicscontext.cpp index 797f31041..a13b9572a 100644 --- a/src/render/backend/qgraphicscontext.cpp +++ b/src/render/backend/qgraphicscontext.cpp @@ -742,6 +742,18 @@ GLint QGraphicsContext::maxClipPlaneCount() return m_glHelper->maxClipPlaneCount(); } +void QGraphicsContext::enablePrimitiveRestart(int restartIndex) +{ + if (m_glHelper->supportsFeature(QGraphicsHelperInterface::PrimitiveRestart)) + m_glHelper->enablePrimitiveRestart(restartIndex); +} + +void QGraphicsContext::disablePrimitiveRestart() +{ + if (m_glHelper->supportsFeature(QGraphicsHelperInterface::PrimitiveRestart)) + m_glHelper->disablePrimitiveRestart(); +} + /*! \internal Returns a texture unit for a texture, -1 if all texture units are assigned. diff --git a/src/render/backend/qgraphicscontext_p.h b/src/render/backend/qgraphicscontext_p.h index 04f498ba6..afffbf4ec 100644 --- a/src/render/backend/qgraphicscontext_p.h +++ b/src/render/backend/qgraphicscontext_p.h @@ -181,6 +181,8 @@ public: void enableClipPlane(int clipPlane); void disableClipPlane(int clipPlane); GLint maxClipPlaneCount(); + void enablePrimitiveRestart(int restartIndex); + void disablePrimitiveRestart(); // Helper methods static GLint elementType(GLint type); diff --git a/src/render/backend/qgraphicshelperes2.cpp b/src/render/backend/qgraphicshelperes2.cpp index 4481101b3..4559497c4 100644 --- a/src/render/backend/qgraphicshelperes2.cpp +++ b/src/render/backend/qgraphicshelperes2.cpp @@ -302,12 +302,6 @@ void QGraphicsHelperES2::bindFrameBufferAttachment(QOpenGLTexture *texture, cons bool QGraphicsHelperES2::supportsFeature(QGraphicsHelperInterface::Feature feature) const { switch (feature) { - case MRT: - return false; - case Tessellation: - return false; - case UniformBufferObject: - return false; default: return false; } @@ -528,6 +522,14 @@ GLint QGraphicsHelperES2::maxClipPlaneCount() return 0; } +void QGraphicsHelperES2::enablePrimitiveRestart(int) +{ +} + +void QGraphicsHelperES2::disablePrimitiveRestart() +{ +} + } // Render } //Qt3D diff --git a/src/render/backend/qgraphicshelperes2_p.h b/src/render/backend/qgraphicshelperes2_p.h index 3e15ee9bf..57e77e9ec 100644 --- a/src/render/backend/qgraphicshelperes2_p.h +++ b/src/render/backend/qgraphicshelperes2_p.h @@ -89,6 +89,8 @@ public: void enableClipPlane(int clipPlane) Q_DECL_OVERRIDE; void disableClipPlane(int clipPlane) Q_DECL_OVERRIDE; GLint maxClipPlaneCount() Q_DECL_OVERRIDE; + void enablePrimitiveRestart(int primitiveRestartIndex) Q_DECL_OVERRIDE; + void disablePrimitiveRestart() Q_DECL_OVERRIDE; private: QOpenGLFunctions *m_funcs; diff --git a/src/render/backend/qgraphicshelpergl2.cpp b/src/render/backend/qgraphicshelpergl2.cpp index 5a9373860..b3ef699bc 100644 --- a/src/render/backend/qgraphicshelpergl2.cpp +++ b/src/render/backend/qgraphicshelpergl2.cpp @@ -303,10 +303,6 @@ bool QGraphicsHelperGL2::supportsFeature(QGraphicsHelperInterface::Feature featu switch (feature) { case MRT: return (m_fboFuncs != Q_NULLPTR); - case Tessellation: - return false; - case UniformBufferObject: - return false; default: return false; } @@ -536,6 +532,14 @@ GLint QGraphicsHelperGL2::maxClipPlaneCount() return max; } +void QGraphicsHelperGL2::enablePrimitiveRestart(int) +{ +} + +void QGraphicsHelperGL2::disablePrimitiveRestart() +{ +} + } // Render } // Qt3D diff --git a/src/render/backend/qgraphicshelpergl2_p.h b/src/render/backend/qgraphicshelpergl2_p.h index ae25e201d..673c48125 100644 --- a/src/render/backend/qgraphicshelpergl2_p.h +++ b/src/render/backend/qgraphicshelpergl2_p.h @@ -91,6 +91,8 @@ public: void enableClipPlane(int clipPlane) Q_DECL_OVERRIDE; void disableClipPlane(int clipPlane) Q_DECL_OVERRIDE; GLint maxClipPlaneCount() Q_DECL_OVERRIDE; + void enablePrimitiveRestart(int primitiveRestartIndex) Q_DECL_OVERRIDE; + void disablePrimitiveRestart() Q_DECL_OVERRIDE; private: QOpenGLFunctions_2_0 *m_funcs; diff --git a/src/render/backend/qgraphicshelpergl3.cpp b/src/render/backend/qgraphicshelpergl3.cpp index 8901185a7..f5c046e61 100644 --- a/src/render/backend/qgraphicshelpergl3.cpp +++ b/src/render/backend/qgraphicshelpergl3.cpp @@ -324,11 +324,11 @@ bool QGraphicsHelperGL3::supportsFeature(QGraphicsHelperInterface::Feature featu { switch (feature) { case MRT: + case UniformBufferObject: + case PrimitiveRestart: return true; case Tessellation: return !m_tessFuncs.isNull(); - case UniformBufferObject: - return true; default: return false; } @@ -881,6 +881,17 @@ GLint QGraphicsHelperGL3::maxClipPlaneCount() return max; } +void QGraphicsHelperGL3::enablePrimitiveRestart(int primitiveRestartIndex) +{ + m_funcs->glPrimitiveRestartIndex(primitiveRestartIndex); + m_funcs->glEnable(GL_PRIMITIVE_RESTART); +} + +void QGraphicsHelperGL3::disablePrimitiveRestart() +{ + m_funcs->glDisable(GL_PRIMITIVE_RESTART); +} + } // Render } // Qt3D diff --git a/src/render/backend/qgraphicshelpergl3_p.h b/src/render/backend/qgraphicshelpergl3_p.h index 80917d089..7a3d7a61c 100644 --- a/src/render/backend/qgraphicshelpergl3_p.h +++ b/src/render/backend/qgraphicshelpergl3_p.h @@ -92,6 +92,8 @@ public: void enableClipPlane(int clipPlane) Q_DECL_OVERRIDE; void disableClipPlane(int clipPlane) Q_DECL_OVERRIDE; GLint maxClipPlaneCount() Q_DECL_OVERRIDE; + void enablePrimitiveRestart(int primitiveRestartIndex) Q_DECL_OVERRIDE; + void disablePrimitiveRestart() Q_DECL_OVERRIDE; private: QOpenGLFunctions_3_2_Core *m_funcs; diff --git a/src/render/backend/qgraphicshelpergl4.cpp b/src/render/backend/qgraphicshelpergl4.cpp index 103ea15bf..4102bfa4c 100644 --- a/src/render/backend/qgraphicshelpergl4.cpp +++ b/src/render/backend/qgraphicshelpergl4.cpp @@ -863,6 +863,17 @@ GLint QGraphicsHelperGL4::maxClipPlaneCount() return max; } +void QGraphicsHelperGL4::enablePrimitiveRestart(int primitiveRestartIndex) +{ + m_funcs->glPrimitiveRestartIndex(primitiveRestartIndex); + m_funcs->glEnable(GL_PRIMITIVE_RESTART); +} + +void QGraphicsHelperGL4::disablePrimitiveRestart() +{ + m_funcs->glDisable(GL_PRIMITIVE_RESTART); +} + } // Render } // Qt3D diff --git a/src/render/backend/qgraphicshelpergl4_p.h b/src/render/backend/qgraphicshelpergl4_p.h index 0c2f82f3c..d74ebfe80 100644 --- a/src/render/backend/qgraphicshelpergl4_p.h +++ b/src/render/backend/qgraphicshelpergl4_p.h @@ -91,6 +91,8 @@ public: void enableClipPlane(int clipPlane) Q_DECL_OVERRIDE; void disableClipPlane(int clipPlane) Q_DECL_OVERRIDE; GLint maxClipPlaneCount() Q_DECL_OVERRIDE; + void enablePrimitiveRestart(int primitiveRestartIndex) Q_DECL_OVERRIDE; + void disablePrimitiveRestart() Q_DECL_OVERRIDE; private: QOpenGLFunctions_4_3_Core *m_funcs; diff --git a/src/render/backend/qgraphicshelperinterface_p.h b/src/render/backend/qgraphicshelperinterface_p.h index 4ec22e28e..16543382d 100644 --- a/src/render/backend/qgraphicshelperinterface_p.h +++ b/src/render/backend/qgraphicshelperinterface_p.h @@ -56,7 +56,8 @@ public: MRT = 0, Tessellation, UniformBufferObject, - BindableFragmentOutputs + BindableFragmentOutputs, + PrimitiveRestart }; virtual ~QGraphicsHelperInterface() {} @@ -96,6 +97,8 @@ public: virtual void enableClipPlane(int clipPlane) = 0; virtual void disableClipPlane(int clipPlane) = 0; virtual GLint maxClipPlaneCount() = 0; + virtual void enablePrimitiveRestart(int primitiveRestartIndex) = 0; + virtual void disablePrimitiveRestart() = 0; }; diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp index b79ebbecb..5e91da014 100644 --- a/src/render/backend/renderer.cpp +++ b/src/render/backend/renderer.cpp @@ -916,6 +916,9 @@ void Renderer::executeCommands(const QVector &commands) if (rGeometryRenderer->primitiveType() == QGeometryRenderer::Patches) m_graphicsContext->setVerticesPerPatch(rGeometry->verticesPerPatch()); + if (rGeometryRenderer->primitiveRestart()) + m_graphicsContext->enablePrimitiveRestart(rGeometryRenderer->restartIndex()); + // TO DO: Add glMulti Draw variants if (!drawInstanced) { // Non instanced Rendering if (drawIndexed) @@ -945,6 +948,8 @@ void Renderer::executeCommands(const QVector &commands) if (err) qCWarning(Rendering) << "GL error after drawing mesh:" << QString::number(err, 16); + if (rGeometryRenderer->primitiveRestart()) + m_graphicsContext->disablePrimitiveRestart(); // 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 ? -- cgit v1.2.3