Skip to content

Commit 0ce51b1

Browse files
author
pandamicro
committed
Fix scissor clipping issue
1 parent bb0c171 commit 0ce51b1

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

cocos2d/core/platform/CCEGLView.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ switch (__BrowserGetter.adaptationType) {
102102
break;
103103
}
104104

105-
var _scissorRect = cc.rect();
105+
var _scissorRect = null;
106106

107107
/**
108108
* cc.view is the singleton object which represents the game window.<br/>
@@ -801,15 +801,24 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
801801
* @param {Number} h
802802
*/
803803
setScissorInPoints: function (x, y, w, h) {
804-
var zoomFactor = this._frameZoomFactor, scaleX = this._scaleX, scaleY = this._scaleY;
805-
_scissorRect.x = x;
806-
_scissorRect.y = y;
807-
_scissorRect.width = w;
808-
_scissorRect.height = h;
809-
cc._renderContext.scissor(x * scaleX * zoomFactor + this._viewPortRect.x * zoomFactor,
810-
y * scaleY * zoomFactor + this._viewPortRect.y * zoomFactor,
811-
w * scaleX * zoomFactor,
812-
h * scaleY * zoomFactor);
804+
var locFrameZoomFactor = this._frameZoomFactor, locScaleX = this._scaleX, locScaleY = this._scaleY;
805+
var sx = Math.ceil(x * locScaleX * locFrameZoomFactor + this._viewPortRect.x * locFrameZoomFactor);
806+
var sy = Math.ceil(y * locScaleY * locFrameZoomFactor + this._viewPortRect.y * locFrameZoomFactor);
807+
var sw = Math.ceil(w * locScaleX * locFrameZoomFactor);
808+
var sh = Math.ceil(h * locScaleY * locFrameZoomFactor);
809+
810+
if (!_scissorRect) {
811+
var boxArr = gl.getParameter(gl.SCISSOR_BOX);
812+
_scissorRect = cc.rect(boxArr[0], boxArr[1], boxArr[2], boxArr[3]);
813+
}
814+
815+
if (_scissorRect.x != sx || _scissorRect.y != sy || _scissorRect.width != sw || _scissorRect.height != sh) {
816+
_scissorRect.x = sx;
817+
_scissorRect.y = sy;
818+
_scissorRect.width = sw;
819+
_scissorRect.height = sh;
820+
cc._renderContext.scissor(sx, sy, sw, sh);
821+
}
813822
},
814823

815824
/**
@@ -825,7 +834,18 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
825834
* @return {cc.Rect}
826835
*/
827836
getScissorRect: function () {
828-
return cc.rect(_scissorRect);
837+
if (!_scissorRect) {
838+
var boxArr = gl.getParameter(gl.SCISSOR_BOX);
839+
_scissorRect = cc.rect(boxArr[0], boxArr[1], boxArr[2], boxArr[3]);
840+
}
841+
var scaleX = this._scaleX;
842+
var scaleY = this._scaleY;
843+
return cc.rect(
844+
(_scissorRect.x - this._viewPortRect.x) / scaleX,
845+
(_scissorRect.y - this._viewPortRect.y) / scaleY,
846+
_scissorRect.width / scaleX,
847+
_scissorRect.height / scaleY
848+
);
829849
},
830850

831851
/**

0 commit comments

Comments
 (0)