# nb of vertex bufffer?

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

## Recommended Posts

I have a question, let's say i want to draw many solid in my game, or mesh. Do i need one vertex buffer per mesh or solid? or do they all use the same vertex buffer? Tried to find it in my book but didnt talk about the possibility that i would want to add more solid :)

##### Share on other sites
No, you can pack as many object as you want in your vertex buffer (as long as they use the same vertex format). You only need to set your index buffer accordingly.

Also, reducing the number of vertex buffers to a minimum is a good thing. See the "Batch, Batch, Batch" presentation on the NVidia developer site for a paper on why this is good.

##### Share on other sites
So if i want to place more than one object/mesh in the same vertex buffer i have absolutly no choice to use an index buffer is that right? ( Which would be a must to use for memory reason but I'm just curious )

Just for the record how many vertex buffer most of the commercial games use?

##### Share on other sites
For what it's worth, my opinion is that switching between stream sources is not as performance costly as most programmers seem to believe. If you have to go way out of your way to combine buffers, it's probably not worth it. There are situations where it could become costly, though. Such as rendering hundreds of small objects. But generally (if there is such a thing), giving each resource object its own buffer makes things easier to manage.

[edited - too sleepy to think straight]

##### Share on other sites
No, you can still use DrawPrimitive and set the 2nd parameter (StartVertex) to a value greater than zero.

I can't really tell how many VBs commercial games use as it depends on their content and design. Some well known commercial engine still use one VB per object because it makes things easier to manage even if it's not the best for performance.

##### Share on other sites
Alright, as i can see i can do it like i want but i have to care about the memory usage. Also, I'm having trouble to understand how i can put my vertices in a specified vertex buffer. Let's say i have 2 vertex buffer. I'm creating somekind of map within the source ( testing and learning purpose ). I Want to add all the wall inside an X vertex buffer and the floor in Y vertex buffer.

While i copy my vertice inside the buffer i use memcpy function, but while using this function there is no way i can (as far as i can see) say in which vertex buffer i want to copy my vertices.

##### Share on other sites
Some quick source. Basically I create a vertex buffer large enough to contain all the wall and floor vertices. I then lock the firt part of the vb and memcpy the wall vertices and then lock the second part of the vb and memcpy the floor vertices. I then bind the vb to stream 0 and draw both primitives depending offseting correctly in the vb using the 2nd parameter of the DrawPrimitive method.

    LPDIRECT3DVERTEXBUFFER9 VertexBuffer;    d3dDevice->CreateVertexBuffer(        (Wall->GetNumVertices() + Floor->GetNumVertices()) * Stride,        0,        0,        D3DPOOL_MANAGED,        &VertexBuffer,        NULL);     Vertex* vertices;     // Copy the vertices of the wall into the first part of the VB     int LockPos = 0;     int LockOffset = Wall->GetNumVertices() * Stride;     VertexBuffer->Lock(LockPos, LockOffset, &vertices, 0);     memcpy(vertices, Wall->GetVertices(), Wall->GetNumVertices() * Stride);     VertexBuffer->Unlock();     // Copy the vertices of the floor into the second part of the VB     LockPos += LockOffset;     LockOffset += Floor->GetNumVertices() * Stride;     VertexBuffer->Lock(LockPos, LockOffset, &vertices, 0);     memcpy(vertices, Floor->GetVertices(), Floor->GetNumVertices() * Stride);     VertexBuffer->Unlock();     // Bind the VertexBuffer to stream 0     d3dDevice->SetStreamSrouce(0, VertexBuffer, 0, Stride);     // Draw the wall     d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, Wall->GetNumTriangles());     // Draw the floor     int offset = Wall->GetNumVertices() * Stride;     d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, offset, Floor->GetNumTriangles());

##### Share on other sites
so if i understand corectly, the vertice are copied inside the curently locked buffer ( or last locked one? )

##### Share on other sites
You lock a VB and copy vertices in and unlock it.

1. VertexBufer->Lock
2. memcpy
3. VertexBuffer->Unlock

Remember that all the vertices inside a VB should have the same format.

##### Share on other sites
Quote:
 Remember that all the vertices inside a VB should have the same format.

Or at least the same vertex stride, if not necessily the same vertex format.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633287
• Total Posts
3011217
• ### Who's Online (See full list)

There are no registered users currently online

×