• Advertisement
Sign in to follow this  

Multiple Indice buffers needed?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
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]

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 this post


Link to post
Share on other sites
Quote:
Original post by Jiia
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?
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 Jiia
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?".

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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
...(which is a pain, since it means your code works fine on nVidia hardware, and breaks on ATI).


Sorry, is that only if you don't specify the range? I always specify the range anyways, so I should be safe...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement