aboutsummaryrefslogtreecommitdiffstats
path: root/src/runtimerender/extensionapi/qssgrenderextensions.h
blob: fad94aa759e1fb130a7532d47d2d8a302d81d5a4 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef QSSGRENDEREXTENSIIONS_H
#define QSSGRENDEREXTENSIIONS_H

//
//  W A R N I N G
//  -------------
//
// This file is part of the QtQuick3D API, with limited compatibility guarantees.
// Usage of this API may make your code source and binary incompatible with
// future versions of Qt.
//

#include <QtQuick3DRuntimeRender/qtquick3druntimerenderexports.h>
#include <ssg/qssgrenderbasetypes.h>
#include <ssg/qssgrendergraphobject.h>
#include <ssg/qssgrhicontext.h>
#include <QtCore/qobject.h>

QT_BEGIN_NAMESPACE

class QSSGRenderContextInterface;
class QSSGLayerRenderData;
class QRhiTexture;
class QRhiRenderBuffer;

class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGFrameData
{
public:
    enum class RenderResult : quint32
    {
        AoTexture,
        DepthTexture,
        ScreenTexture,
        NormalTexture,
        MotionVectorTexture,
    };
    Q_DECLARE_FLAGS(RenderResults, RenderResult)

    enum class AttachmentSelector : quint32
    {
        Attachment0 = 0,
        Attachment1 = 1,
        Attachment2 = 2,
        Attachment3 = 3,
    };

    struct Result
    {
        QRhiTexture *texture = nullptr;
        QRhiRenderBuffer *buffer = nullptr;
    };

    using TypeMask = QSSGRenderGraphObject::TypeT;
    static constexpr TypeMask NodeMask = QSSGRenderGraphObject::BaseType::Node;

    void scheduleRenderResults(RenderResults results) const;

    Result getRenderResult(RenderResult id) const;
    Result getRenderResult(QSSGResourceId userPassId, AttachmentSelector attachment) const;

    qsizetype getAttachmentCount(QSSGResourceId userPassId) const;

    [[nodiscard]] QSSGRhiGraphicsPipelineState getPipelineState() const;

    [[nodiscard]] QSSGCameraId activeCamera() const;

    [[nodiscard]] QSSGRenderContextInterface *contextInterface() const;

    [[nodiscard]] QSSGNodeIdList getLayerNodes(quint32 layerMask, TypeMask typeMask = NodeMask) const;
    [[nodiscard]] QSSGNodeIdList getLayerNodes(QSSGCameraId cameraId, TypeMask typeMask = NodeMask) const;

private:
    friend class QSSGLayerRenderData;
    friend class QSSGRenderOutputProviderExtension;

    void clear();

    [[nodiscard]] QSSGLayerRenderData *getCurrent() const;

    void scheduleRenderResults(QSSGResourceId userPassId) const;

    QSSGFrameData() = default;
    explicit QSSGFrameData(QSSGRenderContextInterface *ctx);
    QSSGRenderContextInterface *m_ctx = nullptr;
};

class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderExtension : public QSSGRenderGraphObject
{
public:
    enum class RenderMode
    {
        Standalone,
        Main
    };

    enum class RenderStage
    {
        PreColor,
        PostColor
    };

    QSSGRenderExtension();
    virtual ~QSSGRenderExtension();

    virtual bool prepareData(QSSGFrameData &data) = 0;
    virtual void prepareRender(QSSGFrameData &data) = 0;
    virtual void render(QSSGFrameData &data) = 0;

    virtual void resetForFrame() = 0;

    virtual RenderMode mode() const = 0;
    virtual RenderStage stage() const = 0;

protected:
    QSSGRenderExtension(Type inType, FlagT inFlags);
};

class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderTextureProviderExtension : public QSSGRenderExtension
{
public:
    QSSGRenderTextureProviderExtension();
    ~QSSGRenderTextureProviderExtension() override;

    RenderMode mode() const final;
    RenderStage stage() const final;
};

QT_END_NAMESPACE

#endif // QSSGRENDEREXTENSIIONS_H