Fixed Dx11 Vertex Buffer problem with some Textures not being drawn.

This commit is contained in:
SND\AstrorEnales_cp 2012-08-29 18:56:51 +00:00
parent aa75450b34
commit b3895055bd

View File

@ -1,15 +1,7 @@
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANX.Framework.NonXNA;
using SharpDX.Direct3D11;
using ANX.Framework.Graphics;
using System.Runtime.InteropServices;
using ANX.Framework.NonXNA.RenderSystem;
#endregion // Using Statements
using SharpDX.Direct3D11;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -30,12 +22,14 @@ namespace ANX.RenderSystem.Windows.DX11
InitializeBuffer(context.Device, vertexDeclaration, vertexCount, usage);
}
internal VertexBuffer_DX11(SharpDX.Direct3D11.Device device, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage 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)
private void InitializeBuffer(SharpDX.Direct3D11.Device device, VertexDeclaration vertexDeclaration, int vertexCount,
BufferUsage usage)
{
this.vertexStride = vertexDeclaration.VertexStride;
@ -56,45 +50,32 @@ namespace ANX.RenderSystem.Windows.DX11
}
}
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes, T[] data, int startIndex, int elementCount)
where T : struct
{
GraphicsDeviceWindowsDX11 dx11GraphicsDevice = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
DeviceContext context = dx11GraphicsDevice.NativeDevice;
//TODO: check offsetInBytes parameter for bounds etc.
GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
IntPtr dataPointer = pinnedArray.AddrOfPinnedObject();
int dataLength = Marshal.SizeOf(typeof(T)) * data.Length;
unsafe
{
using (var vData = new SharpDX.DataStream(dataPointer, dataLength, true, true))
{
if (offsetInBytes > 0)
{
vData.Seek(offsetInBytes / vertexStride, System.IO.SeekOrigin.Begin);
}
SharpDX.DataStream stream;
SharpDX.DataBox box = context.MapSubresource(this.buffer, MapMode.WriteDiscard, MapFlags.None, out stream);
context.MapSubresource(this.buffer, MapMode.WriteDiscard, MapFlags.None, out stream);
if (startIndex > 0 || elementCount < data.Length)
{
for (int i = startIndex; i < startIndex + elementCount; i++)
{
vData.Write<T>(data[i]);
stream.Write<T>(data[i]);
}
}
else
{
vData.CopyTo(stream);
}
context.UnmapSubresource(this.buffer, 0);
for (int i = 0; i < data.Length; i++)
{
stream.Write<T>(data[i]);
}
}
pinnedArray.Free();
context.UnmapSubresource(this.buffer, 0);
}
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct