diff options
Diffstat (limited to 'src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp')
-rw-r--r-- | src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp index e2cee1fcd..eb1bd78b3 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp @@ -47,13 +47,9 @@ #include <QSurface> #include <QWindow> #include <QOpenGLTexture> -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #ifdef QT_OPENGL_LIB #include <QtOpenGL/QOpenGLDebugLogger> #endif -#else -#include <QOpenGLDebugLogger> -#endif QT_BEGIN_NAMESPACE @@ -65,8 +61,6 @@ QT_BEGIN_NAMESPACE #define GL_DRAW_FRAMEBUFFER 0x8CA9 #endif -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace OpenGL { @@ -87,14 +81,14 @@ unsigned int nextFreeContextId() namespace { -GLBuffer::Type attributeTypeToGLBufferType(QAttribute::AttributeType type) +GLBuffer::Type attributeTypeToGLBufferType(Qt3DCore::QAttribute::AttributeType type) { switch (type) { - case QAttribute::VertexAttribute: + case Qt3DCore::QAttribute::VertexAttribute: return GLBuffer::ArrayBuffer; - case QAttribute::IndexAttribute: + case Qt3DCore::QAttribute::IndexAttribute: return GLBuffer::IndexBuffer; - case QAttribute::DrawIndirectAttribute: + case Qt3DCore::QAttribute::DrawIndirectAttribute: return GLBuffer::DrawIndirectBuffer; default: Q_UNREACHABLE(); @@ -470,7 +464,19 @@ void SubmissionContext::endDrawing(bool swapBuffers) void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeId, const AttachmentPack &attachments, GLuint defaultFboId) { GLuint fboId = defaultFboId; // Default FBO - if (renderTargetNodeId) { + resolveRenderTargetFormat(); // Reset m_renderTargetFormat based on the default FBO + + // 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) { @@ -480,9 +486,10 @@ void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeI fboId = createRenderTarget(renderTargetNodeId, attachments); } } else { - fboId = updateRenderTarget(renderTargetNodeId, attachments, true); + fboId = updateRenderTarget(renderTargetNodeId, attachments, true); // Overwrites m_renderTargetFormat based on custom FBO } } + m_activeFBO = fboId; m_activeFBONodeId = renderTargetNodeId; m_glHelper->bindFrameBufferObject(m_activeFBO, GraphicsHelperInterface::FBODraw); @@ -612,6 +619,7 @@ QImage SubmissionContext::readFramebuffer(const QRect &rect) QImage::Format imageFormat; uint stride; + // m_renderTargetFormat is set when the current RV FBO is set in activateRenderTarget /* format value should match GL internalFormat */ GLenum internalFormat = m_renderTargetFormat; @@ -860,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"; } |