Added Sprite Batch
Added new Sprite Batch for fast rendering - pushes transforms to the GPU Added setAttribs function to manage VertexAttribArrays in webGL Modified Point.set function
This commit is contained in:
parent
2ee1f778b3
commit
620d134055
17 changed files with 1781 additions and 21 deletions
|
@ -4,8 +4,16 @@
|
|||
|
||||
PIXI.WebGLShaderManager = function(gl)
|
||||
{
|
||||
this.setContext(gl);
|
||||
|
||||
this.maxAttibs = 10;
|
||||
this.attribState = [];
|
||||
this.tempAttribState = [];
|
||||
|
||||
for (var i = 0; i < this.maxAttibs; i++) {
|
||||
this.attribState[i] = false;
|
||||
}
|
||||
|
||||
this.setContext(gl);
|
||||
// the final one is used for the rendering strips
|
||||
//this.stripShader = new PIXI.StripShader(gl);
|
||||
};
|
||||
|
@ -20,15 +28,80 @@ PIXI.WebGLShaderManager.prototype.setContext = function(gl)
|
|||
// this shader is used for the default sprite rendering
|
||||
this.defaultShader = new PIXI.PixiShader(gl);
|
||||
|
||||
var shaderProgram = this.defaultShader.program;
|
||||
// this shader is used for the fast sprite rendering
|
||||
this.fastShader = new PIXI.PixiFastShader(gl);
|
||||
|
||||
// var shaderProgram = this.defaultShader.program;
|
||||
|
||||
this.activateShader(this.defaultShader);
|
||||
/*
|
||||
gl.useProgram(shaderProgram);
|
||||
|
||||
gl.enableVertexAttribArray(this.defaultShader.aVertexPosition);
|
||||
gl.enableVertexAttribArray(this.defaultShader.colorAttribute);
|
||||
gl.enableVertexAttribArray(this.defaultShader.aTextureCoord);
|
||||
// console.log(">>")
|
||||
//
|
||||
// alert(this.defaultShader.aPositionCoord)
|
||||
gl.enableVertexAttribArray(this.defaultShader.aPositionCoord);
|
||||
gl.enableVertexAttribArray(this.defaultShader.aScale);
|
||||
gl.enableVertexAttribArray(this.defaultShader.aRotation);*/
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
PIXI.WebGLShaderManager.prototype.setAttribs = function(attribs)
|
||||
{
|
||||
// reset temp state
|
||||
|
||||
var i;
|
||||
|
||||
for (i = 0; i < this.tempAttribState.length; i++)
|
||||
{
|
||||
this.tempAttribState[i] = false;
|
||||
}
|
||||
|
||||
// set the new attribs
|
||||
for (i = 0; i < attribs.length; i++)
|
||||
{
|
||||
var attribId = attribs[i];
|
||||
this.tempAttribState[attribId] = true;
|
||||
}
|
||||
|
||||
var gl = this.gl;
|
||||
|
||||
for (i = 0; i < this.attribState.length; i++)
|
||||
{
|
||||
|
||||
if(this.attribState[i] !== this.tempAttribState[i])
|
||||
{
|
||||
this.attribState[i] = this.tempAttribState[i];
|
||||
|
||||
if(this.tempAttribState[i])
|
||||
{
|
||||
gl.enableVertexAttribArray(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl.disableVertexAttribArray(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(this.tempAttribState)
|
||||
};
|
||||
|
||||
PIXI.WebGLShaderManager.prototype.activateShader = function(shader)
|
||||
{
|
||||
//if(this.currentShader == shader)return;
|
||||
|
||||
this.currentShader = shader;
|
||||
// console.log(shader.program)
|
||||
this.gl.useProgram(shader.program);
|
||||
this.setAttribs(shader.attributes);
|
||||
|
||||
// console.log(shader.attributes)
|
||||
|
||||
};
|
||||
|
||||
PIXI.WebGLShaderManager.prototype.activatePrimitiveShader = function()
|
||||
|
@ -37,12 +110,14 @@ PIXI.WebGLShaderManager.prototype.activatePrimitiveShader = function()
|
|||
|
||||
gl.useProgram(this.primitiveShader.program);
|
||||
|
||||
this.setAttribs(this.primitiveShader.attributes);
|
||||
/*
|
||||
gl.disableVertexAttribArray(this.defaultShader.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.defaultShader.colorAttribute);
|
||||
gl.disableVertexAttribArray(this.defaultShader.aTextureCoord);
|
||||
|
||||
gl.enableVertexAttribArray(this.primitiveShader.aVertexPosition);
|
||||
gl.enableVertexAttribArray(this.primitiveShader.colorAttribute);
|
||||
gl.enableVertexAttribArray(this.primitiveShader.colorAttribute);*/
|
||||
};
|
||||
|
||||
PIXI.WebGLShaderManager.prototype.deactivatePrimitiveShader = function()
|
||||
|
@ -51,10 +126,14 @@ PIXI.WebGLShaderManager.prototype.deactivatePrimitiveShader = function()
|
|||
|
||||
gl.useProgram(this.defaultShader.program);
|
||||
|
||||
this.setAttribs(this.defaultShader.attributes);
|
||||
/*
|
||||
gl.disableVertexAttribArray(this.primitiveShader.aVertexPosition);
|
||||
gl.disableVertexAttribArray(this.primitiveShader.colorAttribute);
|
||||
|
||||
gl.enableVertexAttribArray(this.defaultShader.aVertexPosition);
|
||||
gl.enableVertexAttribArray(this.defaultShader.colorAttribute);
|
||||
gl.enableVertexAttribArray(this.defaultShader.aTextureCoord);
|
||||
|
||||
gl.enableVertexAttribArray(this.defaultShader.aPositionCoord);*/
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue