diff options
author | Alexander Busse <alexander.busse@kdab.com> | 2023-02-08 20:20:14 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2023-11-09 09:18:24 +0000 |
commit | ca30b206ccbd93f2304bbfa630a267d3e3ce14fb (patch) | |
tree | 55dbea09900177281b0bbdda81c80b3274aadd3f /src | |
parent | bf1502fc1fd309bd9c4b127fb600fd4b2f2ce5ab (diff) |
Add ability to target Left/Right back buffer to use with stereo mode
RenderTargetOutput adds enums to target stereo buffers.
Change-Id: I7d57ebbad200772e526416d34e2a12135abcec93
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/extras/defaults/qt3dwindow.cpp | 3 | ||||
-rw-r--r-- | src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp | 15 | ||||
-rw-r--r-- | src/render/backend/attachmentpack.cpp | 38 | ||||
-rw-r--r-- | src/render/frontend/qrendertargetoutput.cpp | 12 | ||||
-rw-r--r-- | src/render/frontend/qrendertargetoutput.h | 4 |
5 files changed, 62 insertions, 10 deletions
diff --git a/src/extras/defaults/qt3dwindow.cpp b/src/extras/defaults/qt3dwindow.cpp index 804db0df7..689a0e37e 100644 --- a/src/extras/defaults/qt3dwindow.cpp +++ b/src/extras/defaults/qt3dwindow.cpp @@ -303,7 +303,8 @@ void setupWindowSurface(QWindow *window, Qt3DRender::API api) noexcept } format.setDepthBufferSize(24); - format.setSamples(4); + if (!QSurfaceFormat::defaultFormat().stereo()) + format.setSamples(4); format.setStencilBufferSize(8); window->setFormat(format); QSurfaceFormat::setDefaultFormat(format); diff --git a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp index 6b2536501..eb1bd78b3 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp @@ -466,7 +466,17 @@ void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeI GLuint fboId = defaultFboId; // Default FBO resolveRenderTargetFormat(); // Reset m_renderTargetFormat based on the default FBO - if (renderTargetNodeId) { + // check if target buffer is GL_BACK_LEFT or GL_BACK_RIGHT, as they don't need an + // own fbo + auto allLeftOrRight = std::all_of(attachments.attachments().begin(), attachments.attachments().end(), + [](const Attachment& att){ + return att.m_point == QRenderTargetOutput::Left || att.m_point == QRenderTargetOutput::Right; + }); + + const bool allAttachmentsAreLeftOrRight = attachments.attachments().size() > 0 && allLeftOrRight; + const bool shouldCreateRenderTarget = !allAttachmentsAreLeftOrRight && renderTargetNodeId; + + if (shouldCreateRenderTarget) { // New RenderTarget if (!m_renderTargets.contains(renderTargetNodeId)) { if (m_defaultFBO && fboId == m_defaultFBO) { @@ -858,6 +868,9 @@ void SubmissionContext::activateDrawBuffers(const AttachmentPack &attachments) m_glHelper->drawBuffers(GLsizei(activeDrawBuffers.size()), activeDrawBuffers.data()); } } + else if (activeDrawBuffers.size() == 1){ + m_glHelper->drawBuffer(activeDrawBuffers.at(0)); + } } else { qCWarning(Backend) << "FBO incomplete"; } diff --git a/src/render/backend/attachmentpack.cpp b/src/render/backend/attachmentpack.cpp index 59a832a66..cf7566e23 100644 --- a/src/render/backend/attachmentpack.cpp +++ b/src/render/backend/attachmentpack.cpp @@ -7,6 +7,13 @@ QT_BEGIN_NAMESPACE +#ifndef GL_BACK_LEFT +#define GL_BACK_LEFT 0x0402 +#endif +#ifndef GL_BACK_RIGHT +#define GL_BACK_RIGHT 0x0403 +#endif + namespace Qt3DRender { namespace Render { @@ -39,15 +46,32 @@ AttachmentPack::AttachmentPack(const RenderTarget *target, // If nothing is specified, use all the attachments as draw buffers if (drawBuffers.empty()) { m_drawBuffers.reserve(m_attachments.size()); - for (const Attachment &attachment : std::as_const(m_attachments)) - // only consider Color Attachments - if (attachment.m_point <= QRenderTargetOutput::Color15) - m_drawBuffers.push_back((int) attachment.m_point); + for (const Attachment &attachment : std::as_const(m_attachments)) { + switch (attachment.m_point) { + case QRenderTargetOutput::Left: + m_drawBuffers.push_back(GL_BACK_LEFT); + case QRenderTargetOutput::Right: + m_drawBuffers.push_back(GL_BACK_RIGHT); + default: + if (attachment.m_point >= QRenderTargetOutput::Color0 && attachment.m_point <= QRenderTargetOutput::Color15) + m_drawBuffers.push_back((int) attachment.m_point); + break; + } + } } else { m_drawBuffers.reserve(drawBuffers.size()); - for (QRenderTargetOutput::AttachmentPoint drawBuffer : drawBuffers) - if (drawBuffer <= QRenderTargetOutput::Color15) - m_drawBuffers.push_back((int) drawBuffer); + for (QRenderTargetOutput::AttachmentPoint drawBuffer : drawBuffers) { + switch (drawBuffer) { + case QRenderTargetOutput::Left: + m_drawBuffers.push_back(GL_BACK_LEFT); + case QRenderTargetOutput::Right: + m_drawBuffers.push_back(GL_BACK_RIGHT); + default: + if (drawBuffer >= QRenderTargetOutput::Color0 && drawBuffer <= QRenderTargetOutput::Color15) + m_drawBuffers.push_back((int) drawBuffer); + break; + } + } } } diff --git a/src/render/frontend/qrendertargetoutput.cpp b/src/render/frontend/qrendertargetoutput.cpp index ed83904ca..3be19a2b4 100644 --- a/src/render/frontend/qrendertargetoutput.cpp +++ b/src/render/frontend/qrendertargetoutput.cpp @@ -20,6 +20,9 @@ namespace Qt3DRender { that is attached to render target. In addition to the attachment point, texture miplevel, layer and cubemap face can be specified. The texture attached to the QRenderTargetOutput must be compatible with the given parameters. + + \note Left and Right attachment points are special values. They do not refer to + render target objects to be either of the back buffers used for stereo rendering. */ /*! @@ -35,6 +38,9 @@ namespace Qt3DRender { that is attached to render target. In addition to the attachment point, texture miplevel, layer and cubemap face can be specified. The texture attached to the RenderTargetOutput must be compatible with the given parameters. + + \note Left and Right attachment points are special values. They do not refer to + render target objects to be either of the back buffers used for stereo rendering. */ /*! @@ -61,6 +67,8 @@ namespace Qt3DRender { \value Depth Depth attachment point \value Stencil Stencil attachment point \value DepthStencil DepthStencil attachment point + \value Left Back Left Draw Buffer + \value Right Back Right Draw Buffer */ /*! @@ -86,6 +94,8 @@ namespace Qt3DRender { \li RenderTargetOutput.Depth \li RenderTargetOutput.Stencil \li RenderTargetOutput.DepthStencil + \li RenderTargetOutput.Left + \li RenderTargetOutput.Right \endlist \sa Qt3DRender::QRenderTargetOutput::AttachmentPoint @@ -123,6 +133,8 @@ namespace Qt3DRender { /*! \property QRenderTargetOutput::attachmentPoint Holds the attachment point of the QRenderTargetOutput. + + */ /*! diff --git a/src/render/frontend/qrendertargetoutput.h b/src/render/frontend/qrendertargetoutput.h index 5a574692e..d2e847773 100644 --- a/src/render/frontend/qrendertargetoutput.h +++ b/src/render/frontend/qrendertargetoutput.h @@ -44,7 +44,9 @@ public: Color15, Depth, Stencil, - DepthStencil + DepthStencil, + Left, + Right }; Q_ENUM(AttachmentPoint) // LCOV_EXCL_LINE |