Exposing GL in Module

81 views
Skip to first unread message

Shachar Langbeheim

unread,
Aug 25, 2020, 7:39:37 AM8/25/20
to emscripten-discuss
Hi,
My app is using the Module.GL.getNewId function in order to create handles to WebGL textures, This is done so that I'll be able to load the textures on the JS side, and use them via OpenGL APIs in WASM. We want to start building with MODULARIZE=1, but this hides the GL object in the Module's closure.
I know that this can be fixed with post-js operations, but I'd like to have a solution that is less likely to be broken by future versions of Emscripten, so I want to open a PR that will fix this situation. I see 3 possible solutions:
1. Expose the GL object as-is on the Module.
2. Expose a wrapper to the getNewId function, and a matching function that allows removal of said handle.
3. Add to the module a JS function that returns a pair - a WebGL texture, and its OpenGL handle, and a matching function to remove said handle.

Are any of these ideas worth pursuing? Anything I might be missing?

Prashanth Nethi

unread,
Aug 26, 2020, 2:31:47 AM8/26/20
to emscripten-discuss
Hi,

There was a  similar requirement in our app. And this is what I did. Although I am not sure if this is the official way or if there are any better way to do it.

1) Added  method to Module["getNewId"] = function() {...} to a new JS file call it EmscriptenExtension.js
2) Link this JS file using em_link_post_js
3) This would make getNewId available to the Module object, that you receive as an argument, upon instantiating the Wasm.

Hope this helps.

Shachar Langbeheim

unread,
Aug 26, 2020, 2:41:14 AM8/26/20
to emscripten-discuss
how does EmscriptenExtension.js access objects in Module's closure?

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/115207d8-284d-4d37-b164-d4851fdb1d70n%40googlegroups.com.

Sam Clegg

unread,
Aug 26, 2020, 5:47:47 AM8/26/20
to emscripte...@googlegroups.com
On Tue, Aug 25, 2020 at 11:41 PM Shachar Langbeheim <nih...@gmail.com> wrote:
how does EmscriptenExtension.js access objects in Module's closure?

Code that you include via `--pre-js` and `--post-js` lives inside the module closure, no?   So it should be trivial.


 

Shachar Langbeheim

unread,
Aug 26, 2020, 1:07:22 PM8/26/20
to emscripten-discuss
Thank you Sam, that's exactly what I needed.

キャロウ マーク

unread,
Aug 26, 2020, 3:30:52 PM8/26/20
to emscripten-discuss
When linking, to prevent Module.GL from disappearing, I use

-s EXTRA_EXPORTED_RUNTIME_METHODS=[\'GL\’]"

then in my c++ wrapper code I use

val texture = val::module_property("GL")["textures"][texname];

to get the id for a texture that was created earlier by c code calling OpenGL ES and therefore the Emscripten wrapper.

Regards

    -Mark


signature.asc

キャロウ マーク

unread,
Aug 26, 2020, 4:37:52 PM8/26/20
to emscripte...@googlegroups.com


On Aug 26, 2020, at 12:30, キャロウ マーク <git...@callow.im> wrote:

-s EXTRA_EXPORTED_RUNTIME_METHODS=[\'GL\’]”

Ignore the weird quotation marks. The above was copy/pasted(badly) from a CMakeLists.txt file. If typing the above on the command line no quotes are necessary.

Regards

    -Mark

signature.asc
Reply all
Reply to author
Forward
0 new messages