matthias_buehlmann
matthias_buehlmann

Reputation: 5071

OpenGL: how to get number of samples of a Texture

Given the OpenGL name of a texture, how do I query whether this texture is a multisample texture and how many samples it was allocated with?

Upvotes: 0

Views: 972

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473866

You cannot query a texture object to find out what its texture target is. That's something you have to remember. So if you have been given some texture, and you don't know if it is a GL_TEXTURE_2D_MULTISAMPLE or not, the only way to find out is to try to bind it as every single texture target. After each bind, check to see if you got an OpenGL error. If you didn't, then that's the right target.

Once you know what the target is, you can query the number of samples with glGetTexLevelParameter for mipmap level 0, using an enum of GL_TEXTURE_SAMPLES.

All of the above is true if you don't have access to ARB_direct_state_access/OpenGL 4.5. With those newer APIs, you don't have to know the texture's target anymore. You can just call glGetTextureLevelParameter on the texture object itself; if the GL_TEXTURE_SAMPLES parameter is zero, then it is not a multisample image.

Upvotes: 3

Related Questions