/// <summary> /// Adds a texture to the resource manager /// </summary> public int AddTexture(string filename) { // See if this font exists for (int i = 0; i < textureCache.Count; i++) { TextureNode tn = textureCache[i] as TextureNode; if (string.Compare(tn.Filename, filename, true) == 0) { // Found it return(i); } } // Doesn't exist, add a new one and try to create it TextureNode newNode = new TextureNode(); newNode.Filename = filename; textureCache.Add(newNode); int texIndex = textureCache.Count - 1; // If a device is available, try to create immediately if (device != null) { CreateTexture(texIndex); } return(texIndex); }
/// <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 ((tn.Filename == null) || (tn.Filename.Length == 0)) { return; } // Find the texture string path = Utility.FindMediaFile(tn.Filename); // Create the new texture ImageInformation info = new ImageInformation(); tn.Texture = TextureLoader.FromFile(device, path, D3DX.Default, D3DX.Default, D3DX.Default, Usage.None, Format.Unknown, Pool.Managed, (Filter)D3DX.Default, (Filter)D3DX.Default, 0, ref info); // Store dimensions tn.Width = (uint)info.Width; tn.Height = (uint)info.Height; }