5#ifndef QSSG_RENDER_SHADER_KEY_H
6#define QSSG_RENDER_SHADER_KEY_H
19#include <QtQuick3DUtils/private/qssgdataref_p.h>
20#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
21#include <QtQuick3DRuntimeRender/private/qssgrenderdefaultmaterial_p.h>
22#include <QtQuick3DRuntimeRender/private/qssgrenderlight_p.h>
23#include <QtQuick3DRuntimeRender/private/qssgrhicontext_p.h>
34struct QSSGShaderKeyPropertyBase
38 explicit constexpr QSSGShaderKeyPropertyBase(
const char *inName =
"") : name(inName), offset(0) {}
39 quint32 getOffset()
const {
return offset; }
40 void setOffset(quint32 of) { offset = of; }
42 template<quint32 TBitWidth>
43 quint32 getMaskTemplate()
const
45 quint32 bit = offset % 32;
46 quint32 startValue = (1 << TBitWidth) - 1;
47 quint32 mask = startValue << bit;
51 quint32 getIdx()
const {
return offset / 32; }
54 void internalToString(QByteArray &ioStr,
const QByteArrayView &inBuffer)
const
58 ioStr.append(inBuffer);
61 static void internalToString(QByteArray &ioStr,
const QByteArrayView &name,
bool inValue)
66 ioStr.append(inValue ? QByteArrayView(
"true") : QByteArrayView(
"false"));
69 static bool getBoolValue(
const QByteArray& str,
const QByteArrayView &name)
71 const int index = str.indexOf(name);
74 const qsizetype nameLen = name.size();
75 if (str[index + nameLen] !=
'=')
77 if (str.mid(index + nameLen + 1, 4) == QByteArrayView(
"true"))
92 void setValue(QSSGDataRef<quint32> inDataStore,
bool inValue)
const
94 const qint32 idx = qint32(getIdx());
95 Q_ASSERT(idx >= 0 && idx <= INT32_MAX);
96 Q_ASSERT(inDataStore.size() > idx);
97 quint32 mask = getMask();
98 quint32 &target = inDataStore[idx];
100 target = target | mask;
103 target = target & mask;
107 bool getValue(QSSGDataView<quint32> inDataStore)
const
109 quint32 idx = getIdx();
110 quint32 mask = getMask();
111 const quint32 &target = inDataStore[idx];
112 return (target & mask) ?
true :
false;
115 void toString(QByteArray &ioStr, QSSGDataView<quint32> inKeySet)
const
117 bool isHigh = getValue(inKeySet);
118 internalToString(ioStr, name, isHigh);
120 void fromString(
const QByteArray &ioStr, QSSGDataRef<quint32> inKeySet)
122 setValue(inKeySet, getBoolValue(ioStr, name));
126template<quint32 TBitWidth>
134 void setValue(QSSGDataRef<quint32> inDataStore, quint32 inValue)
const
136 quint32 startValue = (1 << TBitWidth) - 1;
138 inValue = inValue & startValue;
139 quint32 bit = offset % 32;
140 quint32 mask = getMask();
141 quint32 idx = getIdx();
142 inValue = inValue << bit;
143 quint32 &target = inDataStore[idx];
145 quint32 inverseMask = ~mask;
146 target = target & inverseMask;
147 target = target | inValue;
152 quint32 idx = getIdx();
153 quint32 bit = offset % 32;
154 quint32 mask = getMask();
155 const quint32 &target = inDataStore[idx];
157 quint32 retval = target & mask;
158 retval = retval >> bit;
162 void toString(QByteArray &ioStr, QSSGDataView<quint32> inKeySet)
const
164 quint32 value = getValue(inKeySet);
166 memset(buf, 0,
sizeof (buf));
167 toStr(value, toDataRef(buf, 64));
168 internalToString(ioStr, buf);
171 void fromString(
const QByteArray &ioStr, QSSGDataRef<quint32> inKeySet)
173 const qsizetype nameLen = name.size();
174 const qsizetype strOffset = ioStr.indexOf(name);
175 if (strOffset >= 0) {
177 if (ioStr[strOffset + nameLen] !=
'=')
179 const QByteArray s = ioStr.right(ioStr.size() - strOffset - nameLen - 1);
181 while (QChar(QLatin1Char(s[i])).isDigit())
183 const quint32 value = s.left(i).toInt();
184 setValue(inKeySet, value);
189 static quint32 toStr(quint32 item, QSSGDataRef<
char> buffer)
192 return static_cast<quint32>(::snprintf(buffer.begin(), buffer.size(),
"%u", item));
213 setValue(inKeySet, quint32(channel));
221 void toString(QByteArray &ioStr, QSSGDataView<quint32> inKeySet)
const
225 ioStr.append(textureChannelToChar[getTextureChannel(inKeySet)]);
227 void fromString(
const QByteArray &ioStr, QSSGDataRef<quint32> inKeySet)
229 const qsizetype nameLen = name.size();
230 const qsizetype strOffset = ioStr.indexOf(name);
231 if (strOffset >= 0) {
233 if (ioStr[strOffset + nameLen] !=
'=')
235 const char ch = ioStr[strOffset + nameLen + 1];
263 return (getValue(inKeySet) & imageBit) ?
true :
false;
268 quint32 theValue = getValue(inKeySet);
269 quint32 mask = imageBit;
271 theValue = theValue | mask;
274 theValue = theValue & mask;
276 setValue(inKeySet, theValue);
279 bool isEnabled(QSSGDataView<quint32> inKeySet)
const {
return getBitValue(Enabled, inKeySet); }
280 void setEnabled(QSSGDataRef<quint32> inKeySet,
bool val) { setBitValue(Enabled, val, inKeySet); }
282 bool isEnvMap(QSSGDataView<quint32> inKeySet)
const {
return getBitValue(EnvMap, inKeySet); }
283 void setEnvMap(QSSGDataRef<quint32> inKeySet,
bool val) { setBitValue(EnvMap, val, inKeySet); }
285 bool isLightProbe(QSSGDataView<quint32> inKeySet)
const {
return getBitValue(LightProbe, inKeySet); }
286 void setLightProbe(QSSGDataRef<quint32> inKeySet,
bool val) { setBitValue(LightProbe, val, inKeySet); }
288 bool isIdentityTransform(QSSGDataView<quint32> inKeySet)
const {
return getBitValue(Identity, inKeySet); }
291 bool isUsingUV1(QSSGDataView<quint32> inKeySet)
const {
return getBitValue(UsesUV1, inKeySet); }
292 void setUsesUV1(QSSGDataRef<quint32> inKeySet,
bool val) { setBitValue(UsesUV1, val, inKeySet); }
294 bool isLinear(QSSGDataView<quint32> inKeySet)
const {
return getBitValue(Linear, inKeySet); }
295 void setLinear(QSSGDataRef<quint32> inKeySet,
bool val) { setBitValue(Linear, val, inKeySet); }
297 void toString(QByteArray &ioStr, QSSGDataView<quint32> inKeySet)
const
300 ioStr.append(QByteArrayView(
"={"));
301 internalToString(ioStr, QByteArrayView(
"enabled"), isEnabled(inKeySet));
303 internalToString(ioStr, QByteArrayView(
"envMap"), isEnvMap(inKeySet));
305 internalToString(ioStr, QByteArrayView(
"lightProbe"), isLightProbe(inKeySet));
307 internalToString(ioStr, QByteArrayView(
"identity"), isIdentityTransform(inKeySet));
309 internalToString(ioStr, QByteArrayView(
"usesUV1"), isUsingUV1(inKeySet));
311 internalToString(ioStr, QByteArrayView(
"linear"), isLinear(inKeySet));
320 void setSpecularModel(QSSGDataRef<quint32> inKeySet, QSSGRenderDefaultMaterial::MaterialSpecularModel inModel)
322 setValue(inKeySet, quint32(inModel));
327 return static_cast<QSSGRenderDefaultMaterial::MaterialSpecularModel>(getValue(inKeySet));
330 void toString(QByteArray &ioStr, QSSGDataView<quint32> inKeySet)
const
334 switch (getSpecularModel(inKeySet)) {
335 case QSSGRenderDefaultMaterial::MaterialSpecularModel::SchlickGGX:
336 ioStr.append(QByteArrayView(
"SchlickGGX"));
338 case QSSGRenderDefaultMaterial::MaterialSpecularModel::BlinnPhong:
339 ioStr.append(QByteArrayView(
"BlinnPhong"));
343 void fromString(
const QByteArray &ioStr, QSSGDataRef<quint32> inKeySet)
345 const qsizetype nameLen = name.size();
346 const int strOffset = ioStr.indexOf(name);
347 if (strOffset >= 0) {
349 if (ioStr[strOffset + nameLen] !=
'=')
351 const int codeOffsetBegin = strOffset + nameLen + 1;
353 while (ioStr[codeOffsetBegin + codeOffset] !=
';')
355 const QByteArray val = ioStr.mid(codeOffsetBegin, codeOffset);
356 if (val == QByteArrayView(
"SchlickGGX"))
357 setSpecularModel(inKeySet, QSSGRenderDefaultMaterial::MaterialSpecularModel::SchlickGGX);
358 if (val == QByteArrayView(
"BlinnPhong"))
359 setSpecularModel(inKeySet, QSSGRenderDefaultMaterial::MaterialSpecularModel::BlinnPhong);
368 void setDiffuseModel(QSSGDataRef<quint32> inKeySet, QSSGRenderDefaultMaterial::MaterialDiffuseModel inModel)
370 setValue(inKeySet, quint32(inModel));
375 return static_cast<QSSGRenderDefaultMaterial::MaterialDiffuseModel>(getValue(inKeySet));
378 void toString(QByteArray &ioStr, QSSGDataView<quint32> inKeySet)
const
382 switch (getDiffuseModel(inKeySet)) {
383 case QSSGRenderDefaultMaterial::MaterialDiffuseModel::Burley:
384 ioStr.append(QByteArrayView(
"Burley"));
386 case QSSGRenderDefaultMaterial::MaterialDiffuseModel::Lambert:
387 ioStr.append(QByteArrayView(
"Lambert"));
389 case QSSGRenderDefaultMaterial::MaterialDiffuseModel::LambertWrap:
390 ioStr.append(QByteArrayView(
"LambertWrap"));
394 void fromString(
const QByteArray &ioStr, QSSGDataRef<quint32> inKeySet)
396 const qsizetype nameLen = name.size();
397 const int strOffset = ioStr.indexOf(name);
398 if (strOffset >= 0) {
400 if (ioStr[strOffset + nameLen] !=
'=')
402 const int codeOffsetBegin = strOffset + nameLen + 1;
404 while (ioStr[codeOffsetBegin + codeOffset] !=
';')
406 const QByteArray val = ioStr.mid(codeOffsetBegin, codeOffset);
407 if (val == QByteArrayView(
"Burley"))
408 setDiffuseModel(inKeySet, QSSGRenderDefaultMaterial::MaterialDiffuseModel::Burley);
409 if (val == QByteArrayView(
"Lambert"))
410 setDiffuseModel(inKeySet, QSSGRenderDefaultMaterial::MaterialDiffuseModel::Lambert);
411 if (val == QByteArrayView(
"LambertWrap"))
412 setDiffuseModel(inKeySet, QSSGRenderDefaultMaterial::MaterialDiffuseModel::LambertWrap);
428 void setShadowSoftness(QSSGDataRef<quint32> inKeySet, QSSGRenderLight::SoftShadowQuality inQuality)
432 case QSSGRenderLight::SoftShadowQuality::Hard:
435 case QSSGRenderLight::SoftShadowQuality::PCF4:
438 case QSSGRenderLight::SoftShadowQuality::PCF8:
441 case QSSGRenderLight::SoftShadowQuality::PCF16:
446 setValue(inKeySet, val);
451 quint32 val = getValue(inKeySet);
454 return QSSGRenderLight::SoftShadowQuality::Hard;
456 return QSSGRenderLight::SoftShadowQuality::PCF4;
458 return QSSGRenderLight::SoftShadowQuality::PCF8;
461 return QSSGRenderLight::SoftShadowQuality::PCF16;
465 void toString(QByteArray &ioStr, QSSGDataView<quint32> inKeySet)
const
469 switch (getShadowSoftness(inKeySet)) {
470 case QSSGRenderLight::SoftShadowQuality::Hard:
471 ioStr.append(QByteArrayView(
"Hard"));
473 case QSSGRenderLight::SoftShadowQuality::PCF4:
474 ioStr.append(QByteArrayView(
"PCF4"));
476 case QSSGRenderLight::SoftShadowQuality::PCF8:
477 ioStr.append(QByteArrayView(
"PCF8"));
479 case QSSGRenderLight::SoftShadowQuality::PCF16:
480 case QSSGRenderLight::SoftShadowQuality::PCF32:
481 case QSSGRenderLight::SoftShadowQuality::PCF64:
482 ioStr.append(QByteArrayView(
"PCF16"));
487 void fromString(
const QByteArray &ioStr, QSSGDataRef<quint32> inKeySet)
489 const qsizetype nameLen = name.size();
490 const int strOffset = ioStr.indexOf(name);
491 if (strOffset >= 0) {
493 if (ioStr[strOffset + nameLen] !=
'=')
495 const int codeOffsetBegin = strOffset + nameLen + 1;
497 while (ioStr[codeOffsetBegin + codeOffset] !=
';')
499 const QByteArray val = ioStr.mid(codeOffsetBegin, codeOffset);
500 if (val == QByteArrayView(
"Hard"))
501 setShadowSoftness(inKeySet, QSSGRenderLight::SoftShadowQuality::Hard);
502 if (val == QByteArrayView(
"PCF4"))
503 setShadowSoftness(inKeySet, QSSGRenderLight::SoftShadowQuality::PCF4);
504 if (val == QByteArrayView(
"PCF8"))
505 setShadowSoftness(inKeySet, QSSGRenderLight::SoftShadowQuality::PCF8);
506 if (val == QByteArrayView(
"PCF16"))
507 setShadowSoftness(inKeySet, QSSGRenderLight::SoftShadowQuality::PCF16);
517 void setAlphaMode(QSSGDataRef<quint32> inKeySet, QSSGRenderDefaultMaterial::MaterialAlphaMode inMode)
519 setValue(inKeySet, quint32(inMode));
524 return static_cast<QSSGRenderDefaultMaterial::MaterialAlphaMode>(getValue(inKeySet));
527 void toString(QByteArray &ioStr, QSSGDataView<quint32> inKeySet)
const
531 switch (getAlphaMode(inKeySet)) {
532 case QSSGRenderDefaultMaterial::MaterialAlphaMode::Default:
533 ioStr.append(QByteArrayView(
"Default"));
535 case QSSGRenderDefaultMaterial::MaterialAlphaMode::Mask:
536 ioStr.append(QByteArrayView(
"Mask"));
538 case QSSGRenderDefaultMaterial::MaterialAlphaMode::Blend:
539 ioStr.append(QByteArrayView(
"Blend"));
541 case QSSGRenderDefaultMaterial::MaterialAlphaMode::Opaque:
542 ioStr.append(QByteArrayView(
"Opaque"));
546 void fromString(
const QByteArray &ioStr, QSSGDataRef<quint32> inKeySet)
548 const qsizetype nameLen = name.size();
549 const qsizetype strOffset = ioStr.indexOf(name);
550 if (strOffset >= 0) {
552 if (ioStr[strOffset + nameLen] !=
'=')
554 const int codeOffsetBegin = strOffset + nameLen + 1;
556 while (ioStr[codeOffsetBegin + codeOffset] !=
';')
558 const QByteArray val = ioStr.mid(codeOffsetBegin, codeOffset);
559 if (val == QByteArrayView(
"Default"))
560 setAlphaMode(inKeySet, QSSGRenderDefaultMaterial::MaterialAlphaMode::Default);
561 if (val == QByteArrayView(
"Mask"))
562 setAlphaMode(inKeySet, QSSGRenderDefaultMaterial::MaterialAlphaMode::Mask);
563 if (val == QByteArrayView(
"Blend"))
564 setAlphaMode(inKeySet, QSSGRenderDefaultMaterial::MaterialAlphaMode::Blend);
565 if (val == QByteArrayView(
"Opaque"))
566 setAlphaMode(inKeySet, QSSGRenderDefaultMaterial::MaterialAlphaMode::Opaque);
589 return (getValue(inKeySet) & bit) ?
true :
false;
593 quint32 v = getValue(inKeySet);
594 v = value ? (v | bit) : (v & ~bit);
595 setValue(inKeySet, v);
598 void toString(QByteArray &ioStr, QSSGDataView<quint32> inKeySet)
const
601 ioStr.append(QByteArrayView(
"={"));
602 internalToString(ioStr, QByteArrayView(
"position"), getBitValue(Position, inKeySet));
604 internalToString(ioStr, QByteArrayView(
"normal"), getBitValue(Normal, inKeySet));
606 internalToString(ioStr, QByteArrayView(
"texcoord0"), getBitValue(TexCoord0, inKeySet));
608 internalToString(ioStr, QByteArrayView(
"texcoord1"), getBitValue(TexCoord1, inKeySet));
610 internalToString(ioStr, QByteArrayView(
"tangent"), getBitValue(Tangent, inKeySet));
612 internalToString(ioStr, QByteArrayView(
"binormal"), getBitValue(Binormal, inKeySet));
614 internalToString(ioStr, QByteArrayView(
"color"), getBitValue(Color, inKeySet));
616 internalToString(ioStr, QByteArrayView(
"texcoordlightmap"), getBitValue(TexCoordLightmap, inKeySet));
618 internalToString(ioStr, QByteArrayView(
"joint&weight"), getBitValue(JointAndWeight, inKeySet));
621 void fromString(
const QByteArray &ioStr, QSSGDataRef<quint32> inKeySet)
623 const qsizetype nameLen = name.size();
624 const qsizetype strOffset = ioStr.indexOf(name);
625 if (strOffset >= 0) {
627 if (ioStr[strOffset + nameLen] !=
'=')
629 if (ioStr[strOffset + nameLen + 1] !=
'{')
631 const int codeOffsetBegin = strOffset + nameLen + 2;
633 while (ioStr[codeOffsetBegin + codeOffset] !=
'}')
635 const QByteArray val = ioStr.mid(codeOffsetBegin, codeOffset);
636 const QVector<QByteArray> list = val.split(
';');
637 if (list.size() != 8)
639 setBitValue(Position, inKeySet, getBoolValue(list[0], QByteArrayView(
"position")));
640 setBitValue(Normal, inKeySet, getBoolValue(list[1], QByteArrayView(
"normal")));
641 setBitValue(TexCoord0, inKeySet, getBoolValue(list[2], QByteArrayView(
"texcoord0")));
642 setBitValue(TexCoord1, inKeySet, getBoolValue(list[3], QByteArrayView(
"texcoord1")));
643 setBitValue(Tangent, inKeySet, getBoolValue(list[4], QByteArrayView(
"tangent")));
644 setBitValue(Binormal, inKeySet, getBoolValue(list[5], QByteArrayView(
"binormal")));
645 setBitValue(Color, inKeySet, getBoolValue(list[6], QByteArrayView(
"color")));
646 setBitValue(TexCoordLightmap, inKeySet, getBoolValue(list[7], QByteArrayView(
"texcoordlightmap")));
806 m_imageMaps[0].name =
"diffuseMap";
807 m_imageMaps[1].name =
"emissiveMap";
808 m_imageMaps[2].name =
"specularMap";
809 m_imageMaps[3].name =
"baseColorMap";
810 m_imageMaps[4].name =
"bumpMap";
811 m_imageMaps[5].name =
"specularAmountMap";
812 m_imageMaps[6].name =
"normalMap";
813 m_imageMaps[7].name =
"clearcoatNormalMap";
814 m_imageMaps[8].name =
"opacityMap";
815 m_imageMaps[9].name =
"roughnessMap";
816 m_imageMaps[10].name =
"metalnessMap";
817 m_imageMaps[11].name =
"occlusionMap";
818 m_imageMaps[12].name =
"translucencyMap";
819 m_imageMaps[13].name =
"heightMap";
820 m_imageMaps[14].name =
"clearcoatMap";
821 m_imageMaps[15].name =
"clearcoatRoughnessMap";
822 m_imageMaps[16].name =
"transmissionMap";
823 m_imageMaps[17].name =
"thicknessMap";
825 m_textureChannels[0].name =
"opacityMap_channel";
826 m_textureChannels[1].name =
"roughnessMap_channel";
827 m_textureChannels[2].name =
"metalnessMap_channel";
828 m_textureChannels[3].name =
"occlusionMap_channel";
829 m_textureChannels[4].name =
"translucencyMap_channel";
830 m_textureChannels[5].name =
"heightMap_channel";
831 m_textureChannels[6].name =
"clearcoatMap_channel";
832 m_textureChannels[7].name =
"clearcoatRoughnessMap_channel";
833 m_textureChannels[8].name =
"transmissionMap_channel";
834 m_textureChannels[9].name =
"thicknessMap_channel";
835 m_textureChannels[10].name =
"baseColorMap_channel";
836 m_textureChannels[11].name =
"specularAmountMap_channel";
837 m_textureChannels[12].name =
"emissiveMap_channel";
842 template<
typename TVisitor>
845 inVisitor.visit(m_hasLighting);
846 inVisitor.visit(m_hasPunctualLights);
847 inVisitor.visit(m_hasShadows);
848 inVisitor.visit(m_hasIbl);
849 inVisitor.visit(m_specularEnabled);
850 inVisitor.visit(m_fresnelEnabled);
851 inVisitor.visit(m_fresnelScaleBiasEnabled);
852 inVisitor.visit(m_clearcoatFresnelScaleBiasEnabled);
853 inVisitor.visit(m_baseColorSingleChannelEnabled);
854 inVisitor.visit(m_specularSingleChannelEnabled);
855 inVisitor.visit(m_emissiveSingleChannelEnabled);
856 inVisitor.visit(m_invertOpacityMapValue);
857 inVisitor.visit(m_vertexColorsEnabled);
858 inVisitor.visit(m_vertexColorsMaskEnabled);
859 inVisitor.visit(m_vertexColorRedMask);
860 inVisitor.visit(m_vertexColorGreenMask);
861 inVisitor.visit(m_vertexColorBlueMask);
862 inVisitor.visit(m_vertexColorAlphaMask);
863 inVisitor.visit(m_specularModel);
864 inVisitor.visit(m_diffuseModel);
866 for (quint32 idx = 0, end = ImageMapCount; idx < end; ++idx)
867 inVisitor.visit(m_imageMaps[idx]);
869 for (
auto &textureChannel : m_textureChannels)
870 inVisitor.visit(textureChannel);
872 inVisitor.visit(m_boneCount);
873 inVisitor.visit(m_isDoubleSided);
874 inVisitor.visit(m_overridesPosition);
875 inVisitor.visit(m_usesProjectionMatrix);
876 inVisitor.visit(m_usesInverseProjectionMatrix);
877 inVisitor.visit(m_usesPointsTopology);
878 inVisitor.visit(m_usesVarColor);
879 inVisitor.visit(m_alphaMode);
880 inVisitor.visit(m_vertexAttributes);
881 inVisitor.visit(m_usesFloatJointIndices);
882 inVisitor.visit(m_usesInstancing);
883 inVisitor.visit(m_targetCount);
884 inVisitor.visit(m_targetPositionOffset);
885 inVisitor.visit(m_targetNormalOffset);
886 inVisitor.visit(m_targetTangentOffset);
887 inVisitor.visit(m_targetBinormalOffset);
888 inVisitor.visit(m_targetTexCoord0Offset);
889 inVisitor.visit(m_targetTexCoord1Offset);
890 inVisitor.visit(m_targetColorOffset);
891 inVisitor.visit(m_blendParticles);
892 inVisitor.visit(m_clearcoatEnabled);
893 inVisitor.visit(m_transmissionEnabled);
894 inVisitor.visit(m_specularAAEnabled);
895 inVisitor.visit(m_lightmapEnabled);
896 inVisitor.visit(m_specularGlossyEnabled);
897 inVisitor.visit(m_metallicRoughnessEnabled);
898 inVisitor.visit(m_debugMode);
899 inVisitor.visit(m_fogEnabled);
900 inVisitor.visit(m_viewCount);
901 inVisitor.visit(m_usesViewIndex);
902 inVisitor.visit(m_orderIndependentTransparency);
903 inVisitor.visit(m_shadowSoftness);
910 template<
typename TPropType>
917 quint32 bit = m_offset % 32;
918 if (bit + TPropType::BitWidth > 32) {
919 m_offset += 32 - bit;
922 inProp.setOffset(m_offset);
923 m_offset += TPropType::BitWidth;
933 size += prop.name.size();
945 offsetVisitor.visit(prop);
946 stringSizeVisitor.visit(prop);
953 visitProperties(visitor);
956 Q_ASSERT(visitor.offsetVisitor.m_offset < 768);
959 m_stringBufferSizeHint = visitor.stringSizeVisitor.size;
973 for (size_t idx = 0; idx < DataBufferSize; ++idx)
974 m_dataBuffer[idx] = 0;
979 for (size_t idx = 0; idx < DataBufferSize; ++idx)
980 m_dataBuffer[idx] = 0;
986 for (size_t idx = 0; idx < DataBufferSize; ++idx)
987 retval = retval ^ qHash(m_dataBuffer[idx]);
988 return retval ^ m_featureSetHash;
994 for (size_t idx = 0; idx < DataBufferSize && retval; ++idx)
995 retval = m_dataBuffer[idx] == other.m_dataBuffer[idx];
996 return retval && m_featureSetHash == other.m_featureSetHash;
1028 template<
typename TPropType>
1031 prop.fromString(m_str, m_keyStore);
1037 ioString.reserve(inProperties.m_stringBufferSizeHint);
1038 StringVisitor theVisitor(ioString, *
this);
1044 inProperties.visitProperties(theVisitor);
1049 ret.resize(
sizeof(m_dataBuffer));
1050 memcpy(ret.data(), m_dataBuffer,
sizeof(m_dataBuffer));
1055 if (data.size() !=
sizeof(m_dataBuffer))
1057 memcpy((
void *)m_dataBuffer, data.data(),
sizeof(m_dataBuffer));
1062Q_STATIC_ASSERT(std::is_trivially_destructible<QSSGShaderDefaultMaterialKey>::value);
size_t qHash(const QSSGShaderDefaultMaterialKey &key)
OffsetVisitor offsetVisitor
StringSizeVisitor stringSizeVisitor
void visit(TPropType &inProp)
constexpr void visit(const P &prop)
QSSGShaderKeyBoolean m_usesInverseProjectionMatrix
QSSGShaderKeyUnsigned< 4 > m_debugMode
QSSGShaderKeyBoolean m_usesProjectionMatrix
QSSGShaderKeyUnsigned< 8 > m_targetTexCoord1Offset
QSSGShaderKeyBoolean m_vertexColorsMaskEnabled
QSSGShaderKeyBoolean m_baseColorSingleChannelEnabled
QSSGShaderKeyBoolean m_fogEnabled
QSSGShaderKeyBoolean m_usesInstancing
void visitProperties(TVisitor &inVisitor)
QSSGShaderKeyBoolean m_blendParticles
QSSGShaderKeyBoolean m_hasLighting
QSSGShaderKeyBoolean m_hasPunctualLights
@ SingleChannelImagesFirst
QSSGShaderKeyTextureChannel m_textureChannels[SingleChannelImageCount]
QSSGShaderKeyBoolean m_clearcoatEnabled
QSSGShaderKeyUnsigned< 16 > m_vertexColorAlphaMask
@ ClearcoatRoughnessChannel
QSSGShaderKeyBoolean m_transmissionEnabled
QSSGShaderKeyBoolean m_lightmapEnabled
QSSGShaderKeyBoolean m_usesVarColor
QSSGShaderKeyBoolean m_overridesPosition
QSSGShaderKeyBoolean m_isDoubleSided
QSSGShaderKeyImageMap m_imageMaps[ImageMapCount]
QSSGShaderKeySpecularModel m_specularModel
QSSGShaderKeyBoolean m_usesFloatJointIndices
QSSGShaderKeyBoolean m_specularEnabled
QSSGShaderDefaultMaterialKeyProperties()
QSSGShaderKeyBoolean m_usesViewIndex
QSSGShaderKeyUnsigned< 8 > m_targetPositionOffset
QSSGShaderKeyUnsigned< 16 > m_boneCount
QSSGShaderKeyBoolean m_hasIbl
qsizetype m_stringBufferSizeHint
QSSGShaderKeyUnsigned< 8 > m_targetTangentOffset
QSSGShaderKeyUnsigned< 8 > m_targetTexCoord0Offset
QSSGShaderKeyUnsigned< 16 > m_vertexColorBlueMask
QSSGShaderKeyUnsigned< 8 > m_targetColorOffset
QSSGShaderKeyBoolean m_emissiveSingleChannelEnabled
QSSGShaderKeyBoolean m_vertexColorsEnabled
QSSGShaderKeyVertexAttribute m_vertexAttributes
QSSGShaderKeyUnsigned< 8 > m_targetNormalOffset
QSSGShaderKeyBoolean m_fresnelEnabled
QSSGShaderKeyUnsigned< 8 > m_targetBinormalOffset
QSSGShaderKeyShadowSoftness m_shadowSoftness
QSSGShaderKeyBoolean m_fresnelScaleBiasEnabled
QSSGShaderKeyUnsigned< 16 > m_vertexColorGreenMask
QSSGShaderKeyBoolean m_clearcoatFresnelScaleBiasEnabled
QSSGShaderKeyBoolean m_metallicRoughnessEnabled
QSSGShaderKeyUnsigned< 3 > m_viewCount
@ SingleChannelImageCount
QSSGShaderKeyAlphaMode m_alphaMode
QSSGShaderKeyBoolean m_specularSingleChannelEnabled
QSSGShaderKeyUnsigned< 3 > m_orderIndependentTransparency
QSSGShaderKeyUnsigned< 8 > m_targetCount
QSSGShaderKeyBoolean m_specularGlossyEnabled
QSSGShaderKeyDiffuseModel m_diffuseModel
QSSGShaderKeyBoolean m_hasShadows
QSSGShaderKeyBoolean m_usesPointsTopology
QSSGShaderKeyBoolean m_invertOpacityMapValue
QSSGShaderKeyUnsigned< 16 > m_vertexColorRedMask
QSSGShaderKeyBoolean m_specularAAEnabled
QSSGDataRef< quint32 > m_keyStore
void visit(TPropType &prop)
StringInVisitor(const QByteArray &s, QSSGDataRef< quint32 > ks)
void toString(QByteArray &ioString, const QSSGShaderDefaultMaterialKeyProperties &inProperties) const
quint32 m_dataBuffer[DataBufferSize]
QSSGShaderDefaultMaterialKey(size_t inFeatureSetHash)
bool operator==(const QSSGShaderDefaultMaterialKey &other) const
QSSGShaderDefaultMaterialKey()
void fromString(QByteArray &ioString, QSSGShaderDefaultMaterialKeyProperties &inProperties)
QByteArray toByteArray() const
bool fromByteArray(const QByteArray &data) const
void toString(QByteArray &ioStr, QSSGDataView< quint32 > inKeySet) const
QSSGRenderDefaultMaterial::MaterialAlphaMode getAlphaMode(QSSGDataView< quint32 > inKeySet) const
QSSGShaderKeyAlphaMode(const char *inName="")
void setAlphaMode(QSSGDataRef< quint32 > inKeySet, QSSGRenderDefaultMaterial::MaterialAlphaMode inMode)
void fromString(const QByteArray &ioStr, QSSGDataRef< quint32 > inKeySet)
void setValue(QSSGDataRef< quint32 > inDataStore, bool inValue) const
void toString(QByteArray &ioStr, QSSGDataView< quint32 > inKeySet) const
constexpr QSSGShaderKeyBoolean(const char *inName="")
bool getValue(QSSGDataView< quint32 > inDataStore) const
void fromString(const QByteArray &ioStr, QSSGDataRef< quint32 > inKeySet)
QSSGShaderKeyDiffuseModel(const char *inName="")
void setDiffuseModel(QSSGDataRef< quint32 > inKeySet, QSSGRenderDefaultMaterial::MaterialDiffuseModel inModel)
QSSGRenderDefaultMaterial::MaterialDiffuseModel getDiffuseModel(QSSGDataView< quint32 > inKeySet) const
void fromString(const QByteArray &ioStr, QSSGDataRef< quint32 > inKeySet)
void toString(QByteArray &ioStr, QSSGDataView< quint32 > inKeySet) const
void setIdentityTransform(QSSGDataRef< quint32 > inKeySet, bool val)
void setBitValue(ImageMapBits imageBit, bool inValue, QSSGDataRef< quint32 > inKeySet)
void setEnabled(QSSGDataRef< quint32 > inKeySet, bool val)
bool isUsingUV1(QSSGDataView< quint32 > inKeySet) const
QSSGShaderKeyImageMap(const char *inName="")
void toString(QByteArray &ioStr, QSSGDataView< quint32 > inKeySet) const
bool isIdentityTransform(QSSGDataView< quint32 > inKeySet) const
bool isEnabled(QSSGDataView< quint32 > inKeySet) const
bool isLightProbe(QSSGDataView< quint32 > inKeySet) const
void setLinear(QSSGDataRef< quint32 > inKeySet, bool val)
void setUsesUV1(QSSGDataRef< quint32 > inKeySet, bool val)
bool isEnvMap(QSSGDataView< quint32 > inKeySet) const
bool getBitValue(ImageMapBits imageBit, QSSGDataView< quint32 > inKeySet) const
void setLightProbe(QSSGDataRef< quint32 > inKeySet, bool val)
bool isLinear(QSSGDataView< quint32 > inKeySet) const
void setEnvMap(QSSGDataRef< quint32 > inKeySet, bool val)
QSSGShaderKeyShadowSoftness(const char *inName="")
void setShadowSoftness(QSSGDataRef< quint32 > inKeySet, QSSGRenderLight::SoftShadowQuality inQuality)
void toString(QByteArray &ioStr, QSSGDataView< quint32 > inKeySet) const
void fromString(const QByteArray &ioStr, QSSGDataRef< quint32 > inKeySet)
QSSGRenderLight::SoftShadowQuality getShadowSoftness(QSSGDataView< quint32 > inKeySet) const
QSSGRenderDefaultMaterial::MaterialSpecularModel getSpecularModel(QSSGDataView< quint32 > inKeySet) const
void setSpecularModel(QSSGDataRef< quint32 > inKeySet, QSSGRenderDefaultMaterial::MaterialSpecularModel inModel)
void fromString(const QByteArray &ioStr, QSSGDataRef< quint32 > inKeySet)
void toString(QByteArray &ioStr, QSSGDataView< quint32 > inKeySet) const
QSSGShaderKeySpecularModel(const char *inName="")
void fromString(const QByteArray &ioStr, QSSGDataRef< quint32 > inKeySet)
void setTextureChannel(TexturChannelBits channel, QSSGDataRef< quint32 > inKeySet)
static constexpr char textureChannelToChar[4]
TexturChannelBits getTextureChannel(QSSGDataView< quint32 > inKeySet) const
void toString(QByteArray &ioStr, QSSGDataView< quint32 > inKeySet) const
QSSGShaderKeyTextureChannel(const char *inName="")
void fromString(const QByteArray &ioStr, QSSGDataRef< quint32 > inKeySet)
constexpr QSSGShaderKeyUnsigned(const char *inName="")
void setValue(QSSGDataRef< quint32 > inDataStore, quint32 inValue) const
quint32 getValue(QSSGDataView< quint32 > inDataStore) const
void toString(QByteArray &ioStr, QSSGDataView< quint32 > inKeySet) const
void toString(QByteArray &ioStr, QSSGDataView< quint32 > inKeySet) const
bool getBitValue(VertexAttributeBits bit, QSSGDataView< quint32 > inKeySet) const
QSSGShaderKeyVertexAttribute(const char *inName="")
void fromString(const QByteArray &ioStr, QSSGDataRef< quint32 > inKeySet)
void setBitValue(VertexAttributeBits bit, QSSGDataRef< quint32 > inKeySet, bool value) const