How to reliably find out if OpenGL extension is supported

So I thought I had to call gl.getExtension("OES_standard_derivatives") before using the extension in any shader. It turns out that:

  1. gl.getExtension("OES_standard_derivatives") returns null both on my OSX and Linux dev platforms
  2. gl.getSupportedExtensions() returns 128 names on my OSX and 379 names on my Linux workstation, and OES_standard_derivatives is not among them in both cases
  3. using #extension GL_OES_standard_derivatives : enable in shader source works without calling gl.getExtension somewhere in Haxe source, i.e. shader compilation passes and it renders stuff just fine
  4. OES_standard_derivatives exists and works ok on both of my dev platforms, I can tell that by simply using WebGL through pure javascript, or by running code (other than the one I’m writing in Lime) that uses the extension

So, my question is:

How do I reliably find out if an extension exists/is supported, using Lime API?

I’m on Haxe 4.0.0-rc2, Lime 7.3.0, and am using WebGLRenderContext in my Lime app ( gl is of WebGLRenderContext type ).

Quick update:

this is list of supported extensions reported by lime run html5:


using this code:


class Main extends Application
    public function new()

    public override function onPreloadComplete() : Void {
        var gl = window.context.webgl;
        var exts = gl.getSupportedExtensions();'exts = $exts');

and this is what vanilla javascript reports on the same machine in same browser:


running this code:


function test() {
    var glcanvas = document.getElementById("gl");
    gl = glcanvas.getContext("webgl");
    var supported_extensions = gl.getSupportedExtensions();

<body onload="test();">
    <canvas id="gl" width="10" height="10" ></canvas>

Currently, we default to initializing a WebGL 2 context if available, perhaps this is why the extensions are different?

You can check this by using window.context.type as well as window.context.version at runtime, WebGL would be type WEBGL and version 2

Yes! That’s it!

I spend a good deal of time on spelunking Lime source, but I guess you can’t find everything, eh?

Anyhow, after looking a bit around where window.context.type is used, this is what I added to my project.xml:

<section if="html5">
    <haxedef name="webgl1" />

Now, context type version is 1, OES_standard_derivatives is available and gl.getExtension("OES_standard_derivatives") returns non-null object.


You can also use <define name="webgl1" if="html5" /> to keep it short :slight_smile:

It should also be possible to allow WebGL 2 and to use it without the extension:

In WebGL2, the functionality of this extension is available on the WebGL2 context by default. In WebGL 2, the constant is available as gl.FRAGMENT_SHADER_DERIVATIVE_HINT and it requires GLSL #version 300 es