implemented DrawUserPrimitives for RenderSystem DX10 and DX11 (currently untested)

This commit is contained in:
Glatzemann 2012-01-09 18:09:10 +00:00
parent d982acdbfe
commit 060b732d1b
4 changed files with 46 additions and 11 deletions

View File

@ -334,7 +334,15 @@ namespace ANX.Framework.Windows.DX10
#region DrawUserPrimitives<T>
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
int vertexCount = vertexData.Length;
VertexBuffer_DX10 vb10 = new VertexBuffer_DX10(this.device, vertexDeclaration, vertexCount, BufferUsage.None);
vb10.SetData<T>(null, vertexData);
SharpDX.Direct3D10.VertexBufferBinding nativeVertexBufferBindings = new SharpDX.Direct3D10.VertexBufferBinding(vb10.NativeBuffer, vertexDeclaration.VertexStride, 0);
device.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
DrawPrimitives(primitiveType, vertexOffset, primitiveCount);
}
#endregion // DrawUserPrimitives<T>

View File

@ -65,13 +65,23 @@ namespace ANX.Framework.Windows.DX10
int vertexStride;
public VertexBuffer_DX10(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
{
GraphicsDeviceWindowsDX10 gd10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = gd10 != null ? gd10.NativeDevice as SharpDX.Direct3D10.Device : null;
InitializeBuffer(device, vertexDeclaration, vertexCount, usage);
}
internal VertexBuffer_DX10(SharpDX.Direct3D10.Device device, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
{
InitializeBuffer(device, vertexDeclaration, vertexCount, usage);
}
private void InitializeBuffer(SharpDX.Direct3D10.Device device, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
{
this.vertexStride = vertexDeclaration.VertexStride;
//TODO: translate and use usage
GraphicsDeviceWindowsDX10 gd10 = graphics.NativeDevice as GraphicsDeviceWindowsDX10;
SharpDX.Direct3D10.Device device = gd10 != null ? gd10.NativeDevice as SharpDX.Direct3D10.Device : null;
if (device != null)
{

View File

@ -338,7 +338,15 @@ namespace ANX.RenderSystem.Windows.DX11
#region DrawUserPrimitives<T>
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
int vertexCount = vertexData.Length;
VertexBuffer_DX11 vb11 = new VertexBuffer_DX11(this.deviceContext.Device, vertexDeclaration, vertexCount, BufferUsage.None);
vb11.SetData<T>(null, vertexData);
SharpDX.Direct3D11.VertexBufferBinding nativeVertexBufferBindings = new SharpDX.Direct3D11.VertexBufferBinding(vb11.NativeBuffer, vertexDeclaration.VertexStride, 0);
deviceContext.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
DrawPrimitives(primitiveType, vertexOffset, primitiveCount);
}
#endregion // DrawUserPrimitives<T>

View File

@ -65,15 +65,25 @@ namespace ANX.RenderSystem.Windows.DX11
int vertexStride;
public VertexBuffer_DX11(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
{
GraphicsDeviceWindowsDX11 gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11;
SharpDX.Direct3D11.DeviceContext context = gd11 != null ? gd11.NativeDevice as SharpDX.Direct3D11.DeviceContext : null;
InitializeBuffer(context.Device, vertexDeclaration, vertexCount, usage);
}
internal VertexBuffer_DX11(SharpDX.Direct3D11.Device device, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
{
InitializeBuffer(device, vertexDeclaration, vertexCount, usage);
}
private void InitializeBuffer(SharpDX.Direct3D11.Device device, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
{
this.vertexStride = vertexDeclaration.VertexStride;
//TODO: translate and use usage
GraphicsDeviceWindowsDX11 gd11 = graphics.NativeDevice as GraphicsDeviceWindowsDX11;
SharpDX.Direct3D11.DeviceContext context = gd11 != null ? gd11.NativeDevice as SharpDX.Direct3D11.DeviceContext : null;
if (context != null)
if (device != null)
{
BufferDescription description = new BufferDescription()
{
@ -84,8 +94,7 @@ namespace ANX.RenderSystem.Windows.DX11
OptionFlags = ResourceOptionFlags.None
};
this.buffer = new SharpDX.Direct3D11.Buffer(context.Device, description);
//this.buffer.Unmap();
this.buffer = new SharpDX.Direct3D11.Buffer(device, description);
}
}