PDA

View Full Version : using VBO with Trianglestrips



Qbound
10-26-2003, 07:10 AM
Hi,

i work on a terrainengine, wich is divided in pages and the pages are diveded in small patches. The size of the patches are 64*64 Vertices. Each row is a Trianglestrip.
I have 1 Vertexbuffer and 1 Indexbuffer foreach Patch. The buffers are VBOs now i got the Problem that i want to render each row from a patch as an unique Trianglestrip because if i render the whole patch with one call to glDrawElements() i got ugly crossing triangles from one side of the patch to the other side. Wich is logical...
So ive to render each row of the patch individually, so there is my problem.

Can i use glDrawRangeElements on VBOs?

Here is my Renderloop:



m_pRender->glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, m_pIndices[ m_uiLOD ].uiID );

// Durch alle Strips loopen
for( uiCounter = 0; uiCounter < m_pIndices[ m_uiLOD ].uiSizeX - 1 ; uiCounter++ )
{
// Positionen holen
uiStart = uiCounter * m_pIndices[ m_uiLOD ].uiSizeY * 2 - 2;
uiEnd = uiStart + uiNum;

// Arrays rendern
m_pRender->glDrawRangeElements( GL_TRIANGLE_STRIP, uiStart, uiEnd, uiNum, GL_UNSIGNED_INT, NULL );
}

Zengar
10-26-2003, 07:20 AM
As far as I recall that has nothing to do with glDrawRangeElements. The extension is a driver hint to optimise vertex transfer. It tells the driover that your index range is from a to b, not index indices. You should use glDrawElements with modified indices index(using a offset). Example:
// Index 5 bis 10 rendern
glDrawElements(..., 10, 5*size_of(int));

Qbound
10-26-2003, 09:00 AM
Thanks Zengar for your hint. You mean that it is the best way if i move the indexpointer (&m_puiIndices[ uiPosition ]). The problem i got with this solution is that i use VBO Elements_Buffer and it seam to me that i dont have a direct access to the Indexbuffer. This is my call to glDrawElements if i want to render the complete IB



glDrawElements( GL_TRIANGLE_STRIP, m_pIndices[ m_uiLOD ].uiNumIndices, GL_UNSIGNED_INT, (PCHAR) NULL );

If i use the following one it crashes.



glDrawElements( GL_TRIANGLE_STRIP, uiEnd, GL_UNSIGNED_INT, &amp;m_pIndices[ m_uiLOD ].pIndices[ uiStart ] );

Zengar
10-26-2003, 09:34 AM
One can understand VBO's as pointers with base adress 0. Still, you can access data inside the VBO if you specify a offset inside a buffer(not a pointer to your data).
in your case offset is uiStart*4(size of int). More on it, you can safely delete your vertex array after uploading it to VBO. The server mantains then it's own copy.

Note: you should use count of indices(uiEnd - uiStart), not uiEnd

[This message has been edited by Zengar (edited 10-26-2003).]