2012-09-15 13:43:31 +00:00
|
|
|
#region Using Statements
|
2011-11-16 14:27:53 +00:00
|
|
|
using System;
|
|
|
|
using ANX.Framework.Graphics;
|
2012-02-19 13:41:02 +00:00
|
|
|
using ANX.Framework.NonXNA.RenderSystem;
|
2012-09-07 09:48:45 +00:00
|
|
|
using SharpDX;
|
2012-09-15 13:43:31 +00:00
|
|
|
|
|
|
|
#endregion
|
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-09-15 13:43:31 +00:00
|
|
|
using Dx10 = SharpDX.Direct3D10;
|
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
namespace ANX.RenderSystem.Windows.DX10
|
2011-11-16 14:27:53 +00:00
|
|
|
{
|
2015-01-18 13:10:50 +00:00
|
|
|
public partial class DxIndexBuffer : INativeIndexBuffer, IDisposable
|
|
|
|
{
|
2012-09-15 13:43:31 +00:00
|
|
|
public Dx10.Buffer NativeBuffer { get; protected set; }
|
|
|
|
|
2015-01-18 13:10:50 +00:00
|
|
|
#region Constructor
|
|
|
|
public DxIndexBuffer(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage)
|
|
|
|
{
|
|
|
|
elementSize = size;
|
|
|
|
GraphicsDeviceDX gd10 = graphics.NativeDevice as GraphicsDeviceDX;
|
|
|
|
Dx10.Device device = gd10 != null ? gd10.NativeDevice as Dx10.Device : null;
|
|
|
|
|
|
|
|
InitializeBuffer(device, size, indexCount, usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal DxIndexBuffer(Dx10.Device device, IndexElementSize size, int indexCount, BufferUsage usage)
|
|
|
|
{
|
|
|
|
elementSize = size;
|
|
|
|
InitializeBuffer(device, size, indexCount, usage);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region InitializeBuffer
|
|
|
|
private void InitializeBuffer(Dx10.Device device, IndexElementSize size, int indexCount, BufferUsage usage)
|
|
|
|
{
|
|
|
|
//TODO: translate and use usage
|
|
|
|
var description = new Dx10.BufferDescription()
|
|
|
|
{
|
|
|
|
Usage = Dx10.ResourceUsage.Dynamic,
|
|
|
|
SizeInBytes = GetSizeInBytes(indexCount),
|
|
|
|
BindFlags = Dx10.BindFlags.IndexBuffer,
|
|
|
|
CpuAccessFlags = Dx10.CpuAccessFlags.Write,
|
|
|
|
OptionFlags = Dx10.ResourceOptionFlags.None
|
|
|
|
};
|
|
|
|
|
|
|
|
NativeBuffer = new Dx10.Buffer(device, description);
|
|
|
|
//NativeBuffer.Unmap();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
protected DataStream MapBufferWrite()
|
|
|
|
{
|
|
|
|
return NativeBuffer.Map(Dx10.MapMode.WriteDiscard);
|
|
|
|
}
|
|
|
|
|
|
|
|
private SharpDX.DataStream MapBufferRead(Dx10.Buffer buffer)
|
|
|
|
{
|
|
|
|
return buffer.Map(Dx10.MapMode.Read);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void UnmapBuffer(Dx10.Buffer buffer)
|
|
|
|
{
|
|
|
|
buffer.Unmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void UnmapBuffer()
|
|
|
|
{
|
|
|
|
NativeBuffer.Unmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CopySubresource(Dx10.Buffer source, Dx10.Buffer destination)
|
|
|
|
{
|
|
|
|
BufferHelper.ValidateCopyResource(source, destination);
|
|
|
|
|
|
|
|
this.NativeBuffer.Device.CopyResource(source, destination);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Dx10.Buffer CreateStagingBuffer()
|
|
|
|
{
|
|
|
|
var description = new Dx10.BufferDescription()
|
|
|
|
{
|
|
|
|
Usage = Dx10.ResourceUsage.Staging,
|
|
|
|
SizeInBytes = NativeBuffer.Description.SizeInBytes,
|
|
|
|
CpuAccessFlags = Dx10.CpuAccessFlags.Read,
|
|
|
|
OptionFlags = Dx10.ResourceOptionFlags.None,
|
|
|
|
};
|
|
|
|
|
|
|
|
return new Dx10.Buffer(NativeBuffer.Device, description);
|
|
|
|
}
|
|
|
|
}
|
2011-11-16 14:27:53 +00:00
|
|
|
}
|