Search code examples
openglbuffervbo

First Inizialization of VBO. Does it matter where to bind?


Say i want just to create and fill a buffer.

GLuint ret;
glGenBuffers(1,&ret);
glBindBuffer(GL_ARRAY_BUFFER, ret);
glBufferData(GL_ARRAY_BUFFER,size,data,usage);
glBindBuffer(GL_ARRAY_BUFFER,0);

Does it really matter which target i use in the two calls? (Of course they must be the same). For example: can i fill the buffer writing to the GL_ARRAY_BUFFER target while it's binded on it and later on in the code bind the sane buffer to the GL_UNIFORM_BUFFER target and use it's data for filling a uniform block with glBindBufferRange?


Solution

  • It does not matter; any target should work. I've created buffers with targets matching the intended usage before and it made no difference.

    I guess an OpenGL implementation (i.e. driver) could allocate memory differently depending on the target passed but I've not seen evidence of this.

    Also, the newer glNamedBufferData which does the same thing as glBufferData without requiring a previous glBindBuffer call does not have a target parameter. This hints strongly that the targets are interchangeable.