private static int convertUsage(VertexBufferUsage usage) { int glUsage = (int)BufferUsageHint.StaticDraw; if (usage == VertexBufferUsage.Stream) { glUsage = (int)BufferUsageHint.StreamDraw; } else if (usage == VertexBufferUsage.Dynamic) { glUsage = (int)BufferUsageHint.DynamicDraw; } return(glUsage); }
internal static GlVertexBuffer CreateBuffer <T>(VertexBufferUsage usage, T[] data, int numVertices, VertexElementSet vertexElements) where T : struct { GlVertexBuffer buffer = new GlVertexBuffer(); buffer._declaration = vertexElements; buffer._numVertices = numVertices; buffer._usage = usage; GL.GenBuffers(1, out buffer._buffer); GL.BindBuffer(BufferTarget.ArrayBuffer, buffer._buffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(numVertices * vertexElements.Stride), data, (BufferUsageHint)convertUsage(usage)); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); return(buffer); }
internal static Direct3D9VertexBuffer CreateBuffer <T>(VertexBufferUsage usage, SharpDX.Direct3D9.Device device, T[] data, int numVertices, VertexElementSet vertexElements) where T : struct { Direct3D9VertexBuffer buffer = new Direct3D9VertexBuffer(); buffer._declaration = vertexElements; buffer._numVertices = numVertices; buffer._buffer = new SharpDX.Direct3D9.VertexBuffer(device, numVertices * vertexElements.Stride, SharpDX.Direct3D9.Usage.WriteOnly, VertexFormat.None, Pool.Managed); buffer._usage = usage; if (data != null) { SharpDX.DataStream ds = buffer._buffer.Lock(0, numVertices * vertexElements.Stride, LockFlags.None); for (int i = 0; i < data.Length; i++) { ds.Write(data[i]); } buffer._buffer.Unlock(); } return(buffer); }
public VertexBuffer CreateVertexBuffer <T>(VertexBufferUsage usage, T[] data, int numVertices, VertexElementSet declaration) where T : struct { return(Direct3D9VertexBuffer.CreateBuffer(usage, _device, data, numVertices, declaration)); }
public VertexBuffer(VertexBufferUsage usage = VertexBufferUsage.BUFFER_STATIC) { this._usage = usage; _id = (uint)GL.GenBuffer(); }