MCPcopy Create free account
hub / github.com/Illation/ETEngine / LoadFromMemory

Method LoadFromMemory

Engine/source/EtRendering/MaterialSystem/MaterialData.cpp:93–142  ·  view source on GitHub ↗

--------------------------------- MaterialAsset::LoadFromMemory Load shader data from binary asset content

Source from the content-addressed store, hash-verified

91// Load shader data from binary asset content
92//
93bool MaterialAsset::LoadFromMemory(std::vector<uint8> const& data)
94{
95 MaterialDescriptor descriptor;
96 if (!(core::serialization::DeserializeFromJsonString(core::FileUtil::AsText(data), descriptor)))
97 {
98 LOG("MaterialAsset::LoadFromMemory > Failed to deserialize data from a JSON format into a material descriptor", core::LogLevel::Warning);
99 return false;
100 }
101
102 // extract the shader and texture references
103 std::vector<AssetPtr<TextureData>> textureRefs;
104 AssetPtr<ShaderData> shaderRef;
105
106 for (I_Asset::Reference const& reference : GetReferences())
107 {
108 I_AssetPtr const* const rawAssetPtr = reference.GetAsset();
109
110 if (rawAssetPtr->GetType() == rttr::type::get<ShaderData>())
111 {
112 ET_ASSERT(shaderRef == nullptr, "Materials cannot reference more than one shader!");
113 shaderRef = *static_cast<AssetPtr<ShaderData> const*>(rawAssetPtr);
114 }
115 else if (rawAssetPtr->GetType() == rttr::type::get<TextureData>())
116 {
117 textureRefs.push_back(*static_cast<AssetPtr<TextureData> const*>(rawAssetPtr));
118 }
119 else
120 {
121 ET_ASSERT(false, "unhandled reference type!");
122 }
123 }
124
125 if (shaderRef == nullptr)
126 {
127 LOG("MaterialAsset::LoadFromMemory > Materials must reference a shader!", core::LogLevel::Warning);
128 return false;
129 }
130
131 // convert to a parameter block
132 // ideally this should be done before any uniforms are set in the shader
133 T_ParameterBlock const params = shaderRef->CopyParameterBlock(shaderRef->GetCurrentUniforms());
134 if (params != nullptr)
135 {
136 parameters::ConvertDescriptor(params, descriptor, shaderRef.get(), textureRefs);
137 }
138
139 // Create the material
140 m_Data = new Material(shaderRef, m_DrawType, params, textureRefs);
141 return true;
142}
143
144
145} // namespace render

Callers

nothing calls this directly

Calls 5

ConvertDescriptorFunction · 0.85
CopyParameterBlockMethod · 0.80
GetCurrentUniformsMethod · 0.80
GetAssetMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected