/// <summary> /// Replaces view texture information. /// This should only be used for child textures with a parent. /// </summary> /// <param name="parent">The parent texture</param> /// <param name="info">The new view texture information</param> /// <param name="hostTexture">The new host texture</param> /// <param name="firstLayer">The first layer of the view</param> /// <param name="firstLevel">The first level of the view</param> public void ReplaceView(Texture parent, TextureInfo info, ITexture hostTexture, int firstLayer, int firstLevel) { IncrementReferenceCount(); parent._viewStorage.SynchronizeMemory(); // If this texture has views, they must be given to the new parent. if (_views.Count > 0) { Texture[] viewCopy = _views.ToArray(); foreach (Texture view in viewCopy) { TextureCreateInfo createInfo = TextureManager.GetCreateInfo(view.Info, _context.Capabilities, ScaleFactor); ITexture newView = parent.HostTexture.CreateView(createInfo, view.FirstLayer + firstLayer, view.FirstLevel + firstLevel); view.ReplaceView(parent, view.Info, newView, view.FirstLayer + firstLayer, view.FirstLevel + firstLevel); } } ReplaceStorage(hostTexture); if (_viewStorage != this) { _viewStorage.RemoveView(this); } FirstLayer = parent.FirstLayer + firstLayer; FirstLevel = parent.FirstLevel + firstLevel; parent._viewStorage.AddView(this); SetInfo(info); DecrementReferenceCount(); }
/// <summary> /// Decrements the texture reference count. /// When the reference count hits zero, the texture may be deleted and can't be used anymore. /// </summary> public void DecrementReferenceCount() { int newRefCount = --_referenceCount; if (newRefCount == 0) { if (_viewStorage != this) { _viewStorage.RemoveView(this); } _context.Methods.TextureManager.RemoveTextureFromCache(this); } Debug.Assert(newRefCount >= 0); DeleteIfNotUsed(); }