0 Replies - 774 Views - Last Post: 06 April 2013 - 07:23 AM

#1 PyroCybin  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 02-July 12

Custom Vertex Declaration Issue

Posted 06 April 2013 - 07:23 AM

Im having some major problems implementing a custom Vertex Declaration to a Program Im working on. Basically im using a vertices in the form of a short4 for position, a short4 for the normal and a Normalizedshort2 for the Texture coordinates. To create the buffer i take a list of vertices (verts) and create a VertexBuffer using verts.Count as the number of vertices. Somehow the VertexBuffer becomes the wrong size. This leads me to believe that somehow the stride of my VertexElements is being calculated incorrectly but no matter how hard i try i cant find the bug. Can anyone see what im doing wrong?

Vertex Declaration
struct IntVertexPositionTexture : IVertexType
    {
        public Microsoft.Xna.Framework.Graphics.PackedVector.Short4 Position;
        public Microsoft.Xna.Framework.Graphics.PackedVector.Short4 Normal;
        public Microsoft.Xna.Framework.Graphics.PackedVector.NormalizedShort2 TextureCoordinate;

        public IntVertexPositionTexture(Microsoft.Xna.Framework.Graphics.PackedVector.Short4 position, Microsoft.Xna.Framework.Graphics.PackedVector.Short4 normal, Microsoft.Xna.Framework.Graphics.PackedVector.NormalizedShort2 textureCoordinate)
        {
            this.Position = position;
            this.Normal = normal;
            this.TextureCoordinate = textureCoordinate;
        }

        public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration(new VertexElement[]
    {
        new VertexElement(0, VertexElementFormat.Short4, VertexElementUsage.Position, 0),
        new VertexElement(8, VertexElementFormat.Short4, VertexElementUsage.Normal, 0),
        new VertexElement(16, VertexElementFormat.NormalizedShort2, VertexElementUsage.TextureCoordinate, 0),
    });

        VertexDeclaration IVertexType.VertexDeclaration
        {
            get { return VertexDeclaration; }
        }
    }


Usage
                VB = new VertexBuffer(device,IntVertexPositionTexture.VertexDeclaration, verts.Count, BufferUsage.WriteOnly);
                IB = new IndexBuffer(device, IndexElementSize.SixteenBits, inds.Count, BufferUsage.WriteOnly);
                VB.SetData<IntVertexPositionTexture>(verts.ToArray());
                IB.SetData(inds.ToArray());


Is This A Good Question/Topic? 0
  • +

Page 1 of 1