how to change the current stream input ( vertices )
In the graphicdevice, they exist the property
device.Vertices
which is a collection, so we can put a lot of kind of vertex buffer in it. Very nice but ...
How to say that the current stream is not the Zero but an other ?
because the function drawnprimitive use the current stream and in my case it s always device.Vertices[0]. So if we cannot change the current stream what is the goal of the collection Vertices ?
If you know how to change the current stream to take for example device.Vertices
, can you explain it to me.
PS : sorry but i am french and my english is not really perfect. ;)
The function of GraphicsDevice.Vertices is not a general collection of VertexBuffers that you store and then switch drawing on. There purpose is to allow flexability in how you organize your vertex data and send it to your shaders. By setting multiple vertex streams and then setting the appropriate VertexDeclaration, you can have a shader that takes data from multiple streams at the same time. A common example is tweening animation between two models. You could set two vertex buffers that represent the two models you want to blend between. Your shader would define the inputs to accept the two chunks of data and a blending value and output the position, normal, etc. based on the computation between the two.
I would also like to see an example of using multiple vertices. I am attempting to create a vertex tweening shader, but I get an unknown error when creating the VertexDeclaration. What would a simple vertex declaration for this task look like and how would you address the second stream in the shader?
Thanks,
Dan
The vertex shader won't actually know where its vertices come from, it just has a set of input variables that are identified by the semantics they specify (eg.
COLOR0 is whatever the vertex declaration specified to be the first
VertexElementFormat.Color item with
usageIndex 0).
If you had two VertexBuffers, one containing the positions of your vertices and the other containing the colors, you could set the toGD.Vertices[0].VertexBuffer andGD.Vertices[1].VertexBuffer respectively and use the following VertexDeclaration:
new VertexDeclaration(
graphicsDevice,
new VertexElement[] {
// Positions from vertex stream 0
new VertexElement(
0, // which stream this element comes from
0, // byte offset within the stream
VertexElementFormat.Vector3,
VertexElementMethod.Default,
VertexElementUsage.Position,
0 // usage index (whether it's "POSITION0" or "POSITION1" in the shader)
),
// Colors from vertex stream 1
new VertexElement(
1, // which stream this element comes from
0, // byte offset within the stream
VertexElementFormat.Color,
VertexElementMethod.Default,
VertexElementUsage.Color,
0 // usage index (whether it's "COLOR0" or "COLOR1" in the shader)
)
}
);
The same vertex shader you use to read the data from a single VertexBuffer with both vertex components baked together would now read its data from two VertexBuffers.
-Markus-