| 1 |
// Copyright (C) 2020 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#ifndef WINDOW_H |
| 5 |
#define WINDOW_H |
| 6 |
|
| 7 |
#include <QWindow> |
| 8 |
#include <QOffscreenSurface> |
| 9 |
#include <rhi/qrhi.h> |
| 10 |
|
| 11 |
class Window : public QWindow |
| 12 |
{ |
| 13 |
public: |
| 14 |
Window(QRhi::Implementation graphicsApi); |
| 15 |
|
| 16 |
void releaseSwapChain(); |
| 17 |
|
| 18 |
protected: |
| 19 |
virtual void customInit(); |
| 20 |
virtual void customRender(); |
| 21 |
|
| 22 |
// destruction order matters to a certain degree: the fallbackSurface must |
| 23 |
// outlive the rhi, the rhi must outlive all other resources. The resources |
| 24 |
// need no special order when destroying. |
| 25 |
#if QT_CONFIG(opengl) |
| 26 |
std::unique_ptr<QOffscreenSurface> m_fallbackSurface; |
| 27 |
#endif |
| 28 |
std::unique_ptr<QRhi> m_rhi; |
| 29 |
std::unique_ptr<QRhiSwapChain> m_sc; |
| 30 |
std::unique_ptr<QRhiRenderBuffer> m_ds; |
| 31 |
std::unique_ptr<QRhiRenderPassDescriptor> m_rp; |
| 32 |
|
| 33 |
bool m_hasSwapChain = false; |
| 34 |
QMatrix4x4 m_proj; |
| 35 |
|
| 36 |
private: |
| 37 |
void init(); |
| 38 |
void resizeSwapChain(); |
| 39 |
void render(); |
| 40 |
|
| 41 |
void exposeEvent(QExposeEvent *) override; |
| 42 |
bool event(QEvent *) override; |
| 43 |
|
| 44 |
QRhi::Implementation m_graphicsApi; |
| 45 |
|
| 46 |
bool m_running = false; |
| 47 |
bool m_notExposed = false; |
| 48 |
bool m_newlyExposed = false; |
| 49 |
}; |
| 50 |
|
| 51 |
#endif |