diff --git a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js index bbd3259..b83def8 100644 --- a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js +++ b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class ComplexPrimitiveShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.ComplexPrimitiveShader = function(gl) -{ +function ComplexPrimitiveShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; + this._UID = _UID++; /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ @@ -47,16 +38,15 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ - this.vertexSrc = [ + this.vertexSrc = [ 'attribute vec2 aVertexPosition;', //'attribute vec4 aColor;', 'uniform mat3 translationMatrix;', 'uniform vec2 projectionVector;', 'uniform vec2 offsetVector;', - + 'uniform vec3 tint;', 'uniform float alpha;', 'uniform vec3 color;', @@ -72,20 +62,19 @@ ]; this.init(); -}; +} -PIXI.ComplexPrimitiveShader.prototype.constructor = PIXI.ComplexPrimitiveShader; +ComplexPrimitiveShader.prototype.constructor = ComplexPrimitiveShader; +module.exports = ComplexPrimitiveShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.ComplexPrimitiveShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +ComplexPrimitiveShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); gl.useProgram(program); // get and store the uniforms for the shader @@ -108,12 +97,10 @@ }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.ComplexPrimitiveShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +ComplexPrimitiveShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js index bbd3259..b83def8 100644 --- a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js +++ b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class ComplexPrimitiveShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.ComplexPrimitiveShader = function(gl) -{ +function ComplexPrimitiveShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; + this._UID = _UID++; /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ @@ -47,16 +38,15 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ - this.vertexSrc = [ + this.vertexSrc = [ 'attribute vec2 aVertexPosition;', //'attribute vec4 aColor;', 'uniform mat3 translationMatrix;', 'uniform vec2 projectionVector;', 'uniform vec2 offsetVector;', - + 'uniform vec3 tint;', 'uniform float alpha;', 'uniform vec3 color;', @@ -72,20 +62,19 @@ ]; this.init(); -}; +} -PIXI.ComplexPrimitiveShader.prototype.constructor = PIXI.ComplexPrimitiveShader; +ComplexPrimitiveShader.prototype.constructor = ComplexPrimitiveShader; +module.exports = ComplexPrimitiveShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.ComplexPrimitiveShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +ComplexPrimitiveShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); gl.useProgram(program); // get and store the uniforms for the shader @@ -108,12 +97,10 @@ }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.ComplexPrimitiveShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +ComplexPrimitiveShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/PixiFastShader.js b/src/renderers/webgl/shaders/PixiFastShader.js index 8e685e7..b1d85c1 100644 --- a/src/renderers/webgl/shaders/PixiFastShader.js +++ b/src/renderers/webgl/shaders/PixiFastShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class PixiFastShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.PixiFastShader = function(gl) -{ +function PixiFastShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; - + this._UID = _UID++; + /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision lowp float;', @@ -46,8 +37,7 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ this.vertexSrc = [ 'attribute vec2 aVertexPosition;', @@ -81,27 +71,25 @@ /** * A local texture counter for multi-texture shaders. - * @property textureCount - * @type Number + * @member {number} */ this.textureCount = 0; - - this.init(); -}; -PIXI.PixiFastShader.prototype.constructor = PIXI.PixiFastShader; + this.init(); +} + +PixiFastShader.prototype.constructor = PixiFastShader; +module.exports = PixiFastShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.PixiFastShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +PixiFastShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); - + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); + gl.useProgram(program); // get and store the uniforms for the shader @@ -121,33 +109,30 @@ this.aTextureCoord = gl.getAttribLocation(program, 'aTextureCoord'); this.colorAttribute = gl.getAttribLocation(program, 'aColor'); - + // Begin worst hack eva // // WHY??? ONLY on my chrome pixel the line above returns -1 when using filters? // maybe its somthing to do with the current state of the gl context. // Im convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if(this.colorAttribute === -1) - { + if (this.colorAttribute === -1) { this.colorAttribute = 2; } this.attributes = [this.aVertexPosition, this.aPositionCoord, this.aScale, this.aRotation, this.aTextureCoord, this.colorAttribute]; - + // End worst hack eva // this.program = program; }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.PixiFastShader.prototype.destroy = function() -{ - this.gl.deleteProgram( this.program ); + * Destroys the shader. + * + */ +PixiFastShader.prototype.destroy = function () { + this.gl.deleteProgram(this.program); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js index bbd3259..b83def8 100644 --- a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js +++ b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class ComplexPrimitiveShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.ComplexPrimitiveShader = function(gl) -{ +function ComplexPrimitiveShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; + this._UID = _UID++; /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ @@ -47,16 +38,15 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ - this.vertexSrc = [ + this.vertexSrc = [ 'attribute vec2 aVertexPosition;', //'attribute vec4 aColor;', 'uniform mat3 translationMatrix;', 'uniform vec2 projectionVector;', 'uniform vec2 offsetVector;', - + 'uniform vec3 tint;', 'uniform float alpha;', 'uniform vec3 color;', @@ -72,20 +62,19 @@ ]; this.init(); -}; +} -PIXI.ComplexPrimitiveShader.prototype.constructor = PIXI.ComplexPrimitiveShader; +ComplexPrimitiveShader.prototype.constructor = ComplexPrimitiveShader; +module.exports = ComplexPrimitiveShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.ComplexPrimitiveShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +ComplexPrimitiveShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); gl.useProgram(program); // get and store the uniforms for the shader @@ -108,12 +97,10 @@ }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.ComplexPrimitiveShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +ComplexPrimitiveShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/PixiFastShader.js b/src/renderers/webgl/shaders/PixiFastShader.js index 8e685e7..b1d85c1 100644 --- a/src/renderers/webgl/shaders/PixiFastShader.js +++ b/src/renderers/webgl/shaders/PixiFastShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class PixiFastShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.PixiFastShader = function(gl) -{ +function PixiFastShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; - + this._UID = _UID++; + /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision lowp float;', @@ -46,8 +37,7 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ this.vertexSrc = [ 'attribute vec2 aVertexPosition;', @@ -81,27 +71,25 @@ /** * A local texture counter for multi-texture shaders. - * @property textureCount - * @type Number + * @member {number} */ this.textureCount = 0; - - this.init(); -}; -PIXI.PixiFastShader.prototype.constructor = PIXI.PixiFastShader; + this.init(); +} + +PixiFastShader.prototype.constructor = PixiFastShader; +module.exports = PixiFastShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.PixiFastShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +PixiFastShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); - + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); + gl.useProgram(program); // get and store the uniforms for the shader @@ -121,33 +109,30 @@ this.aTextureCoord = gl.getAttribLocation(program, 'aTextureCoord'); this.colorAttribute = gl.getAttribLocation(program, 'aColor'); - + // Begin worst hack eva // // WHY??? ONLY on my chrome pixel the line above returns -1 when using filters? // maybe its somthing to do with the current state of the gl context. // Im convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if(this.colorAttribute === -1) - { + if (this.colorAttribute === -1) { this.colorAttribute = 2; } this.attributes = [this.aVertexPosition, this.aPositionCoord, this.aScale, this.aRotation, this.aTextureCoord, this.colorAttribute]; - + // End worst hack eva // this.program = program; }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.PixiFastShader.prototype.destroy = function() -{ - this.gl.deleteProgram( this.program ); + * Destroys the shader. + * + */ +PixiFastShader.prototype.destroy = function () { + this.gl.deleteProgram(this.program); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/PixiShader.js b/src/renderers/webgl/shaders/PixiShader.js index e70be7f..60d956b 100644 --- a/src/renderers/webgl/shaders/PixiShader.js +++ b/src/renderers/webgl/shaders/PixiShader.js @@ -1,39 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 - * @author Richard Davey http://www.photonstorm.com @photonstorm + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class PixiShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.PixiShader = function(gl) -{ +function PixiShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; + this._UID = _UID++; /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision lowp float;', @@ -47,49 +37,44 @@ /** * A local texture counter for multi-texture shaders. - * @property textureCount - * @type Number + * @member {number} */ this.textureCount = 0; /** * A local flag - * @property firstRun - * @type Boolean + * @member {boolean} * @private */ this.firstRun = true; /** * A dirty flag - * @property dirty - * @type Boolean + * @member {boolean} */ this.dirty = true; /** * Uniform attributes cache. - * @property attributes - * @type Array + * @member {Array} * @private */ this.attributes = []; this.init(); -}; +} -PIXI.PixiShader.prototype.constructor = PIXI.PixiShader; +PixiShader.prototype.constructor = PixiShader; +module.exports = PixiShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.PixiShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +PixiShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc || PixiShader.defaultVertexSrc, this.fragmentSrc); gl.useProgram(program); @@ -110,8 +95,7 @@ // maybe its something to do with the current state of the gl context. // I'm convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if(this.colorAttribute === -1) - { + if (this.colorAttribute === -1) { this.colorAttribute = 2; } @@ -120,8 +104,7 @@ // End worst hack eva // // add those custom shaders! - for (var key in this.uniforms) - { + for (var key in this.uniforms) { // get the uniform locations.. this.uniforms[key].uniformLocation = gl.getUniformLocation(program, key); } @@ -132,72 +115,58 @@ }; /** -* Initialises the shader uniform values. -* -* Uniforms are specified in the GLSL_ES Specification: http://www.khronos.org/registry/webgl/specs/latest/1.0/ -* http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf -* -* @method initUniforms -*/ -PIXI.PixiShader.prototype.initUniforms = function() -{ + * Initialises the shader uniform values. + * + * Uniforms are specified in the GLSL_ES Specification: http://www.khronos.org/registry/webgl/specs/latest/1.0/ + * http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf + * + */ +PixiShader.prototype.initUniforms = function () { this.textureCount = 1; var gl = this.gl; var uniform; - for (var key in this.uniforms) - { + for (var key in this.uniforms) { uniform = this.uniforms[key]; var type = uniform.type; - if (type === 'sampler2D') - { + if (type === 'sampler2D') { uniform._init = false; - if (uniform.value !== null) - { + if (uniform.value !== null) { this.initSampler2D(uniform); } } - else if (type === 'mat2' || type === 'mat3' || type === 'mat4') - { + else if (type === 'mat2' || type === 'mat3' || type === 'mat4') { // These require special handling uniform.glMatrix = true; uniform.glValueLength = 1; - if (type === 'mat2') - { + if (type === 'mat2') { uniform.glFunc = gl.uniformMatrix2fv; } - else if (type === 'mat3') - { + else if (type === 'mat3') { uniform.glFunc = gl.uniformMatrix3fv; } - else if (type === 'mat4') - { + else if (type === 'mat4') { uniform.glFunc = gl.uniformMatrix4fv; } } - else - { + else { // GL function reference uniform.glFunc = gl['uniform' + type]; - if (type === '2f' || type === '2i') - { + if (type === '2f' || type === '2i') { uniform.glValueLength = 2; } - else if (type === '3f' || type === '3i') - { + else if (type === '3f' || type === '3i') { uniform.glValueLength = 3; } - else if (type === '4f' || type === '4i') - { + else if (type === '4f' || type === '4i') { uniform.glValueLength = 4; } - else - { + else { uniform.glValueLength = 1; } } @@ -206,14 +175,11 @@ }; /** -* Initialises a Sampler2D uniform (which may only be available later on after initUniforms once the texture has loaded) -* -* @method initSampler2D -*/ -PIXI.PixiShader.prototype.initSampler2D = function(uniform) -{ - if (!uniform.value || !uniform.value.baseTexture || !uniform.value.baseTexture.hasLoaded) - { + * Initialises a Sampler2D uniform (which may only be available later on after initUniforms once the texture has loaded) + * + */ +PixiShader.prototype.initSampler2D = function (uniform) { + if (!uniform.value || !uniform.value.baseTexture || !uniform.value.baseTexture.hasLoaded) { return; } @@ -223,8 +189,7 @@ gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]); // Extended texture data - if (uniform.textureData) - { + if (uniform.textureData) { var data = uniform.textureData; // GLTexture = mag linear, min linear_mipmap_linear, wrap repeat + gl.generateMipmap(gl.TEXTURE_2D); @@ -243,16 +208,14 @@ var wrapT = (data.wrapT) ? data.wrapT : gl.CLAMP_TO_EDGE; var format = (data.luminance) ? gl.LUMINANCE : gl.RGBA; - if (data.repeat) - { + if (data.repeat) { wrapS = gl.REPEAT; wrapT = gl.REPEAT; } gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, !!data.flipY); - if (data.width) - { + if (data.width) { var width = (data.width) ? data.width : 512; var height = (data.height) ? data.height : 2; var border = (data.border) ? data.border : 0; @@ -260,8 +223,7 @@ // void texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ArrayBufferView? pixels); gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, border, format, gl.UNSIGNED_BYTE, null); } - else - { + else { // void texImage2D(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, ImageData? pixels); gl.texImage2D(gl.TEXTURE_2D, 0, format, gl.RGBA, gl.UNSIGNED_BYTE, uniform.value.baseTexture.source); } @@ -277,84 +239,66 @@ uniform._init = true; this.textureCount++; - }; /** -* Updates the shader uniform values. -* -* @method syncUniforms -*/ -PIXI.PixiShader.prototype.syncUniforms = function() -{ + * Updates the shader uniform values. + * + */ +PixiShader.prototype.syncUniforms = function () { this.textureCount = 1; var uniform; var gl = this.gl; // This would probably be faster in an array and it would guarantee key order - for (var key in this.uniforms) - { + for (var key in this.uniforms) { uniform = this.uniforms[key]; - if (uniform.glValueLength === 1) - { - if (uniform.glMatrix === true) - { + if (uniform.glValueLength === 1) { + if (uniform.glMatrix === true) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.transpose, uniform.value); } - else - { + else { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value); } } - else if (uniform.glValueLength === 2) - { + else if (uniform.glValueLength === 2) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y); } - else if (uniform.glValueLength === 3) - { + else if (uniform.glValueLength === 3) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z); } - else if (uniform.glValueLength === 4) - { + else if (uniform.glValueLength === 4) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z, uniform.value.w); } - else if (uniform.type === 'sampler2D') - { - if (uniform._init) - { + else if (uniform.type === 'sampler2D') { + if (uniform._init) { gl.activeTexture(gl['TEXTURE' + this.textureCount]); - if(uniform.value.baseTexture._dirty[gl.id]) - { - PIXI.instances[gl.id].updateTexture(uniform.value.baseTexture); + if (uniform.value.baseTexture._dirty[gl.id]) { + instances[gl.id].updateTexture(uniform.value.baseTexture); } - else - { + else { // bind the current texture gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]); } - // gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || PIXI.createWebGLTexture( uniform.value.baseTexture, gl)); + // gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || createWebGLTexture( uniform.value.baseTexture, gl)); gl.uniform1i(uniform.uniformLocation, this.textureCount); this.textureCount++; } - else - { + else { this.initSampler2D(uniform); } } } - }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.PixiShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +PixiShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; @@ -363,12 +307,12 @@ }; /** -* The Default Vertex shader source. -* -* @property defaultVertexSrc -* @type String -*/ -PIXI.PixiShader.defaultVertexSrc = [ + * The Default Vertex shader source. + * + * @property defaultVertexSrc + * @type String + */ +PixiShader.defaultVertexSrc = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', 'attribute vec4 aColor;', @@ -386,4 +330,4 @@ ' vTextureCoord = aTextureCoord;', ' vColor = vec4(aColor.rgb * aColor.a, aColor.a);', '}' -]; \ No newline at end of file +]; diff --git a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js index bbd3259..b83def8 100644 --- a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js +++ b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class ComplexPrimitiveShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.ComplexPrimitiveShader = function(gl) -{ +function ComplexPrimitiveShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; + this._UID = _UID++; /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ @@ -47,16 +38,15 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ - this.vertexSrc = [ + this.vertexSrc = [ 'attribute vec2 aVertexPosition;', //'attribute vec4 aColor;', 'uniform mat3 translationMatrix;', 'uniform vec2 projectionVector;', 'uniform vec2 offsetVector;', - + 'uniform vec3 tint;', 'uniform float alpha;', 'uniform vec3 color;', @@ -72,20 +62,19 @@ ]; this.init(); -}; +} -PIXI.ComplexPrimitiveShader.prototype.constructor = PIXI.ComplexPrimitiveShader; +ComplexPrimitiveShader.prototype.constructor = ComplexPrimitiveShader; +module.exports = ComplexPrimitiveShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.ComplexPrimitiveShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +ComplexPrimitiveShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); gl.useProgram(program); // get and store the uniforms for the shader @@ -108,12 +97,10 @@ }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.ComplexPrimitiveShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +ComplexPrimitiveShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/PixiFastShader.js b/src/renderers/webgl/shaders/PixiFastShader.js index 8e685e7..b1d85c1 100644 --- a/src/renderers/webgl/shaders/PixiFastShader.js +++ b/src/renderers/webgl/shaders/PixiFastShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class PixiFastShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.PixiFastShader = function(gl) -{ +function PixiFastShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; - + this._UID = _UID++; + /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision lowp float;', @@ -46,8 +37,7 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ this.vertexSrc = [ 'attribute vec2 aVertexPosition;', @@ -81,27 +71,25 @@ /** * A local texture counter for multi-texture shaders. - * @property textureCount - * @type Number + * @member {number} */ this.textureCount = 0; - - this.init(); -}; -PIXI.PixiFastShader.prototype.constructor = PIXI.PixiFastShader; + this.init(); +} + +PixiFastShader.prototype.constructor = PixiFastShader; +module.exports = PixiFastShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.PixiFastShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +PixiFastShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); - + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); + gl.useProgram(program); // get and store the uniforms for the shader @@ -121,33 +109,30 @@ this.aTextureCoord = gl.getAttribLocation(program, 'aTextureCoord'); this.colorAttribute = gl.getAttribLocation(program, 'aColor'); - + // Begin worst hack eva // // WHY??? ONLY on my chrome pixel the line above returns -1 when using filters? // maybe its somthing to do with the current state of the gl context. // Im convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if(this.colorAttribute === -1) - { + if (this.colorAttribute === -1) { this.colorAttribute = 2; } this.attributes = [this.aVertexPosition, this.aPositionCoord, this.aScale, this.aRotation, this.aTextureCoord, this.colorAttribute]; - + // End worst hack eva // this.program = program; }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.PixiFastShader.prototype.destroy = function() -{ - this.gl.deleteProgram( this.program ); + * Destroys the shader. + * + */ +PixiFastShader.prototype.destroy = function () { + this.gl.deleteProgram(this.program); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/PixiShader.js b/src/renderers/webgl/shaders/PixiShader.js index e70be7f..60d956b 100644 --- a/src/renderers/webgl/shaders/PixiShader.js +++ b/src/renderers/webgl/shaders/PixiShader.js @@ -1,39 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 - * @author Richard Davey http://www.photonstorm.com @photonstorm + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class PixiShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.PixiShader = function(gl) -{ +function PixiShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; + this._UID = _UID++; /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision lowp float;', @@ -47,49 +37,44 @@ /** * A local texture counter for multi-texture shaders. - * @property textureCount - * @type Number + * @member {number} */ this.textureCount = 0; /** * A local flag - * @property firstRun - * @type Boolean + * @member {boolean} * @private */ this.firstRun = true; /** * A dirty flag - * @property dirty - * @type Boolean + * @member {boolean} */ this.dirty = true; /** * Uniform attributes cache. - * @property attributes - * @type Array + * @member {Array} * @private */ this.attributes = []; this.init(); -}; +} -PIXI.PixiShader.prototype.constructor = PIXI.PixiShader; +PixiShader.prototype.constructor = PixiShader; +module.exports = PixiShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.PixiShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +PixiShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc || PixiShader.defaultVertexSrc, this.fragmentSrc); gl.useProgram(program); @@ -110,8 +95,7 @@ // maybe its something to do with the current state of the gl context. // I'm convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if(this.colorAttribute === -1) - { + if (this.colorAttribute === -1) { this.colorAttribute = 2; } @@ -120,8 +104,7 @@ // End worst hack eva // // add those custom shaders! - for (var key in this.uniforms) - { + for (var key in this.uniforms) { // get the uniform locations.. this.uniforms[key].uniformLocation = gl.getUniformLocation(program, key); } @@ -132,72 +115,58 @@ }; /** -* Initialises the shader uniform values. -* -* Uniforms are specified in the GLSL_ES Specification: http://www.khronos.org/registry/webgl/specs/latest/1.0/ -* http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf -* -* @method initUniforms -*/ -PIXI.PixiShader.prototype.initUniforms = function() -{ + * Initialises the shader uniform values. + * + * Uniforms are specified in the GLSL_ES Specification: http://www.khronos.org/registry/webgl/specs/latest/1.0/ + * http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf + * + */ +PixiShader.prototype.initUniforms = function () { this.textureCount = 1; var gl = this.gl; var uniform; - for (var key in this.uniforms) - { + for (var key in this.uniforms) { uniform = this.uniforms[key]; var type = uniform.type; - if (type === 'sampler2D') - { + if (type === 'sampler2D') { uniform._init = false; - if (uniform.value !== null) - { + if (uniform.value !== null) { this.initSampler2D(uniform); } } - else if (type === 'mat2' || type === 'mat3' || type === 'mat4') - { + else if (type === 'mat2' || type === 'mat3' || type === 'mat4') { // These require special handling uniform.glMatrix = true; uniform.glValueLength = 1; - if (type === 'mat2') - { + if (type === 'mat2') { uniform.glFunc = gl.uniformMatrix2fv; } - else if (type === 'mat3') - { + else if (type === 'mat3') { uniform.glFunc = gl.uniformMatrix3fv; } - else if (type === 'mat4') - { + else if (type === 'mat4') { uniform.glFunc = gl.uniformMatrix4fv; } } - else - { + else { // GL function reference uniform.glFunc = gl['uniform' + type]; - if (type === '2f' || type === '2i') - { + if (type === '2f' || type === '2i') { uniform.glValueLength = 2; } - else if (type === '3f' || type === '3i') - { + else if (type === '3f' || type === '3i') { uniform.glValueLength = 3; } - else if (type === '4f' || type === '4i') - { + else if (type === '4f' || type === '4i') { uniform.glValueLength = 4; } - else - { + else { uniform.glValueLength = 1; } } @@ -206,14 +175,11 @@ }; /** -* Initialises a Sampler2D uniform (which may only be available later on after initUniforms once the texture has loaded) -* -* @method initSampler2D -*/ -PIXI.PixiShader.prototype.initSampler2D = function(uniform) -{ - if (!uniform.value || !uniform.value.baseTexture || !uniform.value.baseTexture.hasLoaded) - { + * Initialises a Sampler2D uniform (which may only be available later on after initUniforms once the texture has loaded) + * + */ +PixiShader.prototype.initSampler2D = function (uniform) { + if (!uniform.value || !uniform.value.baseTexture || !uniform.value.baseTexture.hasLoaded) { return; } @@ -223,8 +189,7 @@ gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]); // Extended texture data - if (uniform.textureData) - { + if (uniform.textureData) { var data = uniform.textureData; // GLTexture = mag linear, min linear_mipmap_linear, wrap repeat + gl.generateMipmap(gl.TEXTURE_2D); @@ -243,16 +208,14 @@ var wrapT = (data.wrapT) ? data.wrapT : gl.CLAMP_TO_EDGE; var format = (data.luminance) ? gl.LUMINANCE : gl.RGBA; - if (data.repeat) - { + if (data.repeat) { wrapS = gl.REPEAT; wrapT = gl.REPEAT; } gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, !!data.flipY); - if (data.width) - { + if (data.width) { var width = (data.width) ? data.width : 512; var height = (data.height) ? data.height : 2; var border = (data.border) ? data.border : 0; @@ -260,8 +223,7 @@ // void texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ArrayBufferView? pixels); gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, border, format, gl.UNSIGNED_BYTE, null); } - else - { + else { // void texImage2D(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, ImageData? pixels); gl.texImage2D(gl.TEXTURE_2D, 0, format, gl.RGBA, gl.UNSIGNED_BYTE, uniform.value.baseTexture.source); } @@ -277,84 +239,66 @@ uniform._init = true; this.textureCount++; - }; /** -* Updates the shader uniform values. -* -* @method syncUniforms -*/ -PIXI.PixiShader.prototype.syncUniforms = function() -{ + * Updates the shader uniform values. + * + */ +PixiShader.prototype.syncUniforms = function () { this.textureCount = 1; var uniform; var gl = this.gl; // This would probably be faster in an array and it would guarantee key order - for (var key in this.uniforms) - { + for (var key in this.uniforms) { uniform = this.uniforms[key]; - if (uniform.glValueLength === 1) - { - if (uniform.glMatrix === true) - { + if (uniform.glValueLength === 1) { + if (uniform.glMatrix === true) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.transpose, uniform.value); } - else - { + else { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value); } } - else if (uniform.glValueLength === 2) - { + else if (uniform.glValueLength === 2) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y); } - else if (uniform.glValueLength === 3) - { + else if (uniform.glValueLength === 3) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z); } - else if (uniform.glValueLength === 4) - { + else if (uniform.glValueLength === 4) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z, uniform.value.w); } - else if (uniform.type === 'sampler2D') - { - if (uniform._init) - { + else if (uniform.type === 'sampler2D') { + if (uniform._init) { gl.activeTexture(gl['TEXTURE' + this.textureCount]); - if(uniform.value.baseTexture._dirty[gl.id]) - { - PIXI.instances[gl.id].updateTexture(uniform.value.baseTexture); + if (uniform.value.baseTexture._dirty[gl.id]) { + instances[gl.id].updateTexture(uniform.value.baseTexture); } - else - { + else { // bind the current texture gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]); } - // gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || PIXI.createWebGLTexture( uniform.value.baseTexture, gl)); + // gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || createWebGLTexture( uniform.value.baseTexture, gl)); gl.uniform1i(uniform.uniformLocation, this.textureCount); this.textureCount++; } - else - { + else { this.initSampler2D(uniform); } } } - }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.PixiShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +PixiShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; @@ -363,12 +307,12 @@ }; /** -* The Default Vertex shader source. -* -* @property defaultVertexSrc -* @type String -*/ -PIXI.PixiShader.defaultVertexSrc = [ + * The Default Vertex shader source. + * + * @property defaultVertexSrc + * @type String + */ +PixiShader.defaultVertexSrc = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', 'attribute vec4 aColor;', @@ -386,4 +330,4 @@ ' vTextureCoord = aTextureCoord;', ' vColor = vec4(aColor.rgb * aColor.a, aColor.a);', '}' -]; \ No newline at end of file +]; diff --git a/src/renderers/webgl/shaders/PrimitiveShader.js b/src/renderers/webgl/shaders/PrimitiveShader.js index bdaab89..ba73b04 100644 --- a/src/renderers/webgl/shaders/PrimitiveShader.js +++ b/src/renderers/webgl/shaders/PrimitiveShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class PrimitiveShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.PrimitiveShader = function(gl) -{ +function PrimitiveShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; - + this._UID = _UID++; + /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision mediump float;', @@ -45,8 +36,7 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ this.vertexSrc = [ 'attribute vec2 aVertexPosition;', @@ -68,20 +58,19 @@ ]; this.init(); -}; +} -PIXI.PrimitiveShader.prototype.constructor = PIXI.PrimitiveShader; +PrimitiveShader.prototype.constructor = PrimitiveShader; +module.exports = PrimitiveShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.PrimitiveShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +PrimitiveShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); gl.useProgram(program); // get and store the uniforms for the shader @@ -103,12 +92,10 @@ }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.PrimitiveShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +PrimitiveShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js index bbd3259..b83def8 100644 --- a/src/renderers/webgl/shaders/ComplexPrimitiveShader.js +++ b/src/renderers/webgl/shaders/ComplexPrimitiveShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class ComplexPrimitiveShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.ComplexPrimitiveShader = function(gl) -{ +function ComplexPrimitiveShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; + this._UID = _UID++; /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ @@ -47,16 +38,15 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ - this.vertexSrc = [ + this.vertexSrc = [ 'attribute vec2 aVertexPosition;', //'attribute vec4 aColor;', 'uniform mat3 translationMatrix;', 'uniform vec2 projectionVector;', 'uniform vec2 offsetVector;', - + 'uniform vec3 tint;', 'uniform float alpha;', 'uniform vec3 color;', @@ -72,20 +62,19 @@ ]; this.init(); -}; +} -PIXI.ComplexPrimitiveShader.prototype.constructor = PIXI.ComplexPrimitiveShader; +ComplexPrimitiveShader.prototype.constructor = ComplexPrimitiveShader; +module.exports = ComplexPrimitiveShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.ComplexPrimitiveShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +ComplexPrimitiveShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); gl.useProgram(program); // get and store the uniforms for the shader @@ -108,12 +97,10 @@ }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.ComplexPrimitiveShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +ComplexPrimitiveShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/PixiFastShader.js b/src/renderers/webgl/shaders/PixiFastShader.js index 8e685e7..b1d85c1 100644 --- a/src/renderers/webgl/shaders/PixiFastShader.js +++ b/src/renderers/webgl/shaders/PixiFastShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class PixiFastShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.PixiFastShader = function(gl) -{ +function PixiFastShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; - + this._UID = _UID++; + /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision lowp float;', @@ -46,8 +37,7 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ this.vertexSrc = [ 'attribute vec2 aVertexPosition;', @@ -81,27 +71,25 @@ /** * A local texture counter for multi-texture shaders. - * @property textureCount - * @type Number + * @member {number} */ this.textureCount = 0; - - this.init(); -}; -PIXI.PixiFastShader.prototype.constructor = PIXI.PixiFastShader; + this.init(); +} + +PixiFastShader.prototype.constructor = PixiFastShader; +module.exports = PixiFastShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.PixiFastShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +PixiFastShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); - + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); + gl.useProgram(program); // get and store the uniforms for the shader @@ -121,33 +109,30 @@ this.aTextureCoord = gl.getAttribLocation(program, 'aTextureCoord'); this.colorAttribute = gl.getAttribLocation(program, 'aColor'); - + // Begin worst hack eva // // WHY??? ONLY on my chrome pixel the line above returns -1 when using filters? // maybe its somthing to do with the current state of the gl context. // Im convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if(this.colorAttribute === -1) - { + if (this.colorAttribute === -1) { this.colorAttribute = 2; } this.attributes = [this.aVertexPosition, this.aPositionCoord, this.aScale, this.aRotation, this.aTextureCoord, this.colorAttribute]; - + // End worst hack eva // this.program = program; }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.PixiFastShader.prototype.destroy = function() -{ - this.gl.deleteProgram( this.program ); + * Destroys the shader. + * + */ +PixiFastShader.prototype.destroy = function () { + this.gl.deleteProgram(this.program); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/PixiShader.js b/src/renderers/webgl/shaders/PixiShader.js index e70be7f..60d956b 100644 --- a/src/renderers/webgl/shaders/PixiShader.js +++ b/src/renderers/webgl/shaders/PixiShader.js @@ -1,39 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 - * @author Richard Davey http://www.photonstorm.com @photonstorm + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class PixiShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.PixiShader = function(gl) -{ +function PixiShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; + this._UID = _UID++; /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision lowp float;', @@ -47,49 +37,44 @@ /** * A local texture counter for multi-texture shaders. - * @property textureCount - * @type Number + * @member {number} */ this.textureCount = 0; /** * A local flag - * @property firstRun - * @type Boolean + * @member {boolean} * @private */ this.firstRun = true; /** * A dirty flag - * @property dirty - * @type Boolean + * @member {boolean} */ this.dirty = true; /** * Uniform attributes cache. - * @property attributes - * @type Array + * @member {Array} * @private */ this.attributes = []; this.init(); -}; +} -PIXI.PixiShader.prototype.constructor = PIXI.PixiShader; +PixiShader.prototype.constructor = PixiShader; +module.exports = PixiShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.PixiShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +PixiShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc || PixiShader.defaultVertexSrc, this.fragmentSrc); gl.useProgram(program); @@ -110,8 +95,7 @@ // maybe its something to do with the current state of the gl context. // I'm convinced this is a bug in the chrome browser as there is NO reason why this should be returning -1 especially as it only manifests on my chrome pixel // If theres any webGL people that know why could happen please help :) - if(this.colorAttribute === -1) - { + if (this.colorAttribute === -1) { this.colorAttribute = 2; } @@ -120,8 +104,7 @@ // End worst hack eva // // add those custom shaders! - for (var key in this.uniforms) - { + for (var key in this.uniforms) { // get the uniform locations.. this.uniforms[key].uniformLocation = gl.getUniformLocation(program, key); } @@ -132,72 +115,58 @@ }; /** -* Initialises the shader uniform values. -* -* Uniforms are specified in the GLSL_ES Specification: http://www.khronos.org/registry/webgl/specs/latest/1.0/ -* http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf -* -* @method initUniforms -*/ -PIXI.PixiShader.prototype.initUniforms = function() -{ + * Initialises the shader uniform values. + * + * Uniforms are specified in the GLSL_ES Specification: http://www.khronos.org/registry/webgl/specs/latest/1.0/ + * http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf + * + */ +PixiShader.prototype.initUniforms = function () { this.textureCount = 1; var gl = this.gl; var uniform; - for (var key in this.uniforms) - { + for (var key in this.uniforms) { uniform = this.uniforms[key]; var type = uniform.type; - if (type === 'sampler2D') - { + if (type === 'sampler2D') { uniform._init = false; - if (uniform.value !== null) - { + if (uniform.value !== null) { this.initSampler2D(uniform); } } - else if (type === 'mat2' || type === 'mat3' || type === 'mat4') - { + else if (type === 'mat2' || type === 'mat3' || type === 'mat4') { // These require special handling uniform.glMatrix = true; uniform.glValueLength = 1; - if (type === 'mat2') - { + if (type === 'mat2') { uniform.glFunc = gl.uniformMatrix2fv; } - else if (type === 'mat3') - { + else if (type === 'mat3') { uniform.glFunc = gl.uniformMatrix3fv; } - else if (type === 'mat4') - { + else if (type === 'mat4') { uniform.glFunc = gl.uniformMatrix4fv; } } - else - { + else { // GL function reference uniform.glFunc = gl['uniform' + type]; - if (type === '2f' || type === '2i') - { + if (type === '2f' || type === '2i') { uniform.glValueLength = 2; } - else if (type === '3f' || type === '3i') - { + else if (type === '3f' || type === '3i') { uniform.glValueLength = 3; } - else if (type === '4f' || type === '4i') - { + else if (type === '4f' || type === '4i') { uniform.glValueLength = 4; } - else - { + else { uniform.glValueLength = 1; } } @@ -206,14 +175,11 @@ }; /** -* Initialises a Sampler2D uniform (which may only be available later on after initUniforms once the texture has loaded) -* -* @method initSampler2D -*/ -PIXI.PixiShader.prototype.initSampler2D = function(uniform) -{ - if (!uniform.value || !uniform.value.baseTexture || !uniform.value.baseTexture.hasLoaded) - { + * Initialises a Sampler2D uniform (which may only be available later on after initUniforms once the texture has loaded) + * + */ +PixiShader.prototype.initSampler2D = function (uniform) { + if (!uniform.value || !uniform.value.baseTexture || !uniform.value.baseTexture.hasLoaded) { return; } @@ -223,8 +189,7 @@ gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]); // Extended texture data - if (uniform.textureData) - { + if (uniform.textureData) { var data = uniform.textureData; // GLTexture = mag linear, min linear_mipmap_linear, wrap repeat + gl.generateMipmap(gl.TEXTURE_2D); @@ -243,16 +208,14 @@ var wrapT = (data.wrapT) ? data.wrapT : gl.CLAMP_TO_EDGE; var format = (data.luminance) ? gl.LUMINANCE : gl.RGBA; - if (data.repeat) - { + if (data.repeat) { wrapS = gl.REPEAT; wrapT = gl.REPEAT; } gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, !!data.flipY); - if (data.width) - { + if (data.width) { var width = (data.width) ? data.width : 512; var height = (data.height) ? data.height : 2; var border = (data.border) ? data.border : 0; @@ -260,8 +223,7 @@ // void texImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, ArrayBufferView? pixels); gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, border, format, gl.UNSIGNED_BYTE, null); } - else - { + else { // void texImage2D(GLenum target, GLint level, GLenum internalformat, GLenum format, GLenum type, ImageData? pixels); gl.texImage2D(gl.TEXTURE_2D, 0, format, gl.RGBA, gl.UNSIGNED_BYTE, uniform.value.baseTexture.source); } @@ -277,84 +239,66 @@ uniform._init = true; this.textureCount++; - }; /** -* Updates the shader uniform values. -* -* @method syncUniforms -*/ -PIXI.PixiShader.prototype.syncUniforms = function() -{ + * Updates the shader uniform values. + * + */ +PixiShader.prototype.syncUniforms = function () { this.textureCount = 1; var uniform; var gl = this.gl; // This would probably be faster in an array and it would guarantee key order - for (var key in this.uniforms) - { + for (var key in this.uniforms) { uniform = this.uniforms[key]; - if (uniform.glValueLength === 1) - { - if (uniform.glMatrix === true) - { + if (uniform.glValueLength === 1) { + if (uniform.glMatrix === true) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.transpose, uniform.value); } - else - { + else { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value); } } - else if (uniform.glValueLength === 2) - { + else if (uniform.glValueLength === 2) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y); } - else if (uniform.glValueLength === 3) - { + else if (uniform.glValueLength === 3) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z); } - else if (uniform.glValueLength === 4) - { + else if (uniform.glValueLength === 4) { uniform.glFunc.call(gl, uniform.uniformLocation, uniform.value.x, uniform.value.y, uniform.value.z, uniform.value.w); } - else if (uniform.type === 'sampler2D') - { - if (uniform._init) - { + else if (uniform.type === 'sampler2D') { + if (uniform._init) { gl.activeTexture(gl['TEXTURE' + this.textureCount]); - if(uniform.value.baseTexture._dirty[gl.id]) - { - PIXI.instances[gl.id].updateTexture(uniform.value.baseTexture); + if (uniform.value.baseTexture._dirty[gl.id]) { + instances[gl.id].updateTexture(uniform.value.baseTexture); } - else - { + else { // bind the current texture gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]); } - // gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || PIXI.createWebGLTexture( uniform.value.baseTexture, gl)); + // gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id] || createWebGLTexture( uniform.value.baseTexture, gl)); gl.uniform1i(uniform.uniformLocation, this.textureCount); this.textureCount++; } - else - { + else { this.initSampler2D(uniform); } } } - }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.PixiShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +PixiShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; @@ -363,12 +307,12 @@ }; /** -* The Default Vertex shader source. -* -* @property defaultVertexSrc -* @type String -*/ -PIXI.PixiShader.defaultVertexSrc = [ + * The Default Vertex shader source. + * + * @property defaultVertexSrc + * @type String + */ +PixiShader.defaultVertexSrc = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', 'attribute vec4 aColor;', @@ -386,4 +330,4 @@ ' vTextureCoord = aTextureCoord;', ' vColor = vec4(aColor.rgb * aColor.a, aColor.a);', '}' -]; \ No newline at end of file +]; diff --git a/src/renderers/webgl/shaders/PrimitiveShader.js b/src/renderers/webgl/shaders/PrimitiveShader.js index bdaab89..ba73b04 100644 --- a/src/renderers/webgl/shaders/PrimitiveShader.js +++ b/src/renderers/webgl/shaders/PrimitiveShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class PrimitiveShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.PrimitiveShader = function(gl) -{ +function PrimitiveShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; - + this._UID = _UID++; + /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision mediump float;', @@ -45,8 +36,7 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ this.vertexSrc = [ 'attribute vec2 aVertexPosition;', @@ -68,20 +58,19 @@ ]; this.init(); -}; +} -PIXI.PrimitiveShader.prototype.constructor = PIXI.PrimitiveShader; +PrimitiveShader.prototype.constructor = PrimitiveShader; +module.exports = PrimitiveShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.PrimitiveShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +PrimitiveShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); gl.useProgram(program); // get and store the uniforms for the shader @@ -103,12 +92,10 @@ }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.PrimitiveShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +PrimitiveShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null; diff --git a/src/renderers/webgl/shaders/StripShader.js b/src/renderers/webgl/shaders/StripShader.js index 6b47244..3f7a586 100644 --- a/src/renderers/webgl/shaders/StripShader.js +++ b/src/renderers/webgl/shaders/StripShader.js @@ -1,38 +1,29 @@ /** - * @author Mat Groves http://matgroves.com/ @Doormat23 + * @class + * @namespace PIXI + * @param gl {WebGLContext} the current WebGL drawing context */ - -/** -* @class StripShader -* @constructor -* @param gl {WebGLContext} the current WebGL drawing context -*/ -PIXI.StripShader = function(gl) -{ +function StripShader(gl) { /** - * @property _UID - * @type Number + * @member {number} * @private */ - this._UID = PIXI._UID++; - + this._UID = _UID++; + /** - * @property gl - * @type WebGLContext + * @member {WebGLContext} */ this.gl = gl; /** * The WebGL program. - * @property program - * @type Any + * @member {Any} */ this.program = null; /** * The fragment shader. - * @property fragmentSrc - * @type Array + * @member {Array} */ this.fragmentSrc = [ 'precision mediump float;', @@ -49,8 +40,7 @@ /** * The vertex shader. - * @property vertexSrc - * @type Array + * @member {Array} */ this.vertexSrc = [ 'attribute vec2 aVertexPosition;', @@ -73,20 +63,19 @@ ]; this.init(); -}; +} -PIXI.StripShader.prototype.constructor = PIXI.StripShader; +StripShader.prototype.constructor = StripShader; +module.exports = StripShader; /** -* Initialises the shader. -* -* @method init -*/ -PIXI.StripShader.prototype.init = function() -{ + * Initialises the shader. + * + */ +StripShader.prototype.init = function () { var gl = this.gl; - var program = PIXI.compileProgram(gl, this.vertexSrc, this.fragmentSrc); + var program = compileProgram(gl, this.vertexSrc, this.fragmentSrc); gl.useProgram(program); // get and store the uniforms for the shader @@ -109,12 +98,10 @@ }; /** -* Destroys the shader. -* -* @method destroy -*/ -PIXI.StripShader.prototype.destroy = function() -{ + * Destroys the shader. + * + */ +StripShader.prototype.destroy = function () { this.gl.deleteProgram( this.program ); this.uniforms = null; this.gl = null;