mirror of
https://github.com/scratchfoundation/scratch-render.git
synced 2025-08-28 22:30:04 -04:00
Fix GL errors when using SVG Drawable early
Drawable now creates its own temporary texture upon construction. This 1x1 transparent texture is ready immediately and is replaced once a real skin is loaded. This slightly simplifies some of the skin loading code but more importantly prevents GL errors caused when trying to draw a Drawable if it hasn't yet created its "real" texture, as in the SVG load path.
This commit is contained in:
parent
b74f9448f5
commit
f0dae7aa48
2 changed files with 10 additions and 12 deletions
|
@ -63,6 +63,10 @@ function Drawable(gl) {
|
|||
this._transformDirty = true;
|
||||
this._effectBits = 0;
|
||||
|
||||
// Create a transparent 1x1 texture for temporary use
|
||||
this._useSkin(twgl.createTexture(gl, {src: [0, 0, 0, 0]}), 0, 0, 1, true);
|
||||
|
||||
// Load a real skin
|
||||
this.setSkin(Drawable._DEFAULT_SKIN);
|
||||
}
|
||||
|
||||
|
@ -170,7 +174,7 @@ Drawable.prototype.setSkin = function (skin_md5ext) {
|
|||
* @param {int} width The width of the skin.
|
||||
* @param {int} height The height of the skin.
|
||||
* @param {int} costumeResolution The resolution to use for this skin.
|
||||
* @param {boolean} [skipPendingCheck] If true, don't compare to _pendingSkin.
|
||||
* @param {Boolean} [skipPendingCheck] If true, don't compare to _pendingSkin.
|
||||
* @private
|
||||
*/
|
||||
Drawable.prototype._useSkin = function(
|
||||
|
@ -267,15 +271,9 @@ Drawable.prototype._setSkinCore = function (source, costumeResolution) {
|
|||
instance._pendingSkin = twgl.createTexture(
|
||||
gl, options, willCallCallback ? callback : null);
|
||||
|
||||
// If we don't already have a texture, or if we won't get a callback when
|
||||
// the new one loads, then just start using the texture immediately.
|
||||
if (willCallCallback) {
|
||||
if (!this._uniforms.u_skin) {
|
||||
this._uniforms.u_skin = instance._pendingSkin;
|
||||
this._setSkinSize(0, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// If we won't get a callback, start using the skin immediately.
|
||||
// This will happen if the data is already local.
|
||||
if (!willCallCallback) {
|
||||
callback(null, instance._pendingSkin, source);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -184,7 +184,7 @@ RenderWebGL.prototype.createDrawable = function () {
|
|||
/**
|
||||
* Destroy a Drawable, removing it from the scene.
|
||||
* @param {int} drawableID The ID of the Drawable to remove.
|
||||
* @returns {boolean} True iff the drawable was found and removed.
|
||||
* @returns {Boolean} True iff the drawable was found and removed.
|
||||
*/
|
||||
RenderWebGL.prototype.destroyDrawable = function (drawableID) {
|
||||
var index = this._drawables.indexOf(drawableID);
|
||||
|
@ -383,7 +383,7 @@ RenderWebGL.prototype.pick = function (
|
|||
* @param {int} drawableID The ID of the Drawable to check.
|
||||
* @param {int[]} color3b Test if the Drawable is touching this color.
|
||||
* @param {int[]} [mask3b] Optionally mask the check to this part of Drawable.
|
||||
* @returns {boolean} True iff the Drawable is touching the color.
|
||||
* @returns {Boolean} True iff the Drawable is touching the color.
|
||||
*/
|
||||
RenderWebGL.prototype.isTouchingColor = function(drawableID, color3b, mask3b) {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue