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


C# VertexBuffer.Dispose方法代码示例

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


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

示例1: RenderHorizontalLine

        private static void RenderHorizontalLine(Device dev, int x, int y, Color color)              
        {
            var vb = new VertexBuffer(dev, 2 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Default);

            vb.Lock(0, 0, LockFlags.None).WriteRange(new[] {
                new Vertex() { Color = color.ToArgb(), Position = new Vector4((float)x, (float)y, 0.0f, 0.0f) },
                new Vertex() { Color = color.ToArgb(), Position = new Vector4((float)panadapter_W, (float)y, 0.0f, 0.0f) }
                 });
            vb.Unlock();

            dev.SetStreamSource(0, vb, 0, 20);
            dev.DrawPrimitives(PrimitiveType.LineList, 0, 1);

            vb.Dispose();
        }
开发者ID:GoranRadivojevic,项目名称:CW-expert,代码行数:15,代码来源:Display.cs

示例2: CreateVertexBuffer

        /// <summary>
        /// Create a vertex buffer for our verticies
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        private static VertexBuffer CreateVertexBuffer(GraphicsDevice device, VolumeModel.PositionNormalTextureVertex[] Verticies)
        {
            VertexPositionNormalTexture[] vertArray = new VertexPositionNormalTexture[Verticies.Length];

            for(int i = 0; i < Verticies.Length; i++)
            {
                GridVector3 pos = Verticies[i].Position;
                GridVector3 norm = Verticies[i].Normal;
                GridVector2 tex = Verticies[i].Texture;

                vertArray[i] = new VertexPositionNormalTexture( new Vector3((float)pos.X,(float)pos.Y, (float)pos.Z),
                                                                new Vector3((float)norm.X,(float)norm.Y,(float)norm.Z),
                                                                new Vector2((float)tex.X, (float)tex.Y));

            }

            VertexBuffer vb = null;
            try
            {
                vb = new VertexBuffer(device, typeof(VertexPositionNormalTexture), vertArray.Length, BufferUsage.None);

                vb.SetData<VertexPositionNormalTexture>(vertArray);
            }
            catch (Exception)
            {
                if (vb != null)
                {
                    vb.Dispose();
                    vb = null;
                }
                throw;
            }

            return vb;
        }
开发者ID:abordt,项目名称:Viking,代码行数:40,代码来源:TileViewModel.cs

示例3: RenderRectangle

        private static void RenderRectangle(Device dev, DXRectangle rect, Color color)
        {
            Vertex[] verts = new Vertex[4];

            var vb = new VertexBuffer(dev, 4 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Default);

            verts[0] = new Vertex();
            verts[0].Color = color.ToArgb();
            verts[0].Position = new Vector4(rect.x1, rect.y1, 0.0f, 0.0f);
            verts[1] = new Vertex();
            verts[1].Color = color.ToArgb();
            verts[1].Position = new Vector4(rect.x2, rect.y2, 0.0f, 0.0f);
            verts[2] = new Vertex();
            verts[2].Color = color.ToArgb();
            verts[2].Position = new Vector4(rect.x3, rect.y3, 0.0f, 0.0f);
            verts[3] = new Vertex();
            verts[3].Color = color.ToArgb();
            verts[3].Position = new Vector4(rect.x4, rect.y4, 0.0f, 0.0f);

            vb.Lock(0, 0, LockFlags.None).WriteRange(verts, 0, 4);
            vb.Unlock();
            device.SetStreamSource(0, vb, 0, 20);
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

            vb.Dispose();
        }
开发者ID:GoranRadivojevic,项目名称:CW-expert,代码行数:26,代码来源:Display.cs

示例4: render


//.........这里部分代码省略.........
                //View
                if (currentModel > -1)
                {
                    minVector = model.model[currentModel].minVector;
                    maxVector = model.model[currentModel].maxVector;
                }
                float minSize = Math.Min(Math.Min(minVector.x, minVector.y), minVector.z);
                float maxSize = Math.Max(Math.Max(maxVector.x, maxVector.y), maxVector.z);
                float scale = (10f / (maxSize - minSize)); //Try to adjust to screen
                if (maxSize - minSize == 0) scale = 1;

                Matrix centerMatrix = Matrix.Translation(
                    -(minVector.x + maxVector.x) / 2,
                    -(minVector.y + maxVector.y) / 2,
                    -(minVector.z + maxVector.z) / 2);
                Matrix translationMatrix = Matrix.Translation(
                    (-translation.X / 50) / scale,
                    (translation.Y / 50) / scale,
                    zoom / scale);
                Matrix baseTransform = Matrix.Identity;
                baseTransform *= Matrix.RotationY(rotation.Y) * Matrix.RotationX(rotation.X);
                baseTransform *= centerMatrix * translationMatrix * Matrix.Scaling(-scale, scale, scale);

                //Grid
                if (showGrid)
                {
                    resetRenderState();
                    device.Transform.World = baseTransform;
                    device.VertexFormat = CustomVertex.PositionColored.Format;
                    VertexBuffer lineBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), gridBuffer.Length, device, Usage.None, CustomVertex.PositionColored.Format, Pool.Managed);
                    lineBuffer.SetData(gridBuffer, 0, LockFlags.None);
                    device.SetStreamSource(0, lineBuffer, 0);
                    device.DrawPrimitives(PrimitiveType.LineList, 0, gridBuffer.Length / 2);
                    lineBuffer.Dispose();
                }

                if (!useLegacyTexturing)
                {
                    fragmentShader.Begin(0);

                    #region "Shader Setup"
                    fragmentShader.SetValue("world", device.Transform.World);
                    fragmentShader.SetValue("view", device.Transform.View);
                    fragmentShader.SetValue("projection", device.Transform.Projection);

                    fragmentShader.SetValue("lights[0].pos", new Vector4(0, -10, -10, 0));
                    fragmentShader.SetValue("lights[0].ambient", new Vector4(0.1f, 0.1f, 0.1f, 1));
                    fragmentShader.SetValue("lights[0].diffuse", new Vector4(1, 1, 1, 1));
                    fragmentShader.SetValue("lights[0].specular", new Vector4(1, 1, 1, 1));
                    fragmentShader.SetValue("numLights", 1);
                    #endregion
                }

                if (wireframeMode)
                    device.RenderState.FillMode = FillMode.WireFrame;
                else
                    device.RenderState.FillMode = FillMode.Solid;

                if (currentModel > -1)
                {
                    RenderBase.OModel mdl = model.model[currentModel];
                    device.Transform.World = getMatrix(mdl.transform) * baseTransform;

                    #region "Skeletal Animation"
                    Matrix[] animationSkeletonTransform = new Matrix[mdl.skeleton.Count];
                    if (ctrlSA.animate)
开发者ID:PokeD,项目名称:Ohana3DS-Rebirth,代码行数:67,代码来源:RenderEngine.cs

示例5: 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

示例6: DrawFilledBox

        private void DrawFilledBox(int x1, int y1, int x2, int y2, Color col)
        {
            VertexBuffer Vertices = new VertexBuffer(dxDevice, 6 * Marshal.SizeOf(typeof(Vertex)), Usage.WriteOnly, VertexFormat.None, Pool.Managed);

            DataStream stream = Vertices.Lock(0, 0, LockFlags.None);
            Vertex[] vertexData = new Vertex[6];
            vertexData[0].Position = new Vector4(x1, y1, 0f, 1f);
            vertexData[0].Color = col.ToArgb();
            vertexData[1].Position = new Vector4(x2, y1, 0f, 1f);
            vertexData[1].Color = col.ToArgb();
            vertexData[2].Position = new Vector4(x2, y2, 0f, 1f);
            vertexData[2].Color = col.ToArgb();

            vertexData[3].Position = new Vector4(x2, y2, 0f, 1f);
            vertexData[3].Color = col.ToArgb();
            vertexData[4].Position = new Vector4(x1, y2, 0f, 1f);
            vertexData[4].Color = col.ToArgb();
            vertexData[5].Position = new Vector4(x1, y1, 0f, 1f);
            vertexData[5].Color = col.ToArgb();
            stream.WriteRange(vertexData);
            Vertices.Unlock();

            dxDevice.SetStreamSource(0, Vertices, 0, Marshal.SizeOf(typeof(Vertex)));
            dxDevice.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Diffuse | VertexFormat.Texture1;

            dxDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);

            stream.Close();
            Vertices.Dispose();
        }
开发者ID:stephenZh,项目名称:l2net,代码行数:30,代码来源:Map.cs

示例7: Dispose

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

示例8: EmitterDraw

        //Draw All the particles found in each particle group of the given emitter
        protected void EmitterDraw(ParticleEmitter emitter)
        {
            foreach (ParticleGroup group in emitter.particleGroups)
            {
                VertexBuffer vertexBuffer;

                GraphicsDevice.BlendState = group.blendState;
                GraphicsDevice.DepthStencilState = group.depthStencil;
                group.effect.CurrentTechnique.Passes[0].Apply();

                //Display Particles in their flat 2D form or fake 3D feel
                if (true)
                {
                    group.LoadVertexArray(ParticleAppearance.ThreeDimensional);
                }
                else
                {
                    group.LoadVertexArray(ParticleAppearance.Flat);
                }

                //Draw each particle
                if (group.vertices.Length > 0)
                {
                    vertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionNormalTexture.VertexDeclaration, group.vertices.Length, BufferUsage.None);
                    vertexBuffer.SetData<VertexPositionNormalTexture>(group.vertices);

                    GraphicsDevice.SetVertexBuffer(vertexBuffer);
                    GraphicsDevice.DrawPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType.TriangleList, 0, (group.vertices.Length / 6) + 1);
                    vertexBuffer.Dispose();
                }
            }
        }
开发者ID:BGCX261,项目名称:zombies-ate-my-students-svn-to-git,代码行数:33,代码来源:Game1.cs

示例9: 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

示例10: Draw


//.........这里部分代码省略.........

                    TotalNearbyBoxes.Clear();

                }
                #endregion

                #region Path Finding Helpers

                if (ShowPathFindingGraph)
                {
                    for (int i = 0; i < PathFindingNodes.Count; i++)
                    {
                        //Draw Graph Nodes
                        DrawPathFindingNode(NodeModel, Matrix.CreateTranslation(PathFindingNodes[i].position) * world, globalEffect.View, globalEffect.Projection);
                    }

                    globalEffect.LightingEnabled = false;
                    globalEffect.CurrentTechnique.Passes[0].Apply();
                    //Draw Links between nodes
                    VertexPositionColor[] LinkLines;
                    LinkLines = vpc;

                    VertexDeclaration VertexDecl = new VertexDeclaration(new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0));
                    VertexBuffer vertexBuffer;

                    if (LinkLines.Length > 0)
                    {
                        vertexBuffer = new VertexBuffer(GraphicsDevice, VertexDecl, LinkLines.Length, BufferUsage.None);
                        vertexBuffer.SetData<VertexPositionColor>(LinkLines);

                        GraphicsDevice.SetVertexBuffer(vertexBuffer);
                        GraphicsDevice.DrawPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType.LineList, 0, LinkLines.Length);

                        vertexBuffer.Dispose();
                    }

                    #region PathFinding links helper drawings

                    /*//Determine set of lines to draw for Graph Links
                vpc = new VertexPositionColor[PathFindingNodes[currentNode].Links.Count * 2];

                int vIndex = 0;

                for (int j = 0; j < PathFindingNodes[currentNode].Links.Count; j++)
                {
                    vpc[vIndex] = new VertexPositionColor(PathFindingNodes[currentNode].position, Color.Red);
                    vpc[vIndex + 1] = new VertexPositionColor((PathFindingNodes[currentNode].Links[j].node.position), Color.Red);
                    vIndex += 2;
                }

                LinkLines = vpc;

                if (LinkLines.Length > 0)
                {
                    vertexBuffer = new VertexBuffer(GraphicsDevice, VertexDecl, LinkLines.Length, BufferUsage.None);
                    vertexBuffer.SetData<VertexPositionColor>(LinkLines);

                    GraphicsDevice.SetVertexBuffer(vertexBuffer);
                    GraphicsDevice.DrawPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType.LineList, 0, LinkLines.Length/2);

                    vertexBuffer.Dispose();
                }

                vpc = new VertexPositionColor[2];

                vpc[0] = new VertexPositionColor(PathFindingNodes[currentNode].position+ new Vector3(0,1,0), Color.Blue);
开发者ID:BGCX261,项目名称:zombies-ate-my-students-svn-to-git,代码行数:67,代码来源:Game1.cs

示例11: DrawBox

        private void DrawBox(Box box, Color color, bool OutlineOnly = false)
        {
            if (box != null)
            {
                //Draw as triangle list with potential solid display
                if (!OutlineOnly)
                {
                    VertexBuffer vertexBuffer;

                    VertexPositionColor[] cubeVertices = new VertexPositionColor[36];

                    Vector3[] Vertices = box.GetVertices();

                    //Front
                    cubeVertices[0] = new VertexPositionColor(Vertices[0], color);
                    cubeVertices[1] = new VertexPositionColor(Vertices[1], color);
                    cubeVertices[2] = new VertexPositionColor(Vertices[2], color);
                    cubeVertices[3] = new VertexPositionColor(Vertices[2], color);
                    cubeVertices[4] = new VertexPositionColor(Vertices[1], color);
                    cubeVertices[5] = new VertexPositionColor(Vertices[3], color);

                    //Top
                    cubeVertices[6] = new VertexPositionColor(Vertices[1], color);
                    cubeVertices[7] = new VertexPositionColor(Vertices[5], color);
                    cubeVertices[8] = new VertexPositionColor(Vertices[3], color);
                    cubeVertices[9] = new VertexPositionColor(Vertices[3], color);
                    cubeVertices[10] = new VertexPositionColor(Vertices[5], color);
                    cubeVertices[11] = new VertexPositionColor(Vertices[7], color);

                    //Back
                    cubeVertices[12] = new VertexPositionColor(Vertices[6], color);
                    cubeVertices[13] = new VertexPositionColor(Vertices[7], color);
                    cubeVertices[14] = new VertexPositionColor(Vertices[5], color);
                    cubeVertices[15] = new VertexPositionColor(Vertices[6], color);
                    cubeVertices[16] = new VertexPositionColor(Vertices[5], color);
                    cubeVertices[17] = new VertexPositionColor(Vertices[4], color);

                    //Bottom
                    cubeVertices[18] = new VertexPositionColor(Vertices[4], color);
                    cubeVertices[19] = new VertexPositionColor(Vertices[0], color);
                    cubeVertices[20] = new VertexPositionColor(Vertices[6], color);
                    cubeVertices[21] = new VertexPositionColor(Vertices[6], color);
                    cubeVertices[22] = new VertexPositionColor(Vertices[0], color);
                    cubeVertices[23] = new VertexPositionColor(Vertices[2], color);

                    //Left Side
                    cubeVertices[24] = new VertexPositionColor(Vertices[4], color);
                    cubeVertices[25] = new VertexPositionColor(Vertices[5], color);
                    cubeVertices[26] = new VertexPositionColor(Vertices[1], color);
                    cubeVertices[27] = new VertexPositionColor(Vertices[4], color);
                    cubeVertices[28] = new VertexPositionColor(Vertices[1], color);
                    cubeVertices[29] = new VertexPositionColor(Vertices[0], color);

                    //Right Side
                    cubeVertices[30] = new VertexPositionColor(Vertices[2], color);
                    cubeVertices[31] = new VertexPositionColor(Vertices[3], color);
                    cubeVertices[32] = new VertexPositionColor(Vertices[7], color);
                    cubeVertices[33] = new VertexPositionColor(Vertices[2], color);
                    cubeVertices[34] = new VertexPositionColor(Vertices[7], color);
                    cubeVertices[35] = new VertexPositionColor(Vertices[6], color);

                    globalEffect.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

                    globalEffect.CurrentTechnique.Passes[0].Apply();

                    vertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionColor.VertexDeclaration, 36, BufferUsage.None);
                    vertexBuffer.SetData<VertexPositionColor>(cubeVertices);

                    GraphicsDevice.SetVertexBuffer(vertexBuffer);
                    GraphicsDevice.DrawPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType.TriangleList, 0, 12);
                    vertexBuffer.Dispose();

                }
                else
                {
                    //Draw as line list for hollow display

                    VertexBuffer vertexBuffer;

                    VertexPositionColor[] cubeVertices = new VertexPositionColor[24];

                    Vector3[] Vertices = box.GetVertices();

                    //Front
                    cubeVertices[0] = new VertexPositionColor(Vertices[0], color);
                    cubeVertices[1] = new VertexPositionColor(Vertices[1], color);
                    cubeVertices[2] = new VertexPositionColor(Vertices[1], color);
                    cubeVertices[3] = new VertexPositionColor(Vertices[3], color);
                    cubeVertices[4] = new VertexPositionColor(Vertices[3], color);
                    cubeVertices[5] = new VertexPositionColor(Vertices[2], color);
                    cubeVertices[6] = new VertexPositionColor(Vertices[2], color);
                    cubeVertices[7] = new VertexPositionColor(Vertices[0], color);

                    cubeVertices[8] = new VertexPositionColor(Vertices[0], color);
                    cubeVertices[9] = new VertexPositionColor(Vertices[4], color);
                    cubeVertices[10] = new VertexPositionColor(Vertices[1], color);
                    cubeVertices[11] = new VertexPositionColor(Vertices[5], color);
                    cubeVertices[12] = new VertexPositionColor(Vertices[2], color);
                    cubeVertices[13] = new VertexPositionColor(Vertices[6], color);
                    cubeVertices[14] = new VertexPositionColor(Vertices[3], color);
//.........这里部分代码省略.........
开发者ID:BGCX261,项目名称:zombies-ate-my-students-svn-to-git,代码行数:101,代码来源:Game1.cs

示例12: setData


//.........这里部分代码省略.........
                        sourceVertexIndex = moduleManager.addNewFunction(sourceFunctionAddress);
                    }

                    if (sourceVertexIndex >= 0)
                    {
                        // Highlight the source index function
                        vertexFunctions[sourceVertexIndex].Color = Color.FromArgb(255, 255, 50).ToArgb();
                        executedVertexIndices.Add(sourceVertexIndex);
                    }

                    // Load the destination vertex index, or create a new vertex if needed
                    int destinationVertexIndex;
                    if (functionLocationsHash.Contains((uint) ((oSingleData) data[i]).destination))
                    {
                        destinationVertexIndex = (int) functionLocationsHash[(uint) data[i].destination];
                    }
                    else
                    {
                        // We need to create the vertex for this funciton
                        destinationVertexIndex = moduleManager.addNewFunction((uint) data[i].destination);
                    }

                    if (destinationVertexIndex >= 0)
                    {
                        // Highlight the destination index function
                        vertexFunctions[destinationVertexIndex].Color = Color.FromArgb(255, 255, 50).ToArgb();
                        executedVertexIndices.Add(destinationVertexIndex);
                    }

                    // Draw the link line
                    if (destinationVertexIndex >= 0 && sourceVertexIndex >= 0)
                    {
                        vertexLinks[vertexLinksCount] =
                            new CustomVertex.TransformedColored(vertexFunctions[sourceVertexIndex].X,
                                                                vertexFunctions[sourceVertexIndex].Y + 1,
                                                                vertexFunctions[sourceVertexIndex].Z,
                                                                vertexFunctions[sourceVertexIndex].Rhw,
                                                                Color.FromArgb(150, 0, 0).ToArgb());
                        vertexLinks[vertexLinksCount + 1] =
                            new CustomVertex.TransformedColored(vertexFunctions[destinationVertexIndex].X,
                                                                vertexFunctions[destinationVertexIndex].Y + 1,
                                                                vertexFunctions[destinationVertexIndex].Z,
                                                                vertexFunctions[destinationVertexIndex].Rhw,
                                                                Color.FromArgb(0, 0, 150).ToArgb());
                        vertexLinksCount += 2;
                    }
                }
            }
            else
            {
                vertexLinksCount = 0;
            }

            // Write the function vertex buffers
            if (vertexFunctionsCount > 0)
            {
                CustomVertex.TransformedColored[] vertexFunctionsRange =
                    new CustomVertex.TransformedColored[vertexFunctionsCount];
                Array.Copy(vertexFunctions, vertexFunctionsRange, vertexFunctionsRange.Length);
                if (vertexBufferFunctions != null)
                    vertexBufferFunctions.Dispose();
                vertexBufferFunctions = new VertexBuffer(typeof (CustomVertex.TransformedColored),
                                                         vertexFunctionsCount,
                                                         device,
                                                         0,
                                                         CustomVertex.TransformedColored.Format,
                                                         Pool.Default);
                GraphicsStream stm = vertexBufferFunctions.Lock(0, 0, 0);
                stm.Seek(0, SeekOrigin.Begin);
                stm.Write(vertexFunctionsRange);
                vertexBufferFunctions.Unlock();
                stm.Dispose();
            }

            // Write the link line vertex buffers
            if (vertexLinksCount > 0)
            {
                CustomVertex.TransformedColored[] vertexLinksRange =
                    new CustomVertex.TransformedColored[vertexLinksCount];
                Array.Copy(vertexLinks, vertexLinksRange, vertexLinksRange.Length);
                if (vertexBufferLinks != null)
                    vertexBufferLinks.Dispose();
                vertexBufferLinks = new VertexBuffer(typeof (CustomVertex.TransformedColored),
                                                     vertexLinksCount,
                                                     device,
                                                     0,
                                                     CustomVertex.TransformedColored.Format,
                                                     Pool.Default);

                GraphicsStream stm = vertexBufferLinks.Lock(0, 0, 0);
                stm.Seek(0, SeekOrigin.Begin);
                stm.Write(vertexLinksRange);
                vertexBufferLinks.Unlock();
                stm.Dispose();
            }
            else
            {
                vertexBufferLinks = null;
            }
        }
开发者ID:obarhleam,项目名称:FunctionHacker,代码行数:101,代码来源:oVisLookup.cs

示例13: RenderRectangle

        private static void RenderRectangle(Device dev, DXRectangle rect, Color color)
        {
            try
            {
                try
                {
                    Vertex[] verts = new Vertex[4];

                    var vb = new VertexBuffer(dev, 4 * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed);

                    verts[0] = new Vertex();
                    verts[0].Color = color.ToArgb();
                    verts[0].Position = new Vector4(rect.x1, rect.y1, 0.0f, 0.0f);
                    verts[1] = new Vertex();
                    verts[1].Color = color.ToArgb();
                    verts[1].Position = new Vector4(rect.x2, rect.y2, 0.0f, 0.0f);
                    verts[2] = new Vertex();
                    verts[2].Color = color.ToArgb();
                    verts[2].Position = new Vector4(rect.x3, rect.y3, 0.0f, 0.0f);
                    verts[3] = new Vertex();
                    verts[3].Color = color.ToArgb();
                    verts[3].Position = new Vector4(rect.x4, rect.y4, 0.0f, 0.0f);

                    vb.Lock(0, 0, LockFlags.None).WriteRange(verts, 0, 4);
                    vb.Unlock();
                    device.SetStreamSource(0, vb, 0, 20);
                    device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

                    vb.Dispose();
                }
                catch (Direct3D9Exception ex)
                {
                    Debug.Write(ex.ToString());

                    if (debug && !console.ConsoleClosing)
                        console.Invoke(new DebugCallbackFunction(console.DebugCallback),
                            "Render Rectangle fault!\n" + ex.ToString());
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }
开发者ID:Dfinitski,项目名称:genesisradio,代码行数:44,代码来源:display_DirectX.cs

示例14: 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

示例15: Render

        /// <summary>
        /// Render the batch of sprites to the display
        /// </summary>
        public static new void Render(bool clear)
        {
            if (batch.Count == 0)
                return;

            // Create a matrix that will rotate all the sprites in view roughly towards the camera
            facingMatrix = Matrix.RotationY(Camera.bearing);

            try
            {
                // Create the vertex buffer
                VertexBuffer VBBatch = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured),
                    batch.Count * 6,								// 6 verts per tile
                    Engine.Device,
                    Usage.WriteOnly,
                    CustomVertex.PositionNormalTextured.Format,
                    Pool.Default);

                // Send the triangles to it
                using (GraphicsStream stream = VBBatch.Lock(0, 0, LockFlags.None))
                {
                    // For each object
                    batch.Reset();
                    Scenery obj;
                    while ((obj = (Scenery)batch.GetNext()) != null)
                        obj.Write(stream);
                    VBBatch.Unlock();
                }
                Engine.Device.SetStreamSource(0, VBBatch, 0);							// make this the stream source
                Fx.DrawPrimitives(PrimitiveType.TriangleList, 0, batch.Count * 2);	// render the primitives via an effect
                VBBatch.Dispose();
                if (clear == true)
                    batch.Clear();														// start filling from beginning next time
            }
            catch (Exception e)
            {
                Debug.WriteLine("unable to render terrain batch");
                throw e;
            }
        }
开发者ID:JamesTryand,项目名称:simergy,代码行数:43,代码来源:Scenery.cs


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