aboutsummaryrefslogtreecommitdiffstats
path: root/src/runtimerender/qssgrhicontext.h
blob: 44f2fea5ec9d78d48fd2deef46676c3ac619682b (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
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef QSSGRHICONTEXT_H
#define QSSGRHICONTEXT_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 <QtCore/qstack.h>
#include <rhi/qrhi.h>

#include <QtQuick3DRuntimeRender/qtquick3druntimerenderexports.h>

QT_BEGIN_NAMESPACE

class QSSGRhiContextPrivate;
class QSSGRhiShaderPipeline;

class QSSGRhiGraphicsPipelineState
{
public:
    enum class Flag : quint32
    {
        DepthTestEnabled  = 0x1,
        DepthWriteEnabled = 0x2,
        BlendEnabled = 0x4,
        UsesStencilRef = 0x8,
        UsesScissor = 0x10
    };
    Q_DECLARE_FLAGS(Flags, Flag)

    QRhiGraphicsPipeline::CompareOp depthFunc = QRhiGraphicsPipeline::LessOrEqual;
    QRhiGraphicsPipeline::CullMode cullMode = QRhiGraphicsPipeline::None;
    std::array<QRhiGraphicsPipeline::TargetBlend, 8> targetBlend;
    QRhiGraphicsPipeline::PolygonMode polygonMode = QRhiGraphicsPipeline::Fill;
    QRhiGraphicsPipeline::StencilOpState stencilOpFrontState {};
    quint32 stencilWriteMask = 0xFF;
    quint32 stencilRef = 0;
    int depthBias = 0;
    int samples = 1;
    int colorAttachmentCount = 1;
    int viewCount = 1;
    float slopeScaledDepthBias = 0.0f;
    float lineWidth = 1.0f;
    Flags flags;
    QRhiViewport viewport;
    QRhiScissor scissor;

private:
    friend struct QSSGRhiGraphicsPipelineStatePrivate;
    friend struct QSSGRhiInputAssemblerStatePrivate;
    struct InputAssemblerState
    {
        enum InputSemantic {
            PositionSemantic,           // attr_pos
            NormalSemantic,             // attr_norm
            TexCoord0Semantic,          // attr_uv0
            TexCoord1Semantic,          // attr_uv1
            TangentSemantic,            // attr_textan
            BinormalSemantic,           // attr_binormal
            ColorSemantic,              // attr_color
            MaxTargetSemantic = ColorSemantic,
            JointSemantic,              // attr_joints
            WeightSemantic,             // attr_weights
            TexCoordLightmapSemantic    // attr_lightmapuv
        };

        QRhiVertexInputLayout inputLayout;
        QVarLengthArray<InputSemantic, 8> inputs;
        QRhiGraphicsPipeline::Topology topology;
        std::array<quint8, MaxTargetSemantic + 1> targetOffsets = { UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX,
                                                                    UINT8_MAX, UINT8_MAX, UINT8_MAX };
        quint8 targetCount = 0;
    } ia;

    // for internal use
    const QSSGRhiShaderPipeline *shaderPipeline = nullptr;
};

struct QSSGRhiSamplerDescription
{
    QRhiSampler::Filter minFilter;
    QRhiSampler::Filter magFilter;
    QRhiSampler::Filter mipmap;
    QRhiSampler::AddressMode hTiling;
    QRhiSampler::AddressMode vTiling;
    QRhiSampler::AddressMode zTiling;
};

class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiContext
{
    Q_DISABLE_COPY(QSSGRhiContext)
public:
    explicit QSSGRhiContext(QRhi *rhi);
    ~QSSGRhiContext();

    QRhi *rhi() const;
    bool isValid() const;

    QRhiRenderPassDescriptor *mainRenderPassDescriptor() const;
    QRhiCommandBuffer *commandBuffer() const;
    QRhiRenderTarget *renderTarget() const;
    int mainPassSampleCount() const;
    int mainPassViewCount() const;

    QRhiSampler *sampler(const QSSGRhiSamplerDescription &samplerDescription);
    void checkAndAdjustForNPoT(QRhiTexture *texture, QSSGRhiSamplerDescription *samplerDescription);
    QRhiTexture *dummyTexture(QRhiTexture::Flags flags, QRhiResourceUpdateBatch *rub,
                              const QSize &size = QSize(64, 64), const QColor &fillColor = Qt::black,
                              int arraySize = 0);

    QRhiCommandBuffer::BeginPassFlags commonPassFlags() const;

private:
    Q_DECLARE_PRIVATE(QSSGRhiContext)
    std::unique_ptr<QSSGRhiContextPrivate> d_ptr;
};

QT_END_NAMESPACE

#endif