| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QSGMATERIALSHADER_P_H |
| 5 | #define QSGMATERIALSHADER_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <private/qtquickglobal_p.h> |
| 19 | #include "qsgmaterialshader.h" |
| 20 | #include "qsgmaterial.h" |
| 21 | #include <rhi/qrhi.h> |
| 22 | #include <rhi/qshader.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QRhiSampler; |
| 27 | |
| 28 | class Q_QUICK_EXPORT QSGMaterialShaderPrivate |
| 29 | { |
| 30 | public: |
| 31 | Q_DECLARE_PUBLIC(QSGMaterialShader) |
| 32 | |
| 33 | QSGMaterialShaderPrivate(QSGMaterialShader *q) : q_ptr(q) { } |
| 34 | static QSGMaterialShaderPrivate *get(QSGMaterialShader *s) { return s->d_func(); } |
| 35 | static const QSGMaterialShaderPrivate *get(const QSGMaterialShader *s) { return s->d_func(); } |
| 36 | |
| 37 | void clearCachedRendererData(); |
| 38 | void prepare(QShader::Variant vertexShaderVariant); |
| 39 | |
| 40 | QShader shader(QShader::Stage stage) const { return shaders[stage].shader; } |
| 41 | |
| 42 | static QShader loadShader(const QString &filename); |
| 43 | |
| 44 | QSGMaterialShader *q_ptr; |
| 45 | QHash<QShader::Stage, QString> shaderFileNames; |
| 46 | QSGMaterialShader::Flags flags; |
| 47 | |
| 48 | struct ShaderStageData { |
| 49 | ShaderStageData() { } // so shader.isValid() == false |
| 50 | ShaderStageData(const QShader &shader) : shader(shader) { } |
| 51 | QShader shader; |
| 52 | QShader::Variant shaderVariant = QShader::StandardShader; |
| 53 | QVector<int> vertexInputLocations; // excluding rewriter-inserted ones |
| 54 | int qt_order_attrib_location = -1; // rewriter-inserted |
| 55 | }; |
| 56 | QHash<QShader::Stage, ShaderStageData> shaders; |
| 57 | |
| 58 | static const int MAX_SHADER_RESOURCE_BINDINGS = 32; |
| 59 | |
| 60 | int ubufBinding = -1; |
| 61 | int ubufSize = 0; |
| 62 | QRhiShaderResourceBinding::StageFlags ubufStages; |
| 63 | QRhiShaderResourceBinding::StageFlags combinedImageSamplerBindings[MAX_SHADER_RESOURCE_BINDINGS]; |
| 64 | int combinedImageSamplerCount[MAX_SHADER_RESOURCE_BINDINGS]; |
| 65 | |
| 66 | ShaderStageData *vertexShader = nullptr; |
| 67 | ShaderStageData *fragmentShader = nullptr; |
| 68 | |
| 69 | QByteArray masterUniformData; |
| 70 | |
| 71 | QVarLengthArray<QSGTexture *, 4> textureBindingTable[MAX_SHADER_RESOURCE_BINDINGS]; |
| 72 | QVarLengthArray<QRhiSampler *, 4> samplerBindingTable[MAX_SHADER_RESOURCE_BINDINGS]; |
| 73 | }; |
| 74 | |
| 75 | Q_DECLARE_TYPEINFO(QSGMaterialShaderPrivate::ShaderStageData, Q_RELOCATABLE_TYPE); |
| 76 | |
| 77 | QT_END_NAMESPACE |
| 78 | |
| 79 | #endif |
| 80 |
