197 m_rhi = m_window->rhi();
199 qWarning(
"No QRhi found for window %p, QQuickRhiItem will not be functional", m_window);
204 m_dpr = m_window->effectiveDevicePixelRatio();
205 const int minTexSize =
m_rhi->resourceLimit(QRhi::TextureSizeMin);
206 const int maxTexSize =
m_rhi->resourceLimit(QRhi::TextureSizeMax);
210 if (newSize.isEmpty())
211 newSize = (QSizeF(m_item->width(), m_item->height()) * m_dpr).toSize();
213 newSize.setWidth(qMin(maxTexSize, qMax(minTexSize, newSize.width())));
214 newSize.setHeight(qMin(maxTexSize, qMax(minTexSize, newSize.height())));
225 if (m_msaaColorBuffer) {
226 if (m_msaaColorBuffer->backingFormat() != itemD->rhiTextureFormat
227 || m_msaaColorBuffer->sampleCount() != itemD->samples)
234 if (m_sgTexture && m_sgTexture->hasAlphaChannel() != itemD->blend) {
240 if (!
m_rhi->isTextureFormatSupported(itemD->rhiTextureFormat)) {
241 qWarning(
"QQuickRhiItem: The requested texture format (%d) is not supported by the "
242 "underlying 3D graphics API implementation",
int(itemD->rhiTextureFormat));
245 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
247 qWarning(
"Failed to create backing texture for QQuickRhiItem");
255 if (!m_msaaColorBuffer) {
256 if (!
m_rhi->isFeatureSupported(QRhi::MultisampleRenderBuffer)) {
257 qWarning(
"QQuickRhiItem: Multisample renderbuffers are reported as unsupported; "
258 "sample count %d will not work as expected", itemD
->samples);
260 if (!
m_rhi->isTextureFormatSupported(itemD->rhiTextureFormat)) {
261 qWarning(
"QQuickRhiItem: The requested texture format (%d) is not supported by the "
262 "underlying 3D graphics API implementation",
int(itemD->rhiTextureFormat));
264 m_msaaColorBuffer.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::Color, newSize, itemD->samples,
265 {}, itemD->rhiTextureFormat));
266 if (!m_msaaColorBuffer->create()) {
267 qWarning(
"Failed to create multisample color buffer for QQuickRhiItem");
268 m_msaaColorBuffer.reset();
274 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
276 qWarning(
"Failed to create resolve texture for QQuickRhiItem");
290 qWarning(
"Failed to rebuild texture for QQuickRhiItem after resizing");
293 if (m_msaaColorBuffer && m_msaaColorBuffer->pixelSize() != newSize) {
294 m_msaaColorBuffer->setPixelSize(newSize);
295 if (!m_msaaColorBuffer->create())
296 qWarning(
"Failed to rebuild multisample color buffer for QQuickRhiitem after resizing");
302 qWarning(
"Failed to rebuild resolve texture for QQuickRhiItem after resizing");
306 QQuickWindow::CreateTextureOptions options;
308 options |= QQuickWindow::TextureHasAlphaChannel;
310 m_sgTexture.reset(m_window->createTextureFromRhiTexture(m_colorTexture ? m_colorTexture : m_resolveTexture,
312 setTexture(m_sgTexture.get());
316 const QSize pixelSize =
m_colorTexture ? m_colorTexture->pixelSize()
317 : m_msaaColorBuffer->pixelSize();
318 if (!m_depthStencilBuffer) {
319 m_depthStencilBuffer.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, pixelSize, itemD->samples,
320 QSGRhiSupport::depthStencilBufferFlags()));
321 if (!m_depthStencilBuffer->create()) {
322 qWarning(
"Failed to create depth-stencil buffer for QQuickRhiItem");
326 }
else if (m_depthStencilBuffer->pixelSize() != pixelSize) {
327 m_depthStencilBuffer->setPixelSize(pixelSize);
328 if (!m_depthStencilBuffer->create()) {
329 qWarning(
"Failed to rebuild depth-stencil buffer for QQuickRhiItem with new size");
333 if (!m_renderTarget) {
336 color0.setTexture(m_colorTexture);
338 color0.setRenderBuffer(m_msaaColorBuffer.get());
339 if (itemD->samples > 1)
340 color0.setResolveTexture(m_resolveTexture);
342 m_renderTarget.reset(m_rhi->newTextureRenderTarget(rtDesc));
343 m_renderPassDescriptor.reset(m_renderTarget->newCompatibleRenderPassDescriptor());
344 m_renderTarget->setRenderPassDescriptor(m_renderPassDescriptor.get());
345 if (!m_renderTarget->create()) {
346 qWarning(
"Failed to create render target for QQuickRhiitem");
355 if (newSize != itemD->effectiveTextureSize) {
356 itemD->effectiveTextureSize = newSize;
357 emit m_item->effectiveColorBufferSizeChanged();
362 m_renderer->initialize(cb);
364 m_renderer->synchronize(m_item);
432QSGNode *QQuickRhiItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
438 if (!oldNode && (width() <= 0 || height() <= 0))
442 QQuickRhiItemNode *n =
static_cast<QQuickRhiItemNode *>(oldNode);
445 d->node =
new QQuickRhiItemNode(
this);
446 if (!d->node->hasRenderer()) {
447 QQuickRhiItemRenderer *r = createRenderer();
450 d->node->setRenderer(r);
452 qWarning(
"No QQuickRhiItemRenderer was created; the item will not render");
469 if (window()->rhi()->isYUpInFramebuffer()) {
470 n->setTextureCoordinatesTransform(d->mirrorVertically
471 ? QSGSimpleTextureNode::NoTransform
472 : QSGSimpleTextureNode::MirrorVertically);
474 n->setTextureCoordinatesTransform(d->mirrorVertically
475 ? QSGSimpleTextureNode::MirrorVertically
476 : QSGSimpleTextureNode::NoTransform);
478 n->setFiltering(d->smooth ? QSGTexture::Linear : QSGTexture::Nearest);
479 n->setRect(0, 0, qMax(qreal(0), width()), qMax(qreal(0), height()));
636void QQuickRhiItem::setColorBufferFormat(TextureFormat format)
639 if (d->itemTextureFormat == format)
642 d->itemTextureFormat = format;
644 case TextureFormat::RGBA8:
645 d->rhiTextureFormat = QRhiTexture::RGBA8;
647 case TextureFormat::RGBA16F:
648 d->rhiTextureFormat = QRhiTexture::RGBA16F;
650 case TextureFormat::RGBA32F:
651 d->rhiTextureFormat = QRhiTexture::RGBA32F;
653 case TextureFormat::RGB10A2:
654 d->rhiTextureFormat = QRhiTexture::RGB10A2;
657 emit colorBufferFormatChanged();
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h