internal static VertexBufferId CreateVertexBuffer(BufferDescription description, int stride, IntPtr?data, string debugName) { if (description.SizeInBytes == 0) { return(VertexBufferId.NULL); } var id = new VertexBufferId { Index = VBuffers.Allocate() }; MyArrayHelpers.Reserve(ref VBuffersData, id.Index + 1); VBuffers.Data[id.Index] = new MyHwBufferDesc { Description = description, DebugName = debugName }; VBuffersData[id.Index] = new MyVertexBufferData { Stride = stride }; VbIndices.Add(id); if (!data.HasValue) { InitVertexBuffer(id); } else { InitVertexBuffer(id, data.Value); } return(id); }
internal static void InitVertexBuffer(VertexBufferId id, IntPtr data) { VBuffersData[id.Index].Buffer = new Buffer(MyRender11.Device, data, VBuffers.Data[id.Index].Description); if (VBuffers.Data[id.Index].DebugName != null) { VBuffersData[id.Index].Buffer.DebugName = VBuffers.Data[id.Index].DebugName; } }
internal static void Destroy(VertexBufferId id) { Debug.Assert(VbIndices.Contains(id)); VbIndices.Remove(id); if (VBuffersData[id.Index].Buffer != null) { VBuffersData[id.Index].Buffer.Dispose(); VBuffersData[id.Index].Buffer = null; } VBuffers.Free(id.Index); }
internal static void ResizeAndUpdateStaticVertexBuffer(ref VertexBufferId id, int capacity, int stride, IntPtr data, string debugName) { if (id == VertexBufferId.NULL) { id = CreateVertexBuffer(capacity, stride, data, debugName); } else { Debug.Assert(stride == id.Stride); if (id.Capacity != capacity) { VBuffersData[id.Index].Buffer.Dispose(); VBuffers.Data[id.Index].Description.SizeInBytes = VBuffersData[id.Index].Stride * capacity; InitVertexBuffer(id, data); } else { UpdateVertexBuffer(id, data); } } }
internal static BufferDescription GetBufferDesc(VertexBufferId id) { return(VBuffers.Data[id.Index].Description); }
internal static int GetVertexBufferCapacity(VertexBufferId id) { return(VBuffers.Data[id.Index].Description.SizeInBytes / VBuffersData[id.Index].Stride); }
internal static int GetVertexBufferStride(VertexBufferId id) { return(VBuffersData[id.Index].Stride); }
internal static Buffer GetVertexBuffer(VertexBufferId id) { return(VBuffersData[id.Index].Buffer); }
internal static void UpdateVertexBuffer(VertexBufferId id, IntPtr data) { MyRender11.RC.UpdateSubresource(new DataBox(data), VBuffersData[id.Index].Buffer); }
internal static void ResizeVertexBuffer(VertexBufferId id, int size) { VBuffersData[id.Index].Buffer.Dispose(); VBuffers.Data[id.Index].Description.SizeInBytes = VBuffersData[id.Index].Stride * size; InitVertexBuffer(id); }