Rewrite testcase for stencil depth mask

This commit is contained in:
ZhangMenghe 2015-08-13 10:45:45 +08:00
parent 0f3a2ca642
commit 7ffde1cdf8
1 changed files with 62 additions and 32 deletions

View File

@ -422,54 +422,84 @@ var RenderTextureZbuffer = RenderTextureBaseLayer.extend({
});
var RenderTextureTestDepthStencil = RenderTextureBaseLayer.extend({
ctor:function () {
//Need to re-write test case for new renderer
this._super();
var gl = cc._renderContext;
_spriteDraw : null,
_rend : null,
_listener : null,
ctor:function () {
this._super();
var winSize = cc.director.getWinSize();
var sprite = new cc.Sprite(s_fire);
sprite.x = winSize.width * 0.25;
sprite.y = 0;
sprite.scale = 10;
//TODO GL_DEPTH24_STENCIL8
//var rend = new cc.RenderTexture(winSize.width, winSize.height, cc.TEXTURE_2D_PIXEL_FORMAT_RGBA4444);
var rend = new cc.RenderTexture(winSize.width, winSize.height);
this._spriteDraw = new cc.Sprite(s_fire);
this._spriteDraw.x = winSize.width * 0.25;
this._spriteDraw.y = 0;
this._spriteDraw.scale = 10;
gl.stencilMask(0xFF);
rend.beginWithClear(0, 0, 0, 0, 0, 0);
this._spriteDraw.x = this._spriteDraw.x + this._spriteDraw.getContentSize().width * this._spriteDraw.getScale() * 0.5;
this._spriteDraw.y = this._spriteDraw.y + this._spriteDraw.getContentSize().height * this._spriteDraw.getScale() * 0.5;
//! mark sprite quad into stencil buffer
gl.enable(gl.STENCIL_TEST);
gl.stencilFunc(gl.ALWAYS, 1, 0xFF);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.REPLACE);
gl.colorMask(0, 0, 0, 1);
sprite.visit();
this._rend = new cc.RenderTexture(winSize.width, winSize.height, cc.Texture2D.PIXEL_FORMAT_RGBA4444, gl.DEPTH24_STENCIL8_OES);
this._rend.x = winSize.width * 0.5;
this._rend.y = winSize.height * 0.5;
this.addChild(this._rend);
var item = new cc.MenuItemFont("Click Me", this.maskTest, this);
var menu = new cc.Menu(item);
menu.x = winSize.width - 90;
menu.y = winSize.height - 100;
//! move sprite half width and height, and draw only where not marked
sprite.x += sprite.width * sprite.scale / 2;
sprite.y += sprite.height * sprite.scale / 2;
var sprite = this._spriteDraw;
var layer = this;
this._listener = cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: function (touch, event) {
var locationInNode = sprite.convertToNodeSpace(touch.getLocation());
var s = sprite.getContentSize();
var rect = cc.rect(0, 0, winSize.width, winSize.height);
if (cc.rectContainsPoint(rect, locationInNode)) {
layer.releaseMask();
return true;
}
return false;
}
});
this.setUserObject(this._listener);
this.addChild(menu);
this.addChild(this._spriteDraw);
},
releaseMask: function () {
var gl = cc._renderContext;
gl.stencilFunc(gl.NOTEQUAL, 1, 0xFF);
gl.colorMask(1, 1, 1, 1);
sprite.visit();
rend.end();
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
gl.disable(gl.STENCIL_TEST);
cc.eventManager.removeListener(this._listener);
},
rend.x = winSize.width * 0.5;
rend.y = winSize.height * 0.5;
maskTest: function (sender) {
var gl = cc._renderContext;
this.addChild(rend);
gl.clear(gl.STENCIL_BUFFER_BIT);
this._rend.beginWithClear(0, 0, 0, 0, 0, 0);
gl.stencilMask(0xFF);
gl.stencilFunc(gl.NEVER, 1, 0xFF);
gl.stencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE);
gl.enable(gl.STENCIL_TEST);
this._rend.end();
cc.eventManager.addListener(this._listener, this._spriteDraw);
},
title:function () {
return "Testing depthStencil attachment";
},
subtitle:function () {
return "Circle should be missing 1/4 of its region";
return "Click to be masked and Touch anywhere to back";
}
});