QtBase  v6.3.1
examplefw.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50 
51 // Adapted from hellominimalcrossgfxtriangle with the frame rendering stripped out.
52 // Include this file and implement Window::customInit, release and render.
53 // Debug/validation layer is enabled for D3D and Vulkan.
54 
55 #include <QGuiApplication>
56 #include <QCommandLineParser>
57 #include <QWindow>
58 #include <QPlatformSurfaceEvent>
59 #include <QElapsedTimer>
60 #include <QTimer>
61 #include <QLoggingCategory>
62 #include <QColorSpace>
63 
64 #include <QtGui/private/qshader_p.h>
65 #include <QFile>
66 #include <QtGui/private/qrhiprofiler_p.h>
67 #include <QtGui/private/qrhinull_p.h>
68 
69 #ifndef QT_NO_OPENGL
70 #include <QtGui/private/qrhigles2_p.h>
71 #include <QOffscreenSurface>
72 #endif
73 
74 #if QT_CONFIG(vulkan)
75 #include <QtGui/private/qrhivulkan_p.h>
76 #endif
77 
78 #ifdef Q_OS_WIN
79 #include <QtGui/private/qrhid3d11_p.h>
80 #endif
81 
82 #if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
83 #include <QtGui/private/qrhimetal_p.h>
84 #endif
85 
87 {
88  QFile f(name);
89  if (f.open(QIODevice::ReadOnly))
90  return QShader::fromSerialized(f.readAll());
91 
92  return QShader();
93 }
94 
96 {
101  Metal
102 };
103 
105 
107 {
108  switch (graphicsApi) {
109  case Null:
110  return QLatin1String("Null (no output)");
111  case OpenGL:
112  return QLatin1String("OpenGL");
113  case Vulkan:
114  return QLatin1String("Vulkan");
115  case D3D11:
116  return QLatin1String("Direct3D 11");
117  case Metal:
118  return QLatin1String("Metal");
119  default:
120  break;
121  }
122  return QString();
123 }
124 
126 int sampleCount = 1;
128 QRhi::BeginFrameFlags beginFrameFlags;
129 QRhi::EndFrameFlags endFrameFlags;
130 int framesUntilTdr = -1;
132 bool debugLayer = true;
133 
134 class Window : public QWindow
135 {
136 public:
139 
140 protected:
141  void init();
145  void render();
146 
147  void customInit();
148  void customRelease();
149  void customRender();
150 
151  void exposeEvent(QExposeEvent *) override;
152  bool event(QEvent *) override;
153 #ifdef EXAMPLEFW_KEYPRESS_EVENTS
154  void keyPressEvent(QKeyEvent *e) override;
155 #endif
156 
157  bool m_running = false;
158  bool m_notExposed = false;
159  bool m_newlyExposed = false;
160 
161  QRhi *m_r = nullptr;
162  bool m_hasSwapChain = false;
163  QRhiSwapChain *m_sc = nullptr;
164  QRhiRenderBuffer *m_ds = nullptr;
165  QRhiRenderPassDescriptor *m_rp = nullptr;
166 
168 
171 
172 #ifndef QT_NO_OPENGL
174 #endif
175 
177 
178  friend int main(int, char**);
179 };
180 
182 {
183  // Tell the platform plugin what we want.
184  switch (graphicsApi) {
185  case OpenGL:
186 #if QT_CONFIG(opengl)
187  setSurfaceType(OpenGLSurface);
189 #endif
190  break;
191  case Vulkan:
192  setSurfaceType(VulkanSurface);
193  break;
194  case D3D11:
195  setSurfaceType(Direct3DSurface);
196  break;
197  case Metal:
198  setSurfaceType(MetalSurface);
199  break;
200  default:
201  break;
202  }
203 
205 }
206 
208 {
210 }
211 
213 {
214  // initialize and start rendering when the window becomes usable for graphics purposes
215  if (isExposed() && !m_running) {
216  m_running = true;
217  init();
218  resizeSwapChain();
219  }
220 
221  const QSize surfaceSize = m_hasSwapChain ? m_sc->surfacePixelSize() : QSize();
222 
223  // stop pushing frames when not exposed (or size is 0)
224  if ((!isExposed() || (m_hasSwapChain && surfaceSize.isEmpty())) && m_running)
225  m_notExposed = true;
226 
227  // continue when exposed again and the surface has a valid size.
228  // note that the surface size can be (0, 0) even though size() reports a valid one...
229  if (isExposed() && m_running && m_notExposed && !surfaceSize.isEmpty()) {
230  m_notExposed = false;
231  m_newlyExposed = true;
232  }
233 
234  // always render a frame on exposeEvent() (when exposed) in order to update
235  // immediately on window resize.
236  if (isExposed() && !surfaceSize.isEmpty())
237  render();
238 }
239 
240 bool Window::event(QEvent *e)
241 {
242  switch (e->type()) {
244  render();
245  break;
246 
248  // this is the proper time to tear down the swapchain (while the native window and surface are still around)
251  break;
252 
253  default:
254  break;
255  }
256 
257  return QWindow::event(e);
258 }
259 
260 void Window::init()
261 {
262  if (graphicsApi == Null) {
265  }
266 
267 #ifndef QT_NO_OPENGL
268  if (graphicsApi == OpenGL) {
271  params.fallbackSurface = m_fallbackSurface;
272  params.window = this;
274  }
275 #endif
276 
277 #if QT_CONFIG(vulkan)
278  if (graphicsApi == Vulkan) {
280  params.inst = vulkanInstance();
281  params.window = this;
283  }
284 #endif
285 
286 #ifdef Q_OS_WIN
287  if (graphicsApi == D3D11) {
289  if (debugLayer)
290  qDebug("Enabling D3D11 debug layer");
291  params.enableDebugLayer = debugLayer;
292  if (framesUntilTdr > 0) {
293  params.framesUntilKillingDeviceViaTdr = framesUntilTdr;
294  params.repeatDeviceKill = true;
295  }
297  }
298 #endif
299 
300 #if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
301  if (graphicsApi == Metal) {
304  }
305 #endif
306 
307  if (!m_r)
308  qFatal("Failed to create RHI backend");
309 
310  // now onto the backend-independent init
311 
312  m_sc = m_r->newSwapChain();
313  // allow depth-stencil, although we do not actually enable depth test/write for the triangle
315  QSize(), // no need to set the size here, due to UsedWithSwapChainOnly
316  sampleCount,
318  m_sc->setWindow(this);
319  m_sc->setDepthStencil(m_ds);
320  m_sc->setSampleCount(sampleCount);
321  m_sc->setFlags(scFlags);
322  m_rp = m_sc->newCompatibleRenderPassDescriptor();
323  m_sc->setRenderPassDescriptor(m_rp);
324 
325  customInit();
326 }
327 
329 {
330  customRelease();
331 
332  delete m_rp;
333  m_rp = nullptr;
334 
335  delete m_ds;
336  m_ds = nullptr;
337 
338  delete m_sc;
339  m_sc = nullptr;
340 
341  delete m_r;
342  m_r = nullptr;
343 
344 #ifndef QT_NO_OPENGL
345  delete m_fallbackSurface;
346  m_fallbackSurface = nullptr;
347 #endif
348 }
349 
350 void Window::resizeSwapChain()
351 {
352  m_hasSwapChain = m_sc->createOrResize(); // also handles m_ds
353 
354  m_frameCount = 0;
355  m_timer.restart();
356 
357  const QSize outputSize = m_sc->currentPixelSize();
359  m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f);
360  m_proj.translate(0, 0, -4);
361 }
362 
364 {
365  if (m_hasSwapChain) {
366  m_hasSwapChain = false;
367  m_sc->destroy();
368  }
369 }
370 
371 void Window::render()
372 {
373  if (!m_hasSwapChain || m_notExposed)
374  return;
375 
376  // If the window got resized or got newly exposed, resize the swapchain.
377  // (the newly-exposed case is not actually required by some
378  // platforms/backends, but f.ex. Vulkan on Windows seems to need it)
379  if (m_sc->currentPixelSize() != m_sc->surfacePixelSize() || m_newlyExposed) {
380  resizeSwapChain();
381  if (!m_hasSwapChain)
382  return;
383  m_newlyExposed = false;
384  }
385 
386  // Start a new frame. This is where we block when too far ahead of
387  // GPU/present, and that's what throttles the thread to the refresh rate.
388  // (except for OpenGL where it happens either in endFrame or somewhere else
389  // depending on the GL implementation)
392  resizeSwapChain();
393  if (!m_hasSwapChain)
394  return;
395  r = m_r->beginFrame(m_sc);
396  }
397  if (r != QRhi::FrameOpSuccess) {
398  requestUpdate();
399  return;
400  }
401 
402  m_frameCount += 1;
403  if (m_timer.elapsed() > 1000) {
404  if (rhiFlags.testFlag(QRhi::EnableProfiling)) {
409  qDebug("ca. %d fps. "
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",
413  m_frameCount,
414  ff.minTime, ff.maxTime, ff.avgTime,
415  be.minTime, be.maxTime, be.avgTime,
416  gp.minTime, gp.maxTime, gp.avgTime);
417  } else {
418  qDebug("ca. %d fps. "
419  "frame-to-frame: min %lld max %lld avg %f. "
420  "frame build: min %lld max %lld avg %f. ",
421  m_frameCount,
422  ff.minTime, ff.maxTime, ff.avgTime,
423  be.minTime, be.maxTime, be.avgTime);
424  }
425  } else {
426  qDebug("ca. %d fps", m_frameCount);
427  }
428 
429  m_timer.restart();
430  m_frameCount = 0;
431  }
432 
433  customRender();
434 
436 
437  if (!scFlags.testFlag(QRhiSwapChain::NoVSync))
438  requestUpdate();
439  else // try prevent all delays when NoVSync
441 }
442 
443 int main(int argc, char **argv)
444 {
445  QGuiApplication app(argc, argv);
446 
448 
449  // Defaults.
450 #if defined(Q_OS_WIN)
451  graphicsApi = D3D11;
452 #elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
453  graphicsApi = Metal;
454 #elif QT_CONFIG(vulkan)
456 #else
458 #endif
459 
460  // Allow overriding via the command line.
461  QCommandLineParser cmdLineParser;
462  cmdLineParser.addHelpOption();
463  QCommandLineOption nullOption({ "n", "null" }, QLatin1String("Null"));
464  cmdLineParser.addOption(nullOption);
465  QCommandLineOption glOption({ "g", "opengl" }, QLatin1String("OpenGL"));
466  cmdLineParser.addOption(glOption);
467  QCommandLineOption vkOption({ "v", "vulkan" }, QLatin1String("Vulkan"));
468  cmdLineParser.addOption(vkOption);
469  QCommandLineOption d3dOption({ "d", "d3d11" }, QLatin1String("Direct3D 11"));
470  cmdLineParser.addOption(d3dOption);
471  QCommandLineOption mtlOption({ "m", "metal" }, QLatin1String("Metal"));
472  cmdLineParser.addOption(mtlOption);
473  // Testing cleanup both with QWindow::close() (hitting X or Alt-F4) and
474  // QCoreApplication::quit() (e.g. what a menu widget would do) is important.
475  // Use this parameter for the latter.
476  QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self-destruct after 5 seconds."));
477  cmdLineParser.addOption(sdOption);
478  QCommandLineOption coreProfOption({ "c", "core" }, QLatin1String("Request a core profile context for OpenGL"));
479  cmdLineParser.addOption(coreProfOption);
480  // Attempt testing device lost situations on D3D at least.
481  QCommandLineOption tdrOption(QLatin1String("curse"), QLatin1String("Curse the graphics device. "
482  "(generate a device reset every <count> frames when on D3D11)"),
483  QLatin1String("count"));
484  cmdLineParser.addOption(tdrOption);
485  // Allow testing preferring the software adapter (D3D).
486  QCommandLineOption swOption(QLatin1String("software"), QLatin1String("Prefer a software renderer when choosing the adapter. "
487  "Only applicable with some APIs and platforms."));
488  cmdLineParser.addOption(swOption);
489  // Allow testing having a semi-transparent window.
490  QCommandLineOption transparentOption(QLatin1String("transparent"), QLatin1String("Make background transparent"));
491  cmdLineParser.addOption(transparentOption);
492 
493  cmdLineParser.process(app);
494  if (cmdLineParser.isSet(nullOption))
495  graphicsApi = Null;
496  if (cmdLineParser.isSet(glOption))
498  if (cmdLineParser.isSet(vkOption))
500  if (cmdLineParser.isSet(d3dOption))
501  graphicsApi = D3D11;
502  if (cmdLineParser.isSet(mtlOption))
503  graphicsApi = Metal;
504 
505  qDebug("Selected graphics API is %s", qPrintable(graphicsApiName()));
506  qDebug("This is a multi-api example, use command line arguments to override:\n%s", qPrintable(cmdLineParser.helpText()));
507 
508  if (cmdLineParser.isSet(transparentOption)) {
509  transparentBackground = true;
511  }
512 
513 #ifdef EXAMPLEFW_PREINIT
514  void preInit();
515  preInit();
516 #endif
517 
518  // OpenGL specifics.
519  QSurfaceFormat fmt;
520  fmt.setDepthBufferSize(24);
521  fmt.setStencilBufferSize(8);
522  if (cmdLineParser.isSet(coreProfOption)) {
523 #ifdef Q_OS_DARWIN
524  fmt.setVersion(4, 1);
525 #else
526  fmt.setVersion(4, 3);
527 #endif
529  }
530  if (sampleCount > 1)
531  fmt.setSamples(sampleCount);
532  if (scFlags.testFlag(QRhiSwapChain::NoVSync))
533  fmt.setSwapInterval(0);
534  if (scFlags.testFlag(QRhiSwapChain::sRGB))
536  // Exception: The alpha size is not necessarily OpenGL specific.
538  fmt.setAlphaBufferSize(8);
540 
541  // Vulkan setup.
542 #if QT_CONFIG(vulkan)
543  QVulkanInstance inst;
544  if (graphicsApi == Vulkan) {
545  if (debugLayer) {
546  qDebug("Enabling Vulkan validation layer (if available)");
547  inst.setLayers({ "VK_LAYER_KHRONOS_validation" });
548  }
549  const QVersionNumber supportedVersion = inst.supportedApiVersion();
550  qDebug() << "Supported Vulkan API version:" << supportedVersion;
551  if (supportedVersion >= QVersionNumber(1, 1)) {
552  qDebug("Requesting Vulkan API 1.1 on the VkInstance");
553  inst.setApiVersion(QVersionNumber(1, 1));
554  }
556  if (!inst.create()) {
557  qWarning("Failed to create Vulkan instance, switching to OpenGL");
559  }
560  }
561 #endif
562 
563  if (cmdLineParser.isSet(tdrOption))
564  framesUntilTdr = cmdLineParser.value(tdrOption).toInt();
565 
566  if (cmdLineParser.isSet(swOption))
568 
569  // Create and show the window.
570  Window w;
571 #if QT_CONFIG(vulkan)
572  if (graphicsApi == Vulkan)
573  w.setVulkanInstance(&inst);
574 #endif
575  w.resize(1280, 720);
577  w.show();
578 
579  if (cmdLineParser.isSet(sdOption))
580  QTimer::singleShot(5000, qGuiApp, SLOT(quit()));
581 
582  int ret = app.exec();
583 
584  // Window::event() will not get invoked when the
585  // PlatformSurfaceAboutToBeDestroyed event is sent during the QWindow
586  // destruction. That happens only when exiting via app::quit() instead of
587  // the more common QWindow::close(). Take care of it: if the
588  // QPlatformWindow is still around (there was no close() yet), get rid of
589  // the swapchain while it's not too late.
590  if (w.handle())
591  w.releaseSwapChain();
592 
593  return ret;
594 }
static int exec()
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
static QColor fromRgbF(float r, float g, float b, float a=1.0)
Definition: qcolor.cpp:2424
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.
Definition: qelapsedtimer.h:49
qint64 elapsed() const noexcept
qint64 restart() noexcept
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
@ UpdateRequest
Definition: qcoreevent.h:126
@ PlatformSurface
Definition: qcoreevent.h:291
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition: qevent.h:574
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:94
The QGuiApplication class manages the GUI application's control flow and main settings.
The QKeyEvent class describes a key event.
Definition: qevent.h:471
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
Definition: qstring.h:84
static void setFilterRules(const QString &rules)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:61
void perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane)
void translate(const QVector3D &vector)
Definition: qmatrix4x4.cpp:965
The QOffscreenSurface class represents an offscreen surface in the underlying platform.
The QPlatformSurfaceEvent class is used to notify about native platform surface events....
Definition: qevent.h:592
Definition: qrhi_p.h:1536
QMatrix4x4 clipSpaceCorrMatrix() const
Definition: qrhi.cpp:6299
bool isFeatureSupported(QRhi::Feature feature) const
Definition: qrhi.cpp:6318
QRhiRenderBuffer * newRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount=1, QRhiRenderBuffer::Flags flags={}, QRhiTexture::Format backingFormatHint=QRhiTexture::UnknownFormat)
Definition: qrhi.cpp:6589
@ Metal
Definition: qrhi_p.h:1543
@ Vulkan
Definition: qrhi_p.h:1540
@ Null
Definition: qrhi_p.h:1539
@ D3D11
Definition: qrhi_p.h:1542
@ OpenGLES2
Definition: qrhi_p.h:1541
FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags={})
Definition: qrhi.cpp:6759
QRhiSwapChain * newSwapChain()
Definition: qrhi.cpp:6707
static QRhi * create(Implementation impl, QRhiInitParams *params, Flags flags={}, QRhiNativeHandles *importDevice=nullptr)
Definition: qrhi.cpp:4978
FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags={})
Definition: qrhi.cpp:6794
QRhiProfiler * profiler()
Definition: qrhi.cpp:6377
@ Timestamps
Definition: qrhi_p.h:1565
FrameOpResult
Definition: qrhi_p.h:1554
@ FrameOpSuccess
Definition: qrhi_p.h:1555
@ FrameOpSwapChainOutOfDate
Definition: qrhi_p.h:1557
@ EnableProfiling
Definition: qrhi_p.h:1547
@ EnableDebugMarkers
Definition: qrhi_p.h:1548
@ PreferSoftwareRenderer
Definition: qrhi_p.h:1549
CpuTime frameBuildTimes(QRhiSwapChain *sc) const
GpuTime gpuFrameTimes(QRhiSwapChain *sc) const
CpuTime frameToFrameTimes(QRhiSwapChain *sc) const
@ UsedWithSwapChainOnly
Definition: qrhi_p.h:946
@ SurfaceHasPreMulAlpha
Definition: qrhi_p.h:1321
static QShader fromSerialized(const QByteArray &data)
Definition: qshader.cpp:418
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
constexpr int height() const noexcept
Definition: qsize.h:160
constexpr int width() const noexcept
Definition: qsize.h:157
constexpr bool isEmpty() const noexcept
Definition: qsize.h:151
The QString class provides a Unicode character string.
Definition: qstring.h:388
int toInt(bool *ok=nullptr, int base=10) const
Definition: qstring.h:848
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
void setDepthBufferSize(int size)
void setProfile(OpenGLContextProfile profile)
void setAlphaBufferSize(int size)
void setVersion(int major, int minor)
void setStencilBufferSize(int size)
void setSamples(int numSamples)
void setColorSpace(const QColorSpace &colorSpace)
static void setDefaultFormat(const QSurfaceFormat &format)
void setSwapInterval(int interval)
@ OpenGLSurface
Definition: qsurface.h:68
@ MetalSurface
Definition: qsurface.h:72
@ VulkanSurface
Definition: qsurface.h:71
@ Direct3DSurface
Definition: qsurface.h:73
bool singleShot
whether the timer is a single-shot timer
Definition: qtimer.h:60
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.
Definition: qwindow.h:99
virtual bool event(QEvent *) override
Definition: qwindow.cpp:2419
[Window class definition]
Definition: window.h:64
std::unique_ptr< QRhiSwapChain > m_sc
Definition: window.h:89
void releaseSwapChain()
std::unique_ptr< QRhiRenderPassDescriptor > m_rp
Definition: window.h:91
void render()
void keyPressEvent(QKeyEvent *event) override
Definition: window.cpp:112
friend int main(int, char **)
[1]
Definition: main.cpp:1
void customRender()
void init()
bool event(QEvent *event) override
void releaseResources()
QColor m_clearColor
Definition: examplefw.h:176
QPlatformSurfaceEvent::SurfaceEventType surfaceEventType() const
QElapsedTimer m_timer
Definition: examplefw.h:169
QOffscreenSurface * m_fallbackSurface
Definition: examplefw.h:173
bool event(QEvent *) override
QMatrix4x4 m_proj
Definition: window.h:94
void resizeSwapChain()
int m_frameCount
Definition: examplefw.h:170
std::unique_ptr< QRhiRenderBuffer > m_ds
Definition: window.h:90
void customInit()
QRhi * m_r
Definition: examplefw.h:161
void exposeEvent(QExposeEvent *) override
bool m_hasSwapChain
Definition: window.h:93
QSize outputSize
widget setFormat(format)
double e
QRhi::EndFrameFlags endFrameFlags
Definition: examplefw.h:129
QString graphicsApiName()
Definition: examplefw.h:106
bool debugLayer
Definition: examplefw.h:132
QRhiSwapChain::Flags scFlags
Definition: examplefw.h:127
int framesUntilTdr
Definition: examplefw.h:130
int main(int argc, char **argv)
[1]
Definition: examplefw.h:443
QShader getShader(const QString &name)
Definition: examplefw.h:86
GraphicsApi graphicsApi
Definition: examplefw.h:104
QRhi::Flags rhiFlags
Definition: examplefw.h:125
@ Metal
Definition: examplefw.h:101
@ Null
Definition: examplefw.h:97
@ Vulkan
Definition: examplefw.h:99
@ D3D11
Definition: examplefw.h:100
@ OpenGL
Definition: examplefw.h:98
QRhi::BeginFrameFlags beginFrameFlags
Definition: examplefw.h:128
bool transparentBackground
Definition: examplefw.h:131
int sampleCount
Definition: examplefw.h:126
GraphicsApi
Definition: multiwindow.cpp:86
@ transparent
Definition: qnamespace.h:78
void preInit()
#define QString()
Definition: parse-defines.h:51
Flags
#define qGuiApp
#define qDebug
[1]
Definition: qlogging.h:177
#define qWarning
Definition: qlogging.h:179
#define qFatal
Definition: qlogging.h:181
#define SLOT(a)
Definition: qobjectdefs.h:87
GLboolean r
[2]
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat f
GLuint name
void ** params
#define gp
QApplication app(argc, argv)
[0]
Definition: hb-null.hh:93
static QSurfaceFormat adjustedFormat(const QSurfaceFormat &format=QSurfaceFormat::defaultFormat())
Definition: qrhigles2.cpp:442
static QOffscreenSurface * newFallbackSurface(const QSurfaceFormat &format=QSurfaceFormat::defaultFormat())
Definition: qrhigles2.cpp:467
static QByteArrayList preferredInstanceExtensions()
Definition: qrhivulkan.cpp:328