Why does call glBindBuffer() two times?

alryosha
void prepare_axes(void) { 
axes[0][0] = -win_width / 2.5f; axes[0][1] = 0.0f; 
axes[1][0] = win_width / 2.5f; axes[1][1] = 0.0f;    
axes[2][0] = 0.0f; axes[2][1] = -win_height / 2.5f;     
axes[3][0] = 0.0f; axes[3][1] = win_height / 2.5f;

// Initialize vertex buffer object.     
glGenBuffers(1, &VBO_axes);
glBindBuffer(GL_ARRAY_BUFFER, VBO_axes);
glBufferData(GL_ARRAY_BUFFER, sizeof(axes), axes, GL_STATIC_DRAW);

// Initialize vertex array object.  
glGenVertexArrays(1, &VAO_axes); 
glBindVertexArray(VAO_axes);

glBindBuffer(GL_ARRAY_BUFFER, VBO_axes); 
glVertexAttribPointer(LOC_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));

glEnableVertexAttribArray(0); 
glBindBuffer(GL_ARRAY_BUFFER, 0); 
glBindVertexArray(0); 
}

I was looking into OpenGL source code, but I didn't understand why call glBindBuffer(GL_Array_Buffer, VBO_axes) twice.
From my understanding, after the first time they call glGenBuffer, glBindBuffer and glBufferData, the information of the variable 'axes' is stored in GL_ARRAY_BUFFER.
After that, they generate, bind VAO and call glBindBuffer again.
I can't understand why they did that.
I knew that glBufferData() deletes the current buffer store if there already was one, and creates a new buffer store. This means that the information of the variable 'axes' is fade away when calling glBindBuffer secondly.
Help me please..

Nicol Bolas

Technically, they don't have to do the extra bind in this case. However, it's a good idea to do so, because it's very easy to accidentally break code that doesn't use it. If the programmer wants to change the buffer creation code to create two buffer objects, using the GL_ARRAY_BUFFER binding, then the subsequent code would be broken.

However, if you bind the correct buffer, then it will always work, no matter what you did before.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Gmock call function two times

Why is the alert displayed two times on button click?

JQuery - Why does Trigger method call it three times?

Why does the logical AND operator call these two functions in this case

Why does sklearn Pipeline call transform() so many more times than fit()?

Why does scipy.optimize.root call the callback function with the initial value four times?

Why does glVertexAttribPointer without glBindBuffer also work?

Why does my ViewController get modally presented two times in a row after a single call to present(_:animated:completion:) method?

Overload dictionary subscript two times and forward call

Why does editingFinished signal generates two times when QMessageBox is being shown by connected slot?

Why is the first function call is executed two times faster than all other sequential calls?

Why the object disappeared when listed for two times?

Why does the user have to enter their correct credentials two times?

Why does the 'init' method run in two times by the same object?

Why is my new SSD two times slower?

why file js is called two times

android call same dialog two times

Why does my find command get executed two times?

Why Redux need two times dispatch

Why is my function unintentionally executing two times?

Why does one need to compile two times to have a table of contents in the pdf?

Why does not 'while(csv.Read())' work two / three times in CsvHelper?

Why App or Quiz component rendered two times?

Why useEffect running two times?

Why buttons getting placed two times? (Swing)

why does react js renders two times when setting a state

Why do I have to call my protocol functions two times to make it work?

Why does React render the page two times?

why does React counter component print two times console.log?

TOP Ranking

HotTag

Archive