admin管理员组

文章数量:1289620

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.

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.

Share Improve this question edited Feb 20 at 16:54 Rabbid76 211k30 gold badges156 silver badges199 bronze badges asked Feb 20 at 16:39 Benzait SofianeBenzait Sofiane 1572 silver badges12 bronze badges 4
  • To do.. What, exactly? You posted a solution in search of a problem. – Botje Commented Feb 20 at 17:27
  • I just wanted to know if OpenGl can be bound to a kind of functor that can be used to update my vertex/textures information, that's it. – Benzait Sofiane Commented Feb 20 at 18:14
  • Wouldn't your application be the one doing the updating (both VBO and VAO)? There is some kind of context that you're not telling us yet. – Botje Commented Feb 20 at 19:09
  • Do you by 'erased' mean that the VAO is deleted or are you talking about in which memory the vertex data resides (VRAM or RAM)? If you ask about deletion, then that never happens by itself, only when glDelete* method is used, so you should know when it gets deleted. – BDL Commented Feb 21 at 8:32
Add a comment  | 

1 Answer 1

Reset to default 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./opengl/wiki/Load_OpenGL_Functions

本文标签: Does OpenGL provide a way to know if a VAO was quoterasedquot from the GPUStack Overflow