Skip to content

Commit

Permalink
Merge pull request pixijs#2020 from RoryDouglas7/canvas_mask_fix
Browse files Browse the repository at this point in the history
Rebased fixes for canvas masking/renderMode
  • Loading branch information
englercj committed Aug 2, 2015
2 parents a7a3348 + 8967895 commit 4b6b5c4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/core/graphics/Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,10 @@ Graphics.prototype._renderCanvas = function (renderer)
var context = renderer.context;
var transform = this.worldTransform;

if (this.blendMode !== renderer.currentBlendMode)
var compositeOperation = renderer.blendModes[this.blendMode];
if (compositeOperation !== context.globalCompositeOperation)
{
renderer.currentBlendMode = this.blendMode;
context.globalCompositeOperation = renderer.blendModes[renderer.currentBlendMode];
context.globalCompositeOperation = compositeOperation;
}

var resolution = renderer.resolution;
Expand Down
26 changes: 1 addition & 25 deletions src/core/renderers/canvas/CanvasRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,6 @@ function CanvasRenderer(width, height, options)
*/
this.roundPixels = options.roundPixels;

/**
* Tracks the active scale mode for this renderer.
*
* @member {number}
* @default PIXI.SCALE_MODES.DEFAULT
* @see PIXI.SCALE_MODES
*/
this.currentScaleMode = CONST.SCALE_MODES.DEFAULT;

/**
* Tracks the active blend mode for this renderer.
*
* @member {number}
* @default PIXI.BLEND_MODES.NORMAL
* @see PIXI.BLEND_MODES
*/
this.currentBlendMode = CONST.BLEND_MODES.NORMAL;

/**
* The canvas property used to set the canvas smoothing property.
*
Expand Down Expand Up @@ -152,7 +134,6 @@ CanvasRenderer.prototype.render = function (object)

this.context.globalAlpha = 1;

this.currentBlendMode = CONST.BLEND_MODES.NORMAL;
this.context.globalCompositeOperation = this.blendModes[CONST.BLEND_MODES.NORMAL];

if (navigator.isCocoonJS && this.view.screencanvas)
Expand Down Expand Up @@ -198,9 +179,6 @@ CanvasRenderer.prototype.destroy = function (removeView)

this.roundPixels = false;

this.currentScaleMode = 0;
this.currentBlendMode = 0;

this.smoothProperty = null;
};

Expand All @@ -225,11 +203,9 @@ CanvasRenderer.prototype.resize = function (w, h)

//reset the scale mode.. oddly this seems to be reset when the canvas is resized.
//surely a browser bug?? Let pixi fix that for you..
this.currentScaleMode = CONST.SCALE_MODES.DEFAULT;

if(this.smoothProperty)
{
this.context[this.smoothProperty] = (this.currentScaleMode === CONST.SCALE_MODES.LINEAR);
this.context[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR);
}

};
Expand Down
12 changes: 6 additions & 6 deletions src/core/sprites/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ Sprite.prototype._renderCanvas = function (renderer)
return;
}

if (this.blendMode !== renderer.currentBlendMode)
var compositeOperation = renderer.blendModes[this.blendMode];
if (compositeOperation !== renderer.context.globalCompositeOperation)
{
renderer.currentBlendMode = this.blendMode;
renderer.context.globalCompositeOperation = renderer.blendModes[renderer.currentBlendMode];
renderer.context.globalCompositeOperation = compositeOperation;
}

// Ignore null sources
Expand All @@ -400,10 +400,10 @@ Sprite.prototype._renderCanvas = function (renderer)
renderer.context.globalAlpha = this.worldAlpha;

// If smoothingEnabled is supported and we need to change the smoothing property for this texture
if (renderer.smoothProperty && renderer.currentScaleMode !== texture.baseTexture.scaleMode)
var smoothingEnabled = texture.baseTexture.scaleMode === CONST.SCALE_MODES.LINEAR;
if (renderer.smoothProperty && renderer.context[renderer.smoothProperty] !== smoothingEnabled)
{
renderer.currentScaleMode = texture.baseTexture.scaleMode;
renderer.context[renderer.smoothProperty] = (renderer.currentScaleMode === CONST.SCALE_MODES.LINEAR);
renderer.context[renderer.smoothProperty] = smoothingEnabled;
}

// If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions
Expand Down
6 changes: 3 additions & 3 deletions src/extras/TilingSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ TilingSprite.prototype._renderCanvas = function (renderer)
modY + (this.anchor.y * -this._height));

// check blend mode
if (this.blendMode !== renderer.currentBlendMode)
var compositeOperation = renderer.blendModes[this.blendMode];
if (compositeOperation !== renderer.context.globalCompositeOperation)
{
renderer.currentBlendMode = this.blendMode;
context.globalCompositeOperation = renderer.blendModes[renderer.currentBlendMode];
context.globalCompositeOperation = compositeOperation;
}

// fill the pattern!
Expand Down

0 comments on commit 4b6b5c4

Please sign in to comment.