diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp index 1addca29..0e5ad492 100644 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp +++ b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp @@ -405,16 +405,15 @@ namespace IW4 } else if (blendFunc == GDT_BLEND_FUNC_CUSTOM) { - const auto customBlendOpRgb = ReadEnumProperty("customBlendOpRgb", GdtBlendOpNames, std::extent_v); - const auto srcCustomBlendFunc = ReadEnumProperty("srcCustomBlendFunc", GdtCustomBlendFuncNames, std::extent_v); - const auto destCustomBlendFunc = ReadEnumProperty("destCustomBlendFunc", GdtCustomBlendFuncNames, std::extent_v); - const auto customBlendOpAlpha = ReadEnumProperty("customBlendOpAlpha", GdtBlendOpNames, std::extent_v); - const auto srcCustomBlendFuncAlpha = ReadEnumProperty("srcCustomBlendFuncAlpha", GdtCustomBlendFuncNames, std::extent_v); - const auto destCustomBlendFuncAlpha = ReadEnumProperty("destCustomBlendFuncAlpha", GdtCustomBlendFuncNames, std::extent_v); + const auto customBlendOpRgb = ReadEnumProperty("customBlendOpRgb", GdtBlendOpNames, std::extent_v); + const auto srcCustomBlendFunc = ReadEnumProperty("srcCustomBlendFunc", GdtCustomBlendFuncNames, std::extent_v); + const auto destCustomBlendFunc = ReadEnumProperty("destCustomBlendFunc", GdtCustomBlendFuncNames, std::extent_v); + const auto customBlendOpAlpha = ReadEnumProperty("customBlendOpAlpha", GdtBlendOpNames, std::extent_v); + const auto srcCustomBlendFuncAlpha = ReadEnumProperty("srcCustomBlendFuncAlpha", GdtCustomBlendFuncNames, std::extent_v); + const auto destCustomBlendFuncAlpha = ReadEnumProperty("destCustomBlendFuncAlpha", GdtCustomBlendFuncNames, std::extent_v); - SetBlendFunc(static_cast(customBlendOpRgb), static_cast(srcCustomBlendFunc), static_cast(destCustomBlendFunc)); - SetSeparateAlphaBlendFunc(static_cast(customBlendOpAlpha), static_cast(srcCustomBlendFuncAlpha), - static_cast(destCustomBlendFuncAlpha)); + SetBlendFunc(customBlendOpRgb, srcCustomBlendFunc, destCustomBlendFunc); + SetSeparateAlphaBlendFunc(customBlendOpAlpha, srcCustomBlendFuncAlpha, destCustomBlendFuncAlpha); } else { @@ -426,17 +425,19 @@ namespace IW4 void colorwrite_template() { - const auto colorWriteRed = ReadEnumProperty("colorWriteRed", GdtStateBitsEnabledStatusNames, std::extent_v); - const auto colorWriteGreen = ReadEnumProperty("colorWriteGreen", GdtStateBitsEnabledStatusNames, std::extent_v); - const auto colorWriteBlue = ReadEnumProperty("colorWriteBlue", GdtStateBitsEnabledStatusNames, std::extent_v); - const auto colorWriteAlpha = ReadEnumProperty("colorWriteAlpha", GdtStateBitsEnabledStatusNames, std::extent_v); + const auto colorWriteRed = ReadEnumProperty("colorWriteRed", GdtStateBitsEnabledStatusNames, std::extent_v); + const auto colorWriteGreen = ReadEnumProperty("colorWriteGreen", GdtStateBitsEnabledStatusNames, std::extent_v); + const auto colorWriteBlue = ReadEnumProperty("colorWriteBlue", GdtStateBitsEnabledStatusNames, std::extent_v); + const auto colorWriteAlpha = ReadEnumProperty("colorWriteAlpha", GdtStateBitsEnabledStatusNames, std::extent_v); - SetColorWrite(static_cast(colorWriteRed), static_cast(colorWriteGreen), static_cast(colorWriteBlue), - static_cast(colorWriteAlpha)); + SetColorWrite(colorWriteRed, colorWriteGreen, colorWriteBlue, colorWriteAlpha); } void cullface_template() { + const auto cullFace = ReadEnumProperty("cullFace", GdtCullFaceNames, std::extent_v); + + SetCullFace(cullFace); } void depthtest_template() @@ -596,6 +597,32 @@ namespace IW4 m_base_statebits.loadBits[0] |= GFXS0_COLORWRITE_ALPHA; } + void SetCullFace(const CullFace_e cullFace) + { + if (cullFace == CullFace_e::UNKNOWN) + { + std::ostringstream ss; + ss << "Unknown cullFace values: \"\""; + throw GdtReadingException(ss.str()); + } + + m_base_statebits.loadBits[0] &= ~GFXS0_CULL_MASK; + + if (cullFace == CullFace_e::FRONT) + { + m_base_statebits.loadBits[0] |= GFXS0_CULL_FRONT; + } + else if (cullFace == CullFace_e::BACK) + { + m_base_statebits.loadBits[0] |= GFXS0_CULL_BACK; + } + else + { + assert(cullFace == CullFace_e::NONE); + m_base_statebits.loadBits[0] |= GFXS0_CULL_NONE; + } + } + void FinalizeMaterial() const { if (!m_textures.empty()) @@ -624,9 +651,10 @@ namespace IW4 throw GdtReadingException(ss.str()); } - size_t ReadEnumProperty(const std::string& propertyName, const char** validValuesArray, const size_t validValuesArraySize) const + template + T ReadEnumProperty(const std::string& propertyName, const char** validValuesArray, const size_t validValuesArraySize) const { - return GetIndexForString(propertyName, ReadStringProperty(propertyName), validValuesArray, validValuesArraySize); + return static_cast(GetIndexForString(propertyName, ReadStringProperty(propertyName), validValuesArray, validValuesArraySize)); } MemoryManager* m_memory;