| 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_RENDER_DYNAMIC_OBJECT_SYSTEM_H |
| 6 | #define QSSG_RENDER_DYNAMIC_OBJECT_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 <QtQuick3DUtils/private/qssgrenderbasetypes_p.h> |
| 20 | #include <QtQuick3DUtils/private/qqsbcollection_p.h> |
| 21 | |
| 22 | #include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h> |
| 23 | #include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h> |
| 24 | #include <QtQuick3DRuntimeRender/private/qssgrendershaderkeys_p.h> |
| 25 | |
| 26 | #include <QtGui/QVector2D> |
| 27 | |
| 28 | #include <QtCore/QString> |
| 29 | #include <QtCore/QReadWriteLock> |
| 30 | |
| 31 | QT_BEGIN_NAMESPACE |
| 32 | |
| 33 | class QSSGRenderContextInterface; |
| 34 | |
| 35 | struct QSSGCustomShaderMetaData |
| 36 | { |
| 37 | enum Flag { |
| 38 | UsesScreenTexture = 1 << 0, |
| 39 | UsesDepthTexture = 1 << 1, |
| 40 | UsesAoTexture = 1 << 2, |
| 41 | OverridesPosition = 1 << 3, |
| 42 | UsesProjectionMatrix = 1 << 4, |
| 43 | UsesInverseProjectionMatrix = 1 << 5, |
| 44 | UsesScreenMipTexture = 1 << 6, |
| 45 | UsesVarColor = 1 << 7, |
| 46 | UsesSharedVars = 1 << 8, |
| 47 | UsesIblOrientation = 1 << 9, |
| 48 | UsesLightmap = 1 << 10, |
| 49 | UsesSkinning = 1 << 11, |
| 50 | UsesMorphing = 1 << 12, |
| 51 | UsesViewIndex = 1 << 13, |
| 52 | UsesInputTexture = 1 << 14, |
| 53 | UsesClearcoat = 1 << 15, |
| 54 | UsesClearcoatFresnelScaleBias = 1 << 16, |
| 55 | UsesFresnelScaleBias = 1 << 17, |
| 56 | UsesTransmission = 1 << 18, |
| 57 | }; |
| 58 | Q_DECLARE_FLAGS(Flags, Flag) |
| 59 | |
| 60 | Flags flags; |
| 61 | QSet<QByteArray> customFunctions; |
| 62 | QSSGShaderFeatures features; |
| 63 | }; |
| 64 | |
| 65 | Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGCustomShaderMetaData::Flags) |
| 66 | |
| 67 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGShaderLibraryManager |
| 68 | { |
| 69 | Q_DISABLE_COPY(QSSGShaderLibraryManager) |
| 70 | public: |
| 71 | typedef QHash<QByteArray, QByteArray> TPathDataMap; |
| 72 | typedef QSet<QString> TPathSet; |
| 73 | |
| 74 | TPathDataMap m_expandedFiles; |
| 75 | QHash<QByteArray, QSSGCustomShaderMetaData> m_metadata; |
| 76 | QByteArray m_vertShader; |
| 77 | QByteArray m_fragShader; |
| 78 | |
| 79 | QQsbCollection::EntryMap m_preGeneratedShaderEntries; |
| 80 | |
| 81 | QReadWriteLock m_lock; |
| 82 | |
| 83 | static QString getShaderCodeLibraryDirectory(); |
| 84 | |
| 85 | explicit QSSGShaderLibraryManager(); |
| 86 | |
| 87 | ~QSSGShaderLibraryManager(); |
| 88 | |
| 89 | void setShaderSource(const QByteArray &inShaderPathKey, QSSGShaderCache::ShaderType type, |
| 90 | const QByteArray &inSource, const QSSGCustomShaderMetaData &meta); |
| 91 | |
| 92 | // Does not load any shaders, only information about the content of the pregenerated shaders |
| 93 | void loadPregeneratedShaderInfo(); |
| 94 | |
| 95 | void resolveIncludeFiles(QByteArray &theReadBuffer, const QByteArray &inMaterialInfoString); |
| 96 | QByteArray getIncludeContents(const QByteArray &inShaderPathKey); |
| 97 | |
| 98 | QByteArray getShaderSource(const QByteArray &inShaderPathKey, QSSGShaderCache::ShaderType type); |
| 99 | QSSGCustomShaderMetaData getShaderMetaData(const QByteArray &inShaderPathKey, QSSGShaderCache::ShaderType type); |
| 100 | |
| 101 | void setShaderCodeLibraryVersion(const QByteArray &version); |
| 102 | |
| 103 | static bool compare(const QSSGShaderDefaultMaterialKey &key1, const QSSGShaderDefaultMaterialKey &key2); |
| 104 | }; |
| 105 | |
| 106 | QT_END_NAMESPACE |
| 107 | |
| 108 | #endif |
| 109 | |