MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / load

Method load

Source/Engine/Content/Assets/Material.cpp:153–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151#endif
152
153Asset::LoadResult Material::load()
154{
155 ASSERT(_materialShader == nullptr);
156 FlaxChunk* materialParamsChunk;
157
158 // Wait for the GPU Device to be ready (eg. case when loading material before GPU init)
159 if (WaitForInitGraphics())
160 return LoadResult::CannotLoadData;
161
162 // If engine was compiled with shaders compiling service:
163 // - Material should be changed in need to convert it to the newer version (via Visject Surface)
164 // Shader should be recompiled if shader source code has been modified
165 // otherwise:
166 // - If material version is not supported then material cannot be loaded
167#if COMPILE_WITH_SHADER_COMPILER
168
169 // Check if current engine has different materials version or convert it by force or has no source generated at all
170 if (_shaderHeader.Material.GraphVersion != MATERIAL_GRAPH_VERSION
171#if MATERIAL_AUTO_GENERATE_MISSING_SOURCE
172 || !HasChunk(SHADER_FILE_CHUNK_SOURCE)
173#endif
174 || HasDependenciesModified()
175#if COMPILE_WITH_DEV_ENV
176 // Set to true to enable force GPU shader regeneration (don't commit it)
177 || false
178#endif
179 )
180 {
181 // Guard file with the lock during shader generation (prevents FlaxStorage::Tick from messing with the file)
182 auto lock = Storage->Lock();
183
184 // Prepare
185 const String name = ToString();
186 MaterialGenerator generator;
187 generator.Error.Bind(&OnGeneratorError);
188 if (_shaderHeader.Material.GraphVersion != MATERIAL_GRAPH_VERSION)
189 {
190 LOG(Info, "Converting material \'{0}\', from version {1} to {2}...", name, _shaderHeader.Material.GraphVersion, MATERIAL_GRAPH_VERSION);
191 }
192 else
193 {
194 LOG(Info, "Updating material \'{0}\'...", name);
195 }
196
197 // Load or create material surface
198 MaterialLayer* layer;
199 if (HasChunk(SHADER_FILE_CHUNK_VISJECT_SURFACE))
200 {
201 // Load graph
202 if (LoadChunks(GET_CHUNK_FLAG(SHADER_FILE_CHUNK_VISJECT_SURFACE)))
203 {
204 LOG(Warning, "Cannot load \'{0}\' data from chunk {1}.", name, SHADER_FILE_CHUNK_VISJECT_SURFACE);
205 return LoadResult::Failed;
206 }
207
208 // Get stream with graph data
209 auto surfaceChunk = GetChunk(SHADER_FILE_CHUNK_VISJECT_SURFACE);
210 MemoryReadStream stream(surfaceChunk->Get(), surfaceChunk->Size());

Callers

nothing calls this directly

Calls 15

HasChunkFunction · 0.85
GetChunkFunction · 0.85
GetIDFunction · 0.85
MemoryClearFunction · 0.85
GetPathFunction · 0.85
LockMethod · 0.80
AddOneMethod · 0.80
AddLayerMethod · 0.80
SaveToFileMethod · 0.80
UnlockMethod · 0.80
ToStringFunction · 0.50
LoadFunction · 0.50

Tested by

no test coverage detected