Пример #1
0
        public unsafe VertexBuffer CreateImmutableBuffer(T[] data, int offset = 0, int length = -1)
        {
            int realLength       = length == -1 ? data.Length - offset : length;
            BufferDescription bd = new BufferDescription()
            {
                ByteWidth           = (uint)(_Size * realLength),
                Usage               = 0, //default
                BindFlags           = 1, //vertexbuffer
                CPUAccessFlags      = 0, //none. or write (65536)
                MiscFlags           = 0,
                StructureByteStride = (uint)_Size
            };

            fixed(T *pData = &data[offset])
            {
                DataBox box = new DataBox
                {
                    DataPointer = pData,
                    RowPitch    = 0,
                    SlicePitch  = 0,
                };

                using (var vb = new ComScopeGuard())
                {
                    Device.CreateBuffer(_device.DevicePtr, &bd, &box, out vb.Ptr).Check();
                    return(new VertexBuffer(_device, _bufferUpdate, vb.Move(), _inputLayout.AddRef(), _Size, realLength, false));
                }
            }
        }