This topic is now archived and is closed to further replies.


using Dynamic Buffering with static data?

Recommended Posts

Santharn    122
I have a problem with my static index data, that i have precalculated (i thought copying them each frame would be a little faster than building up the indices each frame again) - but it doesn't work. The index and vertex-data is accordingly stored in common system memory-arrays (called m_pIndices and m_pVertices). The indices are related absolutely from the first vertex in my precalculated data - and there also is my problem: Copying this data from these arrays in the index-and vertex buffers at runtime, the indices are still related to the originally vertex-array and are NOT related to the vertex buffer, from which i am rendering. Is there any possibility to adjust this problem with my index-buffer (maybe with the ->SetIndices-Function or ->DrawIndexedPrimitives-parameters) or is there absolutely no chance and will i have to calculate the indices for each looppass? My engine follows this principles out of DX-Docu:
for loop()
    pBuffer->Lock(...D3DLOCK_DISCARD...); //Ensures that hardware 

                                          //doesn't stall by returning 

                                          //a new pointer.

    Fill data (optimally 1000s of vertices/indices, no fewer) in pBuffer.
    Change state(s).
    DrawPrimitive() or DrawIndexedPrimitive()
My vertex and index buffers are only as big as they need to be for one loop-cycle:
// Create the vertex buffer

				sizeof( CFunctionVertex ) * (m_uiNumOfBatchVertices+1), 
				&m_pVB );

//Create the index buffer:

				sizeof( *m_pIndices ) * (m_uiNumOfBatchIndices+1),
				&m_pIB );
The rendering-code looks like this:
m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof( CFunctionVertex ) );		
m_pd3dDevice->SetVertexShader( CFUNCTION_VERTEX_FORMAT );	

BYTE* pData = 0; //Used as Pointer to the vertexbuffer and to the indexbuffer

   //in the loop while rendering

m_pd3dDevice->SetIndices( m_pIB, 0 );

//Calculate here the pointer-data for the first loopcycle


//Here is the core-loop:

for( iNumOfLoops ) {
   //Update indices, i'm aware that this is not correct, but perhaps i'm using it wrong?

   m_pd3dDevice->SetIndices( m_pIB, m_CurrentCycle.uiStartIndex );

   //Lock the vertex buffer

   m_pVB->Lock( 0, 0, &pData, D3DLOCK_DISCARD );

   //Copy the face vertices into the buffer

   CopyMemory( pData, 
      sizeof( MyVertex ) * m_CurrentCycle.uiNumOfVertices );

   //Unlock the Vertex Buffer:



   //Lock the index buffer

   m_pIB->Lock( 0, 0, &pData, D3DLOCK_DISCARD );
   //Copy the indices into the buffer

   CopyMemory( pData, 
      (void*)&m_pIndices[ m_CurrentCycle.uiStartIndex ], 
      sizeof( *m_pIndices ) * m_CurrentCycle.uiNumOfIndices );

   //Unlock the index Buffer:


   //And render the indexed triangles:


   hr = m_pd3dDevice->DrawIndexedPrimitive(	
      m_CurrentCycle.uiNumOfIndices/3 );


   //Calculate the pointer data for the next loopcycle


   } //for( iNumOfLoops )

This works only well when all the indices can be rendered within one loop-cycle. thanks for your help! [edited by - Santharn on September 30, 2002 12:49:47 PM]

Share this post

Link to post
Share on other sites