Merge pull request #17520 from eska014/wasm-webgl1

Check only for WebGL 1.0 before starting downloads, move test to HTML file
This commit is contained in:
Rémi Verschelde 2018-03-15 08:55:14 +01:00 committed by GitHub
commit 506c492657
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 23 deletions

View file

@ -244,9 +244,6 @@ $GODOT_HEAD_INCLUDE
var statusMode = 'hidden'; var statusMode = 'hidden';
var indeterminiateStatusAnimationId = 0; var indeterminiateStatusAnimationId = 0;
setStatusMode('indeterminate');
engine.setCanvas(canvas);
function setStatusMode(mode) { function setStatusMode(mode) {
if (statusMode === mode || !initializing) if (statusMode === mode || !initializing)
@ -367,18 +364,27 @@ $GODOT_HEAD_INCLUDE
}); });
} }
engine.startGame(BASENAME + '.pck').then(() => { function displayFailureNotice(err) {
setStatusMode('hidden'); var msg = err.message || err;
initializing = false;
}, err => {
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
printError(err.message); printError(msg);
console.warn(err);
} }
setStatusNotice(err.message); console.error(msg);
setStatusNotice(msg);
setStatusMode('notice'); setStatusMode('notice');
initializing = false; initializing = false;
}); };
if (!Engine.isWebGLAvailable()) {
displayFailureNotice("WebGL not available");
} else {
setStatusMode('indeterminate');
engine.setCanvas(canvas);
engine.startGame(BASENAME + '.pck').then(() => {
setStatusMode('hidden');
initializing = false;
}, displayFailureNotice);
}
})(); })();
//]]></script> //]]></script>
</body> </body>

View file

@ -138,18 +138,6 @@
} }
var actualCanvas = this.rtenv.canvas; var actualCanvas = this.rtenv.canvas;
var testContext = false;
var testCanvas;
try {
testCanvas = document.createElement('canvas');
testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
} catch (e) {}
if (!testContext) {
throw new Error("WebGL 2 not available");
}
testCanvas = null;
testContext = null;
// canvas can grab focus on click // canvas can grab focus on click
if (actualCanvas.tabIndex < 0) { if (actualCanvas.tabIndex < 0) {
actualCanvas.tabIndex = 0; actualCanvas.tabIndex = 0;
@ -273,6 +261,20 @@
Engine.RuntimeEnvironment = engine.RuntimeEnvironment; Engine.RuntimeEnvironment = engine.RuntimeEnvironment;
Engine.isWebGLAvailable = function(majorVersion = 1) {
var testContext = false;
try {
var testCanvas = document.createElement('canvas');
if (majorVersion === 1) {
testContext = testCanvas.getContext('webgl') || testCanvas.getContet('experimental-webgl');
} else if (majorVersion === 2) {
testContext = testCanvas.getContext('webgl2') || testCanvas.getContet('experimental-webgl2');
}
} catch (e) {}
return !!testContext;
};
Engine.load = function(newBasePath) { Engine.load = function(newBasePath) {
if (newBasePath !== undefined) basePath = getBasePath(newBasePath); if (newBasePath !== undefined) basePath = getBasePath(newBasePath);

View file

@ -444,6 +444,7 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
break; break;
} }
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(NULL, &attributes); EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(NULL, &attributes);
ERR_EXPLAIN("WebGL " + itos(attributes.majorVersion) + ".0 not available");
ERR_FAIL_COND_V(emscripten_webgl_make_context_current(ctx) != EMSCRIPTEN_RESULT_SUCCESS, ERR_UNAVAILABLE); ERR_FAIL_COND_V(emscripten_webgl_make_context_current(ctx) != EMSCRIPTEN_RESULT_SUCCESS, ERR_UNAVAILABLE);
video_mode = p_desired; video_mode = p_desired;