Viktor Sehr
Viktor Sehr

Reputation: 13099

Enable WebGL-extensions from Asm.js/emscripten?

How do I enable WebGL-extensions from asm.js/emscripten? I would like to run the equivalent of the javascript code 'var float_texture_ext = gl.getExtension('OES_texture_float');' which ofcourse I could do from a ASM_JS() macro, but I dont know what is the name of the global gl-object?

https://developer.mozilla.org/en-US/docs/Web/WebGL/Using_Extensions

Upvotes: 3

Views: 1267

Answers (1)

HarrisonG16
HarrisonG16

Reputation: 903

I will preface this by saying that you should not be using Emscripten like this. Personally, I would use GLFW3 and GLEW to manage the windowing and extensions. When using emcc or em++ (emscripten compilers) they will change the windowing calls into webgl context creation and what not.

But now to the answer. If you're not interested in using GLFW3, you're going to have to use specific Emscripten methods. There isn't any global "gl-object."

If you're looking to enable all extensions you can use the following:

EM_BOOL enableExtensionsByDefault

  • If "true", all GLES2-compatible non-performance-impacting WebGL extensions will automatically be enabled for you after the context has been created.

  • If "false", no extensions are enabled by default, and you need to manually call "emscripten_webgl_enable_extension()" to enable each extension that you want to use. Default value: "true".

If you are looking to enable a specific extension you can use the following:

EMSCRIPTEN_WEBGL_CONTEXT_HANDLE emscripten_webgl_get_current_context()

Returns the currently active WebGL rendering context, or 0 if no context is active. Calling any WebGL functions when there is no active rendering context is undefined and may throw a JavaScript exception.

Returns:

  • The currently active WebGL rendering context, or

  • 0 if no context is active.

Return type: "EMSCRIPTEN_WEBGL_CONTEXT_HANDLE"

in order to get the WebGL Context Handle and pass that into the following method:

EM_BOOL emscripten_webgl_enable_extension(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context, const char *extension)

Enables the given extension on the given context.

Parameters:

  • context (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE) -- The WebGL context on which the extension is to be enabled.

  • extension (*const char**) -- A string identifying the WebGL extension. For example "OES_texture_float".

Returns:

  • EM_TRUE if the given extension is supported by the context, and

  • EM_FALSE if the extension was not available.

Return type: "EM_BOOL"

All the information you need is here:

http://kripken.github.io/emscripten-site/docs/api_reference/html5.h.html#html5-h

Upvotes: 4

Related Questions