2012-08-09 09:45:04 +00:00
|
|
|
#region Using Statements
|
2011-10-31 05:36:24 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
2012-01-16 15:03:28 +00:00
|
|
|
using System.Runtime.InteropServices;
|
2012-02-19 13:41:02 +00:00
|
|
|
using ANX.Framework.NonXNA;
|
|
|
|
using ANX.Framework.NonXNA.RenderSystem;
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
#endregion // Using Statements
|
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
namespace ANX.Framework.Graphics
|
|
|
|
{
|
|
|
|
public class Texture2D : Texture, IGraphicsResource
|
|
|
|
{
|
2012-02-19 11:24:23 +00:00
|
|
|
#region Private
|
2011-11-28 16:33:22 +00:00
|
|
|
protected internal int width;
|
|
|
|
protected internal int height;
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-02-19 11:24:23 +00:00
|
|
|
private INativeTexture2D nativeTexture2D;
|
2012-02-19 13:41:02 +00:00
|
|
|
private INativeTexture2D NativeTexture2D
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (nativeTexture2D == null)
|
|
|
|
{
|
|
|
|
CreateNativeTextureSurface();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nativeTexture2D;
|
|
|
|
}
|
|
|
|
}
|
2012-02-19 11:24:23 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Public
|
|
|
|
public Rectangle Bounds
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return new Rectangle(0, 0, this.width, this.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Width
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Height
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2012-02-19 13:41:02 +00:00
|
|
|
#region Constructor (TODO)
|
2012-02-19 11:24:23 +00:00
|
|
|
internal Texture2D(GraphicsDevice graphicsDevice)
|
2011-11-28 16:06:52 +00:00
|
|
|
: base(graphicsDevice)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
public Texture2D(GraphicsDevice graphicsDevice, int width, int height)
|
|
|
|
: base(graphicsDevice)
|
|
|
|
{
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
2011-11-11 07:29:49 +00:00
|
|
|
|
|
|
|
base.levelCount = 1;
|
|
|
|
base.format = SurfaceFormat.Color;
|
|
|
|
|
2012-02-19 11:24:23 +00:00
|
|
|
CreateNativeTextureSurface();
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 13:41:02 +00:00
|
|
|
public Texture2D(GraphicsDevice graphicsDevice, int width, int height,
|
|
|
|
[MarshalAsAttribute(UnmanagedType.U1)] bool mipMap, SurfaceFormat format)
|
2011-10-31 05:36:24 +00:00
|
|
|
: base(graphicsDevice)
|
|
|
|
{
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
|
2011-11-11 07:29:49 +00:00
|
|
|
base.levelCount = 1; //TODO: mipmap paramter?!?!?
|
|
|
|
base.format = format;
|
|
|
|
|
2012-02-19 11:24:23 +00:00
|
|
|
CreateNativeTextureSurface();
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
2012-02-19 11:24:23 +00:00
|
|
|
#endregion
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-02-19 11:24:23 +00:00
|
|
|
#region FromStream (TODO)
|
2012-02-19 13:41:02 +00:00
|
|
|
public static Texture2D FromStream(GraphicsDevice graphicsDevice,
|
|
|
|
Stream stream)
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2012-02-19 13:41:02 +00:00
|
|
|
public static Texture2D FromStream(GraphicsDevice graphicsDevice,
|
|
|
|
Stream stream, int width, int height,
|
|
|
|
[MarshalAsAttribute(UnmanagedType.U1)] bool zoom)
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
2012-02-19 11:24:23 +00:00
|
|
|
#endregion
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-02-19 13:41:02 +00:00
|
|
|
#region GetData
|
|
|
|
public void GetData<T>(int level, Nullable<Rectangle> rect, T[] data,
|
|
|
|
int startIndex, int elementCount) where T : struct
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2012-02-19 13:41:02 +00:00
|
|
|
NativeTexture2D.GetData(level, rect, data, startIndex, elementCount);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void GetData<T>(T[] data) where T : struct
|
2012-02-19 13:41:02 +00:00
|
|
|
{
|
|
|
|
NativeTexture.GetData(data);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct
|
|
|
|
{
|
2012-02-19 13:41:02 +00:00
|
|
|
NativeTexture.GetData(data, startIndex, elementCount);
|
2012-02-19 11:24:23 +00:00
|
|
|
}
|
|
|
|
#endregion
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-02-19 13:41:02 +00:00
|
|
|
#region SetData
|
|
|
|
public void SetData<T>(int level, Nullable<Rectangle> rect, T[] data,
|
|
|
|
int startIndex, int elementCount) where T : struct
|
|
|
|
{
|
|
|
|
NativeTexture2D.SetData(level, rect, data, startIndex, elementCount);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetData<T>(T[] data) where T : struct
|
|
|
|
{
|
2011-12-09 08:46:25 +00:00
|
|
|
NativeTexture.SetData<T>(GraphicsDevice, data);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct
|
|
|
|
{
|
2011-12-09 08:46:25 +00:00
|
|
|
NativeTexture.SetData<T>(GraphicsDevice, data, startIndex, elementCount);
|
2012-02-19 11:24:23 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region SaveAsJpeg
|
|
|
|
public void SaveAsJpeg(Stream stream, int width, int height)
|
|
|
|
{
|
2012-02-19 13:41:02 +00:00
|
|
|
NativeTexture2D.SaveAsJpeg(stream, width, height);
|
2012-02-19 11:24:23 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region SaveAsPng
|
|
|
|
public void SaveAsPng(Stream stream, int width, int height)
|
|
|
|
{
|
2012-02-19 13:41:02 +00:00
|
|
|
NativeTexture2D.SaveAsPng(stream, width, height);
|
2012-02-19 11:24:23 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Dispose
|
|
|
|
public override void Dispose()
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2011-11-11 07:29:49 +00:00
|
|
|
base.Dispose(true);
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 11:24:23 +00:00
|
|
|
protected override void Dispose(
|
|
|
|
[MarshalAs(UnmanagedType.U1)] bool disposeManaged)
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
2011-11-11 07:29:49 +00:00
|
|
|
base.Dispose(disposeManaged);
|
2012-02-19 11:24:23 +00:00
|
|
|
}
|
|
|
|
#endregion
|
2011-11-11 07:29:49 +00:00
|
|
|
|
2012-02-19 11:24:23 +00:00
|
|
|
#region ReCreateNativeTextureSurface
|
|
|
|
internal override void ReCreateNativeTextureSurface()
|
2011-12-09 08:46:25 +00:00
|
|
|
{
|
2012-02-19 11:24:23 +00:00
|
|
|
CreateNativeTextureSurface();
|
|
|
|
}
|
|
|
|
#endregion
|
2011-12-09 08:46:25 +00:00
|
|
|
|
2012-02-19 11:24:23 +00:00
|
|
|
#region CreateNativeTextureSurface
|
|
|
|
private void CreateNativeTextureSurface()
|
2011-11-11 07:29:49 +00:00
|
|
|
{
|
2012-02-19 11:24:23 +00:00
|
|
|
nativeTexture2D =
|
|
|
|
AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateTexture(GraphicsDevice, format, width, height, levelCount);
|
|
|
|
base.nativeTexture = nativeTexture2D;
|
|
|
|
}
|
|
|
|
#endregion
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
}
|