Sign in to follow this  
janta

Data offset in a vertex buffer

Recommended Posts

Hello guys, I have a choice to make. I have a vertex buffer whith my data in it but not in all of it (for any reason you could imagine) Of course I (have to) know my data's offset in this buffer, so what do I do with that offset ? - Use it in SetStreamSource like:
pDevice->SetStreamSource(0, pTheBigBuffer, uiOffsetVertex * sizeof(MyVertex), sizeof(MyVertex));
// other calls as appropriate.
pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 200);
- Use it in DrawPrimitive
pDevice->SetStreamSource(0, pTheBigBuffer, 0, sizeof(MyVertex));
// other calls as appropriate.
pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, uiOffsetVertex, 200);
Assuming both would work, I wondered what would be the best choice according to you. I want to chose one way of doing this and keep consistent. And also, assuming that this is a dynamic buffer and that other data in this buffer is completely irrelevant to me, so I won't want to batch draw calls with a unique SetStreamSource or stuff like that, I just want to draw my data. (the purpose of all of this is that I allocate a 2Mb dynamic vertex buffer at initialisation and then I lock it at run time using D3DLOCK_NOOVERWRITE as long as there is space left in the buffer, and with D3DLOCK_DISCARD every once in a while when space runs out) Thanks in advance for any aswers or suggestion.

Share this post


Link to post
Share on other sites
This looks like one of those 'matter of opinion' type situations. I always use the second method you presented, but I suppose either would work. The only thing I can think of is if you did it the first way, you wouldn't have access to the vertex information prior to your offset while with the second way you would just have to change the offset in your DrawPrimitives call to access the data prior to the offset. Hope that helps.

-AJ

Share this post


Link to post
Share on other sites
Yeah thats quite true. I've been thinking about it since I posted, and I now prefer the second solution because
- Generally speaking I could access the buffer before my offset (though in my situation it has absolutely useless)
- DX's doc mention that one should check D3DDEVCAPS2_STREAMOFFSET constant in D3DDEVCAPS2 prior to using an offset in a SetStreamSource, so I guess some graphic cards out there do not support stream offsets (but I think these are pretty old cards out of my target range anyway)

Thx for the reply

Share this post


Link to post
Share on other sites
A SetStreamSource call can be pretty expensive. The second method you specify should definatly see better results.

I would reckon to guess that the Stream Offsets are really there for multiple streams, if you want to offset one stream against another.

Hope this helps :).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this