# Accessing data in a vertex buffer, thru an index buffer

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

## Recommended Posts

Hello, My terrain engine uses one big heightmapped vertex buffer. This is then 'sectorized' in the index buffer, to create concurrent block of indices referring to one sector of terrain. I need to find the heightest point of each sector tho. During the vertex buffer sector, the sectors have not been created, so it can't be stored then. Ideally, I'd be able to check the height of each vertex referred to be a particular index in the indexbuffer as it is being built.... Then the greatest one for each sector can be stored! How would I go about this? Thanks Simon

##### Share on other sites
Something like:

Lock_Vertex_BufferFor( Each Sector ){    Current_Maximum = -99999    Lock_Sector_Index_Buffer    For( Each Index In Buffer )    {        if( VertexBuffer( index ).height > Current_Maximum )            Current_Maximum = VertexBuffer( Index )    }    This_Sector.Maximum_Height = Current_Maximum}

Given that your vertex buffer contains the height data you're going to have to use the index data to look up the information... the rest should fall into a fairly simple algorithm such as the one I typed out above.

Obviously the one above isn't gonna be particularly quick for a large data-set, but for a pre-process/load-time function it shouldn't matter too much.

hth
Jack