67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
using System;
|
|
using ANX.BaseDirectX;
|
|
using ANX.Framework.Graphics;
|
|
using ANX.Framework.NonXNA.RenderSystem;
|
|
using SharpDX;
|
|
using Dx10 = SharpDX.Direct3D10;
|
|
|
|
// 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
|
|
|
|
namespace ANX.RenderSystem.Windows.DX10
|
|
{
|
|
public class IndexBuffer_DX10 : BaseIndexBuffer<Dx10.Buffer>, INativeIndexBuffer, IDisposable
|
|
{
|
|
#region Constructor
|
|
public IndexBuffer_DX10(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage)
|
|
{
|
|
elementSize = size;
|
|
GraphicsDeviceWindowsDX10 gd10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
|
|
Dx10.Device device = gd10 != null ? gd10.NativeDevice as Dx10.Device : null;
|
|
|
|
InitializeBuffer(device, size, indexCount, usage);
|
|
}
|
|
|
|
internal IndexBuffer_DX10(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 override DataStream MapBufferWrite()
|
|
{
|
|
return NativeBuffer.Map(Dx10.MapMode.WriteDiscard);
|
|
}
|
|
|
|
protected override DataStream MapBufferRead()
|
|
{
|
|
return NativeBuffer.Map(Dx10.MapMode.Read);
|
|
}
|
|
|
|
protected override void UnmapBuffer()
|
|
{
|
|
NativeBuffer.Unmap();
|
|
}
|
|
}
|
|
}
|