当前位置: 首页>>代码示例>>C#>>正文


C# IndexBuffer.Dispose方法代码示例

本文整理汇总了C#中IndexBuffer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IndexBuffer.Dispose方法的具体用法?C# IndexBuffer.Dispose怎么用?C# IndexBuffer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IndexBuffer的用法示例。


在下文中一共展示了IndexBuffer.Dispose方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Dispose

 /// <summary>
 /// Dispose
 /// </summary>
 /// <param name="someObject">Some object</param>
 public static void Dispose(ref IndexBuffer someObject)
 {
     if (someObject != null)
         someObject.Dispose();
     someObject = null;
 }
开发者ID:kiichi7,项目名称:XnaTetris,代码行数:10,代码来源:DisposeHelper.cs

示例2: DrawFurcationTriangle

		private void DrawFurcationTriangle(float tipx,float tipy,bool pointUp,Matrix lineMat,int furcationValue) {
			const float triSideLenMM=2f;
			float sign=pointUp?1:-1;
			Color color=GetFurcationColor(furcationValue);
			List<Vector3> triPoints=new List<Vector3>();
			//We form an equilateral triangle.
			triPoints.Add(new Vector3(tipx+triSideLenMM/2f,tipy+sign*((float)(triSideLenMM*Math.Sqrt(3)/2f)),0));
			triPoints.Add(new Vector3(tipx,tipy,0));
			triPoints.Add(new Vector3(tipx-triSideLenMM/2f,tipy+sign*((float)(triSideLenMM*Math.Sqrt(3)/2f)),0));
			if(furcationValue==1) {
				DrawExtended3dLine(new Vector3[] { triPoints[0],triPoints[1],triPoints[2] },0.1f,false,color,2f,lineMat);
			} else if(furcationValue==2) {
				DrawExtended3dLine(new Vector3[] { triPoints[0],triPoints[1],triPoints[2],triPoints[0] },0.1f,true,color,2f,lineMat);
			} else if(furcationValue==3) {
				DrawExtended3dLine(new Vector3[] { triPoints[0],triPoints[1],triPoints[2],triPoints[0] },0.1f,true,color,2f,lineMat);
				VertexBuffer triVb=null;
				IndexBuffer triIb=null;
				try{
					CustomVertex.PositionColored[] solidTriVerts=new CustomVertex.PositionColored[] {
									new CustomVertex.PositionColored(triPoints[0],color.ToArgb()),
									new CustomVertex.PositionColored(triPoints[1],color.ToArgb()),
									new CustomVertex.PositionColored(triPoints[2],color.ToArgb()),
								};
					triVb=new VertexBuffer(typeof(CustomVertex.PositionColored),
						CustomVertex.PositionColored.StrideSize*solidTriVerts.Length,
						device,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
					triVb.SetData(solidTriVerts,0,LockFlags.None);
					int[] triIndicies=new int[] { 0,1,2 };
					triIb=new IndexBuffer(typeof(int),triIndicies.Length,device,Usage.None,Pool.Managed);
					triIb.SetData(triIndicies,0,LockFlags.None);
					device.VertexFormat=CustomVertex.PositionColored.Format;
					device.SetStreamSource(0,triVb,0);
					device.Indices=triIb;
					device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,solidTriVerts.Length,0,triIndicies.Length/3);
				}finally{
					if(triVb!=null){
						triVb.Dispose();
						triVb=null;
					}
					if(triIb!=null){
						triIb.Dispose();
					}
				}
			} else {
				//invalid value. assume no furcation.
			}
		}
开发者ID:mnisl,项目名称:OD,代码行数:47,代码来源:ToothChartDirectX.cs

示例3: CollectGeometry

        private void CollectGeometry(bool enabled, ref VertexBuffer vertexBuffer, ref IndexBuffer indexBuffer)
        {
            // Clear the buffers first.
            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
                vertexBuffer = null;
            }
            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
                indexBuffer = null;
            }

            // Collect the vertices and indices.
            var vertices = new List<Vector2>();
            var indices = new List<ushort>();

            Root.CollectGeometry(vertices, indices, enabled);

            // Create the hardware resources.
            if (vertices.Count > 0 && indices.Count > 0)
            {
                vertexBuffer = new VertexBuffer(_graphics, VertexPositionColorTexture.VertexDeclaration, vertices.Count, BufferUsage.None);
                vertexBuffer.SetData(vertices.Select(e => new VertexPositionColorTexture
                {
                    Position = new Vector3(e, 0.0f),
                    Color = Color.White,
                    TextureCoordinate = e / _size

                }).ToArray());

                indexBuffer = new IndexBuffer(_graphics, IndexElementSize.SixteenBits, indices.Count, BufferUsage.None);
                indexBuffer.SetData(indices.ToArray());
            }
        }
开发者ID:jwvdiermen,项目名称:LD28,代码行数:36,代码来源:QuadTree.cs

示例4: DrawDroplet

		private void DrawDroplet(float x,float y,Color dropletColor){
			int dropletColorArgb=dropletColor.ToArgb();
			List<PointF> dropletVertsP=TcData.GetDropletVertices();
			List<CustomVertex.PositionColored> dropletVertsV=new List<CustomVertex.PositionColored>();
			for(int p=0;p<dropletVertsP.Count;p++) {
				dropletVertsV.Add(new CustomVertex.PositionColored(
					x+dropletVertsP[p].X,y+dropletVertsP[p].Y,0,dropletColorArgb));
			}
			//This point is implied and is the last point.
			dropletVertsV.Add(new CustomVertex.PositionColored(x,y,0,dropletColorArgb));
			VertexBuffer vb=new VertexBuffer(typeof(CustomVertex.PositionColored),
				CustomVertex.PositionColored.StrideSize*dropletVertsV.Count,
				device,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
			vb.SetData(dropletVertsV.ToArray(),0,LockFlags.None);
			List<int> indiciesL=new List<int>();
			for(int v=0;v<dropletVertsV.Count-2;v++) {
				indiciesL.Add(0);
				indiciesL.Add(v+1);
				indiciesL.Add(v+2);
			}
			int[] indicies=indiciesL.ToArray();
			IndexBuffer ib=new IndexBuffer(typeof(int),indicies.Length,device,Usage.None,Pool.Managed);
			ib.SetData(indicies,0,LockFlags.None);
			device.VertexFormat=CustomVertex.PositionColored.Format;
			device.SetStreamSource(0,vb,0);
			device.Indices=ib;
			device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,dropletVertsV.Count,0,indicies.Length/3);
			ib.Dispose();
			vb.Dispose();
		}
开发者ID:mnisl,项目名称:OD,代码行数:30,代码来源:ToothChartDirectX.cs

示例5: DrawProbingBar

		private void DrawProbingBar(int intTooth,PerioSurf perioSurf){
			const float barWidthMM=0.6f;
			Color colorBar;
			LineSimple barPoints=TcData.GetProbingLine(intTooth,perioSurf,out colorBar);
			if(barPoints==null){
				return;
			}
			CustomVertex.PositionColored[] quadVerts=new CustomVertex.PositionColored[] {
			    new CustomVertex.PositionColored(barPoints.Vertices[0].X-barWidthMM/2f,barPoints.Vertices[0].Y,0,colorBar.ToArgb()),
			    new CustomVertex.PositionColored(barPoints.Vertices[0].X-barWidthMM/2f,barPoints.Vertices[1].Y,0,colorBar.ToArgb()),
			    new CustomVertex.PositionColored(barPoints.Vertices[0].X+barWidthMM/2f,barPoints.Vertices[1].Y,0,colorBar.ToArgb()),
			    new CustomVertex.PositionColored(barPoints.Vertices[0].X+barWidthMM/2f,barPoints.Vertices[0].Y,0,colorBar.ToArgb()),
			  };
			VertexBuffer vb=new VertexBuffer(typeof(CustomVertex.PositionColored),
				CustomVertex.PositionColored.StrideSize*quadVerts.Length,
			  device,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
			vb.SetData(quadVerts,0,LockFlags.None);
			int[] indicies=new int[] { 0,1,2,0,2,3 };
			IndexBuffer ib=new IndexBuffer(typeof(int),indicies.Length,device,Usage.None,Pool.Managed);
			ib.SetData(indicies,0,LockFlags.None);
			device.VertexFormat=CustomVertex.PositionColored.Format;
			device.SetStreamSource(0,vb,0);
			device.Indices=ib;
			device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,quadVerts.Length,0,indicies.Length/3);
			ib.Dispose();
			vb.Dispose();
		}
开发者ID:mnisl,项目名称:OD,代码行数:27,代码来源:ToothChartDirectX.cs

示例6: DrawNumber

		///<summary>Draws the number and the small rectangle behind it.  Draws in the appropriate color.  isFullRedraw means that all of the toothnumbers are being redrawn.  This helps with a few optimizations and with not painting blank rectangles when not needed.</summary>
		private void DrawNumber(string tooth_id,bool isSelected,float offsetY) {
			if(!Tooth.IsValidDB(tooth_id)) {
				return;
			}
			if(TcData.ListToothGraphics[tooth_id].HideNumber) {//if this is a "hidden" number
				return;//skip
			}
			//primary, but not set to show primary letters
			if(Tooth.IsPrimary(tooth_id) && !TcData.ListToothGraphics[Tooth.PriToPerm(tooth_id)].ShowPrimaryLetter){
				return;
			}
			device.RenderState.Lighting=false;
			device.RenderState.ZBufferEnable=false;
			device.Transform.World=Matrix.Identity;
			string displayNum=Tooth.GetToothLabelGraphic(tooth_id,TcData.ToothNumberingNomenclature);
			SizeF labelSize=MeasureStringMm(displayNum);
			RectangleF recMm=TcData.GetNumberRecMm(tooth_id,labelSize);
			recMm.Y+=offsetY;
			Color foreColor=TcData.ColorText;
			if(isSelected) {
				foreColor=TcData.ColorTextHighlight;
				//Draw the background rectangle only if the text is selected.
				int backColorARGB=TcData.ColorBackHighlight.ToArgb();
				CustomVertex.PositionColored[] quadVerts=new CustomVertex.PositionColored[] {
			    new CustomVertex.PositionColored(recMm.X,recMm.Y,0,backColorARGB),//LL
			    new CustomVertex.PositionColored(recMm.X,recMm.Y+recMm.Height,0,backColorARGB),//UL
			    new CustomVertex.PositionColored(recMm.X+recMm.Width,recMm.Y+recMm.Height,0,backColorARGB),//UR
			    new CustomVertex.PositionColored(recMm.X+recMm.Width,recMm.Y,0,backColorARGB),//LR
			  };
				VertexBuffer vb=new VertexBuffer(typeof(CustomVertex.PositionColored),CustomVertex.PositionColored.StrideSize*quadVerts.Length,
					device,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
				vb.SetData(quadVerts,0,LockFlags.None);
				int[] indicies=new int[] { 0,1,2,0,2,3 };
				IndexBuffer ib=new IndexBuffer(typeof(int),indicies.Length,device,Usage.None,Pool.Managed);
				ib.SetData(indicies,0,LockFlags.None);
				device.VertexFormat=CustomVertex.PositionColored.Format;
				device.SetStreamSource(0,vb,0);
				device.Indices=ib;
				device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,quadVerts.Length,0,indicies.Length/3);
				ib.Dispose();
				vb.Dispose();
			}
			//Offsets the text by 10% of the rectangle width to ensure that there is at least on pixel of space on
			//the left for the background rectangle.
			PrintString(displayNum,recMm.X+recMm.Width*0.1f,recMm.Y+recMm.Height,0,foreColor,xfont);
		}
开发者ID:mnisl,项目名称:OD,代码行数:47,代码来源:ToothChartDirectX.cs

示例7: DrawColoredRectangle

		public static void DrawColoredRectangle(Device dev,RectangleF rect,Color color){
			VertexBuffer vb=null;
			IndexBuffer ib=null;
			try{
				int colorArgb=color.ToArgb();
				CustomVertex.PositionColored[] quadVerts=new CustomVertex.PositionColored[] {
						new CustomVertex.PositionColored(rect.Left,rect.Bottom,0,colorArgb),
						new CustomVertex.PositionColored(rect.Left,rect.Top,0,colorArgb),
						new CustomVertex.PositionColored(rect.Right,rect.Top,0,colorArgb),
						new CustomVertex.PositionColored(rect.Right,rect.Bottom,0,colorArgb),
					};
				vb=new VertexBuffer(typeof(CustomVertex.PositionColored),
					CustomVertex.PositionColored.StrideSize*quadVerts.Length,
					dev,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
				vb.SetData(quadVerts,0,LockFlags.None);
				int[] indicies=new int[] { 0,1,2,0,2,3 };
				ib=new IndexBuffer(typeof(int),indicies.Length,dev,Usage.None,Pool.Managed);
				ib.SetData(indicies,0,LockFlags.None);
				dev.VertexFormat=CustomVertex.PositionColored.Format;
				dev.SetStreamSource(0,vb,0);
				dev.Indices=ib;
				dev.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,quadVerts.Length,0,indicies.Length/3);
			}finally{
				if(vb!=null){
					vb.Dispose();
					vb=null;
				}
				if(ib!=null){
					ib.Dispose();
					ib=null;
				}
			}
		}
开发者ID:mnisl,项目名称:OD,代码行数:33,代码来源:ToothChartDirectX.cs

示例8: Rebuild

        private void Rebuild(string fIn, string fOut)
        {
            // Check Args
            FileInfo fiIn = new FileInfo(fIn);
            if(!fiIn.Exists) {
                Console.WriteLine("File Does Not Exist");
                return;
            }
            FileInfo fiOut = new FileInfo(fOut);
            if(!fiOut.Directory.Exists) {
                Console.WriteLine("Output Directory Does Not Exist");
                return;
            }

            // Read Model
            Stream s = File.OpenRead(fiIn.FullName);
            VertexPositionNormalTexture[] verts;
            int[] inds;
            if(!ObjParser.TryParse(s, out verts, out inds, ParsingFlags.ConversionOpenGL)) {
                s.Dispose();
                Console.WriteLine("Could Not Read Model");
                return;
            }
            s.Dispose();

            // Compute The AABB Of The Terrain
            BoundingBox aabb = ComputeAABB(verts);
            Vector3 mid = aabb.Max + aabb.Min;
            Vector3 dif = aabb.Max - aabb.Min;
            Vector3 top = new Vector3(mid.X, aabb.Max.Y, mid.Z);
            mid *= 0.5f;
            fx.FogStart = 1f;
            fx.FogEnd = aabb.Max.Y - aabb.Min.Y + 1f;
            fx.World = Matrix.Identity;
            fx.View = Matrix.CreateLookAt(top + Vector3.UnitY, mid, -Vector3.UnitZ);
            fx.Projection = Matrix.CreateOrthographic(dif.X, dif.Z, 0, dif.Y + 2f);

            // Append A Plane At The Bottom
            int vc = verts.Length, ic = inds.Length;
            Array.Resize(ref verts, verts.Length + 4);
            Array.Resize(ref inds, inds.Length + 6);
            inds[ic++] = vc + 0;
            inds[ic++] = vc + 1;
            inds[ic++] = vc + 2;
            inds[ic++] = vc + 2;
            inds[ic++] = vc + 1;
            inds[ic++] = vc + 3;
            verts[vc++] = new VertexPositionNormalTexture(
                new Vector3(aabb.Min.X, aabb.Min.Y, aabb.Min.Z),
                Vector3.UnitY, Vector2.Zero
                );
            verts[vc++] = new VertexPositionNormalTexture(
                new Vector3(aabb.Max.X, aabb.Min.Y, aabb.Min.Z),
                Vector3.UnitY, Vector2.UnitX
                );
            verts[vc++] = new VertexPositionNormalTexture(
                new Vector3(aabb.Min.X, aabb.Min.Y, aabb.Max.Z),
                Vector3.UnitY, Vector2.UnitY
                );
            verts[vc++] = new VertexPositionNormalTexture(
                new Vector3(aabb.Max.X, aabb.Min.Y, aabb.Max.Z),
                Vector3.UnitY, Vector2.One
                );

            // Create Model
            VertexBuffer vb = new VertexBuffer(G, VertexPositionNormalTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            vb.SetData(verts);
            IndexBuffer ib = new IndexBuffer(G, IndexElementSize.ThirtyTwoBits, inds.Length, BufferUsage.WriteOnly);
            ib.SetData(inds);

            // Render The Height
            if(rtHeight != null)
                rtHeight.Dispose();
            rtHeight = new RenderTarget2D(G, 4096, 4096, false, SurfaceFormat.Color, DepthFormat.Depth24);
            G.SetRenderTarget(rtHeight);
            G.SetVertexBuffer(vb);
            G.Indices = ib;
            fx.CurrentTechnique.Passes[0].Apply();
            G.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vb.VertexCount, 0, ib.IndexCount / 3);

            // Dispose Of Buffers
            G.SetRenderTarget(null);
            G.Clear(Color.Black);
            G.SetVertexBuffer(null);
            G.Indices = null;
            vb.Dispose();
            ib.Dispose();

            // Save The Image
            using(Stream os = File.Create(fiOut.FullName)) {
                rtHeight.SaveAsPng(os, rtHeight.Width, rtHeight.Height);
            }

            ShouldRebuild = false;
        }
开发者ID:RegrowthStudios,项目名称:VoxelRTS,代码行数:95,代码来源:ComputeScreen.cs

示例9: ExtractSubset

        public IndexBuffer ExtractSubset(Device device, short[] triList)
        {
            int numTris = triList.Length;
            IndexBuffer result = null;
            try
            {
                result = new IndexBuffer(device, numTris * 6, Usage.WriteOnly, Pool.Managed, true);
                try
                {
                    var str = result.Lock(0, 0, LockFlags.None);
                    for (var i = 0; i < numTris; i++)
                    {
                        int triNum = triList[i];
                        int offset = triNum * 3;

                        str.Write(this.indices[offset]);
                        str.Write(this.indices[offset+1]);
                        str.Write(this.indices[offset+2]);

                        if (!used[triNum])
                        {
                            used[triNum] = true;
                            UsedCount += 3; // 3 indices used
                        }
                    }
                }
                finally
                {
                    result.Unlock();
                }
                return result;
            }
            catch
            {
                if (result != null) { result.Dispose(); }
                throw;
            }
        }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:38,代码来源:Mesh.cs

示例10: BuildRemainder

        public IndexBuffer BuildRemainder(Device device)
        {
            if (UsedCount == indices.Length) { return null; }

            int numIndices = indices.Length - UsedCount;
            IndexBuffer result = null;
            try
            {
                result = new IndexBuffer(device, numIndices * 2, Usage.WriteOnly, Pool.Managed, true);

                try
                {
                    var str = result.Lock(0, 0, LockFlags.None);
                    int numTris = used.Length;
                    for (var i = 0; i < numTris; i++)
                    {
                        if (used[i]) { continue; }

                        int offset = i * 3;

                        str.Write(this.indices[offset]);
                        str.Write(this.indices[offset + 1]);
                        str.Write(this.indices[offset + 2]);
                    }
                }
                finally
                {
                    result.Unlock();
                }
                return result;
            }
            catch
            {
                if (result != null) { result.Dispose(); }
                throw;
            }
        }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:37,代码来源:Mesh.cs


注:本文中的IndexBuffer.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。