我正在寫一個webgl應用程序,並試圖恢復webgl上下文後,它已經丟失,但上下文恢復事件似乎並沒有被解僱。webglcontextrestored事件不發射後上下文
我正在運行以下代碼,根據WebGL specification和WebGL wiki上的文檔,預計將記錄「上下文丟失」和「上下文已恢復」。當我在jsfiddle中同時運行Chrome(50.0.2661.102 m)和Firefox(46.0.1)中的代碼時,我看到「上下文丟失」記錄,但沒有「上下文恢復」,我在電子應用程序中看到了相同的行爲。
var canvas = document.createElement('canvas')
var gl = canvas.getContext("webgl");
var WEBGL_lose_context = gl.getExtension('WEBGL_lose_context');
canvas.addEventListener("webglcontextlost", function(e) {
log("context lost");
e.preventDefault();
}, false);
canvas.addEventListener("webglcontextrestored", function() {
log("context restored");
}, false);
WEBGL_lose_context.loseContext();
function log(msg) {
var div = document.createElement("pre");
div.appendChild(document.createTextNode(msg));
document.body.appendChild(div);
}
我是否需要做額外的事情才能讓上下文恢復事件觸發?我誤解了WebGL規範嗎?
邊注:調用'getExtension(「WEBGL_lose_context」)丟失上下文之後'不再起作用,所以你需要在某處緩存擴展名。 – Thomas