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 9 of 9

Thread: Determine the texture target from the GLuint

  1. #1
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    325

    Question Determine the texture target from the GLuint

    Hello,


    if I just have the GLuint from a texture object, I can check whether it is in fact a texture (glIsTexture()) but I can't check what target it has, right? I can try to bind it to GL_TEXTURE_2D, GL_TEXTURE_3D etc.. and test which call generated errors and which succeeded. Bound to the right target I can query all kinds of parameters (glGetTexParameter*).
    So my question is, have I overlooked a function that can tell me the kind of texture / the target if all I have is a GLuint from which I only know that it is a texture (result from glIsTexture) ?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    I don't think there is one - oddly enough - but should be trivial to implement. I guess you'll have to store the info on the application level.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    This is a hole due to the nature of the API. Remember: DSA doesn't exist. So if you have a texture object, the only way you could ever use it to even query something from it would be to bind it to the context. And glBindTexture will fail if you bind it to the wrong target. So clearly, if you bound it, you must know what target you used. Especially since glGetTexParameter takes the target as a parameter...

    Of course, that in itself tells you one way to do it: try to bind it to every target and see what works and what doesn't.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Could be a valid addition to the API though.

    Not that I would use it, but since the GL in some way has to keep track of the target as soon as you first bind the texture object, a glGetTextureTarget(GLuint) which returns either the target or preferably 0 (i.e. GL_NONE) if not bound yet (or generated an error) could be implemented rather easily, I suspect. Being able to query if a name refers to a texture and not being able to query the target if already bound is simply inconsistent.

    I don't quite get how DSA helps here since for any DSA style texture functions (at least from what I remember from GL_EXT_direct_state_access) you need to provide the target as well. Did I miss something?

  5. #5
    Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    325
    Storing the target in the application is what I do in my apps (I wouldn't query it each time I want to bind a texture even if that would be possible...).
    Trying to bind it to each target and see what fails and what works is what I do now in a special use case where I can't store the target (more of a debugging use case). I hoped I would just have missed a way to do it more elegantly.
    What is the best way to suggest something like glGetTextureTarget(GLuint)? This forum or the Khronos Bugzilla? Some other way?

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    I would suggest the appropriate sub-forum but I don't think there is much evidence for anything in there having an actual effect. It would be nice to know in general if anyone relevant to any significant implementation listens to us here in the forum.

    On the the other hand, there are active fellow board members here which have actively contributed to extensions, namely Groovounet and aqnuep, both for AMD. Maybe those guys have anything to say on this which could give us some insight as to why such a function doesn't exist in the first place.

    I can't speak to the Khronos bug tracker and if feature requests are possible and actually evaluated. IIRC, Alfonse has commented on Khronos' bug tracking/fixing behavior in the past, but I might be wrong.

  7. #7
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    I don't quite get how DSA helps here since for any DSA style texture functions (at least from what I remember from GL_EXT_direct_state_access) you need to provide the target as well.
    Yes, but that doesn't mean they have to.

    glBindImageTexture doesn't need it. Neither does glTextureView (for the source texture). Indeed, there's really no reason why most of the DSA functions have that parameter, save for the fact that it's theoretically possible that you could call glTextureParameter before calling glTextureImage*.

    I would much rather they have a glTextureType function, which sets the texture's type. Attempting to use any DSA function when a texture's type hasn't been set results in an error.

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Quote Originally Posted by Alfonse
    glBindImageTexture doesn't need it. Neither does glTextureView (for the source texture).
    For images I agree. For tex views, however, you'd still need to know the source textures type in order to select a compatible format for the view - if you can't store the information, as in menzel's case, you're doomed to walk the path of trial and error again.

    Quote Originally Posted by Alfonse
    I would much rather they have a glTextureType function, which sets the texture's type.
    Was this suggestion purely in regards to throwing the target out of DSA APIs? If so, I completely agree. Otherwise, this doesn't solve the original problem of not being able to determine the target of a texture if you cannot store the information when creating the texture object in the first place.

    Another approach would be to have the target set immediately at generation time with an alternative

    glGenTypedTextures(GLsizei, GLuint*, GLenum target)

    or similar, which directly associates returned names with the specified target. It's basically a factory. Generating unbound names as with glGenTextures() is a well and good, but really, most of the time I assume we generate and shortly afterwards bind to a specific target anyway so this whole "a texture is without a type until bound" thing doesn't need to be the only way.

  9. #9
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    For tex views, however, you'd still need to know the source textures type in order to select a compatible format for the view - if you can't store the information, as in menzel's case, you're doomed to walk the path of trial and error again.
    You're misunderstanding my point. I mean that the API doesn't need to be told what the texture type is. You can therefore use the API without knowing the type.

    Yes, if you use the wrong type, you get problems. But that's true of anything. Unless you're writing what is essentially a naked wrapper around OpenGL, you probably know what a given texture object is supposed to represent. And that means that you know it's type.

    The point is that you don't have to carry around an OpenGL enum or equivalent information; if all of your textures are 2D or 2D array textures... you don't need to advertise that everywhere. Or maybe you wrap the OpenGL API inside something and know in some other way that's not an enum what the texture's type is.

    You only need a GL enum because the OpenGL API says so.

Posting Permissions

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