205 m_rhi = m_window->rhi();
207 qWarning(
"No QRhi found for window %p, QQuickRhiItem will not be functional", m_window);
212 m_dpr = m_window->effectiveDevicePixelRatio();
213 const int minTexSize = m_rhi->resourceLimit(QRhi::TextureSizeMin);
214 const int maxTexSize = m_rhi->resourceLimit(QRhi::TextureSizeMax);
217 QSize newSize = QSize(itemD->fixedTextureWidth, itemD->fixedTextureHeight);
218 if (newSize.isEmpty())
219 newSize = QSize(
int(m_item->width()),
int(m_item->height())) * m_dpr;
221 newSize.setWidth(qMin(maxTexSize, qMax(minTexSize, newSize.width())));
222 newSize.setHeight(qMin(maxTexSize, qMax(minTexSize, newSize.height())));
233 if (m_msaaColorBuffer) {
234 if (m_msaaColorBuffer->backingFormat() != itemD->rhiTextureFormat
235 || m_msaaColorBuffer->sampleCount() != itemD->samples)
242 if (m_sgTexture && m_sgTexture->hasAlphaChannel() != itemD->blend) {
248 if (!
m_rhi->isTextureFormatSupported(itemD->rhiTextureFormat)) {
249 qWarning(
"QQuickRhiItem: The requested texture format (%d) is not supported by the "
250 "underlying 3D graphics API implementation",
int(itemD->rhiTextureFormat));
252 m_colorTexture = m_rhi->newTexture(itemD->rhiTextureFormat, newSize, itemD->samples,
253 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
255 qWarning(
"Failed to create backing texture for QQuickRhiItem");
263 if (!m_msaaColorBuffer) {
264 if (!m_rhi->isFeatureSupported(QRhi::MultisampleRenderBuffer)) {
265 qWarning(
"QQuickRhiItem: Multisample renderbuffers are reported as unsupported; "
266 "sample count %d will not work as expected", itemD
->samples);
268 if (!
m_rhi->isTextureFormatSupported(itemD->rhiTextureFormat)) {
269 qWarning(
"QQuickRhiItem: The requested texture format (%d) is not supported by the "
270 "underlying 3D graphics API implementation",
int(itemD->rhiTextureFormat));
272 m_msaaColorBuffer.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::Color, newSize, itemD->samples,
273 {}, itemD->rhiTextureFormat));
274 if (!m_msaaColorBuffer->create()) {
275 qWarning(
"Failed to create multisample color buffer for QQuickRhiItem");
276 m_msaaColorBuffer.reset();
281 m_resolveTexture = m_rhi->newTexture(itemD->rhiTextureFormat, newSize, 1,
282 QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource);
284 qWarning(
"Failed to create resolve texture for QQuickRhiItem");
298 qWarning(
"Failed to rebuild texture for QQuickRhiItem after resizing");
301 if (m_msaaColorBuffer && m_msaaColorBuffer->pixelSize() != newSize) {
302 m_msaaColorBuffer->setPixelSize(newSize);
303 if (!m_msaaColorBuffer->create())
304 qWarning(
"Failed to rebuild multisample color buffer for QQuickRhiitem after resizing");
310 qWarning(
"Failed to rebuild resolve texture for QQuickRhiItem after resizing");
314 QQuickWindow::CreateTextureOptions options;
316 options |= QQuickWindow::TextureHasAlphaChannel;
318 m_sgTexture.reset(m_window->createTextureFromRhiTexture(m_colorTexture ? m_colorTexture : m_resolveTexture,
320 setTexture(m_sgTexture.get());
324 const QSize pixelSize = m_colorTexture ? m_colorTexture->pixelSize()
325 : m_msaaColorBuffer->pixelSize();
326 if (!m_depthStencilBuffer) {
327 m_depthStencilBuffer.reset(m_rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, pixelSize, itemD->samples));
328 if (!m_depthStencilBuffer->create()) {
329 qWarning(
"Failed to create depth-stencil buffer for QQuickRhiItem");
333 }
else if (m_depthStencilBuffer->pixelSize() != pixelSize) {
334 m_depthStencilBuffer->setPixelSize(pixelSize);
335 if (!m_depthStencilBuffer->create()) {
336 qWarning(
"Failed to rebuild depth-stencil buffer for QQuickRhiItem with new size");
340 if (!m_renderTarget) {
343 color0.setTexture(m_colorTexture);
345 color0.setRenderBuffer(m_msaaColorBuffer.get());
346 if (itemD->samples > 1)
347 color0.setResolveTexture(m_resolveTexture);
349 m_renderTarget.reset(m_rhi->newTextureRenderTarget(rtDesc));
350 m_renderPassDescriptor.reset(m_renderTarget->newCompatibleRenderPassDescriptor());
351 m_renderTarget->setRenderPassDescriptor(m_renderPassDescriptor.get());
352 if (!m_renderTarget->create()) {
353 qWarning(
"Failed to create render target for QQuickRhiitem");
362 if (newSize != itemD->effectiveTextureSize) {
363 itemD->effectiveTextureSize = newSize;
364 emit m_item->effectiveColorBufferSizeChanged();
369 m_renderer->initialize(cb);
371 m_renderer->synchronize(m_item);
430QSGNode *QQuickRhiItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
436 if (!oldNode && (width() <= 0 || height() <= 0))
440 QQuickRhiItemNode *n =
static_cast<QQuickRhiItemNode *>(oldNode);
443 d->node =
new QQuickRhiItemNode(
this);
444 if (!d->node->hasRenderer()) {
445 QQuickRhiItemRenderer *r = createRenderer();
448 d->node->setRenderer(r);
450 qWarning(
"No QQuickRhiItemRenderer was created; the item will not render");
467 if (window()->rhi()->isYUpInFramebuffer()) {
468 n->setTextureCoordinatesTransform(d->mirrorVertically
469 ? QSGSimpleTextureNode::NoTransform
470 : QSGSimpleTextureNode::MirrorVertically);
472 n->setTextureCoordinatesTransform(d->mirrorVertically
473 ? QSGSimpleTextureNode::MirrorVertically
474 : QSGSimpleTextureNode::NoTransform);
476 n->setFiltering(d->smooth ? QSGTexture::Linear : QSGTexture::Nearest);
477 n->setRect(0, 0, qMax<
int>(0, width()), qMax<
int>(0, height()));
622void QQuickRhiItem::setColorBufferFormat(TextureFormat format)
625 if (d->itemTextureFormat == format)
628 d->itemTextureFormat = format;
630 case TextureFormat::RGBA8:
631 d->rhiTextureFormat = QRhiTexture::RGBA8;
633 case TextureFormat::RGBA16F:
634 d->rhiTextureFormat = QRhiTexture::RGBA16F;
636 case TextureFormat::RGBA32F:
637 d->rhiTextureFormat = QRhiTexture::RGBA32F;
639 case TextureFormat::RGB10A2:
640 d->rhiTextureFormat = QRhiTexture::RGB10A2;
643 emit colorBufferFormatChanged();
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h