2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-scene3d/internal/model-components/material-impl.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/type-registry-helper.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/rendering/sampler.h>
26 #include "material-modify-observer.h"
29 #include <dali-scene3d/internal/graphics/builtin-shader-extern-gen.h>
30 #include <dali-scene3d/public-api/loader/node-definition.h>
31 #include <dali-scene3d/public-api/loader/renderer-state.h>
32 #include <dali-scene3d/public-api/loader/utils.h>
43 * Creates Material through type registry
47 return Scene3D::Material::New();
50 // Setup properties, signals and actions using the type-registry.
51 DALI_TYPE_REGISTRATION_BEGIN(Scene3D::Material, Dali::BaseHandle, Create);
52 DALI_TYPE_REGISTRATION_END()
54 static constexpr uint32_t OFFSET_FOR_DIFFUSE_CUBE_TEXTURE = 2u;
55 static constexpr uint32_t OFFSET_FOR_SPECULAR_CUBE_TEXTURE = 1u;
56 static constexpr uint32_t INVALID_INDEX = 0u;
57 static constexpr uint32_t ALPHA_CUTOFF_FLAG = Scene3D::Loader::MaterialDefinition::Flags::SUBSURFACE << 1;
58 static constexpr std::string_view THREE_TEX_KEYWORD = "THREE_TEX";
59 static constexpr std::string_view GLTF_CHANNELS_KEYWORD = "GLTF_CHANNELS";
73 } // unnamed namespace
75 MaterialPtr Material::New()
77 MaterialPtr material = new Material();
79 material->Initialize();
86 mModifyFlag(MaterialModifyObserver::ModifyFlag::NONE),
87 mObserverNotifying(false)
89 mAsyncImageLoader = Dali::Toolkit::AsyncImageLoader::New();
90 mAsyncImageLoader.ImageLoadedSignal().Connect(this, &Material::TextureLoadComplete);
91 mTextureInformations.assign(TEXTURE_TYPE_NUMBER, TextureInformation());
92 mTextureInformations[BASE_COLOR].mSemantic = Scene3D::Loader::MaterialDefinition::ALBEDO;
93 // TODO : How we support dli manner
94 mTextureInformations[METALLIC_ROUGHNESS].mSemantic = Scene3D::Loader::MaterialDefinition::METALLIC | Scene3D::Loader::MaterialDefinition::ROUGHNESS |
95 Scene3D::Loader::MaterialDefinition::GLTF_CHANNELS;
96 mTextureInformations[NORMAL].mSemantic = Scene3D::Loader::MaterialDefinition::NORMAL;
97 mTextureInformations[OCCLUSION].mSemantic = Scene3D::Loader::MaterialDefinition::OCCLUSION;
98 mTextureInformations[EMISSIVE].mSemantic = Scene3D::Loader::MaterialDefinition::EMISSIVE;
99 mTextureInformations[SPECULAR].mSemantic = Scene3D::Loader::MaterialDefinition::SPECULAR;
100 mTextureInformations[SPECULAR_COLOR].mSemantic = Scene3D::Loader::MaterialDefinition::SPECULAR_COLOR;
102 mTextureInformations[BASE_COLOR].mDefineKeyword = "BASECOLOR_TEX";
103 mTextureInformations[METALLIC_ROUGHNESS].mDefineKeyword = "METALLIC_ROUGHNESS_TEX";
104 mTextureInformations[NORMAL].mDefineKeyword = "NORMAL_TEX";
105 mTextureInformations[OCCLUSION].mDefineKeyword = "OCCLUSION";
106 mTextureInformations[EMISSIVE].mDefineKeyword = "EMISSIVE";
107 mTextureInformations[SPECULAR].mDefineKeyword = "MATERIAL_SPECULAR_TEXTURE";
108 mTextureInformations[SPECULAR_COLOR].mDefineKeyword = "MATERIAL_SPECULAR_COLOR_TEXTURE";
110 mTextureInformations[TextureIndex::EMISSIVE].mFactor = Vector4::ZERO;
113 Material::~Material() = default;
115 void Material::Initialize()
119 void Material::SetProperty(Dali::Property::Index index, Dali::Property::Value propertyValue)
121 bool needToApply = true;
124 case Dali::Scene3D::Material::Property::NAME:
127 if(propertyValue.Get(name))
134 case Dali::Scene3D::Material::Property::BASE_COLOR_URL:
136 std::string baseColorUrl;
137 if(propertyValue.Get(baseColorUrl))
139 RequestTextureLoad(mTextureInformations[TextureIndex::BASE_COLOR], baseColorUrl);
144 case Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR:
146 Vector4 baseColorFactor;
147 if(propertyValue.Get(baseColorFactor))
149 mTextureInformations[TextureIndex::BASE_COLOR].mFactor = baseColorFactor;
150 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
154 case Dali::Scene3D::Material::Property::METALLIC_ROUGHNESS_URL:
156 std::string metallicRoughnessUrl;
157 if(propertyValue.Get(metallicRoughnessUrl))
159 RequestTextureLoad(mTextureInformations[TextureIndex::METALLIC_ROUGHNESS], metallicRoughnessUrl);
164 case Dali::Scene3D::Material::Property::METALLIC_FACTOR:
166 float metallicFactor;
167 if(propertyValue.Get(metallicFactor))
169 mTextureInformations[TextureIndex::METALLIC_ROUGHNESS].mFactor.x = metallicFactor;
170 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
174 case Dali::Scene3D::Material::Property::ROUGHNESS_FACTOR:
176 float roughnessFactor;
177 if(propertyValue.Get(roughnessFactor))
179 mTextureInformations[TextureIndex::METALLIC_ROUGHNESS].mFactor.y = roughnessFactor;
180 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
184 case Dali::Scene3D::Material::Property::NORMAL_URL:
186 std::string normalUrl;
187 if(propertyValue.Get(normalUrl))
189 RequestTextureLoad(mTextureInformations[TextureIndex::NORMAL], normalUrl);
194 case Dali::Scene3D::Material::Property::NORMAL_SCALE:
197 if(propertyValue.Get(normalScale))
199 mTextureInformations[TextureIndex::NORMAL].mFactor.x = normalScale;
200 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
204 case Dali::Scene3D::Material::Property::OCCLUSION_URL:
206 std::string occlusionUrl;
207 if(propertyValue.Get(occlusionUrl))
209 RequestTextureLoad(mTextureInformations[TextureIndex::OCCLUSION], occlusionUrl);
214 case Dali::Scene3D::Material::Property::OCCLUSION_STRENGTH:
216 float occlusionStrength;
217 if(propertyValue.Get(occlusionStrength))
219 mTextureInformations[TextureIndex::OCCLUSION].mFactor.x = occlusionStrength;
220 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
224 case Dali::Scene3D::Material::Property::EMISSIVE_URL:
226 std::string emissiveUrl;
227 if(propertyValue.Get(emissiveUrl))
229 RequestTextureLoad(mTextureInformations[TextureIndex::EMISSIVE], emissiveUrl);
234 case Dali::Scene3D::Material::Property::EMISSIVE_FACTOR:
236 Vector3 emissiveFactor;
237 if(propertyValue.Get(emissiveFactor))
239 mTextureInformations[TextureIndex::EMISSIVE].mFactor = emissiveFactor;
240 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
244 case Dali::Scene3D::Material::Property::ALPHA_MODE:
246 Dali::Scene3D::Material::AlphaModeType alphaMode;
247 if(propertyValue.Get(alphaMode))
249 mAlphaMode = alphaMode;
250 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
254 case Dali::Scene3D::Material::Property::ALPHA_CUTOFF:
257 if(propertyValue.Get(alphaCutoff))
259 mAlphaCutoff = alphaCutoff;
260 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
264 case Dali::Scene3D::Material::Property::DOUBLE_SIDED:
267 if(propertyValue.Get(doubleSided))
269 mDoubleSided = doubleSided;
270 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
274 case Dali::Scene3D::Material::Property::IOR:
277 if(propertyValue.Get(ior))
280 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
284 case Dali::Scene3D::Material::Property::SPECULAR_URL:
286 std::string specularUrl;
287 if(propertyValue.Get(specularUrl))
289 RequestTextureLoad(mTextureInformations[TextureIndex::SPECULAR], specularUrl);
294 case Dali::Scene3D::Material::Property::SPECULAR_FACTOR:
296 float specularFactor;
297 if(propertyValue.Get(specularFactor))
299 mTextureInformations[TextureIndex::SPECULAR].mFactor.x = specularFactor;
300 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
304 case Dali::Scene3D::Material::Property::SPECULAR_COLOR_URL:
306 std::string specularColorUrl;
307 if(propertyValue.Get(specularColorUrl))
309 RequestTextureLoad(mTextureInformations[TextureIndex::SPECULAR_COLOR], specularColorUrl);
314 case Dali::Scene3D::Material::Property::SPECULAR_COLOR_FACTOR:
316 Vector3 specularColorFactor;
317 if(propertyValue.Get(specularColorFactor))
319 mTextureInformations[TextureIndex::SPECULAR_COLOR].mFactor = specularColorFactor;
320 mModifyFlag |= MaterialModifyObserver::ModifyFlag::UNIFORM;
332 Dali::Property::Value Material::GetProperty(Dali::Property::Index index) const
334 Dali::Property::Value value;
337 case Dali::Scene3D::Material::Property::NAME:
342 case Dali::Scene3D::Material::Property::BASE_COLOR_URL:
344 value = mTextureInformations[TextureIndex::BASE_COLOR].mUrl;
347 case Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR:
349 value = mTextureInformations[TextureIndex::BASE_COLOR].mFactor;
352 case Dali::Scene3D::Material::Property::METALLIC_ROUGHNESS_URL:
354 value = mTextureInformations[TextureIndex::METALLIC_ROUGHNESS].mUrl;
357 case Dali::Scene3D::Material::Property::METALLIC_FACTOR:
359 value = mTextureInformations[TextureIndex::METALLIC_ROUGHNESS].mFactor.x;
362 case Dali::Scene3D::Material::Property::ROUGHNESS_FACTOR:
364 value = mTextureInformations[TextureIndex::METALLIC_ROUGHNESS].mFactor.y;
367 case Dali::Scene3D::Material::Property::NORMAL_URL:
369 value = mTextureInformations[TextureIndex::NORMAL].mUrl;
372 case Dali::Scene3D::Material::Property::NORMAL_SCALE:
374 value = mTextureInformations[TextureIndex::NORMAL].mFactor.x;
377 case Dali::Scene3D::Material::Property::OCCLUSION_URL:
379 value = mTextureInformations[TextureIndex::OCCLUSION].mUrl;
382 case Dali::Scene3D::Material::Property::OCCLUSION_STRENGTH:
384 value = mTextureInformations[TextureIndex::OCCLUSION].mFactor.x;
387 case Dali::Scene3D::Material::Property::EMISSIVE_URL:
389 value = mTextureInformations[TextureIndex::EMISSIVE].mUrl;
392 case Dali::Scene3D::Material::Property::EMISSIVE_FACTOR:
394 value = Vector3(mTextureInformations[TextureIndex::EMISSIVE].mFactor);
397 case Dali::Scene3D::Material::Property::ALPHA_MODE:
402 case Dali::Scene3D::Material::Property::ALPHA_CUTOFF:
404 value = mAlphaCutoff;
407 case Dali::Scene3D::Material::Property::DOUBLE_SIDED:
409 value = mDoubleSided;
412 case Dali::Scene3D::Material::Property::IOR:
417 case Dali::Scene3D::Material::Property::SPECULAR_URL:
419 value = mTextureInformations[TextureIndex::SPECULAR].mUrl;
422 case Dali::Scene3D::Material::Property::SPECULAR_FACTOR:
424 value = mTextureInformations[TextureIndex::SPECULAR].mFactor.x;
427 case Dali::Scene3D::Material::Property::SPECULAR_COLOR_URL:
429 value = mTextureInformations[TextureIndex::SPECULAR_COLOR].mUrl;
432 case Dali::Scene3D::Material::Property::SPECULAR_COLOR_FACTOR:
434 value = Vector3(mTextureInformations[TextureIndex::SPECULAR_COLOR].mFactor);
441 void Material::SetTextureInformation(Scene3D::Material::TextureType index, TextureInformation&& textureInformation)
443 mTextureInformations[index].mFactor = textureInformation.mFactor;
444 mTextureInformations[index].mSampler = textureInformation.mSampler;
445 mTextureInformations[index].mTexture = textureInformation.mTexture;
446 mTextureInformations[index].mUrl = std::move(textureInformation.mUrl);
449 void Material::SetTexture(Scene3D::Material::TextureType index, Dali::Texture texture)
451 if(static_cast<uint32_t>(index) < static_cast<uint32_t>(TextureIndex::TEXTURE_TYPE_NUMBER))
453 if(mTextureInformations[index].mTexture != texture)
455 if(mTextureInformations[index].mLoadingTaskId != INVALID_INDEX)
457 mAsyncImageLoader.Cancel(mTextureInformations[index].mLoadingTaskId);
458 mTextureInformations[index].mLoadingTaskId = INVALID_INDEX;
460 mTextureInformations[index].mTexture = texture;
461 if(IsResourceReady())
463 ResourcesLoadComplete();
469 Dali::Texture Material::GetTexture(Scene3D::Material::TextureType index)
471 if(static_cast<uint32_t>(index) < static_cast<uint32_t>(TextureIndex::TEXTURE_TYPE_NUMBER))
473 return mTextureInformations[index].mTexture;
475 return Dali::Texture();
478 TextureSet Material::GetTextureSet()
480 TextureSet textures = TextureSet::New();
481 for(uint32_t i = 0, count = 0; i < TEXTURE_TYPE_NUMBER; ++i)
483 if(!mTextureInformations[i].mTexture)
487 textures.SetTexture(count, mTextureInformations[i].mTexture);
488 Sampler sampler = mTextureInformations[i].mSampler;
491 auto samplerFlag = Scene3D::Loader::SamplerFlags::FILTER_LINEAR | (Scene3D::Loader::SamplerFlags::FILTER_LINEAR << Scene3D::Loader::SamplerFlags::FILTER_MAG_SHIFT) |
492 (Scene3D::Loader::SamplerFlags::WRAP_REPEAT << Scene3D::Loader::SamplerFlags::WRAP_S_SHIFT) | (Scene3D::Loader::SamplerFlags::WRAP_REPEAT << Scene3D::Loader::SamplerFlags::WRAP_T_SHIFT);
493 sampler = Scene3D::Loader::SamplerFlags::MakeSampler(samplerFlag);
495 textures.SetSampler(count, sampler);
501 void Material::SetSampler(Scene3D::Material::TextureType index, Dali::Sampler sampler)
503 if(static_cast<uint32_t>(index) < static_cast<uint32_t>(TextureIndex::TEXTURE_TYPE_NUMBER))
505 mTextureInformations[index].mSampler = sampler;
509 Dali::Sampler Material::GetSampler(Scene3D::Material::TextureType index)
511 if(static_cast<uint32_t>(index) < static_cast<uint32_t>(TextureIndex::TEXTURE_TYPE_NUMBER))
513 return mTextureInformations[index].mSampler;
515 return Dali::Sampler();
518 std::string Material::GetVertexShader()
520 return mShaderData.mVertexShaderSource;
523 std::string Material::GetFragmentShader()
525 return mShaderData.mFragmentShaderSource;
528 void Material::Apply()
530 if(IsResourceReady())
532 UpdateMaterialData();
536 // The cases this material is applied to primitive are,
537 // 1. material is added on Primitive.
538 // When material is added on Primitive (1 case)
539 // 1-1. when IsResourceReady() returns true,
540 // Primitive can takes information from Material
542 // Material will noti to primitives when all resources are ready.
543 // 2. Some properties are changed
544 // 2-1. when IsResourceReady() returns true,
545 // Call NotifyObserver directly.
547 // Material will noti to primitives when all resources are ready.
550 void Material::AddObserver(MaterialModifyObserver* observer)
552 for(auto& observerEntity : mObservers)
554 if(observerEntity.first == observer)
556 observerEntity.second = true;
560 mObservers.push_back({observer, true});
563 void Material::RemoveObserver(MaterialModifyObserver* observer)
565 // Block during notifying to observer
566 if(mObserverNotifying)
568 for(uint32_t i = 0; i<mObservers.size(); ++i)
570 if(mObservers[i].first == observer)
572 mObservers[i].second = false;
579 for(uint32_t i = 0; i<mObservers.size(); ++i)
581 if(mObservers[i].first == observer)
583 mObservers.erase(mObservers.begin() + i);
590 void Material::UpdateMaterialData()
592 uint32_t materialFlag = 0u;
593 if(mAlphaMode == Dali::Scene3D::Material::AlphaModeType::BLEND)
597 materialFlag |= Scene3D::Loader::MaterialDefinition::TRANSPARENCY;
599 else if(mAlphaMode == Dali::Scene3D::Material::AlphaModeType::MASK)
604 const bool hasTransparency = MaskMatch(materialFlag, Scene3D::Loader::MaterialDefinition::TRANSPARENCY);
606 for(auto&& textureInformation : mTextureInformations)
608 if(!textureInformation.mTexture)
612 materialFlag |= textureInformation.mSemantic;
615 if(mMaterialFlag != materialFlag || mShaderData.mVertexShaderSource.empty() || mShaderData.mFragmentShaderSource.empty())
617 mModifyFlag |= MaterialModifyObserver::ModifyFlag::SHADER;
619 mMaterialFlag = materialFlag;
620 mShaderData.mVertexShaderSource = SHADER_DEFAULT_PHYSICALLY_BASED_SHADER_VERT.data();
621 mShaderData.mFragmentShaderSource = SHADER_DEFAULT_PHYSICALLY_BASED_SHADER_FRAG.data();
623 std::vector<std::string> defines;
624 defines.push_back(THREE_TEX_KEYWORD.data());
625 for(auto&& textureInformation : mTextureInformations)
627 if(!textureInformation.mTexture)
631 defines.push_back(textureInformation.mDefineKeyword);
633 defines.push_back(GLTF_CHANNELS_KEYWORD.data());
635 for(const auto& define : defines)
637 Scene3D::Loader::ShaderDefinition::ApplyDefine(mShaderData.mFragmentShaderSource, define);
641 // Finish to make all the material flag according to the gltf2-util.
642 // Then make defines as fallowing shader-definition-factory.
644 // The renderer State below can be used in primitive to set renderer properties.
646 // for renderer setting
647 mRendererState = Scene3D::Loader::RendererState::DEPTH_TEST;
650 mRendererState |= Scene3D::Loader::RendererState::CULL_BACK;
655 mRendererState = (mRendererState | Scene3D::Loader::RendererState::ALPHA_BLEND);
659 bool Material::IsResourceReady()
661 for(auto&& textureInformation : mTextureInformations)
663 if(!textureInformation.IsReady())
671 void Material::SetRendererUniform(Dali::Renderer renderer)
673 renderer.RegisterProperty("uColorFactor", mTextureInformations[TextureIndex::BASE_COLOR].mFactor);
674 renderer.RegisterProperty("uMetallicFactor", mTextureInformations[TextureIndex::METALLIC_ROUGHNESS].mFactor.x);
675 renderer.RegisterProperty("uRoughnessFactor", mTextureInformations[TextureIndex::METALLIC_ROUGHNESS].mFactor.y);
676 renderer.RegisterProperty("uNormalScale", mTextureInformations[TextureIndex::NORMAL].mFactor.x);
677 if(mTextureInformations[TextureIndex::OCCLUSION].mTexture)
679 renderer.RegisterProperty("uOcclusionStrength", mTextureInformations[TextureIndex::OCCLUSION].mFactor.x);
681 renderer.RegisterProperty("uEmissiveFactor", Vector3(mTextureInformations[TextureIndex::EMISSIVE].mFactor));
682 float dielectricSpecular = (Dali::Equals(mIor, -1.0)) ? 0.04f : powf((mIor - 1.0f) / (mIor + 1.0f), 2.0f);
683 renderer.RegisterProperty("uDielectricSpecular", dielectricSpecular);
684 renderer.RegisterProperty("uSpecularFactor", mTextureInformations[TextureIndex::SPECULAR].mFactor.x);
685 renderer.RegisterProperty("uSpecularColorFactor", Vector3(mTextureInformations[TextureIndex::SPECULAR_COLOR].mFactor));
687 float opaque = mIsOpaque ? 1.0f : 0.0f;
688 float mask = mIsMask ? 1.0f : 0.0f;
689 renderer.RegisterProperty("uOpaque", opaque);
690 renderer.RegisterProperty("uMask", mask);
691 renderer.RegisterProperty("uAlphaThreshold", mAlphaCutoff);
693 renderer.RegisterProperty("uCubeMatrix", Matrix::IDENTITY);
695 renderer.RegisterProperty(Scene3D::Loader::NodeDefinition::GetIblMaxLodUniformName().data(), 6.f);
696 renderer.RegisterProperty(Scene3D::Loader::NodeDefinition::GetIblScaleFactorUniformName().data(), 1.0f);
697 renderer.RegisterProperty(Scene3D::Loader::NodeDefinition::GetIblYDirectionUniformName().data(), Vector3(1.0f, -1.0, 1.0));
699 Scene3D::Loader::RendererState::Apply(mRendererState, renderer);
702 uint32_t Material::GetSpecularImageBasedLightTextureOffset()
704 return OFFSET_FOR_SPECULAR_CUBE_TEXTURE;
707 uint32_t Material::GetDiffuseImageBasedLightTextureOffset()
709 return OFFSET_FOR_DIFFUSE_CUBE_TEXTURE;
712 std::string_view Material::GetImageBasedLightScaleFactorName()
714 return Dali::Scene3D::Loader::NodeDefinition::GetIblScaleFactorUniformName();
717 std::string_view Material::GetImageBasedLightMaxLodUniformName()
719 return Dali::Scene3D::Loader::NodeDefinition::GetIblMaxLodUniformName();
722 void Material::ResetFlag()
724 mModifyFlag = MaterialModifyObserver::ModifyFlag::NONE;
727 void Material::NotifyObserver()
729 if(mModifyFlag != MaterialModifyObserver::ModifyFlag::NONE && IsResourceReady())
731 if(mObserverNotifying)
733 DALI_LOG_ERROR("Notify during observing is not allowed.");
737 Dali::Scene3D::Material handle(this); // Keep itself's life during notify
739 // Copy the flag due to the flag can be changed during observe.
740 MaterialModifyObserver::ModifyFlag copiedFlag = mModifyFlag;
741 mModifyFlag = MaterialModifyObserver::ModifyFlag::NONE;
743 // Need to block mObserver container change during observe
744 mObserverNotifying = true;
745 for(uint32_t i = 0; i < mObservers.size(); ++i)
747 if(mObservers[i].second)
749 mObservers[i].first->OnMaterialModified(handle, copiedFlag);
752 mObserverNotifying = false;
754 // Resolve observer queue during notify
755 mObservers.erase(std::remove_if(mObservers.begin(), mObservers.end(), [](auto& e){return !e.second;}), mObservers.end());
759 void Material::RequestTextureLoad(TextureInformation& textureInformation, const std::string& url)
761 if(textureInformation.mUrl == url)
766 textureInformation.mUrl = url;
767 if(textureInformation.mLoadingTaskId != INVALID_INDEX)
769 mAsyncImageLoader.Cancel(textureInformation.mLoadingTaskId);
770 textureInformation.mLoadingTaskId = INVALID_INDEX;
775 textureInformation.mTexture.Reset();
778 textureInformation.mLoadingTaskId = mAsyncImageLoader.Load(url);
781 void Material::TextureLoadComplete(uint32_t loadedTaskId, PixelData pixelData)
783 for(auto&& textureInformation : mTextureInformations)
785 if(textureInformation.mLoadingTaskId != loadedTaskId)
792 textureInformation.mTexture = Texture::New(Dali::TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
793 textureInformation.mTexture.Upload(pixelData);
795 textureInformation.mLoadingTaskId = INVALID_INDEX;
799 if(IsResourceReady())
801 ResourcesLoadComplete();
805 void Material::ResourcesLoadComplete()
807 mModifyFlag |= MaterialModifyObserver::ModifyFlag::TEXTURE;
811 } // namespace Internal
813 } // namespace Scene3D