diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 9da302e..4b9aa28 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -81,8 +81,10 @@ this.vertexBuffers = []; this.vaos = []; - this.vaoMax = 20; + this.vaoMax = 2; this.vertexCount = 0; + + this.renderer.on('prerender', this.onPrerender, this); } @@ -104,12 +106,12 @@ 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.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); - + for (var i = 0; i < this.vaoMax; i++) { this.vertexBuffers[i] = glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); @@ -121,11 +123,16 @@ .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.vao = this.vaos[0]; this.currentBlendMode = 99999; }; +SpriteRenderer.prototype.onPrerender = function () +{ + this.vertexCount = 0; +} + /** * Renders the sprite object. * @@ -281,11 +288,23 @@ currentGroup.size = i - currentGroup.start; this.vertexCount++; - this.vertexCount %= this.vaoMax; + + if(this.vaoMax <= this.vertexCount) + { + this.vaoMax++; + this.vertexBuffers[this.vertexCount] = glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); + // build the vao object that will render.. + this.vaos[this.vertexCount] = this.renderer.createVao() + .addIndex(this.indexBuffer) + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) + .addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + + } this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0); this.vao = this.vaos[this.vertexCount].bind(); - /// render the groups.. for (i = 0; i < groupCount; i++) {