0

Is there any way to check if a GLSL extension has been enabled? That is, that there has been a #extension <extname> : enable directive somewhere before a block of code in the current compilation unit:

#extension GL_OES_standard_derivatives : enable

Something like this:

#if extension_enabled( GL_OES_standard_derivatives )
    // do stuff with fwidth()
#else
    #error Code won't work without GL_OES_standard_derivatives!
#endif
genpfault
  • 47,669
  • 9
  • 68
  • 119

1 Answers1

1

Each OpenGL extension which has a GLSL language counterpart (ie: something that can go into a #extension declaration) includes a #define for the name of that extension which will be set to 1 if the extension has been enabled. For example, the ARB_shader_image_size extension is for GLSL, so if the extension is successfully enabled in a shader, GL_ARB_shader_image_size will be #defined to 1.

So you can use #ifdef GL_ARB_shader_image_size to encapsulate code that needs the extension.

Nicol Bolas
  • 378,677
  • 53
  • 635
  • 829
  • If I'm reading [the spec](https://www.khronos.org/registry/OpenGL/specs/es/2.0/GLSL_ES_Specification_1.00.pdf) right (section 3.5, page 15, "For each extension there is an associated macro. The macro is always defined in an implementation that supports the extension.") those `#define`s only indicate extension support, not enablement. – genpfault May 20 '20 at 17:24
  • @genpfault: What would be the point of that? If you don't enable it, then by definition you cannot use any of its functionality. So there would be nothing you could put in such an #ifdef` that wouldn't be allowable outside of it. Even `#extension` doesn't make sense, as you can just use `enable` if you want it to be active if supported. This may be some weird ES variation, because desktop GL extensions make it clear that the #define is part of the "language features" that are active only when the extension is enabled. – Nicol Bolas May 20 '20 at 17:35