XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Multiple Vertex Streams

Last post 11/22/2007 5:55 AM by Mrmuzz. 2 replies.
  • 11/21/2007 7:20 PM

    Multiple Vertex Streams

    Hi,

    OK, XNA let's you set the vertex data of different streams, like so:
            Device.Vertices[iStream].SetSource(vb, 0, VertexPositionColor.SizeInBytes);

    I've read one use of this is where you have static geography (i.e. physical vertex location) but dynamic texture 'geography' (i.e. texture u-v offset). Or, of course, vice versa.  All sounds useful, but probably a bit more advanced than where i am :-)

    What i have is to "streams" of vertices - one of which is for static geography (e.g. the "world") and the other is for my dynamics stuff (e.g. the player). I have colours but no textures yet.

    Each frame I'm currently going (pseudo-code):

    Update()
    {
    update DynamicVertices
    update DynamicIndices
    update DynamicVertexBuffer
    update DynamicIndexBuffer

    if(worldHasChanged)
    {
    updateStaticEquivalents
    }
    }

    Draw()
    {
    Device.Vertices[0].SetSource(DynamicVB) // (****)
    Effect.Begin() - Draw DynamicVB - Effect.End()

    Device.Vertices[0].SetSpource(StaticVB)
    Effect.Begin() - Draw StaticVB - Effect.End()
    }

    What i'd like to do is not have to SetSource() on the static stuff each frame.  It's static - so I'd like to post it to the graphics card once and leave it there.  Can I do that?? I tried changing the Vertices[0] to Vertices[1] on the (****) line but that gave funny results.

    • Is this workable?
    • Do i have to do something fancy in the shader?
    • Are there any examples?
    • Is it likely to be worth the hassle???
    Thanks for any advice!!

    Muzz

    Muzz http://www.PositronicArts.com/blog
  • 11/21/2007 8:32 PM In reply to

    Re: Multiple Vertex Streams

    Answer
    Reply Quote

    Why does your player need a dynamic vertex buffer?

    Also, I don't think setting a stream source is very costly in the grand scheme of things. You're not uploading anything significant to the GPU with this call, you're just saying "Hey Mr. GPU, you should use these vertices for stream #n when I tell you to".

    The source index corresponds to the vertex declaration you use. Your vertex declaration might look like this:
    put positions in stream 0
    put normals in stream 0
    put vertex colors in stream 1
    put tex coords in stream 2

    If you did this, you'd need to call SetSource for stream 0, 1, and 2 with three different vertex buffers.

    Your shader doesn't care what stream these things come from.

  • 11/22/2007 5:55 AM In reply to

    Re: Multiple Vertex Streams

    Hi,

    Thanks for the reply.  I think i had misread my profiler when i asked this, and I was re-setting my vertex buffer each frame too (even on the static geography), which was slowing things down a lot.  That's now sorted so back up to > 200fps.

    The player has a dynamic vertex buffer because different bits of him are moving round, and spawning other geogrpahy round him as he goes.   I _could_ have each of those other bits of geogrpahy in their own vertex buffer, change their world matrix each frame or something, but that would require more DIPs.  I currently only have 2 DIP's per frame which is nice.  As you say, setting the stream source seems to be working ok for me at the moment.  I'll leave things as is and will re-profile if things start getting worse.

    Thanks!

    Muzz

    Muzz http://www.PositronicArts.com/blog
Page 1 of 1 (3 items) Previous Next