0

I want to use spector.js metadata API to simplify debugging of a WebGL application compiled from C++ using emscripten. Spector.js API expects JavaScript WebGLBuffer objects created via WebGL API. The question is how to get them from the C++ side which operates with raw OpenGL handles. I see two options:

  1. Provide gl buffer handles to js via emscripten C++<->JS API and create WebGL objects from them somehow
  2. Create WebGLBufers on the js side and provide handles to C++ via C++<->JS API

Problem with the first option is that I can't find a way to create a WebGLBuffer from a raw OpenGL buffer handle. Problem with the second option is that I don't see any way to get a raw gl buffer handle from the js WebGLBuffer object to forward it to the C++ code.

Maybe there are also other options?

1 Answer 1

2

Augment the emscripten library. The WebGLObjects are tracked right here

https://github.com/emscripten-core/emscripten/blob/46df50cfd170521d91a31e0a74f2dfdeb4522968/src/library_webgl.js#L112

For example

  javascriptWebGLBuffer = $GL.buffers[openGLBufferId];
  openglBufferId = $GL.buffers.indexOf(javascriptWebGLBuffer);

also see _glGenObject and its usage on how to generate a new WebGLBuffer for both JavaScript and C++

You can plugin spector in that file.

You can use --js-library path-to-file to use your modified library to use it

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the reply! I'll report asap when I've tried it.
Okay, I see how to inject spector there. But I don't really understand how to get access to $GL from the js library I add.
Without liooking into it deeper add a line window.gl = $GL in the library somewhere would be one solution
So modification of the emscripten js library is the way to do it. Not perfect, but it does the trick .Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.