How to use index buffers correctly?

Started by
1 comment, last by cruZ 22 years, 5 months ago
My problem: I have a quadtree, containing my vertexdata of a rather huge landscape. Now i process my tree to determine the visible part of the landscape. Works all fine, but... The way I pass the visible vertexdata to d3d is to lock/update/ and unlock my vertexbuffer every frame. -not very effective I guess. I''m not sure how to re-structure my quadtree-visiblity code correctly in order to use vertex and index buffers effectivly. Should I create an indexbuffer for every treenode? ...well I''m out of ideas, and the DXHelp doesn''t say a word on how to use indexbuffers with things like BSP/Quad or Octrees.
Advertisement
I would probably hack the terrain into chunks of 16x16 or 32x32 tiles, and contain each chunk in an array. Then you use your quadtree to determine what chunks are available, and render the visible chunks. I suppose you could fill out a vertex buffer for each chunk ahead of time, and that way you wouldn't need to lock/unlock the vertex buffer(s) every frame. The same would go for your index buffers.

I think that using a quadtree will only help to a certain extent before you end up taking more time to search for what is supposed to be rendered and actually rendering it than having to render a bit offscreen. You might have to play around with it to find the ideal chunk size.

I hope that helps.

Edited by - Moe on November 9, 2001 6:42:02 PM
I agree, make each leaf of the quad tree a chunk of vertices, instead of one square. As long as your vertex data fits nicely into a single vertex buffer, put ALL of the terrain vertices in there, but locate each leaf of the quad tree in a continous chunk. You can specify which portion (ie. one leaf) of the vertex buffer to draw with a call to the DrawPrimitive function and specifying the offset and size of the leaf within the buffer. There is no need to ever lock the vertex buffer for terrain, unless you are loading new terrain or you have deformable terrain. If you have discreet levels of detail, you can store each level in its own vertex buffer (ex: mip mapped hieghtfields).

If your terrain is really big, use several buffers, and if its really really big, page buffers in from disk as the camera moves to new areas.

This topic is closed to new replies.

Advertisement