diff --git a/test/core/WebGLRenderer.js b/test/core/WebGLRenderer.js index 4fe37a8..032a108 100644 --- a/test/core/WebGLRenderer.js +++ b/test/core/WebGLRenderer.js @@ -4,32 +4,81 @@ describe('PIXI.WebGLRenderer', function () { - it('setting option legacy should disable VAOs and SPRITE_MAX_TEXTURES', withGL(function () + describe('instance', function () { - const renderer = new PIXI.WebGLRenderer(1, 1, { legacy: true }); - - try + if (withGL()) { + afterEach(function () + { + this.renderer.destroy(); + }); + + after(function () + { + this.renderer = null; + }); + } + + it('setting option legacy should disable VAOs and SPRITE_MAX_TEXTURES', withGL(function () + { + this.renderer = new PIXI.WebGLRenderer(1, 1, { legacy: true }); + expect(PIXI.glCore.VertexArrayObject.FORCE_NATIVE).to.equal(true); - expect(renderer.plugins.sprite.MAX_TEXTURES).to.equal(1); - } - finally - { - renderer.destroy(); - } - })); + expect(this.renderer.plugins.sprite.MAX_TEXTURES).to.equal(1); + })); - it('should allow clear() to work despite no containers added to the renderer', withGL(function () + it('should allow clear() to work despite no containers added to the renderer', withGL(function () + { + this.renderer = new PIXI.WebGLRenderer(1, 1); + this.renderer.clear(); + })); + }); + + describe('.setObjectRenderer()', function () { - const renderer = new PIXI.WebGLRenderer(1, 1); + if (withGL()) + { + before(function () + { + this.renderer = new PIXI.WebGLRenderer(); + }); - try - { - renderer.clear(); + beforeEach(function () + { + this.curRenderer = { + start: sinon.spy(), + stop: sinon.spy(), + }; + this.objRenderer = { + start: sinon.spy(), + stop: sinon.spy(), + }; + this.renderer.currentRenderer = this.curRenderer; + }); + + after(function () + { + this.renderer.destroy(); + this.renderer = null; + this.curRenderer = null; + this.objRenderer = null; + }); } - finally + + it('should set objectRenderer as new current renderer', withGL(function () { - renderer.destroy(); - } - })); + this.renderer.setObjectRenderer(this.objRenderer); + expect(this.curRenderer.stop).to.be.calledOnce; + expect(this.renderer.currentRenderer).to.be.equal(this.objRenderer); + expect(this.objRenderer.start).to.be.calledOnce; + })); + + it('should do nothing if objectRenderer is already used as current', withGL(function () + { + this.renderer.setObjectRenderer(this.curRenderer); + expect(this.renderer.currentRenderer).to.be.equal(this.curRenderer); + expect(this.curRenderer.stop).to.not.be.called; + expect(this.curRenderer.start).to.not.be.called; + })); + }); }); diff --git a/test/core/WebGLRenderer.js b/test/core/WebGLRenderer.js index 4fe37a8..032a108 100644 --- a/test/core/WebGLRenderer.js +++ b/test/core/WebGLRenderer.js @@ -4,32 +4,81 @@ describe('PIXI.WebGLRenderer', function () { - it('setting option legacy should disable VAOs and SPRITE_MAX_TEXTURES', withGL(function () + describe('instance', function () { - const renderer = new PIXI.WebGLRenderer(1, 1, { legacy: true }); - - try + if (withGL()) { + afterEach(function () + { + this.renderer.destroy(); + }); + + after(function () + { + this.renderer = null; + }); + } + + it('setting option legacy should disable VAOs and SPRITE_MAX_TEXTURES', withGL(function () + { + this.renderer = new PIXI.WebGLRenderer(1, 1, { legacy: true }); + expect(PIXI.glCore.VertexArrayObject.FORCE_NATIVE).to.equal(true); - expect(renderer.plugins.sprite.MAX_TEXTURES).to.equal(1); - } - finally - { - renderer.destroy(); - } - })); + expect(this.renderer.plugins.sprite.MAX_TEXTURES).to.equal(1); + })); - it('should allow clear() to work despite no containers added to the renderer', withGL(function () + it('should allow clear() to work despite no containers added to the renderer', withGL(function () + { + this.renderer = new PIXI.WebGLRenderer(1, 1); + this.renderer.clear(); + })); + }); + + describe('.setObjectRenderer()', function () { - const renderer = new PIXI.WebGLRenderer(1, 1); + if (withGL()) + { + before(function () + { + this.renderer = new PIXI.WebGLRenderer(); + }); - try - { - renderer.clear(); + beforeEach(function () + { + this.curRenderer = { + start: sinon.spy(), + stop: sinon.spy(), + }; + this.objRenderer = { + start: sinon.spy(), + stop: sinon.spy(), + }; + this.renderer.currentRenderer = this.curRenderer; + }); + + after(function () + { + this.renderer.destroy(); + this.renderer = null; + this.curRenderer = null; + this.objRenderer = null; + }); } - finally + + it('should set objectRenderer as new current renderer', withGL(function () { - renderer.destroy(); - } - })); + this.renderer.setObjectRenderer(this.objRenderer); + expect(this.curRenderer.stop).to.be.calledOnce; + expect(this.renderer.currentRenderer).to.be.equal(this.objRenderer); + expect(this.objRenderer.start).to.be.calledOnce; + })); + + it('should do nothing if objectRenderer is already used as current', withGL(function () + { + this.renderer.setObjectRenderer(this.curRenderer); + expect(this.renderer.currentRenderer).to.be.equal(this.curRenderer); + expect(this.curRenderer.stop).to.not.be.called; + expect(this.curRenderer.start).to.not.be.called; + })); + }); }); diff --git a/test/withGL.js b/test/withGL.js index bd47b2d..f98ab0a 100644 --- a/test/withGL.js +++ b/test/withGL.js @@ -2,7 +2,7 @@ function withGL(fn) { - return PIXI.utils.isWebGLSupported() ? fn : undefined; + return PIXI.utils.isWebGLSupported() ? (fn || true) : undefined; } module.exports = withGL;