2011-11-16 14:27:53 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
2012-09-07 09:48:45 +00:00
|
|
|
using ANX.BaseDirectX;
|
2012-09-06 09:58:13 +00:00
|
|
|
using ANX.Framework.Graphics;
|
|
|
|
using ANX.Framework.NonXNA.RenderSystem;
|
2012-09-07 09:48:45 +00:00
|
|
|
using SharpDX;
|
2012-09-06 09:58:13 +00:00
|
|
|
using Dx10 = SharpDX.Direct3D10;
|
2011-11-16 14:27:53 +00:00
|
|
|
|
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-11-16 14:27:53 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
namespace ANX.RenderSystem.Windows.DX10
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
2012-09-07 09:48:45 +00:00
|
|
|
public class Texture2D_DX10 : BaseTexture2D<Dx10.Texture2D>, INativeTexture2D
|
2012-09-04 21:36:46 +00:00
|
|
|
{
|
2012-09-06 09:58:13 +00:00
|
|
|
#region Public
|
2012-09-07 09:48:45 +00:00
|
|
|
public override int Width
|
2012-09-06 09:58:13 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2012-09-07 09:48:45 +00:00
|
|
|
return NativeTexture != null ? NativeTexture.Description.Width : 0;
|
2012-09-06 09:58:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-07 09:48:45 +00:00
|
|
|
public override int Height
|
2012-09-06 09:58:13 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2012-09-07 09:48:45 +00:00
|
|
|
return NativeTexture != null ? NativeTexture.Description.Height : 0;
|
2012-09-06 09:58:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-07 09:48:45 +00:00
|
|
|
protected internal Dx10.ShaderResourceView NativeShaderResourceView { get; protected set; }
|
2012-09-06 09:58:13 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Constructor
|
2012-09-07 09:48:45 +00:00
|
|
|
internal Texture2D_DX10(GraphicsDevice graphicsDevice, SurfaceFormat surfaceFormat)
|
|
|
|
: base(graphicsDevice, surfaceFormat)
|
2012-09-06 09:58:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Texture2D_DX10(GraphicsDevice graphicsDevice, int width, int height, SurfaceFormat surfaceFormat, int mipCount)
|
2012-09-07 09:48:45 +00:00
|
|
|
: base(graphicsDevice, surfaceFormat)
|
2012-09-06 09:58:13 +00:00
|
|
|
{
|
|
|
|
if (mipCount > 1)
|
|
|
|
throw new Exception("creating textures with mip map not yet implemented");
|
|
|
|
|
|
|
|
Dx10.Texture2DDescription description = new Dx10.Texture2DDescription()
|
|
|
|
{
|
|
|
|
Width = width,
|
|
|
|
Height = height,
|
|
|
|
MipLevels = mipCount,
|
|
|
|
ArraySize = mipCount,
|
2012-09-07 09:48:45 +00:00
|
|
|
Format = BaseFormatConverter.Translate(surfaceFormat),
|
2012-09-06 09:58:13 +00:00
|
|
|
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
|
|
|
|
Usage = Dx10.ResourceUsage.Dynamic,
|
|
|
|
BindFlags = Dx10.BindFlags.ShaderResource,
|
|
|
|
CpuAccessFlags = Dx10.CpuAccessFlags.Write,
|
|
|
|
OptionFlags = Dx10.ResourceOptionFlags.None,
|
|
|
|
};
|
|
|
|
|
2012-09-07 09:48:45 +00:00
|
|
|
Dx10.Device device = (graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX10).NativeDevice;
|
|
|
|
NativeTexture = new Dx10.Texture2D(device, description);
|
|
|
|
NativeShaderResourceView = new Dx10.ShaderResourceView(device, NativeTexture);
|
2012-09-06 09:58:13 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region GetHashCode
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
return NativeTexture.NativePointer.ToInt32();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Dispose
|
2012-09-07 09:48:45 +00:00
|
|
|
public override void Dispose()
|
2012-09-04 21:36:46 +00:00
|
|
|
{
|
2012-09-07 09:48:45 +00:00
|
|
|
if (NativeShaderResourceView != null)
|
2012-09-04 21:36:46 +00:00
|
|
|
{
|
2012-09-07 09:48:45 +00:00
|
|
|
NativeShaderResourceView.Dispose();
|
|
|
|
NativeShaderResourceView = null;
|
2012-09-04 21:36:46 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 09:48:45 +00:00
|
|
|
base.Dispose();
|
2012-09-04 21:36:46 +00:00
|
|
|
}
|
2012-09-06 09:58:13 +00:00
|
|
|
#endregion
|
2012-09-04 21:36:46 +00:00
|
|
|
|
|
|
|
#region SaveAsJpeg (TODO)
|
|
|
|
public void SaveAsJpeg(Stream stream, int width, int height)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region SaveAsPng (TODO)
|
|
|
|
public void SaveAsPng(Stream stream, int width, int height)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2012-09-06 09:58:13 +00:00
|
|
|
#region GetData (TODO)
|
|
|
|
public void GetData<T>(T[] data) where T : struct
|
2012-09-04 21:36:46 +00:00
|
|
|
{
|
2012-09-07 09:48:45 +00:00
|
|
|
GetData(data, 0, data.Length);
|
2012-09-04 21:36:46 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 09:58:13 +00:00
|
|
|
public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct
|
2012-09-04 21:36:46 +00:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2012-09-07 09:48:45 +00:00
|
|
|
public void GetData<T>(int level, Framework.Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
|
2012-09-04 21:36:46 +00:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
#endregion
|
2012-09-07 09:48:45 +00:00
|
|
|
|
|
|
|
#region MapWrite
|
|
|
|
protected override IntPtr MapWrite()
|
|
|
|
{
|
|
|
|
tempSubresource = Dx10.Texture2D.CalculateSubResourceIndex(0, 0, 1);
|
|
|
|
DataRectangle rect = NativeTexture.Map(tempSubresource, Dx10.MapMode.WriteDiscard, Dx10.MapFlags.None);
|
|
|
|
pitch = rect.Pitch;
|
|
|
|
return rect.DataPointer;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region MapRead
|
|
|
|
protected override IntPtr MapRead()
|
|
|
|
{
|
|
|
|
tempSubresource = Dx10.Texture2D.CalculateSubResourceIndex(0, 0, 1);
|
|
|
|
DataRectangle rect = NativeTexture.Map(tempSubresource, Dx10.MapMode.Read, Dx10.MapFlags.None);
|
|
|
|
pitch = rect.Pitch;
|
|
|
|
return rect.DataPointer;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Unmap
|
|
|
|
protected override void Unmap()
|
|
|
|
{
|
|
|
|
NativeTexture.Unmap(tempSubresource);
|
|
|
|
}
|
|
|
|
#endregion
|
2012-09-04 21:36:46 +00:00
|
|
|
}
|
2011-11-16 14:27:53 +00:00
|
|
|
}
|