Data offset in a vertex buffer

Started by
2 comments, last by sirob 17 years, 10 months ago
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.
Advertisement
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
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
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
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 :).
Sirob Yes.» - status: Work-O-Rama.

This topic is closed to new replies.

Advertisement