1

https://developer.mozilla.org/en-US/docs/Web/API/ANGLE_instanced_arrays

Given WebGL2RenderingContext as gl.

We have gl.draw_arrays_instanced.

There is also a web-sys object: web_sys::AngleInstancedArrays with functions like draw_arrays_instanced_angle.

The Web-Sys AngleInstancedArrays must be activated by listing the feature in the Cargo.toml under the dependencies.web_sys entry.

I can access the function but I can not manage to provide the first argument required, which is a reference to a web_sys::AngleInstancedArrays struct. There seems to be no way to construct such an object.

There is also the example posted here: https://developer.mozilla.org/en-US/docs/Web/API/ANGLE_instanced_arrays

I tried that approach in Rust and it doesn't work.

enter image description here

More unwrapping just yields a <js_sys::Object>

Then I saw that web-sys has its own web_sys::AngleInstancedArrays, and tried that. Hence the question.

From the code AngleInstancedArrays::draw_arrays_instanced_angle(&AngleInstancedArrays, GL::TRIANGLES, 0, 6, 2);, yields:

enter image description here

That first argument is just for illustration. The compiler is asking for an instance of AngleInstancedArrays but I can't see how to instantiate one.

kulicuu
  • 15
  • 5

2 Answers2

2

Think what is missing is a cast. Following the javascript example ANGLE_instanced_arrays. Corresponding in web-sys get_extension, if successful, returned JsObject is of type web_sys::AngleInstancedArrays. Before using function draw_arrays_instanced_angle a cast is needed, together with the call from the question:

let etx_angle: web_sys::AngleInstancedArrays = object_js.dyn_into().unwrap();
etx_angle.draw_arrays_instanced_angle(GL::TRIANGLES, 0, 6, 2);

But as the answer above sketches, for WebGL2 the api is simpler WebGl2RenderingContext.draw_arrays_instanced

Jonas Bojesen
  • 855
  • 1
  • 8
  • 22
  • 1
    Thank you. I think this is the correct answer. I've since moved on and not presently in a position to check it, but I will confirm when I get a chance. – kulicuu Jul 03 '22 at 15:01
0

Based on ANGLE_instanced_arrays documentation:

Note: This extension is only available to WebGL1 contexts. In WebGL2, the functionality of this extension is available on the WebGL2 context by default and the constants and methods are available without the "ANGLE" suffix.

MaxV
  • 2,601
  • 3
  • 18
  • 25
  • I already used the get_extension method. I'm not sure if that does anything. You don't call the draw method through the WebGL2RenderingContext (used `as GL`) object. My previous call already used `gl.draw_arrays_instanced` method, but seemingly not working. Another thing was I could not access the gl_InstanceID in variable at the vertex shader. It's weird too that web_sys::AngleInstancedArrays exists independent of WebGLRenderingContext, and carries the method draw instanced. Is that not supposed to be public? – kulicuu Jul 01 '22 at 21:32
  • This comment editor is does not make for easy discussion. For example I'd just paste in screenshot fragments of code and terminal results. I already have a calls to both items you mention. I haven't been able to access the `gl_InstanceID` variable from the vertex shader yet, so I don't know that the `gl.draw_arrays_Instanced` is actually working. It's weird that there is also the web-sys access to the same function. I was wondering if they are redundant or one is only used internally? On line 168 of game.rs linked above is the `gl.draw_arrays_instanced` call. That call goes through. – kulicuu Jul 01 '22 at 21:44
  • I just assumed it wasn't working because I was not able to access `GL_InstanceID` from the vertex shader. I could have been wrong about that, maybe there is another issue. The question above asks how to run the web_sys::AngleInstancedArrays function through its own interface -- if indeed it is what is invoked by the WebGL2RenderingContext::draw_arrays_instanced. Is one wrapping the other iow. – kulicuu Jul 01 '22 at 21:48
  • 1
    @kulicuu "This comment editor is does not make for easy discussion." — That's on purpose. You should **edit your question** with the additional information about things you already have written/tried. – Kevin Reid Jul 01 '22 at 23:11