How to determine an OpenGL texture's size in texels?
opengl, textures
Solution
As Bahbar says, `glGetTexLevelParameteri` can be used to query the `GL_TEXTURE_WIDTH`. However, I strongly advise against using this as a general method. For one thing, you can stall the pipeline with `glGet*` calls, as the driver has to get the GPU to finish what it's doing, figure out what you asked, and return the answer. The result is a massive performance hit.
So you really are better off managing state like this in your own code. Presumably you have a `Sprite` class (or struct or equivalent), with the texture handle. It's nothing to dedicate a few more bytes to keep track of the width and height, and it will save you from having to hit the driver or GPU to get the information.
As for `glTeSubImage*`, well that's a policy decision as to when and how you update the texture.
Problem
I know this is such a trivial question, yet I haven't found any information that seems to help, starting from `glGet()`'s documentation. I'm using my textures as sprites, so it's crucial that I keep track of their sizes in texels/pixels. When I'm creating my textures with `glTexImage2D()` I'm required to pass the size of the pixel data array to it. But does OpenGL store it anywhere, or do I have to keep track of them in my code? (This feels awkward, as client code would still be able to overwrite the texture with `glTexImage2D()` / `glTexSubImage2D()` / `glCopyTexImage2D()` etc. calls while not changing the size accordingly, thereby resulting in visual distortions.)