Implemented all IndexBufferGL3 and VertexBufferGL3 SetData and GetData methods.

This commit is contained in:
SND\AstrorEnales_cp 2012-02-20 19:46:06 +00:00
parent a2dda0ffa2
commit 139e73d432
2 changed files with 137 additions and 38 deletions

View File

@ -188,25 +188,6 @@ namespace ANX.Framework.Windows.GL3
}
#endregion
#region GetData (TODO)
public void GetData<T>(int offsetInBytes, T[] data, int startIndex,
int elementCount) where T : struct
{
throw new NotImplementedException();
}
public void GetData<T>(T[] data) where T : struct
{
throw new NotImplementedException();
}
public void GetData<T>(T[] data, int startIndex, int elementCount)
where T : struct
{
throw new NotImplementedException();
}
#endregion
#region BufferData (private helper)
private void BufferData<T>(T[] data, int offset) where T : struct
{
@ -240,6 +221,64 @@ namespace ANX.Framework.Windows.GL3
}
#endregion
#region GetData
public void GetData<T>(T[] data) where T : struct
{
BufferData(data, 0);
}
#endregion
#region GetData
public void GetData<T>(T[] data, int startIndex, int elementCount)
where T : struct
{
if (startIndex != 0 ||
elementCount != data.Length)
{
T[] subArray = new T[elementCount];
Array.Copy(data, startIndex, subArray, 0, elementCount);
BufferData(subArray, 0);
}
else
{
BufferData(data, 0);
}
}
#endregion
#region GetData
public void GetData<T>(int offsetInBytes, T[] data, int startIndex,
int elementCount) where T : struct
{
if (startIndex != 0 ||
elementCount != data.Length)
{
T[] subArray = new T[elementCount];
Array.Copy(data, startIndex, subArray, 0, elementCount);
BufferData(subArray, offsetInBytes);
}
else
{
BufferData(data, offsetInBytes);
}
}
#endregion
#region GetBufferData (private helper)
private void GetBufferData<T>(T[] data, int offset) where T : struct
{
int size = (elementSize == IndexElementSize.SixteenBits ?
2 : 4) * data.Length;
GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferHandle);
ErrorHelper.Check("BindBuffer");
GL.GetBufferSubData(BufferTarget.ElementArrayBuffer, (IntPtr)offset,
(IntPtr)size, data);
ErrorHelper.Check("GetBufferSubData");
}
#endregion
#region Dispose
/// <summary>
/// Dispose the native index buffer data.

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
using ANX.Framework.Graphics;
using ANX.Framework.NonXNA.RenderSystem;
using ANX.Framework.Windows.GL3.Helpers;
@ -191,37 +192,41 @@ namespace ANX.Framework.Windows.GL3
}
#endregion
#region SetData (TODO)
#region SetData
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes,
T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
{
throw new NotImplementedException();
}
#endregion
T[] elements;
if (startIndex != 0 ||
elementCount != data.Length)
{
elements = new T[elementCount];
Array.Copy(data, startIndex, elements, 0, elementCount);
}
else
{
elements = data;
}
#region GetData (TODO)
public void GetData<T>(int offsetInBytes, T[] data, int startIndex,
int elementCount, int vertexStride) where T : struct
{
throw new NotImplementedException();
}
int size = Marshal.SizeOf(typeof(T));
public void GetData<T>(T[] data) where T : struct
{
throw new NotImplementedException();
}
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
ErrorHelper.Check("BindBuffer");
public void GetData<T>(T[] data, int startIndex, int elementCount)
where T : struct
{
throw new NotImplementedException();
for (int index = 0; index < elementCount; index++)
{
GL.BufferSubData<T>(BufferTarget.ArrayBuffer,
(IntPtr)offsetInBytes + (index * vertexStride),
(IntPtr)size, ref elements[index]);
ErrorHelper.Check("BufferSubData");
}
}
#endregion
#region BufferData (private helper)
private void BufferData<T>(T[] data, int offset) where T : struct
{
int size = vertexDeclaration.VertexStride * data.Length;
int size = Marshal.SizeOf(typeof(T)) * data.Length;
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
ErrorHelper.Check("BindBuffer");
@ -232,6 +237,61 @@ namespace ANX.Framework.Windows.GL3
}
#endregion
#region GetData
public void GetData<T>(T[] data) where T : struct
{
int size = Marshal.SizeOf(typeof(T)) * data.Length;
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
ErrorHelper.Check("BindBuffer");
GL.GetBufferSubData<T>(BufferTarget.ArrayBuffer, IntPtr.Zero,
(IntPtr)size, data);
ErrorHelper.Check("GetBufferSubData");
}
#endregion
#region GetData
public void GetData<T>(T[] data, int startIndex, int elementCount)
where T : struct
{
T[] copyElements = new T[elementCount];
int size = Marshal.SizeOf(typeof(T)) * elementCount;
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
ErrorHelper.Check("BindBuffer");
GL.GetBufferSubData<T>(BufferTarget.ArrayBuffer, (IntPtr)0,
(IntPtr)size, copyElements);
ErrorHelper.Check("GetBufferSubData");
Array.Copy(copyElements, 0, data, startIndex, elementCount);
}
#endregion
#region GetData
public void GetData<T>(int offsetInBytes, T[] data, int startIndex,
int elementCount, int vertexStride) where T : struct
{
T[] copyElements = new T[elementCount];
int size = Marshal.SizeOf(typeof(T));
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
ErrorHelper.Check("BindBuffer");
for (int index = 0; index < elementCount; index++)
{
GL.GetBufferSubData<T>(BufferTarget.ArrayBuffer,
(IntPtr)offsetInBytes + (index * vertexStride),
(IntPtr)size,
ref copyElements[index]);
ErrorHelper.Check("GetBufferSubData");
}
Array.Copy(copyElements, 0, data, startIndex, elementCount);
}
#endregion
#region MapVertexDeclaration
internal void MapVertexDeclaration(EffectGL3 effect)
{