Fixed Dx11 Vertex Buffer problem with some Textures not being drawn.
This commit is contained in:
parent
aa75450b34
commit
b3895055bd
@ -1,15 +1,7 @@
|
|||||||
#region Using Statements
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using ANX.Framework.NonXNA;
|
|
||||||
using SharpDX.Direct3D11;
|
|
||||||
using ANX.Framework.Graphics;
|
using ANX.Framework.Graphics;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using ANX.Framework.NonXNA.RenderSystem;
|
using ANX.Framework.NonXNA.RenderSystem;
|
||||||
|
using SharpDX.Direct3D11;
|
||||||
#endregion // Using Statements
|
|
||||||
|
|
||||||
// This file is part of the ANX.Framework created by the
|
// This file is part of the ANX.Framework created by the
|
||||||
// "ANX.Framework developer group" and released under the Ms-PL license.
|
// "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);
|
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);
|
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;
|
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;
|
GraphicsDeviceWindowsDX11 dx11GraphicsDevice = graphicsDevice.NativeDevice as GraphicsDeviceWindowsDX11;
|
||||||
DeviceContext context = dx11GraphicsDevice.NativeDevice;
|
DeviceContext context = dx11GraphicsDevice.NativeDevice;
|
||||||
|
|
||||||
//TODO: check offsetInBytes parameter for bounds etc.
|
//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.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)
|
if (startIndex > 0 || elementCount < data.Length)
|
||||||
{
|
{
|
||||||
for (int i = startIndex; i < startIndex + elementCount; i++)
|
for (int i = startIndex; i < startIndex + elementCount; i++)
|
||||||
{
|
{
|
||||||
vData.Write<T>(data[i]);
|
stream.Write<T>(data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vData.CopyTo(stream);
|
for (int i = 0; i < data.Length; i++)
|
||||||
}
|
{
|
||||||
context.UnmapSubresource(this.buffer, 0);
|
stream.Write<T>(data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pinnedArray.Free();
|
context.UnmapSubresource(this.buffer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct
|
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) where T : struct
|
||||||
|
Loading…
x
Reference in New Issue
Block a user