Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When are OpenGL object names ever zero? Or, does zero ever have semantics?

Tags:

opengl

I have been wondering for a while: OpenGL object "names", integers generated by glGenTextures etc, seem to never be zero, so I use zero to indicate uninitialised handles and check for errors. So far it's been okay.

I also am told that it is good practice to call glBind*(0) after you're done with an object to make sure that lingering bound objects are not accidentally manipulated afterwards. Sounds sensible.

Are there any situations in which an OpenGL object ID would be zero, making my tests invalid, or when using zero in this way would have surprising effects because it doesn't refer to a non-object?

P.S. Is there a symbolic name for zero-as-a-non-object?

P.P.S. Are there ever going to be performance penalties for heavy use of binding/unbinding pattern? (There are some parts of code which, due to encapsulation, have mostly redundant re-bindings.)

like image 415
spraff Avatar asked Dec 21 '22 01:12

spraff


1 Answers

From the OpenGL 4.4 Core Profile Specification:

Each object type has a corresponding name space. Names of objects are represented by unsigned integers of type uint. The name zero is reserved by the GL; for some object types, zero names a default object of that type, and in others zero will never correspond to an actual instance of that object type.

You can rely on the name-generating functions (e.g. GenBuffers) to never return zero as a generated name. You can use zero to represent “no object”.

like image 84
rob mayoff Avatar answered May 20 '23 16:05

rob mayoff