Update QRhiWidget API based on review comments
Spell out some API names in enum. Some functions are now protected. Remove property for autoRenderTarget. textureFormat -> colorBufferFormat. Used "fixed" instead of "explicit" and follow the above naming, so that explicitSize becomes fixedColorBufferSize. Pick-to: 6.7 Change-Id: I2fd6ad46033313a3febbb8846146021d5dd11010 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
0e8086887a
commit
acebb97b58
@ -24,8 +24,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
ExampleRhiWidget *rhiWidget = new ExampleRhiWidget;
|
ExampleRhiWidget *rhiWidget = new ExampleRhiWidget;
|
||||||
QLabel *overlayLabel = new QLabel(rhiWidget);
|
QLabel *overlayLabel = new QLabel(rhiWidget);
|
||||||
overlayLabel->setText(QLatin1String("This is a\nsemi-transparent\n overlay widget\n"
|
overlayLabel->setText(QObject::tr("This is a\nsemi-transparent\n overlay widget\n"
|
||||||
"placed on top of\nthe QRhiWidget."));
|
"placed on top of\nthe QRhiWidget."));
|
||||||
overlayLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
overlayLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||||
overlayLabel->setAutoFillBackground(true);
|
overlayLabel->setAutoFillBackground(true);
|
||||||
QPalette semiTransparent(QColor(255, 0, 0, 64));
|
QPalette semiTransparent(QColor(255, 0, 0, 64));
|
||||||
@ -44,9 +44,9 @@ int main(int argc, char **argv)
|
|||||||
overlayLabel->setGeometry(rhiWidget->width() / 2 - w / 2, rhiWidget->height() / 2 - h / 2, w, h);
|
overlayLabel->setGeometry(rhiWidget->width() / 2 - w / 2, rhiWidget->height() / 2 - h / 2, w, h);
|
||||||
});
|
});
|
||||||
|
|
||||||
QTextEdit *edit = new QTextEdit(QLatin1String("QRhiWidget!<br><br>"
|
QTextEdit *edit = new QTextEdit(QObject::tr("QRhiWidget!<br><br>"
|
||||||
"The cube is textured with QPainter-generated content.<br><br>"
|
"The cube is textured with QPainter-generated content.<br><br>"
|
||||||
"Regular, non-native widgets on top work just fine."));
|
"Regular, non-native widgets on top work just fine."));
|
||||||
QObject::connect(edit, &QTextEdit::textChanged, edit, [edit, rhiWidget] {
|
QObject::connect(edit, &QTextEdit::textChanged, edit, [edit, rhiWidget] {
|
||||||
rhiWidget->setCubeTextureText(edit->toPlainText());
|
rhiWidget->setCubeTextureText(edit->toPlainText());
|
||||||
});
|
});
|
||||||
@ -61,7 +61,7 @@ int main(int argc, char **argv)
|
|||||||
});
|
});
|
||||||
|
|
||||||
QHBoxLayout *sliderLayout = new QHBoxLayout;
|
QHBoxLayout *sliderLayout = new QHBoxLayout;
|
||||||
sliderLayout->addWidget(new QLabel(QLatin1String("Cube rotation")));
|
sliderLayout->addWidget(new QLabel(QObject::tr("Cube rotation")));
|
||||||
sliderLayout->addWidget(slider);
|
sliderLayout->addWidget(slider);
|
||||||
layout->addLayout(sliderLayout);
|
layout->addLayout(sliderLayout);
|
||||||
|
|
||||||
@ -70,25 +70,25 @@ int main(int argc, char **argv)
|
|||||||
QLabel *apiLabel = new QLabel;
|
QLabel *apiLabel = new QLabel;
|
||||||
btnLayout->addWidget(apiLabel);
|
btnLayout->addWidget(apiLabel);
|
||||||
QObject::connect(rhiWidget, &ExampleRhiWidget::rhiChanged, rhiWidget, [apiLabel](const QString &apiName) {
|
QObject::connect(rhiWidget, &ExampleRhiWidget::rhiChanged, rhiWidget, [apiLabel](const QString &apiName) {
|
||||||
apiLabel->setText(QLatin1String("Using QRhi on ") + apiName);
|
apiLabel->setText(QObject::tr("Using QRhi on ") + apiName);
|
||||||
});
|
});
|
||||||
|
|
||||||
QPushButton *btnMakeWindow = new QPushButton(QLatin1String("Make top-level window"));
|
QPushButton *btnMakeWindow = new QPushButton(QObject::tr("Make top-level window"));
|
||||||
QObject::connect(btnMakeWindow, &QPushButton::clicked, btnMakeWindow, [rhiWidget, btnMakeWindow, layout] {
|
QObject::connect(btnMakeWindow, &QPushButton::clicked, btnMakeWindow, [rhiWidget, btnMakeWindow, layout] {
|
||||||
if (rhiWidget->parentWidget()) {
|
if (rhiWidget->parentWidget()) {
|
||||||
rhiWidget->setParent(nullptr);
|
rhiWidget->setParent(nullptr);
|
||||||
rhiWidget->setAttribute(Qt::WA_DeleteOnClose, true);
|
rhiWidget->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
rhiWidget->show();
|
rhiWidget->show();
|
||||||
btnMakeWindow->setText(QLatin1String("Make child widget"));
|
btnMakeWindow->setText(QObject::tr("Make child widget"));
|
||||||
} else {
|
} else {
|
||||||
rhiWidget->setAttribute(Qt::WA_DeleteOnClose, false);
|
rhiWidget->setAttribute(Qt::WA_DeleteOnClose, false);
|
||||||
layout->addWidget(rhiWidget);
|
layout->addWidget(rhiWidget);
|
||||||
btnMakeWindow->setText(QLatin1String("Make top-level window"));
|
btnMakeWindow->setText(QObject::tr("Make top-level window"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
btnLayout->addWidget(btnMakeWindow);
|
btnLayout->addWidget(btnMakeWindow);
|
||||||
|
|
||||||
QPushButton *btn = new QPushButton(QLatin1String("Grab to image"));
|
QPushButton *btn = new QPushButton(QObject::tr("Grab to image"));
|
||||||
QObject::connect(btn, &QPushButton::clicked, btn, [rhiWidget] {
|
QObject::connect(btn, &QPushButton::clicked, btn, [rhiWidget] {
|
||||||
QImage image = rhiWidget->grabFramebuffer();
|
QImage image = rhiWidget->grabFramebuffer();
|
||||||
qDebug() << "Got image" << image;
|
qDebug() << "Got image" << image;
|
||||||
@ -103,7 +103,7 @@ int main(int argc, char **argv)
|
|||||||
});
|
});
|
||||||
btnLayout->addWidget(btn);
|
btnLayout->addWidget(btn);
|
||||||
|
|
||||||
QCheckBox *cbMsaa = new QCheckBox(QLatin1String("Use 4x MSAA"));
|
QCheckBox *cbMsaa = new QCheckBox(QObject::tr("Use 4x MSAA"));
|
||||||
QObject::connect(cbMsaa, &QCheckBox::stateChanged, cbMsaa, [cbMsaa, rhiWidget] {
|
QObject::connect(cbMsaa, &QCheckBox::stateChanged, cbMsaa, [cbMsaa, rhiWidget] {
|
||||||
if (cbMsaa->isChecked())
|
if (cbMsaa->isChecked())
|
||||||
rhiWidget->setSampleCount(4);
|
rhiWidget->setSampleCount(4);
|
||||||
@ -112,7 +112,7 @@ int main(int argc, char **argv)
|
|||||||
});
|
});
|
||||||
btnLayout->addWidget(cbMsaa);
|
btnLayout->addWidget(cbMsaa);
|
||||||
|
|
||||||
QCheckBox *cbOvberlay = new QCheckBox(QLatin1String("Show overlay widget"));
|
QCheckBox *cbOvberlay = new QCheckBox(QObject::tr("Show overlay widget"));
|
||||||
QObject::connect(cbOvberlay, &QCheckBox::stateChanged, cbOvberlay, [cbOvberlay, overlayLabel] {
|
QObject::connect(cbOvberlay, &QCheckBox::stateChanged, cbOvberlay, [cbOvberlay, overlayLabel] {
|
||||||
if (cbOvberlay->isChecked())
|
if (cbOvberlay->isChecked())
|
||||||
overlayLabel->setVisible(true);
|
overlayLabel->setVisible(true);
|
||||||
@ -121,28 +121,28 @@ int main(int argc, char **argv)
|
|||||||
});
|
});
|
||||||
btnLayout->addWidget(cbOvberlay);
|
btnLayout->addWidget(cbOvberlay);
|
||||||
|
|
||||||
QCheckBox *cbFlip = new QCheckBox(QLatin1String("Flip"));
|
QCheckBox *cbFlip = new QCheckBox(QObject::tr("Flip"));
|
||||||
QObject::connect(cbFlip, &QCheckBox::stateChanged, cbOvberlay, [cbFlip, rhiWidget] {
|
QObject::connect(cbFlip, &QCheckBox::stateChanged, cbOvberlay, [cbFlip, rhiWidget] {
|
||||||
rhiWidget->setMirrorVertically(cbFlip->isChecked());
|
rhiWidget->setMirrorVertically(cbFlip->isChecked());
|
||||||
});
|
});
|
||||||
btnLayout->addWidget(cbFlip);
|
btnLayout->addWidget(cbFlip);
|
||||||
|
|
||||||
QCheckBox *cbExplicitSize = new QCheckBox(QLatin1String("Use explicit size"));
|
QCheckBox *cbFixedSize = new QCheckBox(QObject::tr("Use fixed color buffer size"));
|
||||||
btnLayout->addWidget(cbExplicitSize);
|
btnLayout->addWidget(cbFixedSize);
|
||||||
QSlider *explicitSizeSlider = new QSlider(Qt::Horizontal);
|
QSlider *fixedSizeSlider = new QSlider(Qt::Horizontal);
|
||||||
explicitSizeSlider->setMinimum(16);
|
fixedSizeSlider->setMinimum(16);
|
||||||
explicitSizeSlider->setMaximum(512);
|
fixedSizeSlider->setMaximum(512);
|
||||||
btnLayout->addWidget(explicitSizeSlider);
|
btnLayout->addWidget(fixedSizeSlider);
|
||||||
|
|
||||||
QObject::connect(cbExplicitSize, &QCheckBox::stateChanged, cbExplicitSize, [cbExplicitSize, explicitSizeSlider, rhiWidget] {
|
QObject::connect(cbFixedSize, &QCheckBox::stateChanged, cbFixedSize, [cbFixedSize, fixedSizeSlider, rhiWidget] {
|
||||||
if (cbExplicitSize->isChecked())
|
if (cbFixedSize->isChecked())
|
||||||
rhiWidget->setExplicitSize(QSize(explicitSizeSlider->value(), explicitSizeSlider->value()));
|
rhiWidget->setFixedColorBufferSize(QSize(fixedSizeSlider->value(), fixedSizeSlider->value()));
|
||||||
else
|
else
|
||||||
rhiWidget->setExplicitSize(QSize());
|
rhiWidget->setFixedColorBufferSize(QSize());
|
||||||
});
|
});
|
||||||
QObject::connect(explicitSizeSlider, &QSlider::valueChanged, explicitSizeSlider, [explicitSizeSlider, cbExplicitSize, rhiWidget] {
|
QObject::connect(fixedSizeSlider, &QSlider::valueChanged, fixedSizeSlider, [fixedSizeSlider, cbFixedSize, rhiWidget] {
|
||||||
if (cbExplicitSize->isChecked())
|
if (cbFixedSize->isChecked())
|
||||||
rhiWidget->setExplicitSize(QSize(explicitSizeSlider->value(), explicitSizeSlider->value()));
|
rhiWidget->setFixedColorBufferSize(QSize(fixedSizeSlider->value(), fixedSizeSlider->value()));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Exit when the detached window is closed; there is not much we can do
|
// Exit when the detached window is closed; there is not much we can do
|
||||||
|
@ -32,8 +32,8 @@ QT_BEGIN_NAMESPACE
|
|||||||
reimplement the virtual functions initialize() and render().
|
reimplement the virtual functions initialize() and render().
|
||||||
|
|
||||||
The size of the texture will by default adapt to the size of the widget. If
|
The size of the texture will by default adapt to the size of the widget. If
|
||||||
a fixed size is preferred, set an explicit size specified in pixels by
|
a fixed size is preferred, set a fixed size specified in pixels by calling
|
||||||
calling setExplicitSize().
|
setFixedColorBufferSize().
|
||||||
|
|
||||||
In addition to the texture serving as the color buffer, a depth/stencil
|
In addition to the texture serving as the color buffer, a depth/stencil
|
||||||
buffer and a render target binding these together is maintained implicitly
|
buffer and a render target binding these together is maintained implicitly
|
||||||
@ -148,8 +148,8 @@ QT_BEGIN_NAMESPACE
|
|||||||
\value OpenGL
|
\value OpenGL
|
||||||
\value Metal
|
\value Metal
|
||||||
\value Vulkan
|
\value Vulkan
|
||||||
\value D3D11
|
\value Direct3D11
|
||||||
\value D3D12
|
\value Direct3D12
|
||||||
\value Null
|
\value Null
|
||||||
|
|
||||||
\sa QRhi
|
\sa QRhi
|
||||||
@ -528,7 +528,7 @@ void QRhiWidgetPrivate::ensureTexture(bool *changed)
|
|||||||
{
|
{
|
||||||
Q_Q(QRhiWidget);
|
Q_Q(QRhiWidget);
|
||||||
|
|
||||||
QSize newSize = explicitSize;
|
QSize newSize = fixedSize;
|
||||||
if (newSize.isEmpty())
|
if (newSize.isEmpty())
|
||||||
newSize = q->size() * q->devicePixelRatio();
|
newSize = q->size() * q->devicePixelRatio();
|
||||||
|
|
||||||
@ -702,12 +702,13 @@ QRhiWidget::Api QRhiWidget::api() const
|
|||||||
case QPlatformBackingStoreRhiConfig::Vulkan:
|
case QPlatformBackingStoreRhiConfig::Vulkan:
|
||||||
return Api::Vulkan;
|
return Api::Vulkan;
|
||||||
case QPlatformBackingStoreRhiConfig::D3D11:
|
case QPlatformBackingStoreRhiConfig::D3D11:
|
||||||
return Api::D3D11;
|
return Api::Direct3D11;
|
||||||
case QPlatformBackingStoreRhiConfig::D3D12:
|
case QPlatformBackingStoreRhiConfig::D3D12:
|
||||||
return Api::D3D12;
|
return Api::Direct3D12;
|
||||||
default:
|
case QPlatformBackingStoreRhiConfig::Null:
|
||||||
return Api::Null;
|
return Api::Null;
|
||||||
}
|
}
|
||||||
|
Q_UNREACHABLE_RETURN(Api::Null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -726,7 +727,7 @@ QRhiWidget::Api QRhiWidget::api() const
|
|||||||
backend to render. Attempting to set another value, or to add another
|
backend to render. Attempting to set another value, or to add another
|
||||||
QRhiWidget with a different \a api will not function as expected.
|
QRhiWidget with a different \a api will not function as expected.
|
||||||
|
|
||||||
\sa setTextureFormat(), setDebugLayer(), api()
|
\sa setColorBufferFormat(), setDebugLayer(), api()
|
||||||
*/
|
*/
|
||||||
void QRhiWidget::setApi(Api api)
|
void QRhiWidget::setApi(Api api)
|
||||||
{
|
{
|
||||||
@ -741,10 +742,10 @@ void QRhiWidget::setApi(Api api)
|
|||||||
case Api::Vulkan:
|
case Api::Vulkan:
|
||||||
d->config.setApi(QPlatformBackingStoreRhiConfig::Vulkan);
|
d->config.setApi(QPlatformBackingStoreRhiConfig::Vulkan);
|
||||||
break;
|
break;
|
||||||
case Api::D3D11:
|
case Api::Direct3D11:
|
||||||
d->config.setApi(QPlatformBackingStoreRhiConfig::D3D11);
|
d->config.setApi(QPlatformBackingStoreRhiConfig::D3D11);
|
||||||
break;
|
break;
|
||||||
case Api::D3D12:
|
case Api::Direct3D12:
|
||||||
d->config.setApi(QPlatformBackingStoreRhiConfig::D3D12);
|
d->config.setApi(QPlatformBackingStoreRhiConfig::D3D12);
|
||||||
break;
|
break;
|
||||||
case Api::Null:
|
case Api::Null:
|
||||||
@ -787,13 +788,13 @@ void QRhiWidget::setDebugLayer(bool enable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\property QRhiWidget::textureFormat
|
\property QRhiWidget::colorBufferFormat
|
||||||
|
|
||||||
This property controls the texture format for the texture used as the color
|
This property controls the texture format of the texture (or renderbuffer)
|
||||||
buffer. The default value is TextureFormat::RGBA8. QRhiWidget supports
|
used as the color buffer. The default value is TextureFormat::RGBA8.
|
||||||
rendering to a subset of the formats supported by \l QRhiTexture. Only
|
QRhiWidget supports rendering to a subset of the formats supported by \l
|
||||||
formats that are reported as supported from
|
QRhiTexture. Only formats that are reported as supported from \l
|
||||||
\l QRhi::isTextureFormatSupported() should be specified, rendering will not be
|
QRhi::isTextureFormatSupported() should be specified, rendering will not be
|
||||||
functional otherwise.
|
functional otherwise.
|
||||||
|
|
||||||
\note Setting a new format when the widget is already initialized and has
|
\note Setting a new format when the widget is already initialized and has
|
||||||
@ -805,13 +806,13 @@ void QRhiWidget::setDebugLayer(bool enable)
|
|||||||
creating new ones.
|
creating new ones.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QRhiWidget::TextureFormat QRhiWidget::textureFormat() const
|
QRhiWidget::TextureFormat QRhiWidget::colorBufferFormat() const
|
||||||
{
|
{
|
||||||
Q_D(const QRhiWidget);
|
Q_D(const QRhiWidget);
|
||||||
return d->widgetTextureFormat;
|
return d->widgetTextureFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QRhiWidget::setTextureFormat(TextureFormat format)
|
void QRhiWidget::setColorBufferFormat(TextureFormat format)
|
||||||
{
|
{
|
||||||
Q_D(QRhiWidget);
|
Q_D(QRhiWidget);
|
||||||
if (d->widgetTextureFormat != format) {
|
if (d->widgetTextureFormat != format) {
|
||||||
@ -830,7 +831,7 @@ void QRhiWidget::setTextureFormat(TextureFormat format)
|
|||||||
d->rhiTextureFormat = QRhiTexture::RGB10A2;
|
d->rhiTextureFormat = QRhiTexture::RGB10A2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
emit textureFormatChanged(format);
|
emit colorBufferFormatChanged(format);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -884,7 +885,7 @@ void QRhiWidget::setSampleCount(int samples)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\property QRhiWidget::explicitSize
|
\property QRhiWidget::fixedColorBufferSize
|
||||||
|
|
||||||
The fixed size, in pixels, of the QRhiWidget's associated texture. Relevant
|
The fixed size, in pixels, of the QRhiWidget's associated texture. Relevant
|
||||||
when a fixed texture size is desired that does not depend on the widget's
|
when a fixed texture size is desired that does not depend on the widget's
|
||||||
@ -902,18 +903,18 @@ void QRhiWidget::setSampleCount(int samples)
|
|||||||
size} * \c{device pixel ratio}).
|
size} * \c{device pixel ratio}).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QSize QRhiWidget::explicitSize() const
|
QSize QRhiWidget::fixedColorBufferSize() const
|
||||||
{
|
{
|
||||||
Q_D(const QRhiWidget);
|
Q_D(const QRhiWidget);
|
||||||
return d->explicitSize;
|
return d->fixedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QRhiWidget::setExplicitSize(const QSize &pixelSize)
|
void QRhiWidget::setFixedColorBufferSize(QSize pixelSize)
|
||||||
{
|
{
|
||||||
Q_D(QRhiWidget);
|
Q_D(QRhiWidget);
|
||||||
if (d->explicitSize != pixelSize) {
|
if (d->fixedSize != pixelSize) {
|
||||||
d->explicitSize = pixelSize;
|
d->fixedSize = pixelSize;
|
||||||
emit explicitSizeChanged(pixelSize);
|
emit fixedColorBufferSizeChanged(pixelSize);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -945,31 +946,38 @@ void QRhiWidget::setMirrorVertically(bool enabled)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\property QRhiWidget::autoRenderTarget
|
\return the current setting for automatic depth-stencil buffer and render
|
||||||
|
target maintenance.
|
||||||
|
|
||||||
This property controls if a depth-stencil QRhiRenderBuffer and a
|
By default the value is \c true.
|
||||||
QRhiTextureRenderTarget is created and maintained automatically by the
|
|
||||||
widget. The default value is \c true.
|
|
||||||
|
|
||||||
In automatic mode, the size and sample count of the depth-stencil buffer
|
\sa setAutoRenderTarget()
|
||||||
follows the color buffer texture's settings. In non-automatic mode,
|
|
||||||
renderTarget() and depthStencilBuffer() always return \nullptr and it is
|
|
||||||
then up to the application's implementation of initialize() to take care of
|
|
||||||
setting up and managing these objects.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool QRhiWidget::isAutoRenderTargetEnabled() const
|
bool QRhiWidget::isAutoRenderTargetEnabled() const
|
||||||
{
|
{
|
||||||
Q_D(const QRhiWidget);
|
Q_D(const QRhiWidget);
|
||||||
return d->autoRenderTarget;
|
return d->autoRenderTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Controls if a depth-stencil QRhiRenderBuffer and a QRhiTextureRenderTarget
|
||||||
|
is created and maintained automatically by the widget. The default value is
|
||||||
|
\c true.
|
||||||
|
|
||||||
|
In automatic mode, the size and sample count of the depth-stencil buffer
|
||||||
|
follows the color buffer texture's settings. In non-automatic mode,
|
||||||
|
renderTarget() and depthStencilBuffer() always return \nullptr and it is
|
||||||
|
then up to the application's implementation of initialize() to take care of
|
||||||
|
setting up and managing these objects.
|
||||||
|
|
||||||
|
Call this function with \a enabled set to \c false early on, for example in
|
||||||
|
the derived class' constructor, to disable the automatic mode.
|
||||||
|
*/
|
||||||
void QRhiWidget::setAutoRenderTarget(bool enabled)
|
void QRhiWidget::setAutoRenderTarget(bool enabled)
|
||||||
{
|
{
|
||||||
Q_D(QRhiWidget);
|
Q_D(QRhiWidget);
|
||||||
if (d->autoRenderTarget != enabled) {
|
if (d->autoRenderTarget != enabled) {
|
||||||
d->autoRenderTarget = enabled;
|
d->autoRenderTarget = enabled;
|
||||||
emit autoRenderTargetChanged(enabled);
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -982,7 +990,7 @@ void QRhiWidget::setAutoRenderTarget(bool enabled)
|
|||||||
|
|
||||||
The returned QImage will have a format of QImage::Format_RGBA8888,
|
The returned QImage will have a format of QImage::Format_RGBA8888,
|
||||||
QImage::Format_RGBA16FPx4, QImage::Format_RGBA32FPx4, or
|
QImage::Format_RGBA16FPx4, QImage::Format_RGBA32FPx4, or
|
||||||
QImage::Format_BGR30 depending on textureFormat().
|
QImage::Format_BGR30, depending on colorBufferFormat().
|
||||||
|
|
||||||
QRhiWidget does not know the renderer's approach to blending and
|
QRhiWidget does not know the renderer's approach to blending and
|
||||||
composition, and therefore cannot know if the output has alpha
|
composition, and therefore cannot know if the output has alpha
|
||||||
@ -1004,7 +1012,7 @@ void QRhiWidget::setAutoRenderTarget(bool enabled)
|
|||||||
go through the rest of QWidget infrastructure but can right away trigger
|
go through the rest of QWidget infrastructure but can right away trigger
|
||||||
rendering a new frame and then do the readback.
|
rendering a new frame and then do the readback.
|
||||||
|
|
||||||
\sa setTextureFormat()
|
\sa setColorBufferFormat()
|
||||||
*/
|
*/
|
||||||
QImage QRhiWidget::grabFramebuffer() const
|
QImage QRhiWidget::grabFramebuffer() const
|
||||||
{
|
{
|
||||||
|
@ -20,9 +20,8 @@ class Q_WIDGETS_EXPORT QRhiWidget : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DECLARE_PRIVATE(QRhiWidget)
|
Q_DECLARE_PRIVATE(QRhiWidget)
|
||||||
Q_PROPERTY(int sampleCount READ sampleCount WRITE setSampleCount NOTIFY sampleCountChanged)
|
Q_PROPERTY(int sampleCount READ sampleCount WRITE setSampleCount NOTIFY sampleCountChanged)
|
||||||
Q_PROPERTY(TextureFormat textureFormat READ textureFormat WRITE setTextureFormat NOTIFY textureFormatChanged)
|
Q_PROPERTY(TextureFormat colorBufferFormat READ colorBufferFormat WRITE setColorBufferFormat NOTIFY colorBufferFormatChanged)
|
||||||
Q_PROPERTY(bool autoRenderTarget READ isAutoRenderTargetEnabled WRITE setAutoRenderTarget NOTIFY autoRenderTargetChanged)
|
Q_PROPERTY(QSize fixedColorBufferSize READ fixedColorBufferSize WRITE setFixedColorBufferSize NOTIFY fixedColorBufferSizeChanged)
|
||||||
Q_PROPERTY(QSize explicitSize READ explicitSize WRITE setExplicitSize NOTIFY explicitSizeChanged)
|
|
||||||
Q_PROPERTY(bool mirrorVertically READ isMirrorVerticallyEnabled WRITE setMirrorVertically NOTIFY mirrorVerticallyChanged)
|
Q_PROPERTY(bool mirrorVertically READ isMirrorVerticallyEnabled WRITE setMirrorVertically NOTIFY mirrorVerticallyChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -33,8 +32,8 @@ public:
|
|||||||
OpenGL,
|
OpenGL,
|
||||||
Metal,
|
Metal,
|
||||||
Vulkan,
|
Vulkan,
|
||||||
D3D11,
|
Direct3D11,
|
||||||
D3D12,
|
Direct3D12,
|
||||||
Null
|
Null
|
||||||
};
|
};
|
||||||
Q_ENUM(Api)
|
Q_ENUM(Api)
|
||||||
@ -56,21 +55,22 @@ public:
|
|||||||
int sampleCount() const;
|
int sampleCount() const;
|
||||||
void setSampleCount(int samples);
|
void setSampleCount(int samples);
|
||||||
|
|
||||||
TextureFormat textureFormat() const;
|
TextureFormat colorBufferFormat() const;
|
||||||
void setTextureFormat(TextureFormat format);
|
void setColorBufferFormat(TextureFormat format);
|
||||||
|
|
||||||
QSize explicitSize() const;
|
QSize fixedColorBufferSize() const;
|
||||||
void setExplicitSize(const QSize &pixelSize);
|
void setFixedColorBufferSize(QSize pixelSize);
|
||||||
void setExplicitSize(int w, int h) { setExplicitSize(QSize(w, h)); }
|
void setFixedColorBufferSize(int w, int h) { setFixedColorBufferSize(QSize(w, h)); }
|
||||||
|
|
||||||
bool isAutoRenderTargetEnabled() const;
|
|
||||||
void setAutoRenderTarget(bool enabled);
|
|
||||||
|
|
||||||
bool isMirrorVerticallyEnabled() const;
|
bool isMirrorVerticallyEnabled() const;
|
||||||
void setMirrorVertically(bool enabled);
|
void setMirrorVertically(bool enabled);
|
||||||
|
|
||||||
QImage grabFramebuffer() const;
|
QImage grabFramebuffer() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool isAutoRenderTargetEnabled() const;
|
||||||
|
void setAutoRenderTarget(bool enabled);
|
||||||
|
|
||||||
virtual void initialize(QRhiCommandBuffer *cb);
|
virtual void initialize(QRhiCommandBuffer *cb);
|
||||||
virtual void render(QRhiCommandBuffer *cb);
|
virtual void render(QRhiCommandBuffer *cb);
|
||||||
virtual void releaseResources();
|
virtual void releaseResources();
|
||||||
@ -82,19 +82,17 @@ public:
|
|||||||
QRhiRenderBuffer *depthStencilBuffer() const;
|
QRhiRenderBuffer *depthStencilBuffer() const;
|
||||||
QRhiRenderTarget *renderTarget() const;
|
QRhiRenderTarget *renderTarget() const;
|
||||||
|
|
||||||
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
bool event(QEvent *e) override;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void frameSubmitted();
|
void frameSubmitted();
|
||||||
void renderFailed();
|
void renderFailed();
|
||||||
void sampleCountChanged(int samples);
|
void sampleCountChanged(int samples);
|
||||||
void textureFormatChanged(TextureFormat format);
|
void colorBufferFormatChanged(TextureFormat format);
|
||||||
void autoRenderTargetChanged(bool enabled);
|
void fixedColorBufferSizeChanged(const QSize &pixelSize);
|
||||||
void explicitSizeChanged(const QSize &pixelSize);
|
|
||||||
void mirrorVerticallyChanged(bool enabled);
|
void mirrorVerticallyChanged(bool enabled);
|
||||||
|
|
||||||
protected:
|
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
|
||||||
void paintEvent(QPaintEvent *e) override;
|
|
||||||
bool event(QEvent *e) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
QRhiWidget::TextureFormat widgetTextureFormat = QRhiWidget::TextureFormat::RGBA8;
|
QRhiWidget::TextureFormat widgetTextureFormat = QRhiWidget::TextureFormat::RGBA8;
|
||||||
QRhiTexture::Format rhiTextureFormat = QRhiTexture::RGBA8;
|
QRhiTexture::Format rhiTextureFormat = QRhiTexture::RGBA8;
|
||||||
int samples = 1;
|
int samples = 1;
|
||||||
QSize explicitSize;
|
QSize fixedSize;
|
||||||
bool autoRenderTarget = true;
|
bool autoRenderTarget = true;
|
||||||
bool mirrorVertically = false;
|
bool mirrorVertically = false;
|
||||||
QBackingStoreRhiSupport offscreenRenderer;
|
QBackingStoreRhiSupport offscreenRenderer;
|
||||||
|
@ -31,8 +31,8 @@ private slots:
|
|||||||
void simple();
|
void simple();
|
||||||
void msaa_data();
|
void msaa_data();
|
||||||
void msaa();
|
void msaa();
|
||||||
void explicitSize_data();
|
void fixedSize_data();
|
||||||
void explicitSize();
|
void fixedSize();
|
||||||
void autoRt_data();
|
void autoRt_data();
|
||||||
void autoRt();
|
void autoRt();
|
||||||
void reparent_data();
|
void reparent_data();
|
||||||
@ -91,12 +91,12 @@ void tst_QRhiWidget::testData()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QTest::newRow("D3D11") << QRhiWidget::Api::D3D11;
|
QTest::newRow("D3D11") << QRhiWidget::Api::Direct3D11;
|
||||||
// D3D12 needs to be probed too due to being disabled if the SDK headers
|
// D3D12 needs to be probed too due to being disabled if the SDK headers
|
||||||
// are too old (clang, mingw).
|
// are too old (clang, mingw).
|
||||||
QRhiD3D12InitParams d3d12InitParams;
|
QRhiD3D12InitParams d3d12InitParams;
|
||||||
if (QRhi::probe(QRhi::D3D12, &d3d12InitParams))
|
if (QRhi::probe(QRhi::D3D12, &d3d12InitParams))
|
||||||
QTest::newRow("D3D12") << QRhiWidget::Api::D3D12;
|
QTest::newRow("D3D12") << QRhiWidget::Api::Direct3D12;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +225,8 @@ public:
|
|||||||
std::unique_ptr<QRhiGraphicsPipeline> m_pipeline;
|
std::unique_ptr<QRhiGraphicsPipeline> m_pipeline;
|
||||||
QRhiTextureRenderTarget *m_rt = nullptr; // used when autoRenderTarget is off
|
QRhiTextureRenderTarget *m_rt = nullptr; // used when autoRenderTarget is off
|
||||||
QRhiRenderPassDescriptor *m_rp = nullptr; // used when autoRenderTarget is off
|
QRhiRenderPassDescriptor *m_rp = nullptr; // used when autoRenderTarget is off
|
||||||
|
|
||||||
|
friend class tst_QRhiWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
void SimpleRhiWidget::initialize(QRhiCommandBuffer *cb)
|
void SimpleRhiWidget::initialize(QRhiCommandBuffer *cb)
|
||||||
@ -347,7 +349,7 @@ void tst_QRhiWidget::simple()
|
|||||||
QCOMPARE(errorSpy.count(), 0);
|
QCOMPARE(errorSpy.count(), 0);
|
||||||
|
|
||||||
QCOMPARE(rhiWidget->sampleCount(), 1);
|
QCOMPARE(rhiWidget->sampleCount(), 1);
|
||||||
QCOMPARE(rhiWidget->textureFormat(), QRhiWidget::TextureFormat::RGBA8);
|
QCOMPARE(rhiWidget->colorBufferFormat(), QRhiWidget::TextureFormat::RGBA8);
|
||||||
QVERIFY(rhiWidget->isAutoRenderTargetEnabled());
|
QVERIFY(rhiWidget->isAutoRenderTargetEnabled());
|
||||||
|
|
||||||
// Pull out the QRhiTexture (we know colorTexture() and rhi() and friends
|
// Pull out the QRhiTexture (we know colorTexture() and rhi() and friends
|
||||||
@ -372,10 +374,10 @@ void tst_QRhiWidget::simple()
|
|||||||
case QRhiWidget::Api::Vulkan:
|
case QRhiWidget::Api::Vulkan:
|
||||||
QCOMPARE(rhi->backend(), QRhi::Vulkan);
|
QCOMPARE(rhi->backend(), QRhi::Vulkan);
|
||||||
break;
|
break;
|
||||||
case QRhiWidget::Api::D3D11:
|
case QRhiWidget::Api::Direct3D11:
|
||||||
QCOMPARE(rhi->backend(), QRhi::D3D11);
|
QCOMPARE(rhi->backend(), QRhi::D3D11);
|
||||||
break;
|
break;
|
||||||
case QRhiWidget::Api::D3D12:
|
case QRhiWidget::Api::Direct3D12:
|
||||||
QCOMPARE(rhi->backend(), QRhi::D3D12);
|
QCOMPARE(rhi->backend(), QRhi::D3D12);
|
||||||
break;
|
break;
|
||||||
case QRhiWidget::Api::Null:
|
case QRhiWidget::Api::Null:
|
||||||
@ -462,7 +464,7 @@ void tst_QRhiWidget::msaa()
|
|||||||
QCOMPARE(errorSpy.count(), 0);
|
QCOMPARE(errorSpy.count(), 0);
|
||||||
|
|
||||||
QCOMPARE(rhiWidget->sampleCount(), 4);
|
QCOMPARE(rhiWidget->sampleCount(), 4);
|
||||||
QCOMPARE(rhiWidget->textureFormat(), QRhiWidget::TextureFormat::RGBA8);
|
QCOMPARE(rhiWidget->colorBufferFormat(), QRhiWidget::TextureFormat::RGBA8);
|
||||||
QVERIFY(!rhiWidget->colorTexture());
|
QVERIFY(!rhiWidget->colorTexture());
|
||||||
QVERIFY(rhiWidget->msaaColorBuffer());
|
QVERIFY(rhiWidget->msaaColorBuffer());
|
||||||
QVERIFY(rhiWidget->depthStencilBuffer());
|
QVERIFY(rhiWidget->depthStencilBuffer());
|
||||||
@ -515,12 +517,12 @@ void tst_QRhiWidget::msaa()
|
|||||||
QVERIFY(rhiWidget->msaaColorBuffer());
|
QVERIFY(rhiWidget->msaaColorBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QRhiWidget::explicitSize_data()
|
void tst_QRhiWidget::fixedSize_data()
|
||||||
{
|
{
|
||||||
testData();
|
testData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QRhiWidget::explicitSize()
|
void tst_QRhiWidget::fixedSize()
|
||||||
{
|
{
|
||||||
QFETCH(QRhiWidget::Api, api);
|
QFETCH(QRhiWidget::Api, api);
|
||||||
|
|
||||||
@ -532,7 +534,7 @@ void tst_QRhiWidget::explicitSize()
|
|||||||
QVBoxLayout *layout = new QVBoxLayout;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
layout->addWidget(rhiWidget);
|
layout->addWidget(rhiWidget);
|
||||||
|
|
||||||
rhiWidget->setExplicitSize(QSize(320, 200));
|
rhiWidget->setFixedColorBufferSize(QSize(320, 200));
|
||||||
|
|
||||||
QWidget w;
|
QWidget w;
|
||||||
w.setLayout(layout);
|
w.setLayout(layout);
|
||||||
@ -552,7 +554,7 @@ void tst_QRhiWidget::explicitSize()
|
|||||||
QVERIFY(!rhiWidget->resolveTexture());
|
QVERIFY(!rhiWidget->resolveTexture());
|
||||||
|
|
||||||
frameSpy.clear();
|
frameSpy.clear();
|
||||||
rhiWidget->setExplicitSize(640, 480); // should also trigger update()
|
rhiWidget->setFixedColorBufferSize(640, 480); // should also trigger update()
|
||||||
QTRY_VERIFY(frameSpy.count() > 0);
|
QTRY_VERIFY(frameSpy.count() > 0);
|
||||||
|
|
||||||
QVERIFY(rhiWidget->colorTexture());
|
QVERIFY(rhiWidget->colorTexture());
|
||||||
@ -561,7 +563,7 @@ void tst_QRhiWidget::explicitSize()
|
|||||||
QCOMPARE(rhiWidget->depthStencilBuffer()->pixelSize(), QSize(640, 480));
|
QCOMPARE(rhiWidget->depthStencilBuffer()->pixelSize(), QSize(640, 480));
|
||||||
|
|
||||||
frameSpy.clear();
|
frameSpy.clear();
|
||||||
rhiWidget->setExplicitSize(QSize());
|
rhiWidget->setFixedColorBufferSize(QSize());
|
||||||
QTRY_VERIFY(frameSpy.count() > 0);
|
QTRY_VERIFY(frameSpy.count() > 0);
|
||||||
|
|
||||||
QVERIFY(rhiWidget->colorTexture());
|
QVERIFY(rhiWidget->colorTexture());
|
||||||
@ -611,7 +613,7 @@ void tst_QRhiWidget::autoRt()
|
|||||||
|
|
||||||
frameSpy.clear();
|
frameSpy.clear();
|
||||||
// do something that triggers creating a new backing texture
|
// do something that triggers creating a new backing texture
|
||||||
rhiWidget->setExplicitSize(QSize(320, 200));
|
rhiWidget->setFixedColorBufferSize(QSize(320, 200));
|
||||||
QTRY_VERIFY(frameSpy.count() > 0);
|
QTRY_VERIFY(frameSpy.count() > 0);
|
||||||
|
|
||||||
QVERIFY(rhiWidget->colorTexture());
|
QVERIFY(rhiWidget->colorTexture());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user