Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for WebGL support in Dart

Tags:

dart

webgl

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?

like image 279
martin Avatar asked Dec 27 '22 23:12

martin


1 Answers

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.)

like image 51
Toji Avatar answered Jan 22 '23 18:01

Toji