
Originally Posted by
Alfonse Reinheart
Here's a question.
Since you feed all the data to OpenGL, since you create all of these objects, then you must at the very least know how much room you asked for.
Obviously, pure state objects (FBOs, VAOs) likely don't take up GPU memory (and if they do, it's negligible). And for tiny objects (programs, etc), this is pretty meaningless; it's unlikely that your shader data will be taking up that much room.
If you call glBufferData(... 64000 ...), you asked for 64,000 bytes of data. Under what conditions would you expect the hypothetical "query size of object" function to return a number substantially different from 64,000? Sure, it'll be bigger, but it will also be entirely proportionate to 64,000. The absolute largest discrepancy you might get is rounding to the nearest 16KB, but more likely it rounds to the nearest page size (4KB).
So this feature would be completely useless for buffer objects, since you already know how much buffer object memory you're using.
Something similar happens for textures (and renderbuffers). You know how big of a texture you asked for. You know how many mipmaps you asked for. Therefore, you already have a reasonable approximation of how much memory they take.
The only case where this isn't true for textures is if OpenGL decided to give you a different internal format from the one you asked for. Like you asked for GL_RGBA4 and it gives you GL_RGBA8 for whatever reason. This is certainly a possibility.
But, if I recall correctly, this is something you can test for. You can query exactly how many bits each texture takes up, by using GetTexLevelParameter with GL_TEXTURE_RED/GREEN/BLUE/ALPHA_SIZE.
Sure, there will be a discrepancy, likely along page boundaries just like for buffer objects. But this gives you a pretty reasonable estimate on the size that everything takes, does it not? So why is this request necessary to estimate the usage size of GPU memory?
At the very least, if you're going to propose a memory management solution, make the proposal comprehensive, not something as poorly thought out as "I want to ask for the size of objects, even though I already know their size and can't really use that information anyway."