diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 8d5fea12bec..7d321ba0d93 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -5634,6 +5634,7 @@ bool QGles2TextureRenderTarget::create() d.colorAttCount = 0; int attIndex = 0; + int multiViewCount = 0; for (auto it = m_desc.cbeginColorAttachments(), itEnd = m_desc.cendColorAttachments(); it != itEnd; ++it, ++attIndex) { d.colorAttCount += 1; const QRhiColorAttachment &colorAtt(*it); @@ -5644,10 +5645,11 @@ bool QGles2TextureRenderTarget::create() QGles2Texture *texD = QRHI_RES(QGles2Texture, texture); Q_ASSERT(texD->texture && texD->specified); if (texD->flags().testFlag(QRhiTexture::ThreeDimensional) || texD->flags().testFlag(QRhiTexture::TextureArray)) { - if (it->multiViewCount() < 2) { + if (colorAtt.multiViewCount() < 2) { rhiD->f->glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uint(attIndex), texD->texture, colorAtt.level(), colorAtt.layer()); } else { + multiViewCount = colorAtt.multiViewCount(); rhiD->glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uint(attIndex), texD->texture, colorAtt.level(), colorAtt.layer(), colorAtt.multiViewCount()); } @@ -5696,8 +5698,13 @@ bool QGles2TextureRenderTarget::create() } } else { QGles2Texture *depthTexD = QRHI_RES(QGles2Texture, m_desc.depthTexture()); - rhiD->f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexD->target, - depthTexD->texture, 0); + if (multiViewCount < 2) { + rhiD->f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexD->target, + depthTexD->texture, 0); + } else { + rhiD->glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexD->texture, + 0, 0, multiViewCount); + } if (d.colorAttCount == 0) { d.pixelSize = depthTexD->pixelSize(); d.sampleCount = 1; diff --git a/tests/manual/rhi/multiview/multiview.cpp b/tests/manual/rhi/multiview/multiview.cpp index 1ade109d1c8..203bc2b668e 100644 --- a/tests/manual/rhi/multiview/multiview.cpp +++ b/tests/manual/rhi/multiview/multiview.cpp @@ -96,7 +96,7 @@ void Window::customInit() // rendered with depth test/write enabled. The catch here is that we must // use a texture array for depth/stencil as well, so QRhiRenderBuffer is // not an option anymore. - d.ds = m_r->newTextureArray(QRhiTexture::D24S8, 2, QSize(512, 512), sampleCount, QRhiTexture::RenderTarget); + d.ds = m_r->newTextureArray(QRhiTexture::D24, 2, QSize(512, 512), sampleCount, QRhiTexture::RenderTarget); d.releasePool << d.ds; d.ds->create();