diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index 31d4a12..513e8dd 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -208,7 +208,7 @@ if (!webGLData || webGLData.points.length > 320000) { - webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(webGL.gl, this.primitiveShader); + webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); webGLData.reset(type); webGL.data.push(webGLData); } diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index 31d4a12..513e8dd 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -208,7 +208,7 @@ if (!webGLData || webGLData.points.length > 320000) { - webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(webGL.gl, this.primitiveShader); + webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); webGLData.reset(type); webGL.data.push(webGLData); } diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index 7b7148d..d4649b3 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -9,7 +9,7 @@ * @param gl {WebGLRenderingContext} the current WebGL drawing context * @private */ -function WebGLGraphicsData(gl, shader) +function WebGLGraphicsData(gl, shader, attribsState) { /** @@ -64,7 +64,7 @@ */ this.shader = shader; - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, attribsState) .addIndex(this.indexBuffer) .addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0) .addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4); diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index 31d4a12..513e8dd 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -208,7 +208,7 @@ if (!webGLData || webGLData.points.length > 320000) { - webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(webGL.gl, this.primitiveShader); + webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); webGLData.reset(type); webGL.data.push(webGLData); } diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index 7b7148d..d4649b3 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -9,7 +9,7 @@ * @param gl {WebGLRenderingContext} the current WebGL drawing context * @private */ -function WebGLGraphicsData(gl, shader) +function WebGLGraphicsData(gl, shader, attribsState) { /** @@ -64,7 +64,7 @@ */ this.shader = shader; - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, attribsState) .addIndex(this.indexBuffer) .addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0) .addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4); diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 8c0e68f..2bd1d41 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,6 +9,7 @@ createContext = require('pixi-gl-core').createContext, mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), utils = require('../../utils'), + glCore = require('pixi-gl-core'), CONST = require('../../const'); var CONTEXT_UID = 0; @@ -109,7 +110,7 @@ */ // initialize the context so it is ready for the managers. this.gl = options.context || createContext(this.view, this._contextOptions); - + this.CONTEXT_UID = CONTEXT_UID++; /** @@ -238,8 +239,8 @@ displayObject.renderWebGL(this); // apply transform.. - - this.setObjectRenderer(this.emptyRenderer); + this.currentRenderer.flush(); + //this.setObjectRenderer(this.emptyRenderer); this.emit('postrender'); }; @@ -279,7 +280,7 @@ */ WebGLRenderer.prototype.resize = function (width, height) { - if(width * this.resolution === this.width && height * this.resolution === this.height)return; + // if(width * this.resolution === this.width && height * this.resolution === this.height)return; SystemRenderer.prototype.resize.call(this, width, height); @@ -440,6 +441,11 @@ return this; }; +WebGLRenderer.prototype.createVao = function () +{ + return new glCore.VertexArrayObject(this.gl, this.state.attribState); +} + /** * Resets the WebGL state so you can render things however you fancy! */ diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index 31d4a12..513e8dd 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -208,7 +208,7 @@ if (!webGLData || webGLData.points.length > 320000) { - webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(webGL.gl, this.primitiveShader); + webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); webGLData.reset(type); webGL.data.push(webGLData); } diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index 7b7148d..d4649b3 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -9,7 +9,7 @@ * @param gl {WebGLRenderingContext} the current WebGL drawing context * @private */ -function WebGLGraphicsData(gl, shader) +function WebGLGraphicsData(gl, shader, attribsState) { /** @@ -64,7 +64,7 @@ */ this.shader = shader; - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, attribsState) .addIndex(this.indexBuffer) .addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0) .addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4); diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 8c0e68f..2bd1d41 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,6 +9,7 @@ createContext = require('pixi-gl-core').createContext, mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), utils = require('../../utils'), + glCore = require('pixi-gl-core'), CONST = require('../../const'); var CONTEXT_UID = 0; @@ -109,7 +110,7 @@ */ // initialize the context so it is ready for the managers. this.gl = options.context || createContext(this.view, this._contextOptions); - + this.CONTEXT_UID = CONTEXT_UID++; /** @@ -238,8 +239,8 @@ displayObject.renderWebGL(this); // apply transform.. - - this.setObjectRenderer(this.emptyRenderer); + this.currentRenderer.flush(); + //this.setObjectRenderer(this.emptyRenderer); this.emit('postrender'); }; @@ -279,7 +280,7 @@ */ WebGLRenderer.prototype.resize = function (width, height) { - if(width * this.resolution === this.width && height * this.resolution === this.height)return; + // if(width * this.resolution === this.width && height * this.resolution === this.height)return; SystemRenderer.prototype.resize.call(this, width, height); @@ -440,6 +441,11 @@ return this; }; +WebGLRenderer.prototype.createVao = function () +{ + return new glCore.VertexArrayObject(this.gl, this.state.attribState); +} + /** * Resets the WebGL state so you can render things however you fancy! */ diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3537754..c299c67 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -50,9 +50,14 @@ this.maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); + this.attribState = {tempAttribState:new Array(this.maxAttribs) + ,attribState:new Array(this.maxAttribs)}; + + + this.blendModes = mapWebGLBlendModesToPixi(gl); - + // check we have vao.. this.nativeVaoExtension = ( gl.getExtension('OES_vertex_array_object') || diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index 31d4a12..513e8dd 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -208,7 +208,7 @@ if (!webGLData || webGLData.points.length > 320000) { - webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(webGL.gl, this.primitiveShader); + webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); webGLData.reset(type); webGL.data.push(webGLData); } diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index 7b7148d..d4649b3 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -9,7 +9,7 @@ * @param gl {WebGLRenderingContext} the current WebGL drawing context * @private */ -function WebGLGraphicsData(gl, shader) +function WebGLGraphicsData(gl, shader, attribsState) { /** @@ -64,7 +64,7 @@ */ this.shader = shader; - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, attribsState) .addIndex(this.indexBuffer) .addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0) .addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4); diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 8c0e68f..2bd1d41 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,6 +9,7 @@ createContext = require('pixi-gl-core').createContext, mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), utils = require('../../utils'), + glCore = require('pixi-gl-core'), CONST = require('../../const'); var CONTEXT_UID = 0; @@ -109,7 +110,7 @@ */ // initialize the context so it is ready for the managers. this.gl = options.context || createContext(this.view, this._contextOptions); - + this.CONTEXT_UID = CONTEXT_UID++; /** @@ -238,8 +239,8 @@ displayObject.renderWebGL(this); // apply transform.. - - this.setObjectRenderer(this.emptyRenderer); + this.currentRenderer.flush(); + //this.setObjectRenderer(this.emptyRenderer); this.emit('postrender'); }; @@ -279,7 +280,7 @@ */ WebGLRenderer.prototype.resize = function (width, height) { - if(width * this.resolution === this.width && height * this.resolution === this.height)return; + // if(width * this.resolution === this.width && height * this.resolution === this.height)return; SystemRenderer.prototype.resize.call(this, width, height); @@ -440,6 +441,11 @@ return this; }; +WebGLRenderer.prototype.createVao = function () +{ + return new glCore.VertexArrayObject(this.gl, this.state.attribState); +} + /** * Resets the WebGL state so you can render things however you fancy! */ diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3537754..c299c67 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -50,9 +50,14 @@ this.maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); + this.attribState = {tempAttribState:new Array(this.maxAttribs) + ,attribState:new Array(this.maxAttribs)}; + + + this.blendModes = mapWebGLBlendModesToPixi(gl); - + // check we have vao.. this.nativeVaoExtension = ( gl.getExtension('OES_vertex_array_object') || diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index acb9532..b0a4a03 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -31,7 +31,7 @@ this.gl = this.renderer.gl; // know about sprites! - this.quad = new Quad(this.gl); + this.quad = new Quad(this.gl, renderer.state.attribState); var rootState = new FilterState(); rootState.sourceFrame = rootState.destinationFrame = this.renderer.rootRenderTarget.size; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index 31d4a12..513e8dd 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -208,7 +208,7 @@ if (!webGLData || webGLData.points.length > 320000) { - webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(webGL.gl, this.primitiveShader); + webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); webGLData.reset(type); webGL.data.push(webGLData); } diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index 7b7148d..d4649b3 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -9,7 +9,7 @@ * @param gl {WebGLRenderingContext} the current WebGL drawing context * @private */ -function WebGLGraphicsData(gl, shader) +function WebGLGraphicsData(gl, shader, attribsState) { /** @@ -64,7 +64,7 @@ */ this.shader = shader; - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, attribsState) .addIndex(this.indexBuffer) .addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0) .addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4); diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 8c0e68f..2bd1d41 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,6 +9,7 @@ createContext = require('pixi-gl-core').createContext, mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), utils = require('../../utils'), + glCore = require('pixi-gl-core'), CONST = require('../../const'); var CONTEXT_UID = 0; @@ -109,7 +110,7 @@ */ // initialize the context so it is ready for the managers. this.gl = options.context || createContext(this.view, this._contextOptions); - + this.CONTEXT_UID = CONTEXT_UID++; /** @@ -238,8 +239,8 @@ displayObject.renderWebGL(this); // apply transform.. - - this.setObjectRenderer(this.emptyRenderer); + this.currentRenderer.flush(); + //this.setObjectRenderer(this.emptyRenderer); this.emit('postrender'); }; @@ -279,7 +280,7 @@ */ WebGLRenderer.prototype.resize = function (width, height) { - if(width * this.resolution === this.width && height * this.resolution === this.height)return; + // if(width * this.resolution === this.width && height * this.resolution === this.height)return; SystemRenderer.prototype.resize.call(this, width, height); @@ -440,6 +441,11 @@ return this; }; +WebGLRenderer.prototype.createVao = function () +{ + return new glCore.VertexArrayObject(this.gl, this.state.attribState); +} + /** * Resets the WebGL state so you can render things however you fancy! */ diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3537754..c299c67 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -50,9 +50,14 @@ this.maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); + this.attribState = {tempAttribState:new Array(this.maxAttribs) + ,attribState:new Array(this.maxAttribs)}; + + + this.blendModes = mapWebGLBlendModesToPixi(gl); - + // check we have vao.. this.nativeVaoExtension = ( gl.getExtension('OES_vertex_array_object') || diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index acb9532..b0a4a03 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -31,7 +31,7 @@ this.gl = this.renderer.gl; // know about sprites! - this.quad = new Quad(this.gl); + this.quad = new Quad(this.gl, renderer.state.attribState); var rootState = new FilterState(); rootState.sourceFrame = rootState.destinationFrame = this.renderer.rootRenderTarget.size; diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 9db303b..10e8f4b 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -8,7 +8,7 @@ * @memberof PIXI * @param gl {WebGLRenderingContext} The gl context for this quad to use. */ -function Quad(gl) +function Quad(gl, state) { /* * the current WebGL drawing context @@ -68,7 +68,7 @@ /* * @member {glCore.VertexArrayObject} The index buffer */ - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, state) } diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index 31d4a12..513e8dd 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -208,7 +208,7 @@ if (!webGLData || webGLData.points.length > 320000) { - webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(webGL.gl, this.primitiveShader); + webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); webGLData.reset(type); webGL.data.push(webGLData); } diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index 7b7148d..d4649b3 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -9,7 +9,7 @@ * @param gl {WebGLRenderingContext} the current WebGL drawing context * @private */ -function WebGLGraphicsData(gl, shader) +function WebGLGraphicsData(gl, shader, attribsState) { /** @@ -64,7 +64,7 @@ */ this.shader = shader; - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, attribsState) .addIndex(this.indexBuffer) .addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0) .addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4); diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 8c0e68f..2bd1d41 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,6 +9,7 @@ createContext = require('pixi-gl-core').createContext, mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), utils = require('../../utils'), + glCore = require('pixi-gl-core'), CONST = require('../../const'); var CONTEXT_UID = 0; @@ -109,7 +110,7 @@ */ // initialize the context so it is ready for the managers. this.gl = options.context || createContext(this.view, this._contextOptions); - + this.CONTEXT_UID = CONTEXT_UID++; /** @@ -238,8 +239,8 @@ displayObject.renderWebGL(this); // apply transform.. - - this.setObjectRenderer(this.emptyRenderer); + this.currentRenderer.flush(); + //this.setObjectRenderer(this.emptyRenderer); this.emit('postrender'); }; @@ -279,7 +280,7 @@ */ WebGLRenderer.prototype.resize = function (width, height) { - if(width * this.resolution === this.width && height * this.resolution === this.height)return; + // if(width * this.resolution === this.width && height * this.resolution === this.height)return; SystemRenderer.prototype.resize.call(this, width, height); @@ -440,6 +441,11 @@ return this; }; +WebGLRenderer.prototype.createVao = function () +{ + return new glCore.VertexArrayObject(this.gl, this.state.attribState); +} + /** * Resets the WebGL state so you can render things however you fancy! */ diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3537754..c299c67 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -50,9 +50,14 @@ this.maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); + this.attribState = {tempAttribState:new Array(this.maxAttribs) + ,attribState:new Array(this.maxAttribs)}; + + + this.blendModes = mapWebGLBlendModesToPixi(gl); - + // check we have vao.. this.nativeVaoExtension = ( gl.getExtension('OES_vertex_array_object') || diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index acb9532..b0a4a03 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -31,7 +31,7 @@ this.gl = this.renderer.gl; // know about sprites! - this.quad = new Quad(this.gl); + this.quad = new Quad(this.gl, renderer.state.attribState); var rootState = new FilterState(); rootState.sourceFrame = rootState.destinationFrame = this.renderer.rootRenderTarget.size; diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 9db303b..10e8f4b 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -8,7 +8,7 @@ * @memberof PIXI * @param gl {WebGLRenderingContext} The gl context for this quad to use. */ -function Quad(gl) +function Quad(gl, state) { /* * the current WebGL drawing context @@ -68,7 +68,7 @@ /* * @member {glCore.VertexArrayObject} The index buffer */ - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, state) } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index f382295..59751e8 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -77,6 +77,12 @@ } this.sprites = []; + + this.vertexBuffers = []; + this.vaos = []; + + this.vaoMax = 10 + this.vertexCount = 0; } @@ -100,17 +106,25 @@ this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), CONST.SPRITE_MAX_TEXTURES); this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES); // create a couple of buffers - this.vertexBuffer = glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); - // build the vao object that will render.. - this.vao = new glCore.VertexArrayObject(gl) - .addIndex(this.indexBuffer) - .addAttribute(this.vertexBuffer, this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) - .addAttribute(this.vertexBuffer, this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffer, this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffer, this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + + for (var i = 0; i < this.vaoMax; i++) { + this.vertexBuffers[i] = glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); + // build the vao object that will render.. + this.vaos[i] = this.renderer.createVao() + .addIndex(this.indexBuffer) + .addAttribute(this.vertexBuffers[i], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) + .addAttribute(this.vertexBuffers[i], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) + .addAttribute(this.vertexBuffers[i], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) + .addAttribute(this.vertexBuffers[i], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } + + this.vertexBuffer = this.vertexBuffers[0]; + this.vao = this.vaos[0]; + + this.currentBlendMode = 99999; }; @@ -267,8 +281,12 @@ currentGroup.size = i - currentGroup.start; - this.vertexBuffer.upload(buffer.vertices, 0, true); + this.vertexCount++; + this.vertexCount %= this.vaoMax; + this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0); + this.vao = this.vaos[this.vertexCount].bind(); + /// render the groups.. for (i = 0; i < groupCount; i++) { @@ -296,8 +314,6 @@ SpriteRenderer.prototype.start = function () { this.renderer.bindShader(this.shader); - this.vao.bind(); - this.vertexBuffer.bind(); this.tick %= 1000; }; @@ -312,7 +328,11 @@ */ SpriteRenderer.prototype.destroy = function () { - this.vertexBuffer.destroy(); + for (var i = 0; i < this.vaoMax; i++) { + this.vertexBuffers[i].destroy(); + this.vaoMax[i].destroy(); + }; + this.indexBuffer.destroy(); ObjectRenderer.prototype.destroy.call(this); diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index 31d4a12..513e8dd 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -208,7 +208,7 @@ if (!webGLData || webGLData.points.length > 320000) { - webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(webGL.gl, this.primitiveShader); + webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); webGLData.reset(type); webGL.data.push(webGLData); } diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index 7b7148d..d4649b3 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -9,7 +9,7 @@ * @param gl {WebGLRenderingContext} the current WebGL drawing context * @private */ -function WebGLGraphicsData(gl, shader) +function WebGLGraphicsData(gl, shader, attribsState) { /** @@ -64,7 +64,7 @@ */ this.shader = shader; - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, attribsState) .addIndex(this.indexBuffer) .addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0) .addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4); diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 8c0e68f..2bd1d41 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,6 +9,7 @@ createContext = require('pixi-gl-core').createContext, mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), utils = require('../../utils'), + glCore = require('pixi-gl-core'), CONST = require('../../const'); var CONTEXT_UID = 0; @@ -109,7 +110,7 @@ */ // initialize the context so it is ready for the managers. this.gl = options.context || createContext(this.view, this._contextOptions); - + this.CONTEXT_UID = CONTEXT_UID++; /** @@ -238,8 +239,8 @@ displayObject.renderWebGL(this); // apply transform.. - - this.setObjectRenderer(this.emptyRenderer); + this.currentRenderer.flush(); + //this.setObjectRenderer(this.emptyRenderer); this.emit('postrender'); }; @@ -279,7 +280,7 @@ */ WebGLRenderer.prototype.resize = function (width, height) { - if(width * this.resolution === this.width && height * this.resolution === this.height)return; + // if(width * this.resolution === this.width && height * this.resolution === this.height)return; SystemRenderer.prototype.resize.call(this, width, height); @@ -440,6 +441,11 @@ return this; }; +WebGLRenderer.prototype.createVao = function () +{ + return new glCore.VertexArrayObject(this.gl, this.state.attribState); +} + /** * Resets the WebGL state so you can render things however you fancy! */ diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3537754..c299c67 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -50,9 +50,14 @@ this.maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); + this.attribState = {tempAttribState:new Array(this.maxAttribs) + ,attribState:new Array(this.maxAttribs)}; + + + this.blendModes = mapWebGLBlendModesToPixi(gl); - + // check we have vao.. this.nativeVaoExtension = ( gl.getExtension('OES_vertex_array_object') || diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index acb9532..b0a4a03 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -31,7 +31,7 @@ this.gl = this.renderer.gl; // know about sprites! - this.quad = new Quad(this.gl); + this.quad = new Quad(this.gl, renderer.state.attribState); var rootState = new FilterState(); rootState.sourceFrame = rootState.destinationFrame = this.renderer.rootRenderTarget.size; diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 9db303b..10e8f4b 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -8,7 +8,7 @@ * @memberof PIXI * @param gl {WebGLRenderingContext} The gl context for this quad to use. */ -function Quad(gl) +function Quad(gl, state) { /* * the current WebGL drawing context @@ -68,7 +68,7 @@ /* * @member {glCore.VertexArrayObject} The index buffer */ - this.vao = new glCore.VertexArrayObject(gl) + this.vao = new glCore.VertexArrayObject(gl, state) } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index f382295..59751e8 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -77,6 +77,12 @@ } this.sprites = []; + + this.vertexBuffers = []; + this.vaos = []; + + this.vaoMax = 10 + this.vertexCount = 0; } @@ -100,17 +106,25 @@ this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), CONST.SPRITE_MAX_TEXTURES); this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES); // create a couple of buffers - this.vertexBuffer = glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); - // build the vao object that will render.. - this.vao = new glCore.VertexArrayObject(gl) - .addIndex(this.indexBuffer) - .addAttribute(this.vertexBuffer, this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) - .addAttribute(this.vertexBuffer, this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffer, this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffer, this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + + for (var i = 0; i < this.vaoMax; i++) { + this.vertexBuffers[i] = glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); + // build the vao object that will render.. + this.vaos[i] = this.renderer.createVao() + .addIndex(this.indexBuffer) + .addAttribute(this.vertexBuffers[i], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) + .addAttribute(this.vertexBuffers[i], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) + .addAttribute(this.vertexBuffers[i], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) + .addAttribute(this.vertexBuffers[i], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } + + this.vertexBuffer = this.vertexBuffers[0]; + this.vao = this.vaos[0]; + + this.currentBlendMode = 99999; }; @@ -267,8 +281,12 @@ currentGroup.size = i - currentGroup.start; - this.vertexBuffer.upload(buffer.vertices, 0, true); + this.vertexCount++; + this.vertexCount %= this.vaoMax; + this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0); + this.vao = this.vaos[this.vertexCount].bind(); + /// render the groups.. for (i = 0; i < groupCount; i++) { @@ -296,8 +314,6 @@ SpriteRenderer.prototype.start = function () { this.renderer.bindShader(this.shader); - this.vao.bind(); - this.vertexBuffer.bind(); this.tick %= 1000; }; @@ -312,7 +328,11 @@ */ SpriteRenderer.prototype.destroy = function () { - this.vertexBuffer.destroy(); + for (var i = 0; i < this.vaoMax; i++) { + this.vertexBuffers[i].destroy(); + this.vaoMax[i].destroy(); + }; + this.indexBuffer.destroy(); ObjectRenderer.prototype.destroy.call(this); diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index 1b885cf..3ee97ee 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -181,7 +181,7 @@ } // bind the buffer - buffer.vao.bind( this.shader ) + buffer.vao.bind() .draw(gl.TRIANGLES, amount * 6) .unbind();