I'm playing with WebGL and Dart and I can't figure out how to check if some object has certain method. For example in JavaScript I would check if WebGL is available with window.WebGLRenderingContext
but is there a way to the same in Dart?
IIRC one of the goals of Dart was to normalize the inconsistencies of which browser defines what. As such, WebGL will always be "available" in that the interfaces for it will always exist in Dart wether or not the browser you are running on has them defined natively.
Wether or not WebGL is supported is probably best checked the same way you do in Javascript:
WebGLRenderingContext gl = canvas.getContext("experimental-webgl");
If gl
is null then WebGL is not supported. Otherwise it is!
(BTW: just because window.WebGLRenderingContext
exists in Javascript does NOT mean that WebGL is supported! That only tells you that the browser is capable of dispatching WebGL commands. The system that you are running on may not accept them. It's still best to try creating a context and detect when it fails.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With