CreateIndexBuffer() public method

public CreateIndexBuffer ( IndexElementSize id, int s, BufferUsage usage = BufferUsage.WriteOnly ) : IndexBuffer
id IndexElementSize
s int
usage BufferUsage
return IndexBuffer
示例#1
0
        private void BuildFireModel(RTSRenderer renderer, int div)
        {
            VertexPositionTexture[] verts = new VertexPositionTexture[4 * div];
            short[] inds   = new short[6 * div];
            double  dTheta = Math.PI / div;

            for (int i = 0, ii = 0, vi = 0; i < div; i++)
            {
                inds[ii++] = (short)(vi + 0);
                inds[ii++] = (short)(vi + 1);
                inds[ii++] = (short)(vi + 2);
                inds[ii++] = (short)(vi + 2);
                inds[ii++] = (short)(vi + 1);
                inds[ii++] = (short)(vi + 3);
                float x = (float)Math.Cos(i * dTheta);
                float z = -(float)Math.Sin(i * dTheta);
                verts[vi++] = new VertexPositionTexture(new Vector3(-x, 1, -z), Vector2.Zero);
                verts[vi++] = new VertexPositionTexture(new Vector3(x, 1, z), Vector2.UnitX);
                verts[vi++] = new VertexPositionTexture(new Vector3(-x, 0, -z), Vector2.UnitY);
                verts[vi++] = new VertexPositionTexture(new Vector3(x, 0, z), Vector2.One);
            }

            plFires.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            plFires.VBuffer.SetData(verts);
            plFires.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.SixteenBits, inds.Length, BufferUsage.WriteOnly);
            plFires.IBuffer.SetData(inds);
        }
示例#2
0
        private void BuildBloodModel(RTSRenderer renderer)
        {
            plBloods.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, 12, BufferUsage.WriteOnly);
            plBloods.VBuffer.SetData(new VertexPositionTexture[] {
                new VertexPositionTexture(new Vector3(0, 1, -1), Vector2.Zero),
                new VertexPositionTexture(new Vector3(0, 1, 1), Vector2.UnitX),
                new VertexPositionTexture(new Vector3(0, -1, -1), Vector2.UnitY),
                new VertexPositionTexture(new Vector3(0, -1, 1), Vector2.One),

                new VertexPositionTexture(new Vector3(-1, 0, -1), Vector2.Zero),
                new VertexPositionTexture(new Vector3(1, 0, -1), Vector2.UnitX),
                new VertexPositionTexture(new Vector3(-1, 0, 1), Vector2.UnitY),
                new VertexPositionTexture(new Vector3(1, 0, 1), Vector2.One),

                new VertexPositionTexture(new Vector3(-1, 1, 0), Vector2.Zero),
                new VertexPositionTexture(new Vector3(1, 1, 0), Vector2.UnitX),
                new VertexPositionTexture(new Vector3(-1, -1, 0), Vector2.UnitY),
                new VertexPositionTexture(new Vector3(1, -1, 0), Vector2.One)
            });
            plBloods.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.SixteenBits, 18, BufferUsage.WriteOnly);
            plBloods.IBuffer.SetData(new short[] {
                0, 1, 2, 2, 1, 3,
                4, 5, 6, 6, 5, 7,
                8, 9, 10, 10, 9, 11
            });
        }
示例#3
0
        public void Build(RTSRenderer renderer, string image, Vector3 radii, Vector3 heights)
        {
            fx = renderer.CreateEffect();

            fx.FogEnabled         = false;
            fx.VertexColorEnabled = false;
            fx.LightingEnabled    = false;
            fx.TextureEnabled     = true;

            if (image == null || !File.Exists(image))
            {
                Texture = renderer.CreateTexture2D(3, 3, SurfaceFormat.Color, false);
                Texture.SetData(new Color[] {
                    Color.White, Color.Transparent, Color.White,
                    Color.Transparent, Color.Transparent, Color.Transparent,
                    Color.White, Color.Transparent, Color.White
                });
            }
            else
            {
                Texture = renderer.LoadTexture2D(image);
            }
            fx.Texture = Texture;

            VertexPositionTexture[] verts = new VertexPositionTexture[] {
                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(0.5f, 0)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(0.5f, 0.5f)),

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0.5f, 0)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(1f, 0)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(1f, 0.5f)),

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0, 1f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(0.5f, 1f))
            };
            int[] inds = new int[] {
                0, 1, 2, 2, 1, 3,
                4, 5, 6, 6, 5, 7,
                8, 9, 10, 10, 9, 11
            };
            for (int i = 0; i < 4; i++)
            {
                verts[i].Position     *= new Vector3(radii.X, heights.X, radii.X);
                verts[i + 4].Position *= new Vector3(radii.Y, heights.Y, radii.Y);
                verts[i + 8].Position *= new Vector3(radii.Z, heights.Z, radii.Z);
            }

            vb = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            vb.SetData(verts);
            ib = renderer.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, inds.Length, BufferUsage.WriteOnly);
            ib.SetData(inds);
        }
示例#4
0
 private void BuildAlertModel(RTSRenderer renderer)
 {
     plAlerts.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly);
     plAlerts.VBuffer.SetData(new VertexPositionTexture[] {
         new VertexPositionTexture(new Vector3(-1, 0, -1), Vector2.Zero),
         new VertexPositionTexture(new Vector3(1, 0, -1), Vector2.UnitX),
         new VertexPositionTexture(new Vector3(-1, 0, 1), Vector2.UnitY),
         new VertexPositionTexture(new Vector3(1, 0, 1), Vector2.One)
     });
     plAlerts.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly);
     plAlerts.IBuffer.SetData(new short[] { 0, 1, 2, 2, 1, 3 });
 }
示例#5
0
        private void BuildLightningModel(RTSRenderer renderer)
        {
            VertexPositionTexture[] verts = new VertexPositionTexture[4];
            verts[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), Vector2.Zero);
            verts[1] = new VertexPositionTexture(new Vector3(1, 1, 0), Vector2.UnitX);
            verts[2] = new VertexPositionTexture(new Vector3(-1, 0, 0), Vector2.UnitY);
            verts[3] = new VertexPositionTexture(new Vector3(1, 0, 0), Vector2.One);
            short[] inds = { 0, 1, 2, 2, 1, 3 };

            plBolts.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            plBolts.VBuffer.SetData(verts);
            plBolts.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.SixteenBits, inds.Length, BufferUsage.WriteOnly);
            plBolts.IBuffer.SetData(inds);
        }
示例#6
0
 private void LoadBulletModel(RTSRenderer renderer, Stream s, ParsingFlags pf = ParsingFlags.ConversionOpenGL)
 {
     VertexPositionNormalTexture[] v;
     int[] inds;
     ObjParser.TryParse(s, out v, out inds, pf);
     VertexPositionTexture[] verts = new VertexPositionTexture[v.Length];
     for (int i = 0; i < verts.Length; i++)
     {
         verts[i].Position          = v[i].Position;
         verts[i].TextureCoordinate = v[i].TextureCoordinate;
     }
     plBullets.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
     plBullets.VBuffer.SetData(verts);
     plBullets.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, inds.Length, BufferUsage.WriteOnly);
     plBullets.IBuffer.SetData(inds);
 }
示例#7
0
        public void Build(RTSRenderer renderer, RTSFXEntity fx, string technique, string pass, string texture)
        {
            vb = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly);
            vb.SetData(new VertexPositionTexture[] {
               new VertexPositionTexture(new Vector3(-1, 0, -1), Vector2.Zero),
               new VertexPositionTexture(new Vector3(1, 0, -1), Vector2.UnitX),
               new VertexPositionTexture(new Vector3(-1, 0, 1), Vector2.UnitY),
               new VertexPositionTexture(new Vector3(1, 0, 1), Vector2.One)
            });
            ib = renderer.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, 6, BufferUsage.WriteOnly);
            ib.SetData(new int[] { 0, 1, 2, 2, 1, 3 });
            dvb = renderer.CreateDynamicVertexBuffer(VertexHealthInstance.Declaration, MAX_COUNT, BufferUsage.WriteOnly);
            instances = new VertexHealthInstance[MAX_COUNT];
            vbBinds = new VertexBufferBinding[]{
                new VertexBufferBinding(vb),
                new VertexBufferBinding(dvb, 0, 1)
            };

            fxPass = fx.GetEffectPass(technique, pass);
        }
示例#8
0
        public void Build(RTSRenderer renderer, RTSFXEntity fx, string technique, string pass, string texture)
        {
            vb = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly);
            vb.SetData(new VertexPositionTexture[] {
                new VertexPositionTexture(new Vector3(-1, 0, -1), Vector2.Zero),
                new VertexPositionTexture(new Vector3(1, 0, -1), Vector2.UnitX),
                new VertexPositionTexture(new Vector3(-1, 0, 1), Vector2.UnitY),
                new VertexPositionTexture(new Vector3(1, 0, 1), Vector2.One)
            });
            ib = renderer.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, 6, BufferUsage.WriteOnly);
            ib.SetData(new int[] { 0, 1, 2, 2, 1, 3 });
            dvb       = renderer.CreateDynamicVertexBuffer(VertexHealthInstance.Declaration, MAX_COUNT, BufferUsage.WriteOnly);
            instances = new VertexHealthInstance[MAX_COUNT];
            vbBinds   = new VertexBufferBinding[] {
                new VertexBufferBinding(vb),
                new VertexBufferBinding(dvb, 0, 1)
            };

            fxPass = fx.GetEffectPass(technique, pass);
        }
 private void LoadBulletModel(RTSRenderer renderer, Stream s, ParsingFlags pf = ParsingFlags.ConversionOpenGL)
 {
     VertexPositionNormalTexture[] v;
     int[] inds;
     ObjParser.TryParse(s, out v, out inds, pf);
     VertexPositionTexture[] verts = new VertexPositionTexture[v.Length];
     for(int i = 0; i < verts.Length; i++) {
         verts[i].Position = v[i].Position;
         verts[i].TextureCoordinate = v[i].TextureCoordinate;
     }
     plBullets.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
     plBullets.VBuffer.SetData(verts);
     plBullets.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, inds.Length, BufferUsage.WriteOnly);
     plBullets.IBuffer.SetData(inds);
 }
        private void BuildLightningModel(RTSRenderer renderer)
        {
            VertexPositionTexture[] verts = new VertexPositionTexture[4];
            verts[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), Vector2.Zero);
            verts[1] = new VertexPositionTexture(new Vector3(1, 1, 0), Vector2.UnitX);
            verts[2] = new VertexPositionTexture(new Vector3(-1, 0, 0), Vector2.UnitY);
            verts[3] = new VertexPositionTexture(new Vector3(1, 0, 0), Vector2.One);
            short[] inds = { 0, 1, 2, 2, 1, 3 };

            plBolts.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            plBolts.VBuffer.SetData(verts);
            plBolts.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.SixteenBits, inds.Length, BufferUsage.WriteOnly);
            plBolts.IBuffer.SetData(inds);
        }
        private void BuildFireModel(RTSRenderer renderer, int div)
        {
            VertexPositionTexture[] verts = new VertexPositionTexture[4 * div];
            short[] inds = new short[6 * div];
            double dTheta = Math.PI / div;
            for(int i = 0, ii = 0, vi = 0; i < div; i++) {
                inds[ii++] = (short)(vi + 0);
                inds[ii++] = (short)(vi + 1);
                inds[ii++] = (short)(vi + 2);
                inds[ii++] = (short)(vi + 2);
                inds[ii++] = (short)(vi + 1);
                inds[ii++] = (short)(vi + 3);
                float x = (float)Math.Cos(i * dTheta);
                float z = -(float)Math.Sin(i * dTheta);
                verts[vi++] = new VertexPositionTexture(new Vector3(-x, 1, -z), Vector2.Zero);
                verts[vi++] = new VertexPositionTexture(new Vector3(x, 1, z), Vector2.UnitX);
                verts[vi++] = new VertexPositionTexture(new Vector3(-x, 0, -z), Vector2.UnitY);
                verts[vi++] = new VertexPositionTexture(new Vector3(x, 0, z), Vector2.One);
            }

            plFires.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            plFires.VBuffer.SetData(verts);
            plFires.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.SixteenBits, inds.Length, BufferUsage.WriteOnly);
            plFires.IBuffer.SetData(inds);
        }
        private void BuildBloodModel(RTSRenderer renderer)
        {
            plBloods.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, 12, BufferUsage.WriteOnly);
            plBloods.VBuffer.SetData(new VertexPositionTexture[] {
                new VertexPositionTexture(new Vector3(0, 1, -1), Vector2.Zero),
                new VertexPositionTexture(new Vector3(0, 1, 1), Vector2.UnitX),
                new VertexPositionTexture(new Vector3(0, -1, -1), Vector2.UnitY),
                new VertexPositionTexture(new Vector3(0, -1, 1), Vector2.One),

                new VertexPositionTexture(new Vector3(-1, 0, -1), Vector2.Zero),
                new VertexPositionTexture(new Vector3(1, 0, -1), Vector2.UnitX),
                new VertexPositionTexture(new Vector3(-1, 0, 1), Vector2.UnitY),
                new VertexPositionTexture(new Vector3(1, 0, 1), Vector2.One),

                new VertexPositionTexture(new Vector3(-1, 1, 0), Vector2.Zero),
                new VertexPositionTexture(new Vector3(1, 1, 0), Vector2.UnitX),
                new VertexPositionTexture(new Vector3(-1, -1, 0), Vector2.UnitY),
                new VertexPositionTexture(new Vector3(1, -1, 0), Vector2.One)
            });
            plBloods.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.SixteenBits, 18, BufferUsage.WriteOnly);
            plBloods.IBuffer.SetData(new short[] {
                0, 1, 2, 2, 1, 3,
                4, 5, 6, 6, 5, 7,
                8, 9, 10, 10, 9, 11
            });
        }
 private void BuildAlertModel(RTSRenderer renderer)
 {
     plAlerts.VBuffer = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly);
     plAlerts.VBuffer.SetData(new VertexPositionTexture[] {
         new VertexPositionTexture(new Vector3(-1, 0, -1), Vector2.Zero),
         new VertexPositionTexture(new Vector3(1, 0, -1), Vector2.UnitX),
         new VertexPositionTexture(new Vector3(-1, 0, 1), Vector2.UnitY),
         new VertexPositionTexture(new Vector3(1, 0, 1), Vector2.One)
     });
     plAlerts.IBuffer = renderer.CreateIndexBuffer(IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly);
     plAlerts.IBuffer.SetData(new short[] { 0, 1, 2, 2, 1, 3 });
 }
示例#14
0
        public void Build(RTSRenderer renderer, string image, Vector3 radii, Vector3 heights)
        {
            fx = renderer.CreateEffect();

            fx.FogEnabled = false;
            fx.VertexColorEnabled = false;
            fx.LightingEnabled = false;
            fx.TextureEnabled = true;

            if(image == null || !File.Exists(image)) {
                Texture = renderer.CreateTexture2D(3, 3, SurfaceFormat.Color, false);
                Texture.SetData(new Color[] {
                    Color.White, Color.Transparent, Color.White,
                    Color.Transparent, Color.Transparent, Color.Transparent,
                    Color.White, Color.Transparent, Color.White
                });
            }
            else {
                Texture = renderer.LoadTexture2D(image);
            }
            fx.Texture = Texture;

            VertexPositionTexture[] verts = new VertexPositionTexture[] {
                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(0.5f, 0)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(0.5f, 0.5f)),

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0.5f, 0)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(1f, 0)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(1f, 0.5f)),

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0, 1f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(0.5f, 1f))
            };
            int[] inds = new int[] {
                0, 1, 2, 2, 1, 3,
                4, 5, 6, 6, 5, 7,
                8, 9, 10, 10, 9, 11
            };
            for(int i = 0; i < 4; i++) {
                verts[i].Position *= new Vector3(radii.X, heights.X, radii.X);
                verts[i + 4].Position *= new Vector3(radii.Y, heights.Y, radii.Y);
                verts[i + 8].Position *= new Vector3(radii.Z, heights.Z, radii.Z);
            }

            vb = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            vb.SetData(verts);
            ib = renderer.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, inds.Length, BufferUsage.WriteOnly);
            ib.SetData(inds);
        }