PDA

View Full Version : Get the id of the currently bound texture object?



tleave2000
10-10-2009, 08:49 AM
Hiya. I'm trying to find a function that will let me know the currently bound texture object.

I found the following description in the OpenGL 3.2 specification. I was expecting a simple glGetInteger function, not a glGetIntegerv function. I'm only looking for one value: the value of the texture object currently bound to the active texture unit. Why is it threatening to supply 48* x 3 unsigned integers? (Perhaps it returns the ids of the textures bound to every texture unit? And 48 is the minimum number of texture units? (seems a lot) and even then why the '3'?)



Get value : TEXTURE BINDING xD
Type: 48* x  3 x  Z+
GetCommand: GetIntegerv
Minimum Value: 0
Description: Texture object bound to TEXTURE_xD

Any help with understanding this would be very much appreciated. Thanks for looking.

scratt
10-10-2009, 09:27 AM
glGetBooleanv, glGetDoublev, glGetFloatv, glGetIntegerv - return the value or values of a selected parameter


Description

These four commands return values for simple state variables in GL. pname is a symbolic constant indicating the state variable to be returned, and params is a pointer to an array of the indicated type in which to place the returned data.

Type conversion is performed if params has a different type than the state variable value being requested. If glGetBooleanv is called, a floating-point (or integer) value is converted to GL_FALSE if and only if it is 0.0 (or 0). Otherwise, it is converted to GL_TRUE. If glGetIntegerv is called, boolean values are returned as GL_TRUE or GL_FALSE, and most floating-point values are rounded to the nearest integer value. Floating-point colors and normals, however, are returned with a linear mapping that maps 1.0 to the most positive representable integer value, and -1.0 to the most negative representable integer value. If glGetFloatv or glGetDoublev is called, boolean values are returned as GL_TRUE or GL_FALSE, and integer values are converted to floating-point values.


GL_TEXTURE_BINDING_2D

params returns a single value, the name of the texture currently bound to the target GL_TEXTURE_2D. The initial value is 0. See glBindTexture.

So basically as I understand it you only have to supply an array of the size you expect to get back. In this case a single value.

Frankly, unless there is some overriding reason why, it's always going to be quicker to keep track on the client side, rather than use glGet commands. They are slow, and should certainly not be used in production code which is required to run efficiently.

tleave2000
10-10-2009, 10:33 AM
Cool, thanks for the tip. I'll give that a go (keeping track on the client side). Sounds much better.