Alexander
Alexander

Reputation: 1329

WebGLBuffer object and OpenGL buffer handle interop between JavaScript and C++

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?

Upvotes: 0

Views: 213

Answers (1)

user128511
user128511

Reputation:

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

Upvotes: 2

Related Questions