Skip to main content
GameDev.net gamedev.net
🔒 Locked

Binding multiple buffers.

Started by L. Spiro Mar 28, 2011 at 7:41 AM 1 replies 16.9k views
Original Post
L. Spiro
L. Spiro
In Direct3D you can activate multiple vertex buffers to different “streams”.
In OpenGL I can have multiple vertex buffers (not talking about VBO’s yet) and just use glVertexAttribPointer() to link all of the data from the various buffers to the shader attributes, effectively working the same way as in DirectX.

But how can this be done with VBO’s?
glBindBuffer() removes the buffer previously bound (of the same type, which will always be my case when trying to enable multiple vertex buffers).


So if I have data spread across multiple vertex buffers that use VBO’s, how can I link each of the inputs to the shader attributes?


Thank you,
Yogurt Emperor
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
karwosts
karwosts
Just call glBindBuffer/glVertexAttribPointer back and forth as many times as you need to. Once you call glVertexAttribPointer, there's no need to have the buffer bound (OpenGL doesn't care if the buffer is bound when you render, it only needs to be bound to set the pointer).

If you want to draw something using data from three different VBO's:

1) glBindBuffer( buffer0 )
2) glVertexAttribPointer( ... );
3) glBindBuffer( buffer1 )
4) glVertexAttribPointer( ... );
5) glBindBuffer( buffer2 )
6) glVertexAttribPointer( ... );
7) glBindBuffer( 0 ); // don't need anything bound anymore since pointers are set
8) glDrawElements( ... ); //draw mesh from the three vbo streams
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
L. Spiro
L. Spiro
Oh.

Thank you.
Yogurt Emperor
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.