| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QSSGRHICONTEXT_H |
| 5 | #define QSSGRHICONTEXT_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is part of the QtQuick3D API, with limited compatibility guarantees. |
| 12 | // Usage of this API may make your code source and binary incompatible with |
| 13 | // future versions of Qt. |
| 14 | // |
| 15 | |
| 16 | #include <QtCore/qstack.h> |
| 17 | #include <rhi/qrhi.h> |
| 18 | |
| 19 | #include <QtQuick3DRuntimeRender/qtquick3druntimerenderexports.h> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | class QSSGRhiContextPrivate; |
| 24 | class QSSGRhiShaderPipeline; |
| 25 | |
| 26 | class QSSGRhiGraphicsPipelineState |
| 27 | { |
| 28 | public: |
| 29 | enum class Flag : quint32 |
| 30 | { |
| 31 | DepthTestEnabled = 0x1, |
| 32 | DepthWriteEnabled = 0x2, |
| 33 | BlendEnabled = 0x4, |
| 34 | UsesStencilRef = 0x8, |
| 35 | UsesScissor = 0x10 |
| 36 | }; |
| 37 | Q_DECLARE_FLAGS(Flags, Flag) |
| 38 | |
| 39 | QRhiGraphicsPipeline::CompareOp depthFunc = QRhiGraphicsPipeline::LessOrEqual; |
| 40 | QRhiGraphicsPipeline::CullMode cullMode = QRhiGraphicsPipeline::None; |
| 41 | QRhiGraphicsPipeline::TargetBlend targetBlend; |
| 42 | QRhiGraphicsPipeline::PolygonMode polygonMode = QRhiGraphicsPipeline::Fill; |
| 43 | QRhiGraphicsPipeline::StencilOpState stencilOpFrontState {}; |
| 44 | quint32 stencilWriteMask = 0xFF; |
| 45 | quint32 stencilRef = 0; |
| 46 | int depthBias = 0; |
| 47 | int samples = 1; |
| 48 | int colorAttachmentCount = 1; |
| 49 | int viewCount = 1; |
| 50 | float slopeScaledDepthBias = 0.0f; |
| 51 | float lineWidth = 1.0f; |
| 52 | Flags flags; |
| 53 | QRhiViewport viewport; |
| 54 | QRhiScissor scissor; |
| 55 | |
| 56 | private: |
| 57 | friend struct QSSGRhiGraphicsPipelineStatePrivate; |
| 58 | friend struct QSSGRhiInputAssemblerStatePrivate; |
| 59 | struct InputAssemblerState |
| 60 | { |
| 61 | enum InputSemantic { |
| 62 | PositionSemantic, // attr_pos |
| 63 | NormalSemantic, // attr_norm |
| 64 | TexCoord0Semantic, // attr_uv0 |
| 65 | TexCoord1Semantic, // attr_uv1 |
| 66 | TangentSemantic, // attr_textan |
| 67 | BinormalSemantic, // attr_binormal |
| 68 | ColorSemantic, // attr_color |
| 69 | MaxTargetSemantic = ColorSemantic, |
| 70 | JointSemantic, // attr_joints |
| 71 | WeightSemantic, // attr_weights |
| 72 | TexCoordLightmapSemantic // attr_lightmapuv |
| 73 | }; |
| 74 | |
| 75 | QRhiVertexInputLayout inputLayout; |
| 76 | QVarLengthArray<InputSemantic, 8> inputs; |
| 77 | QRhiGraphicsPipeline::Topology topology; |
| 78 | std::array<quint8, MaxTargetSemantic + 1> targetOffsets = { UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX, |
| 79 | UINT8_MAX, UINT8_MAX, UINT8_MAX }; |
| 80 | quint8 targetCount = 0; |
| 81 | } ia; |
| 82 | |
| 83 | // for internal use |
| 84 | const QSSGRhiShaderPipeline *shaderPipeline = nullptr; |
| 85 | }; |
| 86 | |
| 87 | struct QSSGRhiSamplerDescription |
| 88 | { |
| 89 | QRhiSampler::Filter minFilter; |
| 90 | QRhiSampler::Filter magFilter; |
| 91 | QRhiSampler::Filter mipmap; |
| 92 | QRhiSampler::AddressMode hTiling; |
| 93 | QRhiSampler::AddressMode vTiling; |
| 94 | QRhiSampler::AddressMode zTiling; |
| 95 | }; |
| 96 | |
| 97 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiContext |
| 98 | { |
| 99 | Q_DISABLE_COPY(QSSGRhiContext) |
| 100 | public: |
| 101 | explicit QSSGRhiContext(QRhi *rhi); |
| 102 | ~QSSGRhiContext(); |
| 103 | |
| 104 | QRhi *rhi() const; |
| 105 | bool isValid() const; |
| 106 | |
| 107 | QRhiRenderPassDescriptor *mainRenderPassDescriptor() const; |
| 108 | QRhiCommandBuffer *commandBuffer() const; |
| 109 | QRhiRenderTarget *renderTarget() const; |
| 110 | int mainPassSampleCount() const; |
| 111 | int mainPassViewCount() const; |
| 112 | |
| 113 | QRhiSampler *sampler(const QSSGRhiSamplerDescription &samplerDescription); |
| 114 | void checkAndAdjustForNPoT(QRhiTexture *texture, QSSGRhiSamplerDescription *samplerDescription); |
| 115 | QRhiTexture *dummyTexture(QRhiTexture::Flags flags, QRhiResourceUpdateBatch *rub, |
| 116 | const QSize &size = QSize(64, 64), const QColor &fillColor = Qt::black, |
| 117 | int arraySize = 0); |
| 118 | |
| 119 | QRhiCommandBuffer::BeginPassFlags commonPassFlags() const; |
| 120 | |
| 121 | private: |
| 122 | Q_DECLARE_PRIVATE(QSSGRhiContext) |
| 123 | std::unique_ptr<QSSGRhiContextPrivate> d_ptr; |
| 124 | }; |
| 125 | |
| 126 | QT_END_NAMESPACE |
| 127 | |
| 128 | #endif |
| 129 | |