| 1 | // Copyright (C) 2008-2012 NVIDIA Corporation. |
| 2 | // Copyright (C) 2019 The Qt Company Ltd. |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 4 | |
| 5 | #ifndef QSSG_RHI_CUSTOM_MATERIAL_SYSTEM_H |
| 6 | #define QSSG_RHI_CUSTOM_MATERIAL_SYSTEM_H |
| 7 | |
| 8 | // |
| 9 | // W A R N I N G |
| 10 | // ------------- |
| 11 | // |
| 12 | // This file is not part of the Qt API. It exists purely as an |
| 13 | // implementation detail. This header file may change from version to |
| 14 | // version without notice, or even be removed. |
| 15 | // |
| 16 | // We mean it. |
| 17 | // |
| 18 | |
| 19 | #include <QtQuick3DRuntimeRender/qtquick3druntimerenderglobal.h> |
| 20 | #include <QtQuick3DRuntimeRender/private/qssgrendershaderlibrarymanager_p.h> |
| 21 | #include <QtQuick3DRuntimeRender/private/qssgrenderableobjects_p.h> |
| 22 | #include <QtQuick3DRuntimeRender/private/qssgrendercustommaterial_p.h> |
| 23 | #include <QtQuick3DRuntimeRender/private/qssgrendershaderkeys_p.h> |
| 24 | #include <QtQuick3DRuntimeRender/private/qssgshadermapkey_p.h> |
| 25 | #include <QtCore/qhash.h> |
| 26 | #include <QtGui/QMatrix4x4> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | struct QSSGRenderCustomMaterial; |
| 31 | struct QSSGRenderSubset; |
| 32 | struct QSSGRenderModel; |
| 33 | class QSSGLayerRenderData; |
| 34 | struct QSSGRenderableImage; |
| 35 | struct QSSGRenderLayer; |
| 36 | struct QSSGRenderLight; |
| 37 | struct QSSGRenderCamera; |
| 38 | struct QSSGReflectionMapEntry; |
| 39 | class QRhiTexture; |
| 40 | |
| 41 | |
| 42 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGCustomMaterialSystem |
| 43 | { |
| 44 | Q_DISABLE_COPY(QSSGCustomMaterialSystem) |
| 45 | typedef QPair<QByteArray, QByteArray> TStrStrPair; |
| 46 | typedef QHash<QSSGShaderMapKey, QSSGRhiShaderPipelinePtr> TShaderMap; |
| 47 | |
| 48 | QSSGRenderContextInterface *context = nullptr; |
| 49 | TShaderMap shaderMap; |
| 50 | |
| 51 | void setShaderResources(char *ubufData, |
| 52 | const QSSGRenderCustomMaterial &inMaterial, |
| 53 | const QByteArray &inPropertyName, |
| 54 | const QVariant &propertyValue, |
| 55 | QSSGRenderShaderValue::Type inPropertyType, |
| 56 | QSSGRhiShaderPipeline &shaderPipeline); |
| 57 | |
| 58 | public: |
| 59 | QSSGCustomMaterialSystem(); |
| 60 | ~QSSGCustomMaterialSystem(); |
| 61 | |
| 62 | void setRenderContextInterface(QSSGRenderContextInterface *inContext); |
| 63 | |
| 64 | void releaseCachedResources(); |
| 65 | |
| 66 | // Returns true if the material is dirty and thus will produce a different render result |
| 67 | // than previously. This effects things like progressive AA. |
| 68 | bool prepareForRender(const QSSGRenderModel &inModel, |
| 69 | const QSSGRenderSubset &inSubset, |
| 70 | QSSGRenderCustomMaterial &inMaterial); |
| 71 | |
| 72 | QSSGRhiShaderPipelinePtr shadersForCustomMaterial(QSSGRhiGraphicsPipelineState *ps, |
| 73 | const QSSGRenderCustomMaterial &material, |
| 74 | QSSGSubsetRenderable &renderable, |
| 75 | const QSSGShaderDefaultMaterialKeyProperties &defaultMaterialShaderKeyProperties, |
| 76 | const QSSGShaderFeatures &featureSet); |
| 77 | |
| 78 | void updateUniformsForCustomMaterial(QSSGRhiShaderPipeline &shaderPipeline, |
| 79 | QSSGRhiContext *rhiCtx, |
| 80 | const QSSGLayerRenderData &inData, |
| 81 | char *ubufData, |
| 82 | QSSGRhiGraphicsPipelineState *ps, |
| 83 | const QSSGRenderCustomMaterial &material, |
| 84 | QSSGSubsetRenderable &renderable, |
| 85 | const QSSGRenderCameraList &cameras, |
| 86 | const QVector2D *depthAdjust, |
| 87 | const QMatrix4x4 *alteredModelViewProjection); |
| 88 | |
| 89 | void rhiPrepareRenderable(QSSGRhiGraphicsPipelineState *ps, |
| 90 | QSSGPassKey passKey, |
| 91 | QSSGSubsetRenderable &renderable, |
| 92 | const QSSGShaderFeatures &featureSet, |
| 93 | const QSSGRenderCustomMaterial &material, |
| 94 | const QSSGLayerRenderData &layerData, |
| 95 | QRhiRenderPassDescriptor *renderPassDescriptor, |
| 96 | int samples, |
| 97 | int viewCount, |
| 98 | QSSGRenderCamera *camera = nullptr, |
| 99 | QSSGRenderTextureCubeFace cubeFace = QSSGRenderTextureCubeFaceNone, |
| 100 | QMatrix4x4 *modelViewProjection = nullptr, |
| 101 | QSSGReflectionMapEntry *entry = nullptr); |
| 102 | void applyRhiShaderPropertyValues(char *ubufData, |
| 103 | const QSSGRenderCustomMaterial &inMaterial, |
| 104 | QSSGRhiShaderPipeline &shaderPipeline); |
| 105 | void rhiRenderRenderable(QSSGRhiContext *rhiCtx, |
| 106 | QSSGSubsetRenderable &renderable, |
| 107 | bool *needsSetViewport, |
| 108 | QSSGRenderTextureCubeFace cubeFace, |
| 109 | const QSSGRhiGraphicsPipelineState &state); |
| 110 | }; |
| 111 | |
| 112 | QT_END_NAMESPACE |
| 113 | |
| 114 | #endif |
| 115 | |