public static DX11IndexBuffer CreateImmutable(DxDevice device, uint[] initial, bool allowRawView = false) { BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = initial.Length * 4, Usage = ResourceUsage.Immutable }; if (allowRawView) { bd.BindFlags |= BindFlags.ShaderResource; bd.OptionFlags = ResourceOptionFlags.BufferAllowRawViews; } DX11IndexBuffer result; fixed(uint *ptr = &initial[0]) { result = new DX11IndexBuffer(device, initial.Length, bd, new IntPtr(ptr), true); } return(result); }
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 DX11IndexedGeometry CreateFrom <T>(DxDevice device, T[] vertices, int[] indices, InputElement[] layout) where T : struct { DX11IndexedGeometry geom = new DX11IndexedGeometry(device); geom.VertexBuffer = DX11VertexBuffer.CreateImmutable <T>(device, vertices); geom.IndexBuffer = DX11IndexBuffer.CreateImmutable(device, indices); geom.InputLayout = layout; geom.Topology = PrimitiveTopology.TriangleList; geom.HasBoundingBox = false; return(geom); }
public DX11IndexedGeometry(DX11IndexedGeometry owner) { this.ownsvbo = false; this.ownsido = false; this.device = owner.device; this.drawer = owner.drawer; this.IndexBuffer = owner.IndexBuffer; this.InputLayout = owner.InputLayout; this.Topology = owner.Topology; this.VertexBuffer = owner.VertexBuffer; }
public static DX11IndexBuffer CreateFromRawBuffer(DxDevice device, DX11RawBuffer rawbuffer) { if (!rawbuffer.Description.BindFlags.HasFlag(BindFlags.IndexBuffer)) { throw new ArgumentException("RawBuffer was not created with IndexBuffer bind flags"); } int indicescount = rawbuffer.Size / 4; DX11IndexBuffer result = new DX11IndexBuffer(device, indicescount, rawbuffer.Buffer); return(result); }
public DX11IndexedGeometry(DX11IndexedGeometry owner) { this.ownsvbo = false; this.ownsido = false; this.context = owner.context; this.drawer = owner.drawer; this.IndexBuffer = owner.IndexBuffer; this.InputLayout = owner.InputLayout; this.Topology = owner.Topology; this.VertexBuffer = owner.VertexBuffer; this.VertexSize = owner.VertexSize; this.VerticesCount = owner.VerticesCount; }
public static DX11IndexBuffer CreateImmutable(DxDevice device, short[] initial) { BufferDescription bd = new BufferDescription() { BindFlags = BindFlags.IndexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = initial.Length * 2, Usage = ResourceUsage.Immutable }; DX11IndexBuffer result; fixed(short *ptr = &initial[0]) { result = new DX11IndexBuffer(device, initial.Length, bd, new IntPtr(ptr), false); } return(result); }
public void Update(IPluginIO pin, DX11RenderContext context) { for (int i = 0; i < this.FOutput.SliceCount; i++) { if (this.FOutput[i].Contains(context)) { this.FOutput[i].Dispose(context); } } if (this.FBodies.SliceCount > 0) { int cnt = this.FBodies.SliceCount; for (int i = 0; i < cnt; i++) { SoftBody body = this.FBodies[i]; SoftBodyCustomData sc = (SoftBodyCustomData)body.UserObject; AlignedFaceArray faces = body.Faces; if (FValid[i]) { if (body.Faces.Count > 0) { #region Build from Faces DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VerticesCount = faces.Count*3; if (sc.HasUV) { geom.InputLayout = Pos3Norm3Tex2Vertex.Layout; geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize; } else { geom.InputLayout = Pos3Norm3Vertex.Layout; geom.VertexSize = Pos3Norm3Vertex.VertexSize; } //Mesh mesh = new Mesh(OnDevice, faces.Count, faces.Count * 3, MeshFlags.SystemMemory | MeshFlags.Use32Bit, decl); SlimDX.DataStream verts = new SlimDX.DataStream(geom.VerticesCount * geom.VertexSize*3, false, true); SlimDX.DataStream indices = new SlimDX.DataStream(faces.Count * sizeof(int)*3, false, true); int j; int uvcnt = 0; for (j = 0; j < faces.Count; j++) { NodePtrArray nodes = faces[j].N; verts.Write(nodes[0].X); verts.Write(nodes[0].Normal); //verts.Position += 12; if (sc.HasUV) { verts.Write(sc.UV[uvcnt]); uvcnt++; verts.Write(sc.UV[uvcnt]); uvcnt++; } verts.Write(nodes[1].X); verts.Write(nodes[1].Normal); //verts.Position += 12; if (sc.HasUV) { verts.Write(sc.UV[uvcnt]); uvcnt++; verts.Write(sc.UV[uvcnt]); uvcnt++; } verts.Write(nodes[2].X); verts.Write(nodes[2].Normal); //verts.Position += 12; if (sc.HasUV) { verts.Write(sc.UV[uvcnt]); uvcnt++; verts.Write(sc.UV[uvcnt]); uvcnt++; } indices.Write(j * 3); indices.Write(j * 3 + 1); indices.Write(j * 3 + 2); } geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, verts, false, true); geom.HasBoundingBox = false; DX11IndexBuffer ibo = new DX11IndexBuffer(context, indices,false,true); geom.IndexBuffer = ibo; this.FOutput[i][context] = geom; #endregion } } } } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.ibo == null) { uint[] faceIndices = faceModel.TriangleIndices.ToArray(); fixed (uint* uPtr = &faceIndices[0]) { DataStream ds = new DataStream(new IntPtr(uPtr), faceIndices.Length * 4, true, true); this.ibo = new DX11IndexBuffer(context, ds, false, false); } this.FOutGeom[0][context] = new DX11IndexOnlyGeometry(context); this.FOutGeom[0][context].IndexBuffer = this.ibo; } if (this.faceVertexBuffer == null) { this.faceVertexBuffer = new DX11DynamicStructuredBuffer<Vector3>(context, (int)FaceModel.VertexCount); this.FOutFaceVertices[0][context] = this.faceVertexBuffer; this.faceUVBuffer = new DX11DynamicStructuredBuffer<Vector2>(context, (int)FaceModel.VertexCount); this.FOutFaceUV[0][context] = this.faceUVBuffer; } if (this.FInvalidate) { fixed (CameraSpacePoint* cPtr = &this.cameraPoints[0]) { this.faceVertexBuffer.WriteData(new IntPtr(cPtr)); } fixed (ColorSpacePoint* cPtr = &this.colorPoints[0]) { this.faceUVBuffer.WriteData(new IntPtr(cPtr)); } this.FInvalidate = false; } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (!this.FTextureOutput[0].Contains(context)) { this.FTextureOutput[0][context] = new DX11DynamicTexture2D(context, this.width, this.height, SlimDX.DXGI.Format.R8G8B8A8_UNorm); this.FPCOut[0][context] = new DX11DynamicStructuredBuffer<float>(context, 640 * 480 * 6); } if (this.FInvalidate) { fixed (int* f = &this.pic[0]) { IntPtr ptr = new IntPtr(f); this.FTextureOutput[0][context].WriteData(ptr, this.width * this.height * 4); } /*fixed (float* f = &this.piccloud[0]) {* IntPtr ptr = new IntPtr(f);*/ DX11DynamicStructuredBuffer<float> db = (DX11DynamicStructuredBuffer<float>)this.FPCOut[0][context]; db.WriteData(this.piccloud); //} this.FInvalidate = false; } if (this.FInVoxels[0]) { if (this.FOutVoxels[0].Contains(context)) { this.FOutVoxels[0].Dispose(context); } short[] data = new short[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ]; this.colorVolume.ExportVolumeBlock(0, 0, 0, this.VoxelResolutionX, this.VoxelResolutionY, this.VoxelResolutionZ, 1, data); DX11DynamicStructuredBuffer<int> b = new DX11DynamicStructuredBuffer<int>(context, this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ); int[] idata = new int[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ]; for (int i = 0; i < this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ; i++) { idata[i] = data[i]; } b.WriteData(idata); this.FOutVoxels[0][context] = b; } if (this.FInExport[0]) { if (this.FGeomOut[0].Contains(context)) { this.FGeomOut[0].Dispose(context); } if (this.colorVolume != null) { ColorMesh m = this.colorVolume.CalculateMesh(this.FInGeomVoxelStep[0]); DX11IndexedGeometry geom = new DX11IndexedGeometry(context); ReadOnlyCollection<int> inds = m.GetTriangleIndexes(); DataStream ds = new DataStream(inds.Count*4,true,true); ds.WriteRange<int>(inds.ToArray()); ds.Position = 0; DX11IndexBuffer ibo = new DX11IndexBuffer(context, ds, false, true); ReadOnlyCollection<Microsoft.Kinect.Toolkit.Fusion.Vector3> pos = m.GetVertices(); ReadOnlyCollection<Microsoft.Kinect.Toolkit.Fusion.Vector3> norm = m.GetNormals(); ReadOnlyCollection<int> col = m.GetColors(); DataStream dsv = new DataStream(Pos3Norm3Vertex.VertexSize * pos.Count,true,true); SlimDX.Vector3 bmin = new SlimDX.Vector3(float.MaxValue, float.MaxValue, float.MaxValue); SlimDX.Vector3 bmax = new SlimDX.Vector3(float.MinValue, float.MinValue, float.MinValue); for (int i = 0; i < pos.Count; i++) { Microsoft.Kinect.Toolkit.Fusion.Vector3 p = pos[i]; Microsoft.Kinect.Toolkit.Fusion.Vector3 n = norm[i]; dsv.Write<Microsoft.Kinect.Toolkit.Fusion.Vector3>(p); dsv.Write<Microsoft.Kinect.Toolkit.Fusion.Vector3>(n); dsv.Write<int>(col[i]); if (p.X < bmin.X) { bmin.X = p.X; } if (p.Y < bmin.Y) { bmin.Y = p.Y; } if (p.Z < bmin.Z) { bmin.Z = p.Z; } if (p.X > bmax.X) { bmax.X = p.X; } if (p.Y > bmax.Y) { bmax.Y = p.Y; } if (p.Z > bmax.Z) { bmax.Z = p.Z; } } geom.IndexBuffer = ibo; geom.HasBoundingBox = true; geom.InputLayout = FusionColoredVertex.Layout; geom.Topology = SlimDX.Direct3D11.PrimitiveTopology.TriangleList; geom.VertexSize = FusionColoredVertex.VertexSize; geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, dsv, false, true); geom.VerticesCount = pos.Count; geom.BoundingBox = new BoundingBox(bmin, bmax); this.FGeomOut[0][context] = geom; m.Dispose(); } } }