glGenBuffers doesn't work quite like what you expect. When you call glGenBuffers, it doesn't actuallycreate anything. It just returns a list of integers that are not currently used as buffer names.glBindBuffer. So you can just make up any integer you like and pass it to glBindBuffer and a valid buffer will be created at that index. glGenBuffers is actually not required at all, it's just there as a convenience function to give you an unused integer.glGenBuffers. That's why your code works whether you tell glGenBuffers to create 1 or 2 buffers. As long as you have two buffers with two different names, it doesn't matter where the integer came from.int buf;
glGenBuffers(1, &buf);
glIsBuffer(buf); //FALSE - buffer has not been created yet
glBindBuffer(GL_ARRAY_BUFFER, buf);
glIsBuffer(buf); //TRUE - buffer created on bind
http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml
--- glBufferData()
http://stackoverflow.com/a/5402762
http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml
void glBufferData( | GLenum | target, |
| GLsizeiptr | size, | |
| const GLvoid * | data, | |
| GLenum | usage); |
Parameters
target- Specifies the target buffer object. The symbolic constant must be
GL_ARRAY_BUFFER,GL_ATOMIC_COUNTER_BUFFER,GL_COPY_READ_BUFFER,GL_COPY_WRITE_BUFFER,GL_DRAW_INDIRECT_BUFFER,GL_DISPATCH_INDIRECT_BUFFER,GL_ELEMENT_ARRAY_BUFFER,GL_PIXEL_PACK_BUFFER,GL_PIXEL_UNPACK_BUFFER,GL_SHADER_STORAGE_BUFFER,GL_TEXTURE_BUFFER,GL_TRANSFORM_FEEDBACK_BUFFER, orGL_UNIFORM_BUFFER. size- Specifies the size in bytes of the buffer object's new data store.
data- Specifies a pointer to data that will be copied into the data store for initialization, or
NULLif no data is to be copied. usage- Specifies the expected usage pattern of the data store. The symbolic constant must be
GL_STREAM_DRAW,GL_STREAM_READ,GL_STREAM_COPY,GL_STATIC_DRAW,GL_STATIC_READ,GL_STATIC_COPY,GL_DYNAMIC_DRAW,GL_DYNAMIC_READ, orGL_DYNAMIC_COPY.
Description
glBufferData creates a new data store for the buffer object currently bound to target. Any pre-existing data store is deleted. The new data store is created with the specified size in bytes and usage. If data is not NULL, the data store is initialized with data from this pointer. In its initial state, the new data store is not mapped, it has a NULL mapped pointer, and its mapped access is GL_READ_WRITE.usage is a hint to the GL implementation as to how a buffer object's data store will be accessed. This enables the GL implementation to make more intelligent decisions that may significantly impact buffer object performance. It does not, however, constrain the actual usage of the data store. --- glBindBuffer()
http://www.opengl.org/sdk/docs/man/xhtml/glBindBuffer.xml
void glBindBuffer( | GLenum | target, |
| GLuint | buffer); |
.... Buffer object names are unsigned integers. The value zero is reserved, ...,
buffer set to zero effectively unbinds any buffer object previously bound, and restores client memory usage for that buffer object target (if supported for that target)...