When should i call glDeleteBuffersARB ? Should I do it when application ends? Can I somehow automatize the process of deletion vertex buffer object? For instance something like smart_ptr does.
Never. You should never call glDeleteBuffersARB
. Buffer objects have been core GL functionality for upwards of a decade now; if you're still using the ARB-suffixed extensions functions, STOP. If you're follow a tutorial that uses them, again STOP; it's clearly too old to be useful.
Now, when should you use glDeleteBuffers
? You should use it at the same time you would delete
for a regular C++ object. That is, use it when you are finished with the object. When you have no more use for it and want to get rid of it.
so can I create class for vbo with destructor which will delete vbo object? And then create objects as smart_ptr to automatize everything?
You could, but it's not going to buy you all that much. Also, you run the very real risk of waiting to delete the object until it's too late.
It is illegal to call any OpenGL function before the OpenGL context is created (and made current) or whenever a GL context is not current (for example, after you've destroyed the GL context). Attempts to do so are not good.
If you use shared_ptr
to manage these resources, it becomes theoretically possible for them to outlive the actual OpenGL context. That's bad. Personally, I would prefer a more rigid management scheme, one that firmly ties the lifetime of the GL objects to that of the context.
来源:https://stackoverflow.com/questions/10573684/vertex-buffer-objects-delete-process-opengl