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:

EXT_color_buffer_float
EXT_texture_compression_bptc
EXT_texture_compression_rgtc
EXT_texture_filter_anisotropic
OES_texture_float_linear
WEBGL_compressed_texture_etc
WEBGL_compressed_texture_s3tc
WEBGL_compressed_texture_s3tc_srgb
WEBGL_debug_renderer_info
WEBGL_debug_shaders
WEBGL_lose_context

using this code:

import lime.app.Application;

class Main extends Application
{
    public function new()
    {
        super();
    }

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

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

ANGLE_instanced_arrays
​EXT_blend_minmax
​EXT_color_buffer_half_float
​EXT_texture_compression_bptc
​EXT_texture_compression_rgtc
​EXT_frag_depth
​EXT_sRGB
​EXT_shader_texture_lod
​EXT_texture_filter_anisotropic
​OES_element_index_uint
​OES_standard_derivatives
​OES_texture_float
​OES_texture_float_linear
​OES_texture_half_float
​OES_texture_half_float_linear
​OES_vertex_array_object
​WEBGL_color_buffer_float
​WEBGL_compressed_texture_etc
​WEBGL_compressed_texture_s3tc
​WEBGL_compressed_texture_s3tc_srgb
​WEBGL_debug_renderer_info
​WEBGL_debug_shaders
​WEBGL_depth_texture
​WEBGL_draw_buffers
​WEBGL_lose_context

running this code:

<html>
<head>
<script>

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

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

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" />
</section>

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

Thanks!

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:

https://developer.mozilla.org/en-US/docs/Web/API/OES_standard_derivatives

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