Check WebGL Support in Dart

I play with WebGL and Dart , and I cannot figure out how to check if any object has a specific method. For example, in JavaScript, I would check if WebGL is accessible using window.WebGLRenderingContext , but is there a way in Dart?

+4
source share
2 answers

IIRC's one of Dart's goals was to normalize the inconsistencies that the browser defines. Thus, WebGL will always be “accessible” in the sense that the interfaces for it will always exist in Dart, and not in the browser you are working on, whether they are defined initially.

Supported by Wether or not supported by WebGL, it is probably best tested the same way as in Javascript:

 WebGLRenderingContext gl = canvas.getContext("experimental-webgl"); 

If gl is null, then WebGL is not supported. Otherwise it!

(BTW: just because window.WebGLRenderingContext exists in Javascript does NOT mean that WebGL is supported! This only means that the browser is capable of sending WebGL commands. The system you are working on may not accept them. It's better to try to create a context and detect when it is not working.)

+8
source

EDIT: By the way, there is a Dart path to initialize a WebGL context:

 RenderingContext gl = canvas.getContext3d(); if (gl == null) { print("WebGL: initialization failure"); } 

OLD RESPONSE:

 WebGLRenderingContext gl = canvas.getContext("experimental-webgl"); if (gl == null) { print("WebGL is not supported"); return; } 

This code prints “WebGL not supported” in the Chrome JavaScript console when I enable “Disable WebGL” under chrome: // flags /.

However, if WebGL is disabled in Firefox (about: config → webgl.disabled; true), it gives an error in the web console:

NS_ERROR_FAILURE: Component return code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLCanvasElement.getContext]

EDIT: This is a fixed bug for Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=645792

+2
source

Source: https://habr.com/ru/post/1416423/


All Articles