# Multiple Indice buffers needed?

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

## Recommended Posts

Bit of confusion on my part, probably because I'm just starting to learn DirectX. I have a bunch of vertexes and a bunch of indexes that use the vertexes. However, within these indices, some are desired to have different textures. Do I have to actually make different index buffers for every set of triangles that use different textures? How do I do that? I couldn't figure out a way using DrawIndexedPrimitives to have it only draw some of the indices, then I could switch textures, and then draw more from the index buffer.

##### Share on other sites
HRESULT DrawIndexedPrimitive(    D3DPRIMITIVETYPE Type,    INT BaseVertexIndex,    UINT MinIndex,    UINT NumVertices,    UINT StartIndex,    UINT PrimitiveCount);

You can specify the subset of triangles to render using the parameters passed to the function. But as far as I understand, it's better to seperate the primitives so that each material has an index buffer. Don't assume I'm correct, though.

So you keep a single vertex buffer, but use an index buffer for each subset. Getting the vertex starting points and offsets of each subset can be different depending on how you're loading in your mesh data. D3DXMesh has methods for this, if you use that. Although I doubt you are, or you would probably be using DrawSubset().

Sorry, I'm a little new to the primitive rendering myself.

##### Share on other sites
From the specs of the DrawIndexedPrimitive, it seems tied more to the vertexes than the Indices. It only had vertex offsets, I did not see any way of offsetting into the indice buffer.

I have g_cubeIndices filled in with a list of indexes in the array. It's a WORD g_cubeIndices[100];

LPDIRECT3DINDEXBUFFER9 g_pIndexBuffer;

g_pd3dDevice->CreateIndexBuffer( indiceCount[currentRoomExamined]*sizeof(WORD),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_DEFAULT,
&g_pIndexBuffer,
NULL );

WORD *pIndices = NULL;

g_pIndexBuffer->Lock( 0, indiceCount[currentRoomExamined], (void**)&pIndices, 0 );
memcpy( pIndices, g_cubeIndices, indiceCount);
g_pIndexBuffer->Unlock();

I can't figure out how to either use subsets into that indice buffer, or somehow make additional index buffers that can be used. Any help would be appreciated.

##### Share on other sites
Sorry, I guess you're right. I'm not sure why DirectX would want a subset of the vertex buffer when rendering an indexed mesh. It doesn't make sense.

As for the spawning multiple index buffers, is this a mesh you are creating or loading from file? If you're creating it, you can just create two index buffers and copy each individual subset to each buffer. You will need the vertex subset numbers of each subset to do this. This is also why I'm not sure how to help you if you're loading the mesh in. You'll have to find the vertex index and count for each subset. If you can get that data, you just copy that portion of the indices to a single buffer.

##### Share on other sites
See here. StartIndex is the index to start fetching from, and PrimCount along with PrimType tell it how many indices to fetch.

##### Share on other sites
You can specify the starting index with the StartIndex parameter to DrawIndexedPrimitive. And you can specify the number of primitives to draw using the PrimitiveCount parameter.
You should always try to put as many objects into one buffer as you can, to reduce the need to call IDirect3DDevice9::SetStreamSource and IDirect3DDevice9::SetIndices. You get best performance from putting all static objects into one VB/IB, and rendering from subsets of the buffers.

Edit: Too slow [smile]

##### Share on other sites
I'm not loading a mesh. I'm basically just importing vertexes and indices from a file of mine. I guess I do need multiple indice buffers and have to keep switching to different indice buffers when I draw?

##### Share on other sites
Quote:
 Original post by Evil SteveYou can specify the starting index with the StartIndex parameter to DrawIndexedPrimitive. And you can specify the number of primitives to draw using the PrimitiveCount parameter.You should always try to put as many objects into one buffer as you can, to reduce the need to call IDirect3DDevice9::SetStreamSource and IDirect3DDevice9::SetIndices. You get best performance from putting all static objects into one VB/IB, and rendering from subsets of the buffers.Edit: Too slow [smile]

How does this compare to combining texture calls? If each subset uses a different material, you'll have to set a different texture for each. But if several other subsets belonging to other objects use that texture, you will set that texture several times. Is this better or worse than setting multiple vertex + index streams?

edit:
Also, I read somewhere that rendering a subset of a vertex buffer forces the api to transform the entire buffer. Is that true? Let me see.. I found that.. here. Scroll down to "Q. Why are my Indexed Primitive calls so slow?".

##### Share on other sites
Quote:
 Original post by JiiaHow does this compare to combining texture calls? If each subset uses a different material, you'll have to set a different texture for each. But if several other subsets belonging to other objects use that texture, you will set that texture several times. Is this better or worse than setting multiple vertex + index streams?
It'd be best to render all the triangles using one texture, then SetTexture(), then render the next batch of triangles. You could still get all the triangles into one buffer, it'd just take several calls to SetTexture() and Draw[Indexed]Primitive(), but you'd need to do that anyway (or use a custom shader)

Quote:
 Original post by JiiaAlso, I read somewhere that rendering a subset of a vertex buffer forces the api to transform the entire buffer. Is that true? Let me see.. I found that.. here. Scroll down to "Q. Why are my Indexed Primitive calls so slow?".

Quote:
 Note: The following information is based on D3DIM 7. Under DirectX 8, the DrawIndexedPrimitive command allows you to specify a starting vertex and number of vertices use. By restricting this to the range used in a rendering call, only those vertices get processed.
That also applies to DX9.
Edit: Actually, that doesn't matter at all with recent hardware. Post-GeForce cards do the transformation in hardware, so you effectively get it for free. And the nVidia drivers ignore the vertex range completely, and just transform vertices as needed (which is a pain, since it means your code works fine on nVidia hardware, and breaks on ATI).

##### Share on other sites
Quote:
 It'd be best to render all the triangles using one texture, then SetTexture(), then render the next batch of triangles. You could still get all the triangles into one buffer, it'd just take several calls to SetTexture() and Draw[Indexed]Primitive(), but you'd need to do that anyway (or use a custom shader)

DrawPrimitive it was easily do-able, but I could not figure out how to use one indice buffer, write a little, change the texture, then write more of the indice buffer.

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632955
• Total Posts
3009450
• ### Who's Online (See full list)

There are no registered users currently online

×