2

I would like to fill a VBO with element indices, and then later bind it to the GL_ELEMENT_ARRAY_BUFFER slot on a VAO.

The obvious (but wrong) code is:

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementArrayBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, ...);

but that changes the current VAO, or could cause an error if there is no VAO bound. I don't want to do that, I just want to fill the buffer, and then use it at some later point

If this would be OpenGL 4.5 (which osx doesn't support), the solution would be to just use glNamedBufferData, and not bind it until later.

Is there a reasonable way around this?

Can i use the GL_ARRAY_BUFFER slot to fill the buffer, and then bind it to GL_ELEMENT_ARRAY_BUFFER later, or would that be against the spec?

1
  • Interesting question. Can I ask what you're trying to do? Commented Jul 14, 2017 at 1:31

1 Answer 1

3

Buffer objects are in no way directly associated with particular targets. When you bind a buffer for the purpose of modifying it, you can bind it to any valid buffer target. You could bind it to GL_COPY_READ_BUFFER just to call glBufferSubData on it. You could also use GL_ARRAY_BUFFER, but for such circumstances, it's best to use an innocuous binding point.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.