Extension querying - the right way

5 views
Skip to first unread message

Piotr Bialecki

unread,
Aug 20, 2021, 3:58:37 PM8/20/21
to graphi...@chromium.org
Hi graphics-dev!

I have a question regarding the right way to query for extension presence. As a part of my recent work, I stumbled on a piece of code that needs to check whether a call to glDrawBuffers is available. The code in question does it by checking for presence of GL_EXT_draw_buffers:

// Query the GL context for the multiple draw buffers extension and, if
// present, the actual platform-supported maximum.
if (AreAllGLExtensionsPresent(gl, {"GL_EXT_draw_buffers"})) {
}

}

On the other hand, I looked at how the function pointer for glDrawBuffers function gets populated in the bindings:

if (!ver->is_es || ver->IsAtLeastGLES(3u, 0u)) {
fn.glDrawBuffersARBFn = reinterpret_cast<glDrawBuffersARBProc>(
GetGLProcAddress("glDrawBuffers"));
} else if (ext.b_GL_ARB_draw_buffers) {
GetGLProcAddress("glDrawBuffersARB"));
} else if (ext.b_GL_EXT_draw_buffers) {
GetGLProcAddress("glDrawBuffersEXT"));
}


Which brings me to a question: what is the proper way of checking whether an extension is enabled? It seems to me that even though we expose an OpenGL ES 2.0 interface (through GLES2Interface), it may actually be backed by either OpenGL or OpenGL ES 3.0, where it could be either built in, or present if GL_ARB_draw_buffers extension is present. Do we guarantee that GLES2Interface will report that GL_EXT_draw_buffers is present in all those circumstances (i.e. if and only if glDrawBuffers function pointer is non-null)? Or am I missing something here?

Thanks,
-Piotr

Ken Russell

unread,
Aug 20, 2021, 4:16:59 PM8/20/21
to Piotr Bialecki, graphics-dev
Hi Piotr,

In general it's guaranteed that OpenGL extensions that were folded into the core API in later versions continue to be advertised as available.

There have been some rare situations where an extension had slightly "weird" semantics that had to be changed when it was integrated into core. EXT_draw_buffers is unfortunately one of those extensions. The core ES 3.0 version requires ESSL 3.00 fragment shaders to be used, and Chrome doesn't auto-upgrade ESSL 1.00 shaders to ESSL 3.00. Hopefully this won't affect the surrounding code too much.

You should continue to query for the availability of the extension - don't rely on the presence of the function pointer as an indication that it's supported. Chrome's GL bindings probably guarantee this, but OpenGL drivers don't. We want to write semantically correct code that doesn't rely too heavily on Chrome-isms.

-Ken


Piotr Bialecki

unread,
Aug 20, 2021, 5:27:30 PM8/20/21
to Ken Russell, graphics-dev
> In general it's guaranteed that OpenGL extensions that were folded into the core API in later versions continue to be advertised as available.

Great, this is the answer I was hoping for, thanks!

Reply all
Reply to author
Forward
0 new messages