I am interested in understanding a bit more behind how OpenGL does its memory management and what are some good practices before I start heavily coding and back myself into a corner.
The real question I have is regarding memory. I have a class called
Mesh that consists of a pointer to some vertex data, a pointer to the face data, as well as the number of vertices and faces. I am familiar with one possible process that OpenGL uses to get these drawn on the screen: generate a buffer for vertices and a buffer for faces, bind them as
glBufferData to move the data to the buffers, and lastly call
glDrawElements to draw them. From here I can understand how I can load several
Mesh objects and draw them on screen, and I have no issue there.
My question then lies in where the memory is stored and what I should be doing in order to conserve memory. My assumption is that after the call to
glBufferData, the data is copied to the GPU (or to some other register to later be copied to the GPU). Is it safe for me to delete the original
Mesh object that was used with the buffer calls? In my head, the mesh data is retained inside the GPU so the data is not lost, and so long as I do not need to reload this data using OpenGL later then I won't miss this data at any point. Also in my head, this frees up RAM space for other uses, so my
Mesh, in some sense, now totally lives in GPU memory and nowhere else, and I can do my drawing solely by making OpenGL calls to the correct buffers (so I obviously need to save the generated buffer IDs, but that part goes without saying).
If someone could tell me if this is correct/incorrect logic, as well as good/bad game dev practice?