Include WebGL extensions from Asm.js / emscripten?

How can I enable WebGL extensions from asm.js / emscripten? I would like to run the equivalent of javascript code 'var float_texture_ext = gl.getExtension('OES_texture_float');'

that I could make from a macro ASM_JS()

, but I don't know what is the name of the global gl object?

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

+3


source to share


1 answer


I will predetermine this by saying that you should not use Emscripten like this. Personally, I've used GLFW3 and GLEW to manage windows and extensions. When using emcc or em ++ (emscripten compilers), they will modify windowing calls in creating webgl context and what not.

But now to the answer. If you are not interested in using GLFW3, you will have to use certain Emscripten methods. There is no global "gl object".

If you want to enable all extensions, you can use the following:

EM_BOOL enableExtensionsByDefault

  • If true, all GLES2 compliant ineffective WebGL extensions will be automatically activated for you after the context has been created.

  • If false, the extensions are not enabled by default and you need to manually call "emscripten_webgl_enable_extension ()" to enable each extension you want to use. The default is "true".

If you want to include 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 no active rendering context is undefined and may throw a JavaScript exception.

Returns:

  • The currently active WebGL rendering context, or

  • 0 if the context is not active.

Return type: "EMSCRIPTEN_WEBGL_CONTEXT_HANDLE"

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

EM_BOOL emscripten_webgl_enable_extension (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context, const char * extension)

Includes the specified extension in this context.

Parameters:

  • context (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE) - WebGL context on which the extension should be enabled.

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

Return:

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

  • EM_FALSE if the extension is not available.

Return type: "EM_BOOL"

All the information you need can be found here:

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

+2


source







All Articles