Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

nickwinters

Multiple vertex buffers and index buffers

This topic is 5225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m currently working through Tom Miller''s Managed DX Kick Start. The source code shows how to use a single vertex buffer and a single index buffer. But how do I use multiple vertex buffers and index buffers on a single frame? The lines that lead me to believe there can only be one are the following:
device.VertexFormat = CustomVertex.PositionColored.Format;
device.SetStreamSource(0, vb, 0);
device.Indices = ib; 
Where vb is the vertex buffer and ib is the index buffer. Thanks. -Nick

Share this post


Link to post
Share on other sites
Advertisement
you can have any number of vertex/index buffers (depending on ur sys mem and video card mem).
when rendering (in dx), use SetSourceStream to set your Vertex buffer and use SetIndices to set your index buffer and call the DrawIndexedPrimitive function. so you are not restricted to 1 of each.

hope this helps.

[edited by - krad7 on February 27, 2004 5:07:18 PM]

Share this post


Link to post
Share on other sites
After looking a bit at SetStreamSource, I think I understand. Do I set the first parameter (streamNumber) to a different value for each buffer?

In terms of indices, I am unable to find a method to set them. May I say device.Indices+=ib1; device.Indices+=ib2; etc.? Or is there any other way to do it? Perhaps some sample code would help.

Thanks.

-Nick

Share this post


Link to post
Share on other sites
I don''t know about that "StreamNumber" parameter, but what I usually do when using multiple vertex/index buffers is that before calling the DrawIndexedPrimitive function, I call SetStreamSource, SetIndices, and SetVertexShader (or SetFVF in DX9). That should work fine...

Share this post


Link to post
Share on other sites
quote:
Original post by nickwinters
I''m currently working through Tom Miller''s Managed DX Kick Start. The source code shows how to use a single vertex buffer and a single index buffer. But how do I use multiple vertex buffers and index buffers on a single frame?


Are you asking how to use multiple vertex buffers in a single render call or are you asking about how to use multiple vertex buffers to draw different objects on the screen? I ask this because you say you want o use multiple vertex buffers on a single frame, so it''s not clear which one you mean.

neneboricua

Share this post


Link to post
Share on other sites
I believe what I want is to use them in a single render call. So I''d have one set for walls, another for players, another for obstacles, etc.

-Nick

Share this post


Link to post
Share on other sites
quote:
Original post by nickwinters
I believe what I want is to use them in a single render call. So I''d have one set for walls, another for players, another for obstacles, etc.

-Nick

In that case, then you should not be using multiple streams. The rationale for multiple streams is that sometimes different meshes have data that they can have in common.

For example, if you have two vertex buffers with different position values but that use the same texture coordinates, it would be a waste of memory to allocate space for these texture coordinates in both vertex buffers. You could just make the texture coordinates into their own vertex buffer and use multiple streams when rendering your data.

Trying to have a vertex buffer for walls, another for players, another for obstacles, and trying to render them all at the same time will cause you massive headaches. For example, vertex shaders (as well as the fixed function pipeline for that matter) can only output one transformed position. There is no way to output a bunch of different positions for different streams. The idea of multiple streams is there to be able to share data, not to try to render multiple meshes at once.

Hope this clears it up for you,
neneboricua

Share this post


Link to post
Share on other sites
I never said it was expensive. What I was trying to say was that it is not possible. Let me try to explain in a little more detail why you can't do this. Do a search for "Programming One or More Streams" in the SDK docs for an explanation as to what multiple streams are and how to use them.

The reason what you're suggesting is not possible is because for a given vertex, you can only output one transformed position. To do what you're suggesting, you'd have to be able to output n transformed positions (one for each stream you're using). The hardware isn't made that way. Even if you could do it, the hardware would have to do deal internally with the fact that the geometry for one of those n streams could overlap the geometry for another.

Another reason is that internally, D3D drivers use index buffers for everything. So even if you use DrawPrimitive, internally the driver will use an index buffer of {0,1,2,3,4...}
for how ever many triangles you're rendering. For your idea to work, you would have to be able to set n index buffers as well as n streams. D3D doesn't have the functionality to do this.

neneboricua

[edited by - neneboricua19 on February 29, 2004 5:04:16 PM]

Share this post


Link to post
Share on other sites
Alright, that makes sense. So instead, is it possible for me to make the walls in one vertex buffer, and load everything else as meshes?

Thanks.

-Nick

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!