Benzait Sofiane
Benzait Sofiane

Reputation: 157

Does OpenGL provide a way to know if a VAO was "erased" from the GPU?

I am wondering when a VAO ID gets 'erased' from VRAM (and whether the corresponding vertex data is also removed). Is there any way to get a notification from the GPU when it discards a VAO and its associated vertex data?

If that's not possible, I plan to maintain a map of active VAOs in the GPU. For each new VAO creation, I will check whether the newly created VAO is already in the map and remove it if necessary.

Upvotes: 1

Views: 56

Answers (1)

There is only one way to determine if a name corresponds to a vertex array object.

glIsVertexArray

returns GL_TRUE if array is currently the name of a vertex array object

...

If array is a name returned by glGenVertexArrays, by that has not yet been bound through a call to glBindVertexArray, then the name is not a vertex array object and glIsVertexArray returns GL_FALSE.

I don't know what you mean by "erasing" a vertex array object (from VRAM) but i assume you mean deleting it (glDeleteVertexArrays). I mean it is straightforward, generate a name, create the object (bind), do something with it and when done, delete it. OpenGL is a state machine, there is no event mechanism that informs the user when a state has been modified, but you can set and query the current state, like to query if a name is associated with an object.


But you could do something like this (since gl functions are loaded at run-time):

//function pointer, set by gl loader
PFNGLBINDVERTEXARRAYPROC gl_bind_vertex_array_proc;
    
static inline void glBindVertexArray(GLuint array)
{
    //test if current bound array equals array
    if (current_array == array) {
        return;
    }
    
    //invoke the 'real' gl function
    gl_bind_vertex_array_proc(array);

    //test for error
    GLenum err = glGetError();

    if (err == GL_NO_ERROR) {

        //notify about new binding, e.g. invoke some global handler
    
        //store current array
        current_array = array;

    } else {

        //invoke error handler

    }
}

See also: https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions

Upvotes: 1

Related Questions