Rendering From Vertex and Index buffers with texture switching SLOW???

Started by
3 comments, last by Dark 21 years, 3 months ago
Ok... I have the following problem I have a tile landscape with a heightmap (so the tiles are squares with height for the vertices) I have a large vertex buffer (lets just say 65536 vertices) I have an index buffer of 255*255*6 (255 by 255 tiles... each tile takes 2 triangles that is 6 indices) = 390150 indices (shit that is a lot) now... I do not want every tile to have the same texture... so lets just say I have 256 different textures (easy calculation). I batched the indices together (that is filled the index buffer so that they use the vertex buffer accoring to whichever uses a texture... I mean... if triangles use texture 0 they will be in front of the index buffer... after that triangles using texture 1, etc)... now I make a call like so g_cRenderSystem.getDevice()->SetFVF(D3DFVF_TERRAINVERTEX); g_cRenderSystem.getDevice()->SetStreamSource(0, m_pD3DVertexBuffer, 0, sizeof(SVertex)); g_cRenderSystem.getDevice()->SetIndices(m_pD3DIndexBuffer); and I then render everything in a loop like this: // this is not the actual code... but you will probably know what I mean for(int tex = 0; tex < l_TexBatchCount; ++tex) { l_numPrimitives = l_aTexBatchPrimitives[tex]; g_cRenderSystem.getDevice()->SetTexture(0, l_TexID); g_cRenderSystem.getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, m_numIndices, 0, l_numPrimitives); } now... this code seems to RETRANSFORM the vertex buffer every DrawIndexedPrimitive call... and that slows things down TERRIBLY Put in another way: How can I render quickly from a large vertex and index buffer while being able to switch textures between DrawPrimitive calls? so if you know a way around this... please tell me... thank you in advance ICQ: 130925152 Email: e.j.folkertsma@student.utwente.nl
ICQ: 130925152Email: e.j.folkertsma@student.utwente.nl
Advertisement
From the DX8.1 FAQ:

quote:When I submit an indexed list of primitives, does Direct3D process all of the vertices in the buffer, or just the ones I indexed?

When using the software geometry pipeline, Direct3D first transforms all of the vertices in the range you submitted, rather than transforming them "on demand" as they are indexed. For densely packed data (that is, where most of the vertices are used) this is more efficient, particularly when SIMD instructions are available. If your data is sparsely packed (that is, many vertices are not used) then you may want to consider rearranging your data to avoid too many redundant transformations. When using the hardware geometry acceleration, vertices are typically transformed on demand as they are required.


So you also want to group vertices in the VB by texture and pass the range into DIP so that only they are transformed.
Ok thanks...

this means a major problem for the internal data structure though, but I guess I will have to live with that

ICQ: 130925152Email: e.j.folkertsma@student.utwente.nl
You might also ProcessVertices at start of frame and use the transformed VB for rendering. This of course isn''t best for HW TnL, but with HW TnL you don''t have this problem. (Instead you worry about the vertex cache.)
If you look up DrawSubset() for rendering the terrain mesh instead of using drawindexedprimitive() you will find the tiled landscape will be rendered at a much improved framerate. DrawSubset() groups the mesh by textures.

This topic is closed to new replies.

Advertisement