Why does my VertexDeclaration apparently not contain Position0?
Posted
by
Phil
on Game Development
See other posts from Game Development
or by Phil
Published on 2012-11-25T07:01:07Z
Indexed on
2012/11/25
11:24 UTC
Read the original article
Hit count: 255
I'm trying to get my code from calling each individual draw call down to using at least a VertexBuffer, and preferably an indexBuffer, but now that I'm attempting to test my code, I'm getting the error:
The current vertex declaration does not include all the elements required by the current vertex shader. Position0 is missing.
Which makes absolutely no sense to me, as my VertexDeclaration is:
public readonly static VertexDeclaration VertexDeclaration
= new VertexDeclaration(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(sizeof(float) * 3, VertexElementFormat.Color, VertexElementUsage.Color, 0),
new VertexElement(sizeof(float) * 3 + 4, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0)
);
Which clearly contains the information. I am attempting to draw with the following lines:
VertexBuffer vb = new VertexBuffer(GraphicsDevice, VertexPositionColorNormal.VertexDeclaration, c.VertexList.Count, BufferUsage.WriteOnly);
IndexBuffer ib = new IndexBuffer(GraphicsDevice, typeof(int), c.IndexList.Count, BufferUsage.WriteOnly);
vb.SetData<VertexPositionColorNormal>(c.VertexList.ToArray());
ib.SetData<int>(c.IndexList.ToArray());
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vb.VertexCount, 0, c.IndexList.Count/3);
Where c is a Chunk class containing an 8x8x8 array of boxes.
Full code is available at https://github.com/mrbaggins/Box/tree/ProperMeshing/box/box.
Relevant locations are Chunk.cs (Contains the VertexDeclaration) and Game1.cs (Draw() is in Lines 230-250). Not much else of relevance to this problem anywhere else. Note that large commented sections are from old version of drawing.
© Game Development or respective owner