Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: finding out the active texture from the texture unit

  1. #1
    Intern Contributor
    Join Date
    Oct 2012
    Posts
    60

    finding out the active texture from the texture unit

    Hi

    1.
    I have a piece of code that activates the texture unit 0 but there is no code doing the texture binding (such as
    glBindTextre(GL_TEXTURE_2D,texId)) following the glActiveTexture(GL_TEXTURE0). As a result, I am wondering if there is any way I can find what texture is being used at this point of time where i call glActiveTexture(GL_TEXTURE0).
    It would be nice if i could find out the texture buffer object name/texture id variabe name instead of the GLuint number associated with the texture but I guess that's asking for too much.

    2.
    The project I am working on has textures bound at many places. So is it possible that you can do activate a texture unit and bind a texture and then just activate the texture unit later on (withoutrebinding the texture) and openGl would know that the texture you want is the one you bound a long time ago to the texture unit in question.

    thank you

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810
    A1) Use
    Code :
    GLint whichID;
    glGetIntegerv(GL_TEXTURE_BINDING_2D, &whichID);
    this will return the id of the texture bound to the currently active texture unit.

    A2) I am not sure if i got you correctly but once you bind a texture to an active texture target, it remains bound to it until you unbind it.
    Regards,
    Mobeen

  3. #3
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,924
    1) You can't. Not really.

    glGet-ing with GL_TEXTURE_BINDING_2D will only get the texture bound to GL_TEXTURE_2D. It won't get a texture bound to, for example, GL_TEXTURE_CUBE_MAP; there's a separate binding get for that (GL_TEXTURE_BINDING_CUBE_MAP). In order to know which texture you bound to which texture unit, you have to know it's texture type.

  4. #4
    Intern Contributor
    Join Date
    Oct 2012
    Posts
    60
    The problem is that I have many types such as GL_TEXTURE_2D , GL_TEXTURE_3D bound to the same texture unit 0.
    When I activate glActiveTexture(GL_TEXTURE0), how do I know which type is activates? If I had code such as glBindTexture(GL_TEXTURE_2D,texId)) following glActiveTexture(GL_TEXTURE0), then I would know which texture is being used.

    The way things are in the project code .....with only glActiveTexture(GL_TEXTURE0) , I don't know which type or which texture.

  5. #5
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,924
    All of them become active. Which one gets used depends on the sampler type in the shader. Or if you're using the fixed-function pipeline, there's a complex system of priorities for the different types that I don't care to remember, since I stopped using fixed-function a decade ago.

  6. #6
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    456
    Quote Originally Posted by driver View Post
    It would be nice if i could find out the texture buffer object name/texture id variabe name instead of the GLuint number associated with the texture but I guess that's asking for too much.
    If your driver supports the GL_KHR_debug extension, you can label GL objects with glObjectLabel (assuming you are using an extension retrieving library that is up to date, or you declare+retrieve the functions yourself). I think the intent of this extension is mostly to provide a common way for applications to mark objects for display in external debuggers rather than for internal application use though. For internal use you can use wrapper classes that contain the object id + name etc.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •