Ejemplo n.º 1
0
        /// <summary>
        /// Adds a texture to the resource manager
        /// </summary>
        public int AddTexture(string filename)
        {
            // See if this texture exists
            for (int i = 0; i < _textureCache.Count; i++)
            {
                TextureNode tn = _textureCache[i];
                if (string.Compare(tn.Filename, filename, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // Found it
                    return(i);
                }
            }

            // Doesn't exist, add a new one and try to create it
            var newNode = new TextureNode {
                Filename = filename
            };

            _textureCache.Add(newNode);

            int texIndex = _textureCache.Count - 1;

            // If a device is available, try to create immediately
            if (Engine != null)
            {
                CreateTexture(texIndex);
            }

            return(texIndex);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a texture
        /// </summary>
        public void CreateTexture(int tex)
        {
            // Get the texture node here
            TextureNode tn = GetTextureNode(tex);

            // Make sure there's a texture to create
            if (string.IsNullOrEmpty(tn.Filename))
            {
                return;
            }

            // Create the new texture
            var info = new ImageInformation();

            using (var stream = ContentManager.GetFileStream("GUI/Textures", tn.Filename))
            {
                tn.Texture = Texture.FromStream(Engine.Device, stream, D3DX.Default, D3DX.Default, D3DX.Default, Usage.None,
                                                Format.Unknown, Pool.Managed, Filter.Default, Filter.Default, 0);
            }

            // Store dimensions
            tn.Width  = (uint)info.Width;
            tn.Height = (uint)info.Height;
        }