using System;
using System.IO;
namespace Gwen
{
///
/// Represents a texture.
///
public class Texture : IDisposable
{
///
/// Texture name. Usually file name, but exact meaning depends on renderer.
///
public String Name { get; set; }
///
/// Renderer data.
///
public object RendererData { get; set; }
///
/// Indicates that the texture failed to load.
///
public bool Failed { get; set; }
///
/// Texture width.
///
public int Width { get; set; }
///
/// Texture height.
///
public int Height { get; set; }
private readonly Renderer.Base m_Renderer;
///
/// Initializes a new instance of the class.
///
/// Renderer to use.
public Texture(Renderer.Base renderer)
{
m_Renderer = renderer;
Width = 4;
Height = 4;
Failed = false;
}
///
/// Loads the specified texture.
///
/// Texture name.
public void Load(String name)
{
Name = name;
m_Renderer.LoadTexture(this);
}
///
/// Initializes the texture from raw pixel data.
///
/// Texture width.
/// Texture height.
/// Color array in RGBA format.
public void LoadRaw(int width, int height, byte[] pixelData)
{
Width = width;
Height = height;
m_Renderer.LoadTextureRaw(this, pixelData);
}
public void LoadStream(Stream data)
{
m_Renderer.LoadTextureStream(this, data);
}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
m_Renderer.FreeTexture(this);
GC.SuppressFinalize(this);
}
#if DEBUG
~Texture()
{
throw new InvalidOperationException(String.Format("IDisposable object finalized: {0}", GetType()));
//Debug.Print(String.Format("IDisposable object finalized: {0}", GetType()));
}
#endif
}
}