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 QSSGSHADERMAPKEY_P_H
6#define QSSGSHADERMAPKEY_P_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/qssgrendershaderkeys_p.h>
21#include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h>
22
23struct QSSGShaderMapKey
24{
25 QByteArray m_name;
26 const QSSGShaderFeatures m_featuresOrig;
27 const QSSGShaderDefaultMaterialKey *m_materialKeyOrig;
28 QSSGShaderDefaultMaterialKey m_materialKeyCopy;
29 size_t m_hashCode;
30
31 void detach()
32 {
33 if (m_materialKeyOrig) {
34 m_materialKeyCopy = *m_materialKeyOrig;
35 m_materialKeyOrig = nullptr;
36 }
37 }
38
39 QSSGShaderMapKey(const QByteArray &inName,
40 const QSSGShaderFeatures &inFeatures,
41 const QSSGShaderDefaultMaterialKey &inMaterialKey)
42 : m_name(inName), m_featuresOrig(inFeatures), m_materialKeyOrig(&inMaterialKey)
43 {
44 m_hashCode = qHash(key: m_name) ^ qHash(features: m_featuresOrig) ^ qHash(key: m_materialKeyOrig->hash());
45 }
46};
47
48inline bool operator==(const QSSGShaderMapKey &a, const QSSGShaderMapKey &b) Q_DECL_NOTHROW
49{
50 if (a.m_name != b.m_name)
51 return false;
52
53 const QSSGShaderDefaultMaterialKey *keyA = a.m_materialKeyOrig ? a.m_materialKeyOrig : &a.m_materialKeyCopy;
54 const QSSGShaderDefaultMaterialKey *keyB = b.m_materialKeyOrig ? b.m_materialKeyOrig : &b.m_materialKeyCopy;
55 if (!(*keyA == *keyB))
56 return false;
57
58 return (a.m_featuresOrig == b.m_featuresOrig);
59}
60
61inline size_t qHash(const QSSGShaderMapKey &key, size_t seed)
62{
63 return key.m_hashCode ^ seed;
64}
65
66#endif
67

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