| 1 |
// Copyright (C) 2022 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 |
QVulkanInstance instance; |
| 20 |
std::unique_ptr<QOffscreenSurface> m_fallbackSurface; |
| 21 |
std::unique_ptr<QRhi> m_rhi; |
| 22 |
std::unique_ptr<QRhiSwapChain> m_sc; |
| 23 |
std::unique_ptr<QRhiRenderBuffer> m_ds; |
| 24 |
std::unique_ptr<QRhiRenderPassDescriptor> m_rp; |
| 25 |
|
| 26 |
QRhi::Implementation m_graphicsApi; |
| 27 |
bool m_hasSwapChain = false; |
| 28 |
QMatrix4x4 m_proj; |
| 29 |
|
| 30 |
private: |
| 31 |
void init(); |
| 32 |
void resizeSwapChain(); |
| 33 |
void render(); |
| 34 |
void recordFrame(); |
| 35 |
|
| 36 |
void exposeEvent(QExposeEvent *) override; |
| 37 |
bool event(QEvent *) override; |
| 38 |
|
| 39 |
bool m_running = false; |
| 40 |
bool m_notExposed = false; |
| 41 |
bool m_newlyExposed = false; |
| 42 |
|
| 43 |
QShader getShader(const QString &name); |
| 44 |
|
| 45 |
std::unique_ptr<QRhiBuffer> m_vbuf; |
| 46 |
bool m_vbufReady = false; |
| 47 |
std::unique_ptr<QRhiBuffer> m_ubuf; |
| 48 |
std::unique_ptr<QRhiBuffer> m_ubuf2; |
| 49 |
std::unique_ptr<QRhiShaderResourceBindings> m_srb; |
| 50 |
std::unique_ptr<QRhiShaderResourceBindings> m_srb2; |
| 51 |
std::unique_ptr<QRhiGraphicsPipeline> m_ps; |
| 52 |
|
| 53 |
float m_rotation = 0; |
| 54 |
float m_translation = -5; |
| 55 |
int m_translationDir = -1; |
| 56 |
}; |
| 57 |
|
| 58 |
#endif |