-1

I'm a beginner of OpenGL, this question confused me a long time.
Traditionaly, if we want set data to a buffer, we need to bind the buffer to a target, and then set data to the target. Like this:

glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), data, GL_STATIC_DRAW);

I think it is counterintuitive.
If a Buffer represents a section of VRAM, set the buffer directly by the name of the buffer object is more natural.
Why OpenGL is designed to set data by binding buffer to target in the beginning?
I knew about glNamedBufferData() when I search for this question, Why not use this function in the beginning?

  • [`glNamedBufferData`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferData.xhtml) was only introduced with OpenGL version 4.5. Before you had to use `glBindBuffer`/`glBufferData` – Rabbid76 May 07 '22 at 07:59
  • @Rabbid76 I know about this. What confused me is why it was designed in such an incomprehensible way. – CarrotRider May 07 '22 at 08:06
  • OpenGL is a state engine. `glBindBuffer` sets a global state (except for `GL_ELEMENT_ARRAY_BUFFER`). `glBufferData` uses the global states. – Rabbid76 May 07 '22 at 08:09
  • @Rabbid76 I think it has a technical reason. – CarrotRider May 07 '22 at 08:11
  • Yes, because it is a state engine. The decision was to make a state machine. – Rabbid76 May 07 '22 at 08:11

0 Answers0