Пример #1
0
        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);
        }
Пример #2
0
 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;
     }
 }
Пример #3
0
 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);
 }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
 internal static BufferDescription GetBufferDesc(VertexBufferId id)
 {
     return(VBuffers.Data[id.Index].Description);
 }
Пример #6
0
 internal static int GetVertexBufferCapacity(VertexBufferId id)
 {
     return(VBuffers.Data[id.Index].Description.SizeInBytes / VBuffersData[id.Index].Stride);
 }
Пример #7
0
 internal static int GetVertexBufferStride(VertexBufferId id)
 {
     return(VBuffersData[id.Index].Stride);
 }
Пример #8
0
 internal static Buffer GetVertexBuffer(VertexBufferId id)
 {
     return(VBuffersData[id.Index].Buffer);
 }
Пример #9
0
 internal static void UpdateVertexBuffer(VertexBufferId id, IntPtr data)
 {
     MyRender11.RC.UpdateSubresource(new DataBox(data), VBuffersData[id.Index].Buffer);
 }
Пример #10
0
 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);
 }