202 m_rhi = m_window->rhi();
204 qWarning(
"No QRhi found for window %p, QQuickRhiItem will not be functional", m_window);
209 m_dpr = m_window->effectiveDevicePixelRatio();
210 const int minTexSize =
m_rhi->resourceLimit(QRhi::TextureSizeMin);
211 const int maxTexSize =
m_rhi->resourceLimit(QRhi::TextureSizeMax);
215 if (newSize.isEmpty())
216 newSize = (QSizeF(m_item->width(), m_item->height()) * m_dpr).toSize();
218 newSize.setWidth(qMin(maxTexSize, qMax(minTexSize, newSize.width())));
219 newSize.setHeight(qMin(maxTexSize, qMax(minTexSize, newSize.height())));
230 if (m_msaaColorBuffer) {
231 if (m_msaaColorBuffer->backingFormat() != itemD->rhiTextureFormat
232 || m_msaaColorBuffer->sampleCount() != itemD->samples)
239 if (m_sgTexture && m_sgTexture->hasAlphaChannel() != itemD->blend) {
245 if (!
m_rhi->isTextureFormatSupported(itemD->rhiTextureFormat)) {
246 qWarning(
"QQuickRhiItem: The requested texture format (%d) is not supported by the "
247 "underlying 3D graphics API implementation",
int(itemD->rhiTextureFormat));
250 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
252 qWarning(
"Failed to create backing texture for QQuickRhiItem");
260 if (!m_msaaColorBuffer) {
261 if (!
m_rhi->isFeatureSupported(QRhi::MultisampleRenderBuffer)) {
262 qWarning(
"QQuickRhiItem: Multisample renderbuffers are reported as unsupported; "
263 "sample count %d will not work as expected", itemD
->samples);
265 if (!
m_rhi->isTextureFormatSupported(itemD->rhiTextureFormat)) {
266 qWarning(
"QQuickRhiItem: The requested texture format (%d) is not supported by the "
267 "underlying 3D graphics API implementation",
int(itemD->rhiTextureFormat));
269 m_msaaColorBuffer.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::Color, newSize, itemD->samples,
270 {}, itemD->rhiTextureFormat));
271 if (!m_msaaColorBuffer->create()) {
272 qWarning(
"Failed to create multisample color buffer for QQuickRhiItem");
273 m_msaaColorBuffer.reset();
279 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
281 qWarning(
"Failed to create resolve texture for QQuickRhiItem");
295 qWarning(
"Failed to rebuild texture for QQuickRhiItem after resizing");
298 if (m_msaaColorBuffer && m_msaaColorBuffer->pixelSize() != newSize) {
299 m_msaaColorBuffer->setPixelSize(newSize);
300 if (!m_msaaColorBuffer->create())
301 qWarning(
"Failed to rebuild multisample color buffer for QQuickRhiitem after resizing");
307 qWarning(
"Failed to rebuild resolve texture for QQuickRhiItem after resizing");
311 QQuickWindow::CreateTextureOptions options;
313 options |= QQuickWindow::TextureHasAlphaChannel;
315 m_sgTexture.reset(m_window->createTextureFromRhiTexture(m_colorTexture ? m_colorTexture : m_resolveTexture,
317 setTexture(m_sgTexture.get());
321 const QSize pixelSize = m_colorTexture ? m_colorTexture->pixelSize()
322 : m_msaaColorBuffer->pixelSize();
323 if (!m_depthStencilBuffer) {
324 m_depthStencilBuffer.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, pixelSize, itemD->samples,
325 QSGRhiSupport::depthStencilBufferFlags()));
326 if (!m_depthStencilBuffer->create()) {
327 qWarning(
"Failed to create depth-stencil buffer for QQuickRhiItem");
331 }
else if (m_depthStencilBuffer->pixelSize() != pixelSize) {
332 m_depthStencilBuffer->setPixelSize(pixelSize);
333 if (!m_depthStencilBuffer->create()) {
334 qWarning(
"Failed to rebuild depth-stencil buffer for QQuickRhiItem with new size");
338 if (!m_renderTarget) {
341 color0.setTexture(m_colorTexture);
343 color0.setRenderBuffer(m_msaaColorBuffer.get());
344 if (itemD->samples > 1)
345 color0.setResolveTexture(m_resolveTexture);
347 m_renderTarget.reset(m_rhi->newTextureRenderTarget(rtDesc));
348 m_renderPassDescriptor.reset(m_renderTarget->newCompatibleRenderPassDescriptor());
349 m_renderTarget->setRenderPassDescriptor(m_renderPassDescriptor.get());
350 if (!m_renderTarget->create()) {
351 qWarning(
"Failed to create render target for QQuickRhiitem");
360 if (newSize != itemD->effectiveTextureSize) {
361 itemD->effectiveTextureSize = newSize;
362 emit m_item->effectiveColorBufferSizeChanged();
367 m_renderer->initialize(cb);
369 m_renderer->synchronize(m_item);
437QSGNode *QQuickRhiItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
443 if (!oldNode && (width() <= 0 || height() <= 0))
447 QQuickRhiItemNode *n =
static_cast<QQuickRhiItemNode *>(oldNode);
450 d->node =
new QQuickRhiItemNode(
this);
451 if (!d->node->hasRenderer()) {
452 QQuickRhiItemRenderer *r = createRenderer();
455 d->node->setRenderer(r);
457 qWarning(
"No QQuickRhiItemRenderer was created; the item will not render");
474 if (window()->rhi()->isYUpInFramebuffer()) {
475 n->setTextureCoordinatesTransform(d->mirrorVertically
476 ? QSGSimpleTextureNode::NoTransform
477 : QSGSimpleTextureNode::MirrorVertically);
479 n->setTextureCoordinatesTransform(d->mirrorVertically
480 ? QSGSimpleTextureNode::MirrorVertically
481 : QSGSimpleTextureNode::NoTransform);
483 n->setFiltering(d->smooth ? QSGTexture::Linear : QSGTexture::Nearest);
484 n->setRect(0, 0, qMax(qreal(0), width()), qMax(qreal(0), height()));
641void QQuickRhiItem::setColorBufferFormat(TextureFormat format)
644 if (d->itemTextureFormat == format)
647 d->itemTextureFormat = format;
649 case TextureFormat::RGBA8:
650 d->rhiTextureFormat = QRhiTexture::RGBA8;
652 case TextureFormat::RGBA16F:
653 d->rhiTextureFormat = QRhiTexture::RGBA16F;
655 case TextureFormat::RGBA32F:
656 d->rhiTextureFormat = QRhiTexture::RGBA32F;
658 case TextureFormat::RGB10A2:
659 d->rhiTextureFormat = QRhiTexture::RGB10A2;
662 emit colorBufferFormatChanged();
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h