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/private/qtquick3druntimerenderglobal_p.h>
20#include <QtQuick3DRuntimeRender/private/qssgrendershaderlibrarymanager_p.h>
21#include <QtQuick3DRuntimeRender/private/qssgvertexpipelineimpl_p.h>
22#include <QtQuick3DRuntimeRender/private/qssgrenderableobjects_p.h>
23#include <QtQuick3DRuntimeRender/private/qssgrendercustommaterial_p.h>
24#include <QtQuick3DRuntimeRender/private/qssgrendershaderkeys_p.h>
25#include <QtQuick3DRuntimeRender/private/qssgshadermapkey_p.h>
26#include <QtCore/qhash.h>
27#include <QtGui/QMatrix4x4>
28
29QT_BEGIN_NAMESPACE
30
31struct QSSGRenderCustomMaterial;
32struct QSSGRenderSubset;
33struct QSSGRenderModel;
34class QSSGLayerRenderData;
35struct QSSGRenderableImage;
36struct QSSGRenderLayer;
37struct QSSGRenderLight;
38struct QSSGRenderCamera;
39struct QSSGReflectionMapEntry;
40class QRhiTexture;
41
42
43class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGCustomMaterialSystem
44{
45 Q_DISABLE_COPY(QSSGCustomMaterialSystem)
46 typedef QPair<QByteArray, QByteArray> TStrStrPair;
47 typedef QHash<QSSGShaderMapKey, QSSGRhiShaderPipelinePtr> TShaderMap;
48
49 QSSGRenderContextInterface *context = nullptr;
50 TShaderMap shaderMap;
51
52 void setShaderResources(char *ubufData,
53 const QSSGRenderCustomMaterial &inMaterial,
54 const QByteArray &inPropertyName,
55 const QVariant &propertyValue,
56 QSSGRenderShaderValue::Type inPropertyType,
57 QSSGRhiShaderPipeline &shaderPipeline);
58
59public:
60 QSSGCustomMaterialSystem();
61 ~QSSGCustomMaterialSystem();
62
63 void setRenderContextInterface(QSSGRenderContextInterface *inContext);
64
65 void releaseCachedResources();
66
67 // Returns true if the material is dirty and thus will produce a different render result
68 // than previously. This effects things like progressive AA.
69 bool prepareForRender(const QSSGRenderModel &inModel,
70 const QSSGRenderSubset &inSubset,
71 QSSGRenderCustomMaterial &inMaterial);
72
73 QSSGRhiShaderPipelinePtr shadersForCustomMaterial(QSSGRhiGraphicsPipelineState *ps,
74 const QSSGRenderCustomMaterial &material,
75 QSSGSubsetRenderable &renderable,
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 QSSGRenderCamera &camera,
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 QSSGRenderCamera *camera = nullptr,
98 QSSGRenderTextureCubeFace cubeFace = QSSGRenderTextureCubeFaceNone,
99 QMatrix4x4 *modelViewProjection = nullptr,
100 QSSGReflectionMapEntry *entry = nullptr);
101 void applyRhiShaderPropertyValues(char *ubufData,
102 const QSSGRenderCustomMaterial &inMaterial,
103 QSSGRhiShaderPipeline &shaderPipeline);
104 void rhiRenderRenderable(QSSGRhiContext *rhiCtx,
105 QSSGSubsetRenderable &renderable,
106 bool *needsSetViewport,
107 QSSGRenderTextureCubeFace cubeFace,
108 const QSSGRhiGraphicsPipelineState &state);
109};
110
111QT_END_NAMESPACE
112
113#endif
114

source code of qtquick3d/src/runtimerender/qssgrhicustommaterialsystem_p.h