aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/rendercontrol/rendercontrol_d3d11/engine.h
blob: 02f0fa904915fe564b47ca302a979caa2b17b070 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef ENGINE_H
#define ENGINE_H

#include <QWindow>
#include <QtCore/qt_windows.h> // suppress windows.h include coming from d3d11_1.h

#include <d3d11_1.h>
#include <dxgi1_3.h>

#define RELEASE(obj) { if (obj) { obj->Release(); obj = nullptr; } }

QString comErrorMessage(HRESULT hr);

struct Swapchain
{
    IDXGISwapChain1 *swapchain;
    ID3D11Texture2D *tex;
    ID3D11RenderTargetView *rtv;
    ID3D11Texture2D *ds;
    ID3D11DepthStencilView *dsv;
    QSize pixelSize;

    void destroy();
};

class Engine
{
public:
    ~Engine();
    bool create();
    QSize swapchainSizeForWindow(QWindow *window) const;
    Swapchain createSwapchain(QWindow *window);
    void resizeSwapchain(Swapchain *sc, QWindow *window);
    ID3D11Device *device() { return m_device; }
    ID3D11DeviceContext *context() { return m_context; }

private:
    void createSwapchainBuffers(Swapchain *sc);

    IDXGIFactory1 *m_dxgiFactory = nullptr;
    ID3D11Device *m_device = nullptr;
    ID3D11DeviceContext *m_context = nullptr;
    D3D_FEATURE_LEVEL m_featureLevel;
};

#endif