// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; namespace SharpDX.Direct3D11 { public partial class Buffer { /// /// Initializes a new instance of the class. /// /// The device with which to associate the buffer. /// The description of the buffer. /// ff476501 /// HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer) /// ID3D11Device::CreateBuffer public Buffer(Device device, BufferDescription description) : base(IntPtr.Zero) { device.CreateBuffer(ref description, null, this); } /// /// Initializes a new instance of the class. /// /// The device with which to associate the buffer. /// Initial data used to initialize the buffer. /// The description of the buffer. /// ff476501 /// HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer) /// ID3D11Device::CreateBuffer public Buffer(Device device, DataStream data, BufferDescription description) : base(IntPtr.Zero) { device.CreateBuffer(ref description, new DataBox(data.PositionPointer, 0, 0), this); } /// /// Initializes a new instance of the class. /// /// The device with which to associate the buffer. /// The data pointer. /// The description of the buffer. /// ff476501 /// HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer) /// ID3D11Device::CreateBuffer public Buffer(Device device, IntPtr dataPointer, BufferDescription description) : base(IntPtr.Zero) { device.CreateBuffer(ref description, dataPointer != IntPtr.Zero ? new DataBox(dataPointer, 0, 0) : (DataBox?)null, this); } /// /// Initializes a new instance of the class. /// /// The device with which to associate the buffer. /// The size, in bytes, of the buffer. /// The usage pattern for the buffer. /// Flags specifying how the buffer will be bound to the pipeline. /// Flags specifying how the buffer will be accessible from the CPU. /// Miscellaneous resource options. /// The size (in bytes) of the structure element for structured buffers. /// ff476501 /// HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer) /// ID3D11Device::CreateBuffer public Buffer(Device device, int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags accessFlags, ResourceOptionFlags optionFlags, int structureByteStride) : base(IntPtr.Zero) { var description = new BufferDescription() { BindFlags = bindFlags, CpuAccessFlags = accessFlags, OptionFlags = optionFlags, SizeInBytes = sizeInBytes, Usage = usage, StructureByteStride = structureByteStride }; device.CreateBuffer(ref description, null, this); } /// /// Initializes a new instance of the class. /// /// The device with which to associate the buffer. /// Initial data used to initialize the buffer. /// The size, in bytes, of the buffer. /// The usage pattern for the buffer. /// Flags specifying how the buffer will be bound to the pipeline. /// Flags specifying how the buffer will be accessible from the CPU. /// Miscellaneous resource options. /// The size (in bytes) of the structure element for structured buffers. /// ff476501 /// HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer) /// ID3D11Device::CreateBuffer public Buffer(Device device, DataStream data, int sizeInBytes, ResourceUsage usage, BindFlags bindFlags, CpuAccessFlags accessFlags, ResourceOptionFlags optionFlags, int structureByteStride) : base(IntPtr.Zero) { var description = new BufferDescription() { BindFlags = bindFlags, CpuAccessFlags = accessFlags, OptionFlags = optionFlags, SizeInBytes = sizeInBytes, Usage = usage, StructureByteStride = structureByteStride }; device.CreateBuffer(ref description, new DataBox(data.PositionPointer, 0, 0), this); } /// /// Creates a new instance of the class. /// /// Type of the data to upload /// The device with which to associate the buffer. /// Flags specifying how the buffer will be bound to the pipeline. /// Initial data used to initialize the buffer. /// The size, in bytes, of the buffer. If 0 is specified, sizeof(T) is used. /// The usage pattern for the buffer. /// Flags specifying how the buffer will be accessible from the CPU. /// Miscellaneous resource options. /// The size (in bytes) of the structure element for structured buffers. /// An initialized buffer /// ff476501 /// HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer) /// ID3D11Device::CreateBuffer public static Buffer Create( Device device, BindFlags bindFlags, ref T data, int sizeInBytes = 0, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags accessFlags = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, int structureByteStride = 0) where T : struct { var buffer = new Buffer(IntPtr.Zero); var description = new BufferDescription() { BindFlags = bindFlags, CpuAccessFlags = accessFlags, OptionFlags = optionFlags, SizeInBytes = sizeInBytes == 0 ? Utilities.SizeOf() : sizeInBytes, Usage = usage, StructureByteStride = structureByteStride }; unsafe { device.CreateBuffer(ref description, new DataBox((IntPtr)Interop.Fixed(ref data)), buffer); } return buffer; } /// /// Creates a new instance of the class. /// /// Type of the data to upload /// The device with which to associate the buffer. /// Flags specifying how the buffer will be bound to the pipeline. /// Initial data used to initialize the buffer. /// The size, in bytes, of the buffer. If 0 is specified, sizeof(T) * data.Length is used. /// The usage pattern for the buffer. /// Flags specifying how the buffer will be accessible from the CPU. /// Miscellaneous resource options. /// The size (in bytes) of the structure element for structured buffers. /// An initialized buffer /// ff476501 /// HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer) /// ID3D11Device::CreateBuffer public static Buffer Create(Device device, BindFlags bindFlags, T[] data, int sizeInBytes = 0, ResourceUsage usage = ResourceUsage.Default, CpuAccessFlags accessFlags = CpuAccessFlags.None, ResourceOptionFlags optionFlags = ResourceOptionFlags.None, int structureByteStride = 0) where T : struct { var buffer = new Buffer(IntPtr.Zero); var description = new BufferDescription() { BindFlags = bindFlags, CpuAccessFlags = accessFlags, OptionFlags = optionFlags, SizeInBytes = sizeInBytes == 0 ? Utilities.SizeOf() * data.Length : sizeInBytes, Usage = usage, StructureByteStride = structureByteStride }; unsafe { device.CreateBuffer(ref description, new DataBox((IntPtr)Interop.Fixed(data)), buffer); } return buffer; } /// /// Creates a new instance of the class. /// /// Type of the data to upload /// The device with which to associate the buffer. /// Initial data used to initialize the buffer. /// The description. /// /// An initialized buffer /// /// /// If the is at 0, sizeof(T) is used. /// /// ff476501 /// HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer) /// ID3D11Device::CreateBuffer public static Buffer Create(Device device, ref T data, BufferDescription description) where T : struct { var buffer = new Buffer(IntPtr.Zero); unsafe { if (description.SizeInBytes == 0) description.SizeInBytes = Utilities.SizeOf(); device.CreateBuffer(ref description, new DataBox((IntPtr)Interop.Fixed(ref data)), buffer); } return buffer; } /// /// Creates a new instance of the class. /// /// Type of the data to upload /// The device with which to associate the buffer. /// Initial data used to initialize the buffer. /// The description. /// /// An initialized buffer /// /// /// If the is at 0, sizeof(T) * data.Length is used. /// /// ff476501 /// HRESULT ID3D11Device::CreateBuffer([In] const D3D11_BUFFER_DESC* pDesc,[In, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Buffer** ppBuffer) /// ID3D11Device::CreateBuffer public static Buffer Create(Device device, T[] data, BufferDescription description) where T : struct { var buffer = new Buffer(IntPtr.Zero); unsafe { if (description.SizeInBytes == 0) description.SizeInBytes = Utilities.SizeOf() * data.Length; device.CreateBuffer(ref description, new DataBox((IntPtr)Interop.Fixed(data)), buffer); } return buffer; } } }