55 #include <QGuiApplication>
56 #include <QCommandLineParser>
58 #include <QPlatformSurfaceEvent>
59 #include <QElapsedTimer>
61 #include <QLoggingCategory>
62 #include <QColorSpace>
64 #include <QtGui/private/qshader_p.h>
66 #include <QtGui/private/qrhiprofiler_p.h>
67 #include <QtGui/private/qrhinull_p.h>
70 #include <QtGui/private/qrhigles2_p.h>
71 #include <QOffscreenSurface>
75 #include <QtGui/private/qrhivulkan_p.h>
79 #include <QtGui/private/qrhid3d11_p.h>
82 #if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
83 #include <QtGui/private/qrhimetal_p.h>
153 #ifdef EXAMPLEFW_KEYPRESS_EVENTS
157 bool m_running =
false;
158 bool m_notExposed =
false;
159 bool m_newlyExposed =
false;
178 friend int main(
int,
char**);
186 #if QT_CONFIG(opengl)
215 if (isExposed() && !m_running) {
229 if (isExposed() && m_running && m_notExposed && !surfaceSize.
isEmpty()) {
230 m_notExposed =
false;
231 m_newlyExposed =
true;
236 if (isExposed() && !surfaceSize.
isEmpty())
277 #if QT_CONFIG(vulkan)
280 params.inst = vulkanInstance();
290 qDebug(
"Enabling D3D11 debug layer");
294 params.repeatDeviceKill =
true;
300 #if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
308 qFatal(
"Failed to create RHI backend");
318 m_sc->setWindow(
this);
322 m_rp =
m_sc->newCompatibleRenderPassDescriptor();
323 m_sc->setRenderPassDescriptor(
m_rp);
350 void Window::resizeSwapChain()
371 void Window::render()
379 if (
m_sc->currentPixelSize() !=
m_sc->surfacePixelSize() || m_newlyExposed) {
383 m_newlyExposed =
false;
410 "frame-to-frame: min %lld max %lld avg %f. "
411 "frame build: min %lld max %lld avg %f. "
412 "gpu frame time: min %f max %f avg %f",
416 gp.minTime,
gp.maxTime,
gp.avgTime);
419 "frame-to-frame: min %lld max %lld avg %f. "
420 "frame build: min %lld max %lld avg %f. ",
443 int main(
int argc,
char **argv)
450 #if defined(Q_OS_WIN)
452 #elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
454 #elif QT_CONFIG(vulkan)
482 "(generate a device reset every <count> frames when on D3D11)"),
487 "Only applicable with some APIs and platforms."));
491 cmdLineParser.
addOption(transparentOption);
494 if (cmdLineParser.
isSet(nullOption))
496 if (cmdLineParser.
isSet(glOption))
498 if (cmdLineParser.
isSet(vkOption))
500 if (cmdLineParser.
isSet(d3dOption))
502 if (cmdLineParser.
isSet(mtlOption))
506 qDebug(
"This is a multi-api example, use command line arguments to override:\n%s", qPrintable(cmdLineParser.
helpText()));
508 if (cmdLineParser.
isSet(transparentOption)) {
513 #ifdef EXAMPLEFW_PREINIT
522 if (cmdLineParser.
isSet(coreProfOption)) {
542 #if QT_CONFIG(vulkan)
546 qDebug(
"Enabling Vulkan validation layer (if available)");
547 inst.setLayers({
"VK_LAYER_KHRONOS_validation" });
549 const QVersionNumber supportedVersion = inst.supportedApiVersion();
550 qDebug() <<
"Supported Vulkan API version:" << supportedVersion;
552 qDebug(
"Requesting Vulkan API 1.1 on the VkInstance");
556 if (!inst.create()) {
557 qWarning(
"Failed to create Vulkan instance, switching to OpenGL");
563 if (cmdLineParser.
isSet(tdrOption))
566 if (cmdLineParser.
isSet(swOption))
571 #if QT_CONFIG(vulkan)
573 w.setVulkanInstance(&inst);
579 if (cmdLineParser.
isSet(sdOption))
591 w.releaseSwapChain();
The QColor class provides colors based on RGB, HSV or CMYK values.
static QColor fromRgbF(float r, float g, float b, float a=1.0)
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
The QCommandLineParser class provides a means for handling the command line options.
QString value(const QString &name) const
bool addOption(const QCommandLineOption &commandLineOption)
bool isSet(const QString &name) const
void process(const QStringList &arguments)
QCommandLineOption addHelpOption()
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
QString applicationName
the name of this application
The QElapsedTimer class provides a fast way to calculate elapsed times.
qint64 elapsed() const noexcept
qint64 restart() noexcept
The QEvent class is the base class of all event classes. Event objects contain event parameters.
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
The QFile class provides an interface for reading from and writing to files.
The QGuiApplication class manages the GUI application's control flow and main settings.
The QKeyEvent class describes a key event.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
static void setFilterRules(const QString &rules)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane)
void translate(const QVector3D &vector)
The QOffscreenSurface class represents an offscreen surface in the underlying platform.
QMatrix4x4 clipSpaceCorrMatrix() const
bool isFeatureSupported(QRhi::Feature feature) const
QRhiRenderBuffer * newRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount=1, QRhiRenderBuffer::Flags flags={}, QRhiTexture::Format backingFormatHint=QRhiTexture::UnknownFormat)
FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags={})
QRhiSwapChain * newSwapChain()
static QRhi * create(Implementation impl, QRhiInitParams *params, Flags flags={}, QRhiNativeHandles *importDevice=nullptr)
FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags={})
QRhiProfiler * profiler()
@ FrameOpSwapChainOutOfDate
CpuTime frameBuildTimes(QRhiSwapChain *sc) const
GpuTime gpuFrameTimes(QRhiSwapChain *sc) const
CpuTime frameToFrameTimes(QRhiSwapChain *sc) const
static QShader fromSerialized(const QByteArray &data)
The QSize class defines the size of a two-dimensional object using integer point precision.
constexpr int height() const noexcept
constexpr int width() const noexcept
constexpr bool isEmpty() const noexcept
The QString class provides a Unicode character string.
int toInt(bool *ok=nullptr, int base=10) const
bool singleShot
whether the timer is a single-shot timer
The QVersionNumber class contains a version number with an arbitrary number of segments.
The QVulkanInstance class represents a native Vulkan instance, enabling Vulkan rendering onto a QSurf...
The QWindow class represents a window in the underlying windowing system.
virtual bool event(QEvent *) override
[Window class definition]
std::unique_ptr< QRhiSwapChain > m_sc
std::unique_ptr< QRhiRenderPassDescriptor > m_rp
void keyPressEvent(QKeyEvent *event) override
friend int main(int, char **)
[1]
bool event(QEvent *event) override
QPlatformSurfaceEvent::SurfaceEventType surfaceEventType() const
QOffscreenSurface * m_fallbackSurface
bool event(QEvent *) override
std::unique_ptr< QRhiRenderBuffer > m_ds
void exposeEvent(QExposeEvent *) override
QRhi::EndFrameFlags endFrameFlags
QString graphicsApiName()
QRhiSwapChain::Flags scFlags
int main(int argc, char **argv)
[1]
QShader getShader(const QString &name)
QRhi::BeginFrameFlags beginFrameFlags
bool transparentBackground
GLfloat GLfloat GLfloat w
[0]
QApplication app(argc, argv)
[0]
static QSurfaceFormat adjustedFormat(const QSurfaceFormat &format=QSurfaceFormat::defaultFormat())
static QOffscreenSurface * newFallbackSurface(const QSurfaceFormat &format=QSurfaceFormat::defaultFormat())
static QByteArrayList preferredInstanceExtensions()