示例#1
0
        /// <remarks>On big loops, or whenever recommendable, cache the returned reference</remarks>
        public ITexture GetTexture(string name, MyFileTextureEnum type, bool waitTillLoaded = false, bool skipQualityReduction = false)
        {
            if (name == null || name.Length <= 0)
            {
                return(ReturnDefaultTexture(type));
            }

            Uri uri;

            if (!MyResourceUtils.NormalizeFileTextureName(ref name, out uri))
            {
                IGeneratedTexture texture;
                if (m_generatedTextures.TryGetValue(name, out texture))
                {
                    return(texture);
                }
                else
                {
                    MyRenderProxy.Assert(false, "Can't find generated texture with name \"" + name + "\"");
                    return(ReturnDefaultTexture(type));
                }
            }

            MyFileTexture texOut;

            if (!m_textures.TryGetValue(name, out texOut))
            {
                if (uri.Scheme != FILE_SCHEME)
                {
                    Debug.Assert(false, "Cannot initialize a non file texture");
                    return(ReturnDefaultTexture(type));
                }

                m_texturesPool.AllocateOrCreate(out texOut);
                texOut.Init(name, uri.LocalPath, type, waitTillLoaded, skipQualityReduction);
                m_textures.Add(name, texOut);
            }

            switch (texOut.TextureState)
            {
            case FileTextureState.Unloaded:
            case FileTextureState.Requested:
                if (waitTillLoaded)
                {
                    LoadInternal(name);
                }
                else
                {
                    texOut.TextureState = FileTextureState.Requested;
                    m_requestedTextures.Add(name);
                }
                break;

            case FileTextureState.Loaded:
                break;
            }

            return(texOut);
        }
示例#2
0
        public bool TryGetTexture(string name, out IUserGeneratedTexture texture)
        {
            Uri uri;

            if (MyResourceUtils.NormalizeFileTextureName(ref name, out uri))
            {
                texture = null;
                return(false);
            }

            IGeneratedTexture generatedTexture;

            m_generatedTextures.TryGetValue(name, out generatedTexture);
            texture = generatedTexture as IUserGeneratedTexture;
            return(texture != null);
        }
示例#3
0
        public bool TryGetTexture(string name, out ITexture texture)
        {
            Uri  uri;
            bool found;

            if (!MyResourceUtils.NormalizeFileTextureName(ref name, out uri))
            {
                IGeneratedTexture generatedTexture;
                found   = m_generatedTextures.TryGetValue(name, out generatedTexture);
                texture = generatedTexture;
                return(found);
            }

            MyFileTexture fileTexture;

            found   = m_textures.TryGetValue(name, out fileTexture);
            texture = fileTexture;
            return(found);
        }
示例#4
0
        void DisposeTexInternal(string name, bool alterLoaded = true, bool ignoreFailure = false)
        {
            if (!MyResourceUtils.NormalizeFileTextureName(ref name))
            {
                IGeneratedTexture texture;
                if (m_generatedTextures.TryGetValue(name, out texture))
                {
                    IUserGeneratedTexture userTexture = texture as IUserGeneratedTexture;
                    if (userTexture == null)
                    {
                        MyRenderProxy.Assert(false, "Can't dispose system texture");
                    }
                    else
                    {
                        MyManagers.GeneratedTextures.DisposeTex(userTexture);
                    }

                    return;
                }
                else
                {
                    MyRenderProxy.Assert(false, "Can't find generated texture with name \"" + name + "\"");
                    return;
                }
            }

            MyRenderProxy.Assert(m_textures.ContainsKey(name) || ignoreFailure, "The texture has not been created by this manager");

            if (!m_loadedTextures.Contains(name))
            {
                return;
            }

            if (alterLoaded)
            {
                m_loadedTextures.Remove(name); // Will not throw if not found
            }
            m_requestedTextures.Remove(name);  // Will not throw if not found

            // We keep the texture object but destroy the dx resources
            m_textures[name].Destroy();
        }