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


C# IndexBuffer类代码示例

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


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

示例1: Initilize

 public static void Initilize(GraphicsDevice gd)
 {
     ConstructCube();
     vBuffer = new VertexBuffer(gd, VertexPositionNormalTexture.VertexDeclaration, 36, BufferUsage.WriteOnly);
     vBuffer.SetData(verts);
     gd.SetVertexBuffer(vBuffer);
     ib = new IndexBuffer(gd, IndexElementSize.SixteenBits, 14, BufferUsage.WriteOnly);
     ib.SetData(new short[14]
     {
         0,
         1,
         2,
         3,
         4,
         5,
         6,
         7,
         8,
         9,
         10,
         11,
         12,
         13
     });
     gd.Indices = ib;
     wireframeRaster = new RasterizerState();
     wireframeRaster.FillMode = FillMode.WireFrame;
     wireframeRaster.CullMode = CullMode.None;
     wireframeEfect = new BasicEffect(gd);
     wireframeEfect.Projection = Matrix.CreatePerspectiveFieldOfView(0.7853982f,
         wireframeEfect.GraphicsDevice.Viewport.AspectRatio, 0.01f, 3000f);
 }
开发者ID:strangea,项目名称:OpenHacknet,代码行数:32,代码来源:Cube3D.cs

示例2: Sphere

    public Sphere(float Radius, GraphicsDevice graphics, Texture2D tex, Texture2D prograde, Texture2D retrograde,
        Texture2D maneuverPrograde, Texture2D targetPrograde, Texture2D targetRetrograde)
    {
        this.prograde = new Bilboard (prograde, Matrix.CreateScale (1.0f));
        this.retrograde = new Bilboard (retrograde, Matrix.CreateScale (1.0f));
        this.maneuverPrograde = new Bilboard (maneuverPrograde, Matrix.CreateScale (1.0f));
        this.targetPrograde = new Bilboard (targetPrograde, Matrix.CreateScale (1.0f));
        this.targetRetrograde = new Bilboard (targetRetrograde, Matrix.CreateScale (1.0f));

        texture = tex;
        radius = Radius;
        graphicd = graphics;
        effect = new BasicEffect(graphicd);

        nvertices = res * res; // 90 vertices in a circle, 90 circles in a sphere
        nindices = res * res * 6;
        vbuffer = new VertexBuffer(graphics, typeof(VertexPositionNormalTexture), nvertices, BufferUsage.WriteOnly);
        ibuffer = new IndexBuffer(graphics, IndexElementSize.SixteenBits, nindices, BufferUsage.WriteOnly);
        createspherevertices();
        createindices();
        vbuffer.SetData<VertexPositionNormalTexture>(vertices);
        ibuffer.SetData<short>(indices);
        effect.TextureEnabled = true;
        effect.LightingEnabled = true;

        rotQuat = Quaternion.Identity;
    }
开发者ID:BackgroundNose,项目名称:KSP_External_Navball_MK2,代码行数:27,代码来源:Sphere.cs

示例3: FromScene

        public static Model FromScene(Scene scene, Device device)
        {
            VertexDeclaration vertexDeclaration = new VertexDeclaration(device,
                VertexPositionNormalTexture.VertexElements);
            Model result = new Model(scene, device, vertexDeclaration);
            foreach (Mesh mesh in scene.Meshes)
            {
                VertexBuffer vertexBuffer = new VertexBuffer(device,
                    mesh.Positions.Count * VertexPositionNormalTexture.SizeInBytes,
                    Usage.WriteOnly, VertexFormat.None, Pool.Default);
                DataStream vertexDataStream = vertexBuffer.Lock(0,
                    mesh.Positions.Count * VertexPositionNormalTexture.SizeInBytes,
                    LockFlags.None);
                VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[mesh.Positions.Count];
                for (int i = 0; i < vertices.Length; ++i)
                    vertices[i] = new VertexPositionNormalTexture(mesh.Positions[i], (mesh.Normals.Count > i) ? mesh.Normals[i] : Vector3D.Zero, Point2D.Zero);
                vertexDataStream.WriteRange(vertices);
                vertexBuffer.Unlock();

                IndexBuffer indexBuffer = new IndexBuffer(device, mesh.Indices.Count * sizeof(int),
                    Usage.WriteOnly, Pool.Default, false);
                DataStream indexDataStream = indexBuffer.Lock(0, mesh.Indices.Count * sizeof(int), LockFlags.None);
                indexDataStream.WriteRange(mesh.Indices.ToArray());
                indexBuffer.Unlock();

                ModelMesh modelMesh = new ModelMesh(mesh, device, vertexBuffer,
                    mesh.Positions.Count, indexBuffer, mesh.PrimitiveCount,
                    Matrix3D.Identity, mesh.Material);
                result.Meshes.Add(modelMesh);
            }
            return result;
        }
开发者ID:bondehagen,项目名称:meshellator,代码行数:32,代码来源:ModelConverter.cs

示例4: Reload

			public void Reload()
			{
				Ovr.DistortionMesh meshData = this.main.VRHmd.CreateDistortionMesh(this.eye, this.fov, this.main.VRHmd.GetDesc().DistortionCaps).Value;
				Point textureSize = this.main.ScreenSize;
				Ovr.Vector2f[] scaleAndOffset = this.main.VRHmd.GetRenderScaleAndOffset(this.fov, new Ovr.Sizei(textureSize.X, textureSize.Y), new Ovr.Recti { Size = { w = textureSize.X, h = textureSize.Y } });
				this.uvScale = new Vector2(scaleAndOffset[0].x, scaleAndOffset[0].y);
				this.uvOffset = new Vector2(scaleAndOffset[1].x, scaleAndOffset[1].y);
				Vertex[] vertices = new Vertex[meshData.VertexCount];
				for (int i = 0; i < meshData.VertexCount; i++)
				{
					Ovr.DistortionVertex v = meshData.pVertexData[i];
					vertices[i].ScreenPosNDC = new Vector2(v.ScreenPosNDC.x, v.ScreenPosNDC.y);
					vertices[i].TimeWarpFactor = v.TimeWarpFactor;
					vertices[i].VignetteFactor = v.VignetteFactor;
					vertices[i].TanEyeAnglesR = new Vector2(v.TanEyeAnglesR.x, v.TanEyeAnglesR.y);
					vertices[i].TanEyeAnglesG = new Vector2(v.TanEyeAnglesG.x, v.TanEyeAnglesG.y);
					vertices[i].TanEyeAnglesB = new Vector2(v.TanEyeAnglesB.x, v.TanEyeAnglesB.y);
				}

				this.vb = new VertexBuffer(this.main.GraphicsDevice, typeof(Vertex), (int)meshData.VertexCount, BufferUsage.WriteOnly);
				this.vb.SetData<Vertex>(vertices);

				this.ib = new IndexBuffer(this.main.GraphicsDevice, IndexElementSize.SixteenBits, (int)meshData.IndexCount, BufferUsage.WriteOnly);
				this.ib.SetData<short>(meshData.pIndexData);
			}
开发者ID:dsmo7206,项目名称:Lemma,代码行数:25,代码来源:Oculus.cs

示例5: TextureStrip

        public TextureStrip(GraphicsDevice device,Texture2D tex)
        {
            worldMatrix = Matrix.Identity;
            Indices = new int[4];
            effect = new BasicEffect(device);
            float aspectRatio = (float)device.Viewport.Width /
            device.Viewport.Height;
            CamX = 0.0f;
            CamY = 2.0f;
            CamZ = 2.0f;
            effect.View = Matrix.CreateLookAt(new Vector3(CamX, CamY, CamZ),Vector3.Zero, Vector3.Up);
            effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10.0f);
            effect.VertexColorEnabled = false;
            textura = tex;
            effect.Texture = this.textura;
            effect.TextureEnabled = true;

            CreateVertices();

            Indices[0]=0;
            Indices[1]=1;
            Indices[2]=2;
            Indices[3]=3;

            effect.LightingEnabled = true;
            effect.DirectionalLight0.DiffuseColor = new Vector3(1, 1, 1);
            effect.DirectionalLight0.Direction = new Vector3(0, -1, 0);
            effect.DirectionalLight0.SpecularColor = new Vector3(0, 0, 0);

            vertexBuffer1 = new VertexBuffer(device, typeof(VertexPositionNormalTexture), vertices.Length, BufferUsage.None);
            vertexBuffer1.SetData<VertexPositionNormalTexture>(vertices);

            indexBuffer1 = new IndexBuffer(device, typeof(int), Indices.Length, BufferUsage.None);
            indexBuffer1.SetData<int>(Indices);
        }
开发者ID:joaomlo2,项目名称:TPC4,代码行数:35,代码来源:TextureStrip.cs

示例6: Batcher

		public Batcher( GraphicsDevice graphicsDevice )
		{
			Assert.isTrue( graphicsDevice != null );

			this.graphicsDevice = graphicsDevice;

			_vertexInfo = new VertexPositionColorTexture4[MAX_SPRITES];
			_textureInfo = new Texture2D[MAX_SPRITES];
			_vertexBuffer = new DynamicVertexBuffer( graphicsDevice, typeof( VertexPositionColorTexture ), MAX_VERTICES, BufferUsage.WriteOnly );
			_indexBuffer = new IndexBuffer( graphicsDevice, IndexElementSize.SixteenBits, MAX_INDICES, BufferUsage.WriteOnly );
			_indexBuffer.SetData( _indexData );

			_spriteEffect = new SpriteEffect();
			_spriteEffectPass = _spriteEffect.CurrentTechnique.Passes[0];

			_projectionMatrix = new Matrix(
				0f, //(float)( 2.0 / (double)viewport.Width ) is the actual value we will use
				0.0f,
				0.0f,
				0.0f,
				0.0f,
				0f, //(float)( -2.0 / (double)viewport.Height ) is the actual value we will use
				0.0f,
				0.0f,
				0.0f,
				0.0f,
				1.0f,
				0.0f,
				-1.0f,
				1.0f,
				0.0f,
				1.0f
			);
		}
开发者ID:prime31,项目名称:Nez,代码行数:34,代码来源:Batcher.cs

示例7: IndexBufferObject

 /// <summary>
 /// Constructor of IndexBufferObject class
 /// </summary>
 /// <param name="device">Graphics device</param>
 /// <param name="type">Type of buffer to use</param>
 /// <param name="buffer">Underlying index buffer</param>
 internal IndexBufferObject(GraphicsDevice device, BufferType type, IndexBuffer buffer)
 {
     _device = device;
     _bufferType = type;
     _elementSize = buffer.IndexElementSize;
     CreateWrapper(buffer);
 }
开发者ID:Julien-Pires,项目名称:Pulsar,代码行数:13,代码来源:IndexBufferObject.cs

示例8: InitializePrimitive

 public void InitializePrimitive(GraphicsDevice graphicsDevice)
 {
     VertexBuffer = new VertexBuffer(graphicsDevice, typeof(Vertex), Vertices.Count, BufferUsage.None);
     VertexBuffer.SetData(Vertices.ToArray());
     IndexBuffer = new IndexBuffer(graphicsDevice, typeof(int), Indices.Count, BufferUsage.None);
     IndexBuffer.SetData(Indices.ToArray());
 }
开发者ID:wazka,项目名称:NightPark,代码行数:7,代码来源:PrimitiveElement.cs

示例9: HeightMappedTerrain

        public HeightMappedTerrain(Texture2D heightmap, float cellsize, float height, Texture2D basetex, float textile, Vector3 lightdir, GraphicsDevice device, ContentManager content)
        {
            baseTexture = basetex;
            textureTiling = textile;
            lightDirection = lightdir;

            heightMap = heightmap;
            width = heightmap.Width;
            length = heightMap.Height;

            cellSize = cellsize;
            this.height = height;
            GraphicsDevice = device;

            effect = content.Load<Effect>("TerrainEffect");
            nVertices = width * length;
            nIndices = (width - 1) * (length - 1) * 6;

            vertexBuffer = new VertexBuffer(device, typeof(VertexPositionNormalTexture), nVertices, BufferUsage.WriteOnly);
            indexBuffer = new IndexBuffer(device, IndexElementSize.ThirtyTwoBits, nIndices, BufferUsage.WriteOnly);

            extractHeightData();
            createVertexData();
            createIndexData();
            createNormalData();

            vertexBuffer.SetData<VertexPositionNormalTexture>(vertices);
            indexBuffer.SetData<int>(indices);
        }
开发者ID:AlmostPete,项目名称:HeightmapTest,代码行数:29,代码来源:HeightMappedTerrain.cs

示例10: LoadContent

        protected override void LoadContent()
        {
            base.LoadContent();

             effect = new BasicEffect(GraphicsDevice, null);
             effect.VertexColorEnabled = true;
             effect.Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1);

             vertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements);

             Color c = Color.Red;

             for (int x = 0; x <= Constants.WIN_X; x += xMax)
             {
            listVertices.Add(new VertexPositionColor(new Vector3(x, Constants.WIN_Y - y, 0), Color.Red));
            listVertices.Add(new VertexPositionColor(new Vector3(x, Constants.WIN_Y, 0), Color.Blue));
             }

             for (int i = 0; i < listVertices.Count - 1; i+=2)
             {
            listIndices.Add((short)(i));
            listIndices.Add((short)(3 + i));
            listIndices.Add((short)(1 + i));
            listIndices.Add((short)(i));
            listIndices.Add((short)(2 + i));
            listIndices.Add((short)(3 + i));
             }

             buffVertex = new VertexBuffer(GraphicsDevice, VertexPositionColor.SizeInBytes * listVertices.Count, BufferUsage.WriteOnly);
             buffVertex.SetData<VertexPositionColor>(listVertices.ToArray());

             buffIndex = new IndexBuffer(GraphicsDevice, typeof(short), listIndices.Count, BufferUsage.WriteOnly);
             buffIndex.SetData<short>(listIndices.ToArray());
        }
开发者ID:qrush,项目名称:q-blizzard,代码行数:34,代码来源:Square.cs

示例11: Initialize

        /// <summary>
        /// Performs further custom initialization for this instance.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            VertexPositionColor[] vertices = new VertexPositionColor[3];
            vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f);
            vertices[0].Color = Color.Red;

            vertices[1].Position = new Vector3(0f, 0.5f, 0f);
            vertices[1].Color = Color.Green;

            vertices[2].Position = new Vector3(0.5f, -0.5f, 0f);
            vertices[2].Color = Color.Yellow;

            var vertexBuffer = new VertexBuffer(VertexPositionColor.VertexFormat);
            vertexBuffer.SetData(vertices, 3);
            
            ushort[] indices = new ushort[3];
            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;

            var indexBuffer = new IndexBuffer(indices);

            this.mesh = new Mesh(0, vertices.Length, 0, 1, vertexBuffer, indexBuffer, PrimitiveType.TriangleList);
        }
开发者ID:123asd123A,项目名称:Samples,代码行数:29,代码来源:CustomGeometryRenderer.cs

示例12: Attach

        /// <inheritdoc/>
        public override void Attach(IndexBuffer ibuffer)
        {
            Contract.Require(ibuffer, "ibuffer");
            Contract.EnsureNot(HasIndices, UltravioletStrings.GeometryStreamAlreadyHasIndices);
            Contract.EnsureNotDisposed(this, Disposed);

            Ultraviolet.ValidateResource(ibuffer);

            var sdlIndexBuffer = (OpenGLIndexBuffer)ibuffer;
            var sdlIndexBufferName = sdlIndexBuffer.OpenGLName;

            this.ibuffer = sdlIndexBuffer;

            if (IsUsingVertexArrayObject)
            {
                using (OpenGLState.ScopedBindVertexArrayObject(vao, 0, 0, true))
                {
                    gl.BindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, sdlIndexBufferName);
                    gl.ThrowIfError();
                }
            }

            this.glElementArrayBufferBinding = sdlIndexBufferName;
            this.indexBufferElementType      = ibuffer.IndexElementType;
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:26,代码来源:OpenGLGeometryStream.cs

示例13: Terrain

        public Terrain(Texture2D heightMap,
            Effect effect,
            float cellSize,
            int maxHeight,
            GraphicsDevice device)
        {
            this.HeightMap = heightMap;
            this.Width = heightMap.Width;
            this.Height = maxHeight;
            this.Length = heightMap.Height;
            this.CellSize = cellSize;

            this.Device = device;
            this.Effect = effect;

            this.VerticesCount = Width * Length;
            this.IndexCount = (Width - 1) * (Length - 1) * 6;

            this.VertexBuffer = new VertexBuffer(device,
                typeof(VertexPositionNormalTexture), VerticesCount,
                BufferUsage.WriteOnly);

            this.IndexBuffer = new IndexBuffer(device,
                IndexElementSize.ThirtyTwoBits,
                IndexCount, BufferUsage.WriteOnly);

            ComputeHeights();
            CreateVertices();
            CreateIndices();
            ComputeNormals();

            this.VertexBuffer.SetData<VertexPositionNormalTexture>(Vertices);
            this.IndexBuffer.SetData<int>(Indexes);
        }
开发者ID:JoseIsac,项目名称:VamosAprenderXNA,代码行数:34,代码来源:Terrain.cs

示例14: Render

        public void Render( ViewRenderArguments args )
        {
            if ( Indicies.Count == 0 ) return;

            var device = args.Device;

            if ( VB==null || VB.Description.SizeInBytes < Vertex.Size * Verticies.Count ) {
                using ( VB ) {}
                using ( IB ) {}
                VB = new VertexBuffer( device, Vertex.Size * Verticies.Count, Usage.None, Vertex.FVF, Pool.Managed );
                IB = new IndexBuffer(  device, sizeof(uint)* Indicies .Count, Usage.None, Pool.Managed, false );
            }

            var vb = VB.Lock(0,0,LockFlags.None);
            vb.WriteRange(Verticies.ToArray());
            VB.Unlock();

            var ib = IB.Lock(0,0,LockFlags.None);
            ib.WriteRange(Indicies.ToArray());
            IB.Unlock();

            device.SetTexture(0,null);
            device.Indices = IB;
            device.VertexFormat = Vertex.FVF;
            device.SetStreamSource(0,VB,0,Vertex.Size);
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,Verticies.Count,0,Verticies.Count/2);

            Indicies.Clear();
            Verticies.Clear();
        }
开发者ID:MaulingMonkey,项目名称:Human-Castle,代码行数:30,代码来源:BatchAtmosphereRenderer2D.cs

示例15: 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:nampn,项目名称:ODental,代码行数:34,代码来源:ToothChartDirectX.cs


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