/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include namespace AZ { namespace RPI { const char* ToString(MaterialPropertyOutputType materialPropertyOutputType) { switch (materialPropertyOutputType) { case MaterialPropertyOutputType::ShaderInput: return "ShaderInput"; case MaterialPropertyOutputType::ShaderOption: return "ShaderOption"; default: AZ_Assert(false, "Unhandled type"); return ""; } } const char* ToString(MaterialPropertyDataType materialPropertyDataType) { switch (materialPropertyDataType) { case MaterialPropertyDataType::Bool: return "Bool"; case MaterialPropertyDataType::Int: return "Int"; case MaterialPropertyDataType::UInt: return "UInt"; case MaterialPropertyDataType::Float: return "Float"; case MaterialPropertyDataType::Vector2: return "Vector2"; case MaterialPropertyDataType::Vector3: return "Vector3"; case MaterialPropertyDataType::Vector4: return "Vector4"; case MaterialPropertyDataType::Color: return "Color"; case MaterialPropertyDataType::Image: return "Image"; case MaterialPropertyDataType::Enum: return "Enum"; case MaterialPropertyDataType::Invalid: return "Invalid"; default: AZ_Assert(false, "Unhandled type"); return ""; } } AZStd::string GetMaterialPropertyDataTypeString(AZ::TypeId typeId) { if (typeId == azrtti_typeid()) { return ToString(MaterialPropertyDataType::Bool); } else if (typeId == azrtti_typeid()) { return ToString(MaterialPropertyDataType::Int); } else if (typeId == azrtti_typeid()) { return ToString(MaterialPropertyDataType::UInt); } else if (typeId == azrtti_typeid()) { return ToString(MaterialPropertyDataType::Float); } else if (typeId == azrtti_typeid()) { return ToString(MaterialPropertyDataType::Vector2); } else if (typeId == azrtti_typeid()) { return ToString(MaterialPropertyDataType::Vector3); } else if (typeId == azrtti_typeid()) { return ToString(MaterialPropertyDataType::Vector4); } else if (typeId == azrtti_typeid()) { return ToString(MaterialPropertyDataType::Color); } else if (typeId == azrtti_typeid()) { return ToString(MaterialPropertyDataType::Color); } else if (typeId == azrtti_typeid>()) { return ToString(MaterialPropertyDataType::Image); } else { return AZStd::string::format("", typeId.ToString().c_str()); } } void MaterialPropertyOutputId::Reflect(ReflectContext* context) { if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() ->Version(1) ->Field("m_type", &MaterialPropertyOutputId::m_type) ->Field("m_containerIndex", &MaterialPropertyOutputId::m_containerIndex) ->Field("m_itemIndex", &MaterialPropertyOutputId::m_itemIndex) ; } } void MaterialPropertyDescriptor::Reflect(ReflectContext* context) { if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Enum() ->Value(ToString(MaterialPropertyOutputType::ShaderInput), MaterialPropertyOutputType::ShaderInput) ->Value(ToString(MaterialPropertyOutputType::ShaderOption), MaterialPropertyOutputType::ShaderOption) ; serializeContext->Enum() ->Value(ToString(MaterialPropertyDataType::Invalid), MaterialPropertyDataType::Invalid) ->Value(ToString(MaterialPropertyDataType::Bool), MaterialPropertyDataType::Bool) ->Value(ToString(MaterialPropertyDataType::Int), MaterialPropertyDataType::Int) ->Value(ToString(MaterialPropertyDataType::UInt), MaterialPropertyDataType::UInt) ->Value(ToString(MaterialPropertyDataType::Float), MaterialPropertyDataType::Float) ->Value(ToString(MaterialPropertyDataType::Vector2), MaterialPropertyDataType::Vector2) ->Value(ToString(MaterialPropertyDataType::Vector3), MaterialPropertyDataType::Vector3) ->Value(ToString(MaterialPropertyDataType::Vector4), MaterialPropertyDataType::Vector4) ->Value(ToString(MaterialPropertyDataType::Color), MaterialPropertyDataType::Color) ->Value(ToString(MaterialPropertyDataType::Image), MaterialPropertyDataType::Image) ->Value(ToString(MaterialPropertyDataType::Enum), MaterialPropertyDataType::Enum) ; serializeContext->Class() ->Version(2) ->Field("Name", &MaterialPropertyDescriptor::m_nameId) ->Field("DataType", &MaterialPropertyDescriptor::m_dataType) ->Field("OutputConnections", &MaterialPropertyDescriptor::m_outputConnections) ->Field("EnumNames", &MaterialPropertyDescriptor::m_enumNames) ; } MaterialPropertyIndex::Reflect(context); } MaterialPropertyDataType MaterialPropertyDescriptor::GetDataType() const { return m_dataType; } const Name& MaterialPropertyDescriptor::GetName() const { return m_nameId; } const MaterialPropertyDescriptor::OutputList& MaterialPropertyDescriptor::GetOutputConnections() const { return m_outputConnections; } AZ::TypeId MaterialPropertyDescriptor::GetStorageDataTypeId() const { switch (m_dataType) { case MaterialPropertyDataType::Bool: return azrtti_typeid(); case MaterialPropertyDataType::Int: return azrtti_typeid(); case MaterialPropertyDataType::UInt: return azrtti_typeid(); case MaterialPropertyDataType::Float: return azrtti_typeid(); case MaterialPropertyDataType::Vector2: return azrtti_typeid(); case MaterialPropertyDataType::Vector3: return azrtti_typeid(); case MaterialPropertyDataType::Vector4: return azrtti_typeid(); case MaterialPropertyDataType::Color: return azrtti_typeid(); case MaterialPropertyDataType::Enum: case MaterialPropertyDataType::Image: return azrtti_typeid(); default: AZ_Error("MaterialPropertyValueSourceData", false, "Unhandle material property type %s.", ToString(m_dataType)); return Uuid::CreateNull(); } } uint32_t MaterialPropertyDescriptor::GetEnumValue(const AZ::Name& enumName) const { const uint32_t total = aznumeric_cast(m_enumNames.size()); for (uint32_t i = 0; i < total; ++i) { if (m_enumNames[i] == enumName) { return i; } } return InvalidEnumValue; } } // namespace RPI } // namespace AZ