0

I am learning OpenGL via the Superbible and internet, and a concept that I always see causing trouble is the glBindxxx (See for instance the accepted answer of Concept behind OpenGL's 'Bind' functions for a typical problem related to bindings.)

You can/have to bind buffers (glBindBuffer) before setting them to be used by glVertexAttribPointer. You can/have to bind the VAO (glBindVertexArray) before setting your glVerteyAttribPointer, and so on, with a never ending chain of current binding dependencies.

Sometimes, even if you forget binding something your program might still work if its simple enough, but I have seen lots of people taking too much time to find that the source of their bug is some hidden binding that they were not aware of.

Is there a command in OpenGL to list the last binding? Something similar to glGetAllBindings, and this would return the last bound ID of each glBindxxx functions (a small list of them is below based on Superbible 6th edition)

glBindBuffer glBindBufferBase glBindFrameBuffer glBindImageTexture glBindProgramPipeline glBindSampler glBindTexture glBindTransformFeedback glBindVertexArray glBindVertexBuffer

For instance, if I performed a glBindBuffer with buffer ID 1 as parameter and then again with buffer ID 2, glBindVertexArray with ID 3 and then glBindVertexArray with ID 5, the function would return 2 for glBindBuffer and 5 for glBindVertexArray.

With that, I can always know in which context I am before applying new settings.

I believe this would greatly help anyone needing to understand and debug binding problems.

Community
  • 1
  • 1
user5193682
  • 260
  • 1
  • 11
  • 1
    These binding problems can be avoided altogether by using Direct State Access. This is a core feature in GL 4.5 and has been supported by NVIDIA and AMD's proprietary drivers for years and years. With DSA you don't clobber previous bindings just to modify the state of some object. – Andon M. Coleman Aug 09 '16 at 18:35

1 Answers1

0

Is there a command in OpenGL to list all current bindings?

No. Really, how could there be?

Many objects are bound to specific targets for that particular type of object. Buffer objects alone have a dozen. And textures not only are bound to a target, they are bound to a combination of texture unit and target. So the combination of (unit 0, GL_TEXTURE2D) can have a different texture bound than (unit 0, GL_TEXTURE3D). And the number of texture units for modern hardware is required to be at least 96 (16 per stage * 6 shader stages).

It would not be reasonable to have a single function regurgitate all of that information.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • I see you understood I want to see all the bindings, but I want to see all the last activates ones, for instance if I used glBindBuffer with buffer 1, the command would return me 1. – user5193682 Aug 08 '16 at 23:27
  • 1
    @user9589: Maybe you misunderstand how targets work. If you bind a buffer to `GL_ARRAY_BUFFER` and then to `GL_PIXEL_UNPACK_BUFFER`, the buffer bound to `GL_ARRAY_BUFFER` is *still active*. It is no less active than the one bound to pixel-unpack. That's just how the object model works. – Nicol Bolas Aug 09 '16 at 00:54
  • Can you recommend any reference on this? I am reading the Superbible, but there this information is not strongly clear, but a very weak sublety. My post was also an attempt of making this clear for me by watching current bindings instead of trying to speculate about them – user5193682 Aug 09 '16 at 06:45
  • @user9589: I find the [OpenGL wiki's explanation of the object model](https://www.opengl.org/wiki/OpenGL_Object) to be reasonable. I also find [this unfinished book](http://alfonse.bitbucket.org/oldtut/index.html) to have a good explanation of the object model. Granted, since I wrote both of those, take my recommendation with a grain of salt. – Nicol Bolas Aug 09 '16 at 13:51
  • I read those websites and found them quite enlightning. They ticked the same way in my head and I know why. I was thinking they should put the website owner as the official writer of the Superbible book, so take it as a compliment :) – user5193682 Aug 09 '16 at 13:55