Concept behind OpenGL's 'Bind' functions

后端 未结 5 1292
旧时难觅i
旧时难觅i 2021-01-29 22:35

I am learning OpenGL from this tutorial. My question is about the specification in general, not about a specific function or topic. When seeing code like the following:

5条回答
  •  梦毁少年i
    2021-01-29 22:58

    the commands in opengl don't exist in isolation. they assume the existence of a context. one way to think of this is that there is, hidden in the background, an opengl object, and the functions are methods on that object.

    so when you call a function, what it does depends on the arguments, of course, but also on the internal state of opengl - on the context/object.

    this is very clear with bind, which says "set this as the current X". then later functions modify the "current X" (where X might be buffer, for example). [update:] and as you say, the thing that is being set (the attribute in the object, or the "data member") is the first argument to bind. so GL_ARRAY_BUFFER names a particular thing that you are setting.

    and to answer the second part of the question - setting it to 0 simply clears the value so you don't accidentally make unplanned changes elsewhere.

提交回复
热议问题