Archived

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

arie

Different vertex-formats in one VB ??

Recommended Posts

Somehow there is something in my mind saying it''s possible to put vertices with different (variable) vertex-formats in one and the same vertex-buffer. But on creating this VB you must specify the vertex-format. I want to render a large amount of triangles (30000) without textures in one VB and some 10 other triangles containing textures in the same (or another VB?). What''s wise to do ? Arie.

Share this post


Link to post
Share on other sites
Hmm, normally I consider the ''shift of vertex buffer'' a costly operation, and I wouldn''t mind making my vertex data a -little- larger if it accomodates a new FVF and allows me to use a single buffer for two triangle styles. If you''re wondering how, well I''d use the vertex data that accomodates everything I need, even if it means a bit of useless data for a reasonable amount of triangles.
But your case is this: A large number of tris with small data, few tris with more data. So enlarging the FVF of the buffer to accomodate the ''biggest FVF'' will actually be very costly in the render steps.

Profiling could prove me wrong, but it sounds to me like you''re better off with two vertex buffers in -this- project. Just because you have many triangles with no texture. (They don''t need that extra data)

Put in perspective it''s not -so- terrible: So what if shifting VBs is slow, it''s still a sub-hundreth of a second operation. So two per frame isn''t much of a loss, eh?

Share this post


Link to post
Share on other sites
I think you would use two vertex buffers as well. In the first buffer, store the vertex coordinates of all the vertices. In the second buffer, store only the texture coordinates of those vertices using textures.

When rendering, just set the 1st stream as stream #0 and render as you normally would. When rendering the textured polygons, set the 2nd stream as stream #1 and use a shader declaration that points to stream #1 for using textures.

Jim Adams

Share this post


Link to post
Share on other sites
Aha, it seems my thinking was not too bad at all, but now I have a second ''problem'', due to Jim''s answer about setting a vertex shader. (Note that I am a kind of Newbie). Does he mean, just specify a second new vertex-format in the SetVertexShader call ?

My simplified (VB6) code is the following:

.BeginScene

.SetStreamSource 0, g_Vbuf, Len(VtxBuf(1))
.SetVertexShader D3DFVF_VERTEX

.SetIndices g_Ibuf, 0
.DrawIndexedPrimitive D3DPT_TRIANGLELIST, 0, _
g_NrIdx, 0, g_NrIdx / 3

.EndScene

How does Jim''s answer effect this. Supposed my textured index and vertex buffers are named g_Vbuf2 and g_Ibuf2 and so on.

Please don''t bother using exact syntax and/or VB code. C++ examples or ''pseudo code'' are also helpfull.

Arie.

Share this post


Link to post
Share on other sites