QtBase  v6.3.1
window.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 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 #ifndef WINDOW_H
52 #define WINDOW_H
53 
54 #include <QWindow>
55 
56 #include <QtGui/private/qrhinull_p.h>
57 #if QT_CONFIG(opengl)
58 #include <QtGui/private/qrhigles2_p.h>
59 #include <QOffscreenSurface>
60 #endif
61 #if QT_CONFIG(vulkan)
62 #include <QtGui/private/qrhivulkan_p.h>
63 #endif
64 #ifdef Q_OS_WIN
65 #include <QtGui/private/qrhid3d11_p.h>
66 #endif
67 #if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
68 #include <QtGui/private/qrhimetal_p.h>
69 #endif
70 
71 class Window : public QWindow
72 {
73 public:
74  Window(QRhi::Implementation graphicsApi);
75 
76  void releaseSwapChain();
77 
78 protected:
79  virtual void customInit();
80  virtual void customRender();
81 
82  // destruction order matters to a certain degree: the fallbackSurface must
83  // outlive the rhi, the rhi must outlive all other resources. The resources
84  // need no special order when destroying.
85 #if QT_CONFIG(opengl)
86  std::unique_ptr<QOffscreenSurface> m_fallbackSurface;
87 #endif
88  std::unique_ptr<QRhi> m_rhi;
89  std::unique_ptr<QRhiSwapChain> m_sc;
90  std::unique_ptr<QRhiRenderBuffer> m_ds;
91  std::unique_ptr<QRhiRenderPassDescriptor> m_rp;
92 
93  bool m_hasSwapChain = false;
95 
96 private:
97  void init();
98  void resizeSwapChain();
99  void render();
100 
101  void exposeEvent(QExposeEvent *) override;
102  bool event(QEvent *) override;
103 
104  QRhi::Implementation m_graphicsApi;
105 
106  bool m_running = false;
107  bool m_notExposed = false;
108  bool m_newlyExposed = false;
109 };
110 
111 #endif
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition: qevent.h:574
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:61
Implementation
Definition: qrhi_p.h:1538
The QWindow class represents a window in the underlying windowing system.
Definition: qwindow.h:99
[Window class definition]
Definition: window.h:64
std::unique_ptr< QRhiSwapChain > m_sc
Definition: window.h:89
void releaseSwapChain()
Definition: window.cpp:200
std::unique_ptr< QRhiRenderPassDescriptor > m_rp
Definition: window.h:91
std::unique_ptr< QRhi > m_rhi
Definition: window.h:88
virtual void customRender()
bool event(QEvent *event) override
Window()
[0]
Definition: window.cpp:60
QOffscreenSurface * m_fallbackSurface
Definition: examplefw.h:173
QMatrix4x4 m_proj
Definition: window.h:94
std::unique_ptr< QRhiRenderBuffer > m_ds
Definition: window.h:90
virtual void customInit()
void exposeEvent(QExposeEvent *) override
Definition: window.cpp:136
bool m_hasSwapChain
Definition: window.h:93