geometrian
geometrian

Reputation: 15387

Is it Okay to Ignore GL_INVALID_OPERATION Caused by Calling `wglGetProcAddress` Inside `glBegin`/`glEnd`?

I discovered recently that calling wglGetProcAddress(...) between calls to glBegin(...) and glEnd() produces a GL_INVALID_OPERATION. Evidently, (from the most technical source I could find):

The MS opengl32.dll library apparently calls glFlush from wglGetProcAddress(). If we're inside glBegin/End(), glFlush will dispatch to _mesa_generic_nop() and we'll generate a GL_INVALID_OPERATION error.

The generated function pointer is null, but trying again with GetProcAddress(...) produces a valid function pointer, and the program seems to continue happily.

My question: is ignoring the error (i.e. glGetError()) okay?


Edit: why would I want to do this? Loading OpenGL functions is overhead, and doing it lazily is a performance concern on slower hardware (this approach is used e.g. in glbinding). It's a big deal if you have multiple contexts and you want to only use a subset of the functionality in each, or if you're creating/deleting contexts frequently. My code implements every API function by a dynamically backed store, so unloaded functions also save space, which is important on smaller systems and becomes significant with many contexts.

Upvotes: 1

Views: 228

Answers (1)

spirulence
spirulence

Reputation: 721

I can't tell whether you've found undefined behaviour or just a mis-implemented specification. In either case, these things might break easily with future versions of the libraries involved, and I think you should find another way of getting OpenGL function pointers than in the middle of drawing your graphics.

Upvotes: 1

Related Questions