What is the correct way to reset and load new data into GL_ARRAY_BUFFER?
        Posted  
        
            by 
                Geto
            
        on Game Development
        
        See other posts from Game Development
        
            or by Geto
        
        
        
        Published on 2014-06-02T09:29:43Z
        Indexed on 
            2014/06/02
            9:54 UTC
        
        
        Read the original article
        Hit count: 279
        
I am using an array buffer for colors data. If I want to load different colors for the current mesh in real time what is the correct way to do it. At the moment I am doing:
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
glBufferData(GL_ARRAY_BUFFER, SIZE, colorsData, GL_STATIC_DRAW);
glEnableVertexAttribArray(shader->attrib("color"));
glVertexAttribPointer(shader->attrib("color"), 3, GL_FLOAT, GL_TRUE, 0, NULL);
glBindBuffer(GL_ARRAY_BUFFER, 0);
It works, but I am not sure if this is good and efficient way to do it. What happens to the previous data ? Does it write on top of it ?
Do I need to call :
glDeleteBuffers(1, colorBuffer);
glGenBuffers(1, colorBuffer);
before transfering the new data into the buffer ?
© Game Development or respective owner