Permalink
Browse files

RenderTexture and MovieTexture should handle context lost

  • Loading branch information...
1 parent f3691d9 commit d70e0fe77953a09e990993469d8ac044b7051b05 @mortennobel committed Jul 20, 2013
Showing with 97 additions and 21 deletions.
  1. +48 −10 build/kick-debug.js
  2. +1 −1 build/kick.js
  3. +35 −7 src/js/kick/texture/MovieTexture.js
  4. +12 −0 src/js/kick/texture/RenderTexture.js
  5. +1 −3 src/js/kick/texture/Texture.js
View
@@ -11658,7 +11658,6 @@ define('kick/texture/Texture',["kick/core/ProjectAsset", "kick/core/Constants",
},
contextLost = function () {
- console.log("_textureId ", _textureId, gl);
gl = null;
},
contextRestored = function (newGl) {
@@ -11667,8 +11666,7 @@ define('kick/texture/Texture',["kick/core/ProjectAsset", "kick/core/Constants",
if (createImageFunction) {
createImageFunction.apply(thisObj, createImageFunctionParameters);
}
- }
- ;
+ };
/**
* Trigger getImageData if dataURI is defined
@@ -15868,6 +15866,14 @@ define('kick/texture/RenderTexture',["kick/core/ProjectAsset", "kick/math/Vec2",
}
}
gl.bindFramebuffer(36160, null);
+ },
+ contextLost = function () {
+ gl = null;
+ },
+ contextRestored = function (newGl) {
+ gl = newGl;
+ framebuffer = gl.createFramebuffer();
+ initFBO();
};
/**
@@ -15935,6 +15941,8 @@ define('kick/texture/RenderTexture',["kick/core/ProjectAsset", "kick/math/Vec2",
gl.deleteFramebuffer(framebuffer);
framebuffer = null;
engine.project.removeResourceDescriptor(thisObj.uid);
+ engine.removeEventListener("contextLost", contextLost);
+ engine.removeEventListener("contextRestored", contextRestored);
}
};
@@ -15950,6 +15958,8 @@ define('kick/texture/RenderTexture',["kick/core/ProjectAsset", "kick/math/Vec2",
};
this.init(config);
+ engine.addEventListener('contextLost', contextLost);
+ engine.addEventListener('contextRestored', contextRestored);
};
});
@@ -22342,7 +22352,21 @@ define('kick/texture/MovieTexture',["kick/core/ProjectAsset", "kick/core/Constan
_generateMipmaps = false,
timer = engine.time,
thisObj = this,
- lastGrappedFrame = -1;
+ lastGrappedFrame = -1,
+ setTextureProperties = function(){
+ gl.texParameteri(3553, 10240, _magFilter);
+ gl.texParameteri(3553, 10241, _minFilter);
+ gl.texParameteri(3553, 10242, _wrapS);
+ gl.texParameteri(3553, 10243, _wrapT);
+ },
+ contextLost = function () {
+ gl = null;
+ },
+ contextRestored = function (newGl) {
+ gl = newGl;
+ _textureId = gl.createTexture();
+ setTextureProperties();
+ };
/**
* Bind the current texture
@@ -22374,6 +22398,8 @@ define('kick/texture/MovieTexture',["kick/core/ProjectAsset", "kick/core/Constan
gl.deleteTexture(_textureId);
_textureId = null;
engine.project.removeResourceDescriptor(thisObj.uid);
+ engine.removeEventListener("contextLost", contextLost);
+ engine.removeEventListener("contextRestored", contextRestored);
}
};
@@ -22386,10 +22412,7 @@ define('kick/texture/MovieTexture',["kick/core/ProjectAsset", "kick/core/Constan
thisObj.bind(0); // bind to texture slot 0
gl.pixelStorei(3317, 1);
gl.texImage2D(3553, 0, 6407, 2, 2, 0, 6407, 5121, blackWhiteCheckerboard);
- gl.texParameteri(3553, 10240, _magFilter);
- gl.texParameteri(3553, 10241, _minFilter);
- gl.texParameteri(3553, 10242, _wrapS);
- gl.texParameteri(3553, 10243, _wrapT);
+ setTextureProperties();
glState.currentMaterial = null; // for material to rebind
};
@@ -22477,6 +22500,9 @@ define('kick/texture/MovieTexture',["kick/core/ProjectAsset", "kick/core/Constan
}
}
_wrapS = value;
+ gl.bindTexture(3553, _textureId);
+ gl.texParameteri(3553, 10242, _wrapS);
+ glState.currentMaterial = null; // for material to rebind
}
},
/**
@@ -22496,6 +22522,9 @@ define('kick/texture/MovieTexture',["kick/core/ProjectAsset", "kick/core/Constan
}
}
_wrapT = value;
+ gl.bindTexture(3553, _textureId);
+ gl.texParameteri(3553, 10243, _wrapT);
+ glState.currentMaterial = null; // for material to rebind
}
},
/**
@@ -22521,6 +22550,9 @@ define('kick/texture/MovieTexture',["kick/core/ProjectAsset", "kick/core/Constan
}
}
_minFilter = value;
+ gl.bindTexture(3553, _textureId);
+ gl.texParameteri(3553, 10241, _minFilter);
+ glState.currentMaterial = null; // for material to rebind
}
},
/**
@@ -22540,6 +22572,9 @@ define('kick/texture/MovieTexture',["kick/core/ProjectAsset", "kick/core/Constan
}
}
_magFilter = value;
+ gl.bindTexture(3553, _textureId);
+ gl.texParameteri(3553, 10240, _magFilter);
+ glState.currentMaterial = null; // for material to rebind
}
},
/**
@@ -22553,6 +22588,7 @@ define('kick/texture/MovieTexture',["kick/core/ProjectAsset", "kick/core/Constan
* @property internalFormat
* @type Number
* @default GL_RGBA
+ * @deprecated
*/
internalFormat: {
get: function () {
@@ -22585,12 +22621,14 @@ define('kick/texture/MovieTexture',["kick/core/ProjectAsset", "kick/core/Constan
wrapT: _wrapT,
minFilter: _minFilter,
name: _name,
- magFilter: _magFilter,
- internalFormat: _intFormat
+ magFilter: _magFilter
};
};
+ // Invoke init in project asset
this.init(config);
+ engine.addEventListener("contextLost", contextLost);
+ engine.addEventListener("contextRestored", contextRestored);
};
});
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -38,7 +38,21 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
_generateMipmaps = false,
timer = engine.time,
thisObj = this,
- lastGrappedFrame = -1;
+ lastGrappedFrame = -1,
+ setTextureProperties = function(){
+ gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_MAG_FILTER, _magFilter);
+ gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_MIN_FILTER, _minFilter);
+ gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_WRAP_S, _wrapS);
+ gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_WRAP_T, _wrapT);
+ },
+ contextLost = function () {
+ gl = null;
+ },
+ contextRestored = function (newGl) {
+ gl = newGl;
+ _textureId = gl.createTexture();
+ setTextureProperties();
+ };
/**
* Bind the current texture
@@ -70,6 +84,8 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
gl.deleteTexture(_textureId);
_textureId = null;
engine.project.removeResourceDescriptor(thisObj.uid);
+ engine.removeEventListener("contextLost", contextLost);
+ engine.removeEventListener("contextRestored", contextRestored);
}
};
@@ -82,10 +98,7 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
thisObj.bind(0); // bind to texture slot 0
gl.pixelStorei(Constants.GL_UNPACK_ALIGNMENT, 1);
gl.texImage2D(Constants.GL_TEXTURE_2D, 0, Constants.GL_RGB, 2, 2, 0, Constants.GL_RGB, Constants.GL_UNSIGNED_BYTE, blackWhiteCheckerboard);
- gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_MAG_FILTER, _magFilter);
- gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_MIN_FILTER, _minFilter);
- gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_WRAP_S, _wrapS);
- gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_WRAP_T, _wrapT);
+ setTextureProperties();
glState.currentMaterial = null; // for material to rebind
};
@@ -173,6 +186,9 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
}
}
_wrapS = value;
+ gl.bindTexture(Constants.GL_TEXTURE_2D, _textureId);
+ gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_WRAP_S, _wrapS);
+ glState.currentMaterial = null; // for material to rebind
}
},
/**
@@ -192,6 +208,9 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
}
}
_wrapT = value;
+ gl.bindTexture(Constants.GL_TEXTURE_2D, _textureId);
+ gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_WRAP_T, _wrapT);
+ glState.currentMaterial = null; // for material to rebind
}
},
/**
@@ -217,6 +236,9 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
}
}
_minFilter = value;
+ gl.bindTexture(Constants.GL_TEXTURE_2D, _textureId);
+ gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_MIN_FILTER, _minFilter);
+ glState.currentMaterial = null; // for material to rebind
}
},
/**
@@ -236,6 +258,9 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
}
}
_magFilter = value;
+ gl.bindTexture(Constants.GL_TEXTURE_2D, _textureId);
+ gl.texParameteri(Constants.GL_TEXTURE_2D, Constants.GL_TEXTURE_MAG_FILTER, _magFilter);
+ glState.currentMaterial = null; // for material to rebind
}
},
/**
@@ -249,6 +274,7 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
* @property internalFormat
* @type Number
* @default GL_RGBA
+ * @deprecated
*/
internalFormat: {
get: function () {
@@ -281,11 +307,13 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
wrapT: _wrapT,
minFilter: _minFilter,
name: _name,
- magFilter: _magFilter,
- internalFormat: _intFormat
+ magFilter: _magFilter
};
};
+ // Invoke init in project asset
this.init(config);
+ engine.addEventListener("contextLost", contextLost);
+ engine.addEventListener("contextRestored", contextRestored);
};
});
@@ -76,6 +76,14 @@ define(["kick/core/ProjectAsset", "kick/math/Vec2", "kick/core/Constants", "kick
}
}
gl.bindFramebuffer(Constants.GL_FRAMEBUFFER, null);
+ },
+ contextLost = function () {
+ gl = null;
+ },
+ contextRestored = function (newGl) {
+ gl = newGl;
+ framebuffer = gl.createFramebuffer();
+ initFBO();
};
/**
@@ -143,6 +151,8 @@ define(["kick/core/ProjectAsset", "kick/math/Vec2", "kick/core/Constants", "kick
gl.deleteFramebuffer(framebuffer);
framebuffer = null;
engine.project.removeResourceDescriptor(thisObj.uid);
+ engine.removeEventListener("contextLost", contextLost);
+ engine.removeEventListener("contextRestored", contextRestored);
}
};
@@ -158,6 +168,8 @@ define(["kick/core/ProjectAsset", "kick/math/Vec2", "kick/core/Constants", "kick
};
this.init(config);
+ engine.addEventListener('contextLost', contextLost);
+ engine.addEventListener('contextRestored', contextRestored);
};
});
@@ -64,7 +64,6 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
},
contextLost = function () {
- console.log("_textureId ", _textureId, gl);
gl = null;
},
contextRestored = function (newGl) {
@@ -73,8 +72,7 @@ define(["kick/core/ProjectAsset", "kick/core/Constants", "kick/core/Util", "kick
if (createImageFunction) {
createImageFunction.apply(thisObj, createImageFunctionParameters);
}
- }
- ;
+ };
/**
* Trigger getImageData if dataURI is defined

0 comments on commit d70e0fe

Please sign in to comment.