public static DX11IndexBuffer FromReference(DX11RenderContext context, SlimDX.Direct3D11.Buffer bufferRef, int elementCount) { DX11IndexBuffer ibo = new DX11IndexBuffer(context); ibo.Buffer = bufferRef; ibo.IndicesCount = elementCount; ibo.isOwner = false; return(ibo); }
public static Buffer CreateDynamicVertexBuffer(DX11RenderContext context, int size) { var vertices = new SlimDX.Direct3D11.Buffer(context.Device, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = size, Usage = ResourceUsage.Dynamic }); return vertices; }
public static Buffer CreateDynamicVertexBuffer(DX11RenderContext context, int size) { var vertices = new SlimDX.Direct3D11.Buffer(context.Device, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = size, Usage = ResourceUsage.Dynamic }); return(vertices); }
public static Buffer CreateStreamOutBuffer(DX11RenderContext context, int vertexsize, int maxelements) { //Create a stream out buffer (no init data, but also allow to bind as SO //Allow access as raw if possible Buffer buffer = new SlimDX.Direct3D11.Buffer(context.Device, new BufferDescription() { BindFlags = BindFlags.VertexBuffer | BindFlags.StreamOutput | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = context.ComputeShaderSupport ? ResourceOptionFlags.RawBuffer : ResourceOptionFlags.None, SizeInBytes = vertexsize * maxelements, Usage = ResourceUsage.Default }); return buffer; }
public static Buffer CreateDynamicVertexBuffer(DX11RenderContext context, DataStream ds, bool dispose = false) { ds.Position = 0; var vertices = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Dynamic }); if (dispose) { ds.Dispose(); } return vertices; }
public static Buffer CreateDynamicVertexBuffer(DX11RenderContext context, DataStream ds, bool dispose = false) { ds.Position = 0; var vertices = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Dynamic }); if (dispose) { ds.Dispose(); } return(vertices); }
public static DX11IndexedGeometry CreateFrom <T>(DX11RenderContext context, T[] vertices, int[] indices, InputElement[] layout) where T : struct { int vertexsize = Marshal.SizeOf(typeof(T)); DX11IndexedGeometry geom = new DX11IndexedGeometry(context); DataStream ds = new DataStream(vertices.Length * vertexsize, true, true); ds.Position = 0; ds.WriteRange(vertices); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(indices.Length * 4, true, true); indexstream.WriteRange(indices); indexstream.Position = 0; geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vertices.Length; geom.VertexSize = vertexsize; geom.HasBoundingBox = false; // geom.BoundingBox = new BoundingBox(new Vector3(-radius), new Vector3(radius)); return(geom); }
public static Buffer CreateStreamOutBuffer(DX11RenderContext context, int vertexsize, int maxelements, bool allowvbo = true, bool allowibo = false) { BindFlags flags = BindFlags.StreamOutput; //Flag as raw if possible //flags |= context.ComputeShaderSupport ? BindFlags.UnorderedAccess : BindFlags.None; flags |= context.ComputeShaderSupport ? BindFlags.ShaderResource : BindFlags.None; flags |= allowvbo ? BindFlags.VertexBuffer : BindFlags.None; flags |= allowibo ? BindFlags.IndexBuffer : BindFlags.None; //Allow access as raw if possible Buffer buffer = new SlimDX.Direct3D11.Buffer(context.Device, new BufferDescription() { BindFlags = flags, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = context.ComputeShaderSupport ? ResourceOptionFlags.RawBuffer : ResourceOptionFlags.None, SizeInBytes = vertexsize * maxelements, Usage = ResourceUsage.Default }); return buffer; }
public static Buffer CreateStreamOutBuffer(DX11RenderContext context, int vertexsize, int maxelements, bool allowvbo = true, bool allowibo = false) { BindFlags flags = BindFlags.StreamOutput; //Flag as raw if possible //flags |= context.ComputeShaderSupport ? BindFlags.UnorderedAccess : BindFlags.None; flags |= context.ComputeShaderSupport ? BindFlags.ShaderResource : BindFlags.None; flags |= allowvbo ? BindFlags.VertexBuffer : BindFlags.None; flags |= allowibo ? BindFlags.IndexBuffer : BindFlags.None; //Allow access as raw if possible Buffer buffer = new SlimDX.Direct3D11.Buffer(context.Device, new BufferDescription() { BindFlags = flags, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = context.ComputeShaderSupport ? ResourceOptionFlags.RawBuffer : ResourceOptionFlags.None, SizeInBytes = vertexsize * maxelements, Usage = ResourceUsage.Default }); return(buffer); }