bool Texture2D::Load(Deserializer& source) { PROFILE(LoadTexture2D); // In headless mode, do not actually load the texture, just return success Graphics* graphics = GetSubsystem<Graphics>(); if (!graphics) return true; // If device is lost, retry later if (graphics_->IsDeviceLost()) { LOGWARNING("Texture load while device is lost"); dataPending_ = true; return true; } // If over the texture budget, see if materials can be freed to allow textures to be freed CheckTextureBudget(GetTypeStatic()); SharedPtr<Image> image(new Image(context_)); if (!image->Load(source)) return false; // Before actually loading the texture, get optional parameters from an XML description file LoadParameters(); return Load(image); }
bool TextureCube::Load(Deserializer& source) { PROFILE(LoadTextureCube); ResourceCache* cache = GetSubsystem<ResourceCache>(); // In headless mode, do not actually load the texture, just return success Graphics* graphics = GetSubsystem<Graphics>(); if (!graphics) return true; // If device is lost, retry later if (graphics_->IsDeviceLost()) { LOGWARNING("Texture load while device is lost"); dataPending_ = true; return true; } // If over the texture budget, see if materials can be freed to allow textures to be freed CheckTextureBudget(GetTypeStatic()); String texPath, texName, texExt; SplitPath(GetName(), texPath, texName, texExt); SharedPtr<XMLFile> xml(new XMLFile(context_)); if (!xml->Load(source)) return false; LoadParameters(xml); XMLElement textureElem = xml->GetRoot(); XMLElement faceElem = textureElem.GetChild("face"); unsigned faces = 0; while (faceElem && faces < MAX_CUBEMAP_FACES) { String name = faceElem.GetAttribute("name"); String faceTexPath, faceTexName, faceTexExt; SplitPath(name, faceTexPath, faceTexName, faceTexExt); // If path is empty, add the XML file path if (faceTexPath.Empty()) name = texPath + name; SharedPtr<Image> image(cache->GetResource<Image>(name)); Load((CubeMapFace)faces, image); ++faces; faceElem = faceElem.GetNext("face"); } return true; }
bool Texture2D::EndLoad() { // In headless mode, do not actually load the texture, just return success if (!graphics_ || graphics_->IsDeviceLost()) return true; // If over the texture budget, see if materials can be freed to allow textures to be freed CheckTextureBudget(GetTypeStatic()); SetParameters(loadParameters_); bool success = SetData(loadImage_); loadImage_.Reset(); loadParameters_.Reset(); return success; }
bool TextureCube::EndLoad() { // In headless mode, do not actually load the texture, just return success if (!graphics_ || graphics_->IsDeviceLost()) return true; // If over the texture budget, see if materials can be freed to allow textures to be freed CheckTextureBudget(GetTypeStatic()); SetParameters(loadParameters_); for (unsigned i = 0; i < loadImages_.Size() && i < MAX_CUBEMAP_FACES; ++i) SetData((CubeMapFace)i, loadImages_[i]); loadImages_.Clear(); loadParameters_.Reset(); return true; }
bool Texture2DArray::EndLoad() { // In headless mode, do not actually load the texture, just return success if (!graphics_ || graphics_->IsDeviceLost()) return true; // If over the texture budget, see if materials can be freed to allow textures to be freed CheckTextureBudget(GetTypeStatic()); SetParameters(loadParameters_); SetLayers(loadImages_.size()); for (unsigned i = 0; i < loadImages_.size(); ++i) SetData(i, loadImages_[i]); loadImages_.clear(); loadParameters_.Reset(); return true; }
bool Texture3D::Load(Deserializer& source) { PROFILE(LoadTexture3D); // In headless mode, do not actually load the texture, just return success if (!graphics_) return true; // If device is lost, retry later if (graphics_->IsDeviceLost()) { LOGWARNING("Texture load while device is lost"); dataPending_ = true; return true; } // If over the texture budget, see if materials can be freed to allow textures to be freed CheckTextureBudget(GetTypeStatic()); // Before actually loading the texture, get optional parameters from an XML description file LoadParameters(); String texPath, texName, texExt; SplitPath(GetName(), texPath, texName, texExt); SharedPtr<XMLFile> xml(new XMLFile(context_)); if (!xml->Load(source)) return false; XMLElement textureElem = xml->GetRoot(); XMLElement volumeElem = textureElem.GetChild("volume"); XMLElement colorlutElem = textureElem.GetChild("colorlut"); if (volumeElem) { String name = volumeElem.GetAttribute("name"); String volumeTexPath, volumeTexName, volumeTexExt; SplitPath(name, volumeTexPath, volumeTexName, volumeTexExt); // If path is empty, add the XML file path if (volumeTexPath.Empty()) name = texPath + name; SharedPtr<Image> image(GetSubsystem<ResourceCache>()->GetResource<Image>(name)); return Load(image); } else if (colorlutElem) { String name = colorlutElem.GetAttribute("name"); String colorlutTexPath, colorlutTexName, colorlutTexExt; SplitPath(name, colorlutTexPath, colorlutTexName, colorlutTexExt); // If path is empty, add the XML file path if (colorlutTexPath.Empty()) name = texPath + name; SharedPtr<File> file = GetSubsystem<ResourceCache>()->GetFile(name); SharedPtr<Image> image(new Image(context_)); if (!image->LoadColorLUT(*(file.Get()))) return false; return Load(image); } return false; }