Beispiel #1
0
        public IUserGeneratedTexture CreateGeneratedTexture(string name, int width, int height, MyGeneratedTextureType type, int numMipLevels)
        {
            IGeneratedTexture texture;

            if (m_generatedTextures.TryGetValue(name, out texture))
            {
                IUserGeneratedTexture userTexture = texture as IUserGeneratedTexture;
                if (userTexture == null)
                {
                    MyRenderProxy.Fail("Trying to replace system texture");
                    return(null);
                }

                if (userTexture.Size.X != width || userTexture.Size.Y != height ||
                    userTexture.Type != type || userTexture.MipmapCount != numMipLevels)
                {
                    MyRenderProxy.Fail("Trying to replace existing texture");
                }

                return(userTexture);
            }

            var manager = MyManagers.GeneratedTextures;
            IUserGeneratedTexture ret = manager.NewUserTexture(name, width, height, type, numMipLevels);

            m_generatedTextures[name] = ret;
            return(ret);
        }
Beispiel #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);
        }
Beispiel #3
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();
        }
Beispiel #4
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;
        }