199 m_rhi = m_window->rhi();
201 qWarning(
"No QRhi found for window %p, QQuickRhiItem will not be functional", m_window);
206 m_dpr = m_window->effectiveDevicePixelRatio();
207 const int minTexSize =
m_rhi->resourceLimit(QRhi::TextureSizeMin);
208 const int maxTexSize =
m_rhi->resourceLimit(QRhi::TextureSizeMax);
212 if (newSize.isEmpty())
213 newSize = (QSizeF(m_item->width(), m_item->height()) * m_dpr).toSize();
215 newSize.setWidth(qMin(maxTexSize, qMax(minTexSize, newSize.width())));
216 newSize.setHeight(qMin(maxTexSize, qMax(minTexSize, newSize.height())));
227 if (m_msaaColorBuffer) {
228 if (m_msaaColorBuffer->backingFormat() != itemD->rhiTextureFormat
229 || m_msaaColorBuffer->sampleCount() != itemD->samples)
236 if (m_sgTexture && m_sgTexture->hasAlphaChannel() != itemD->blend) {
242 if (!
m_rhi->isTextureFormatSupported(itemD->rhiTextureFormat)) {
243 qWarning(
"QQuickRhiItem: The requested texture format (%d) is not supported by the "
244 "underlying 3D graphics API implementation",
int(itemD->rhiTextureFormat));
247 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
249 qWarning(
"Failed to create backing texture for QQuickRhiItem");
257 if (!m_msaaColorBuffer) {
258 if (!
m_rhi->isFeatureSupported(QRhi::MultisampleRenderBuffer)) {
259 qWarning(
"QQuickRhiItem: Multisample renderbuffers are reported as unsupported; "
260 "sample count %d will not work as expected", itemD
->samples);
262 if (!
m_rhi->isTextureFormatSupported(itemD->rhiTextureFormat)) {
263 qWarning(
"QQuickRhiItem: The requested texture format (%d) is not supported by the "
264 "underlying 3D graphics API implementation",
int(itemD->rhiTextureFormat));
266 m_msaaColorBuffer.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::Color, newSize, itemD->samples,
267 {}, itemD->rhiTextureFormat));
268 if (!m_msaaColorBuffer->create()) {
269 qWarning(
"Failed to create multisample color buffer for QQuickRhiItem");
270 m_msaaColorBuffer.reset();
276 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
278 qWarning(
"Failed to create resolve texture for QQuickRhiItem");
292 qWarning(
"Failed to rebuild texture for QQuickRhiItem after resizing");
295 if (m_msaaColorBuffer && m_msaaColorBuffer->pixelSize() != newSize) {
296 m_msaaColorBuffer->setPixelSize(newSize);
297 if (!m_msaaColorBuffer->create())
298 qWarning(
"Failed to rebuild multisample color buffer for QQuickRhiitem after resizing");
304 qWarning(
"Failed to rebuild resolve texture for QQuickRhiItem after resizing");
308 QQuickWindow::CreateTextureOptions options;
310 options |= QQuickWindow::TextureHasAlphaChannel;
312 m_sgTexture.reset(m_window->createTextureFromRhiTexture(m_colorTexture ? m_colorTexture : m_resolveTexture,
314 setTexture(m_sgTexture.get());
318 const QSize pixelSize =
m_colorTexture ? m_colorTexture->pixelSize()
319 : m_msaaColorBuffer->pixelSize();
320 if (!m_depthStencilBuffer) {
321 m_depthStencilBuffer.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, pixelSize, itemD->samples,
322 QSGRhiSupport::depthStencilBufferFlags()));
323 if (!m_depthStencilBuffer->create()) {
324 qWarning(
"Failed to create depth-stencil buffer for QQuickRhiItem");
328 }
else if (m_depthStencilBuffer->pixelSize() != pixelSize) {
329 m_depthStencilBuffer->setPixelSize(pixelSize);
330 if (!m_depthStencilBuffer->create()) {
331 qWarning(
"Failed to rebuild depth-stencil buffer for QQuickRhiItem with new size");
335 if (!m_renderTarget) {
338 color0.setTexture(m_colorTexture);
340 color0.setRenderBuffer(m_msaaColorBuffer.get());
341 if (itemD->samples > 1)
342 color0.setResolveTexture(m_resolveTexture);
344 m_renderTarget.reset(m_rhi->newTextureRenderTarget(rtDesc));
345 m_renderPassDescriptor.reset(m_renderTarget->newCompatibleRenderPassDescriptor());
346 m_renderTarget->setRenderPassDescriptor(m_renderPassDescriptor.get());
347 if (!m_renderTarget->create()) {
348 qWarning(
"Failed to create render target for QQuickRhiitem");
357 if (newSize != itemD->effectiveTextureSize) {
358 itemD->effectiveTextureSize = newSize;
359 emit m_item->effectiveColorBufferSizeChanged();
364 m_renderer->initialize(cb);
366 m_renderer->synchronize(m_item);
434QSGNode *QQuickRhiItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
440 if (!oldNode && (width() <= 0 || height() <= 0))
444 QQuickRhiItemNode *n =
static_cast<QQuickRhiItemNode *>(oldNode);
447 d->node =
new QQuickRhiItemNode(
this);
448 if (!d->node->hasRenderer()) {
449 QQuickRhiItemRenderer *r = createRenderer();
452 d->node->setRenderer(r);
454 qWarning(
"No QQuickRhiItemRenderer was created; the item will not render");
471 if (window()->rhi()->isYUpInFramebuffer()) {
472 n->setTextureCoordinatesTransform(d->mirrorVertically
473 ? QSGSimpleTextureNode::NoTransform
474 : QSGSimpleTextureNode::MirrorVertically);
476 n->setTextureCoordinatesTransform(d->mirrorVertically
477 ? QSGSimpleTextureNode::MirrorVertically
478 : QSGSimpleTextureNode::NoTransform);
480 n->setFiltering(d->smooth ? QSGTexture::Linear : QSGTexture::Nearest);
481 n->setRect(0, 0, qMax(qreal(0), width()), qMax(qreal(0), height()));
638void QQuickRhiItem::setColorBufferFormat(TextureFormat format)
641 if (d->itemTextureFormat == format)
644 d->itemTextureFormat = format;
646 case TextureFormat::RGBA8:
647 d->rhiTextureFormat = QRhiTexture::RGBA8;
649 case TextureFormat::RGBA16F:
650 d->rhiTextureFormat = QRhiTexture::RGBA16F;
652 case TextureFormat::RGBA32F:
653 d->rhiTextureFormat = QRhiTexture::RGBA32F;
655 case TextureFormat::RGB10A2:
656 d->rhiTextureFormat = QRhiTexture::RGB10A2;
659 emit colorBufferFormatChanged();
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h