diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 755ea02..8ba7d88 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,6 @@ var extractUniformsFromSrc = require('./extractUniformsFromSrc'), utils = require('../../../utils'), + Const = require('../../../const'), SOURCE_KEY_MAP = {}; // var math = require('../../../math'); @@ -28,6 +29,10 @@ */ this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; + this.vertexSrc = this.vertexSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + + this.fragmentSrc = this.fragmentSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 755ea02..8ba7d88 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,6 @@ var extractUniformsFromSrc = require('./extractUniformsFromSrc'), utils = require('../../../utils'), + Const = require('../../../const'), SOURCE_KEY_MAP = {}; // var math = require('../../../math'); @@ -28,6 +29,10 @@ */ this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; + this.vertexSrc = this.vertexSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + + this.fragmentSrc = this.fragmentSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); diff --git a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag index 690dab0..951f03f 100644 --- a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag +++ b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vMaskCoord; varying vec2 vTextureCoord; diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 755ea02..8ba7d88 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,6 @@ var extractUniformsFromSrc = require('./extractUniformsFromSrc'), utils = require('../../../utils'), + Const = require('../../../const'), SOURCE_KEY_MAP = {}; // var math = require('../../../math'); @@ -28,6 +29,10 @@ */ this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; + this.vertexSrc = this.vertexSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + + this.fragmentSrc = this.fragmentSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); diff --git a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag index 690dab0..951f03f 100644 --- a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag +++ b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vMaskCoord; varying vec2 vTextureCoord; diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index 062cc0b..c77cb50 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -26,7 +26,7 @@ while(true) { - var fragmentSrc = fragTemplate.replace(/\%forloop\%/gi, generateIfTestSrc(maxIfs)); + var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs)); gl.shaderSource(shader, fragmentSrc); gl.compileShader(shader); diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 755ea02..8ba7d88 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,6 @@ var extractUniformsFromSrc = require('./extractUniformsFromSrc'), utils = require('../../../utils'), + Const = require('../../../const'), SOURCE_KEY_MAP = {}; // var math = require('../../../math'); @@ -28,6 +29,10 @@ */ this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; + this.vertexSrc = this.vertexSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + + this.fragmentSrc = this.fragmentSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); diff --git a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag index 690dab0..951f03f 100644 --- a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag +++ b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vMaskCoord; varying vec2 vTextureCoord; diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index 062cc0b..c77cb50 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -26,7 +26,7 @@ while(true) { - var fragmentSrc = fragTemplate.replace(/\%forloop\%/gi, generateIfTestSrc(maxIfs)); + var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs)); gl.shaderSource(shader, fragmentSrc); gl.compileShader(shader); diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index e749168..1ac5853 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,8 +1,9 @@ var Shader = require('pixi-gl-core').GLShader; var glslify = require('glslify'); +var Const = require('../../const'); var fragTemplate = [ - 'precision lowp float;', + 'precision %PRECISION% float;', 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -17,11 +18,11 @@ function generateMultiTextureShader(gl, maxTextures) { - var vertexSrc = glslify('./texture.vert'); - var fragmentSrc = fragTemplate; + var vertexSrc = glslify('./texture.vert').replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + var fragmentSrc = fragTemplate.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); - fragmentSrc = fragmentSrc.replace(/\%count\%/gi, maxTextures); - fragmentSrc = fragmentSrc.replace(/\%forloop\%/gi, generateSampleSrc(maxTextures)); + fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); + fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures)); var shader = new Shader(gl, vertexSrc, fragmentSrc); diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 755ea02..8ba7d88 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,6 @@ var extractUniformsFromSrc = require('./extractUniformsFromSrc'), utils = require('../../../utils'), + Const = require('../../../const'), SOURCE_KEY_MAP = {}; // var math = require('../../../math'); @@ -28,6 +29,10 @@ */ this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; + this.vertexSrc = this.vertexSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + + this.fragmentSrc = this.fragmentSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); diff --git a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag index 690dab0..951f03f 100644 --- a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag +++ b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vMaskCoord; varying vec2 vTextureCoord; diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index 062cc0b..c77cb50 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -26,7 +26,7 @@ while(true) { - var fragmentSrc = fragTemplate.replace(/\%forloop\%/gi, generateIfTestSrc(maxIfs)); + var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs)); gl.shaderSource(shader, fragmentSrc); gl.compileShader(shader); diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index e749168..1ac5853 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,8 +1,9 @@ var Shader = require('pixi-gl-core').GLShader; var glslify = require('glslify'); +var Const = require('../../const'); var fragTemplate = [ - 'precision lowp float;', + 'precision %PRECISION% float;', 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -17,11 +18,11 @@ function generateMultiTextureShader(gl, maxTextures) { - var vertexSrc = glslify('./texture.vert'); - var fragmentSrc = fragTemplate; + var vertexSrc = glslify('./texture.vert').replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + var fragmentSrc = fragTemplate.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); - fragmentSrc = fragmentSrc.replace(/\%count\%/gi, maxTextures); - fragmentSrc = fragmentSrc.replace(/\%forloop\%/gi, generateSampleSrc(maxTextures)); + fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); + fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures)); var shader = new Shader(gl, vertexSrc, fragmentSrc); diff --git a/src/core/sprites/webgl/texture.vert b/src/core/sprites/webgl/texture.vert index 87a6199..56cf3d8 100644 --- a/src/core/sprites/webgl/texture.vert +++ b/src/core/sprites/webgl/texture.vert @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; attribute vec4 aColor; @@ -15,4 +15,4 @@ vTextureCoord = aTextureCoord; vTextureId = aTextureId; vColor = vec4(aColor.rgb * aColor.a, aColor.a); -} \ No newline at end of file +} diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 755ea02..8ba7d88 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,6 @@ var extractUniformsFromSrc = require('./extractUniformsFromSrc'), utils = require('../../../utils'), + Const = require('../../../const'), SOURCE_KEY_MAP = {}; // var math = require('../../../math'); @@ -28,6 +29,10 @@ */ this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; + this.vertexSrc = this.vertexSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + + this.fragmentSrc = this.fragmentSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); diff --git a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag index 690dab0..951f03f 100644 --- a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag +++ b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vMaskCoord; varying vec2 vTextureCoord; diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index 062cc0b..c77cb50 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -26,7 +26,7 @@ while(true) { - var fragmentSrc = fragTemplate.replace(/\%forloop\%/gi, generateIfTestSrc(maxIfs)); + var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs)); gl.shaderSource(shader, fragmentSrc); gl.compileShader(shader); diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index e749168..1ac5853 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,8 +1,9 @@ var Shader = require('pixi-gl-core').GLShader; var glslify = require('glslify'); +var Const = require('../../const'); var fragTemplate = [ - 'precision lowp float;', + 'precision %PRECISION% float;', 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -17,11 +18,11 @@ function generateMultiTextureShader(gl, maxTextures) { - var vertexSrc = glslify('./texture.vert'); - var fragmentSrc = fragTemplate; + var vertexSrc = glslify('./texture.vert').replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + var fragmentSrc = fragTemplate.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); - fragmentSrc = fragmentSrc.replace(/\%count\%/gi, maxTextures); - fragmentSrc = fragmentSrc.replace(/\%forloop\%/gi, generateSampleSrc(maxTextures)); + fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); + fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures)); var shader = new Shader(gl, vertexSrc, fragmentSrc); diff --git a/src/core/sprites/webgl/texture.vert b/src/core/sprites/webgl/texture.vert index 87a6199..56cf3d8 100644 --- a/src/core/sprites/webgl/texture.vert +++ b/src/core/sprites/webgl/texture.vert @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; attribute vec4 aColor; @@ -15,4 +15,4 @@ vTextureCoord = aTextureCoord; vTextureId = aTextureId; vColor = vec4(aColor.rgb * aColor.a, aColor.a); -} \ No newline at end of file +} diff --git a/src/extras/webgl/tilingSprite.frag b/src/extras/webgl/tilingSprite.frag index 21d8ee6..5da42e1 100644 --- a/src/extras/webgl/tilingSprite.frag +++ b/src/extras/webgl/tilingSprite.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vTextureCoord; varying vec4 vColor; @@ -15,4 +15,4 @@ coord += uFrame.xy; gl_FragColor = texture2D(uSampler, coord) ; -} \ No newline at end of file +} diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 755ea02..8ba7d88 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,6 @@ var extractUniformsFromSrc = require('./extractUniformsFromSrc'), utils = require('../../../utils'), + Const = require('../../../const'), SOURCE_KEY_MAP = {}; // var math = require('../../../math'); @@ -28,6 +29,10 @@ */ this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; + this.vertexSrc = this.vertexSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + + this.fragmentSrc = this.fragmentSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); diff --git a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag index 690dab0..951f03f 100644 --- a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag +++ b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vMaskCoord; varying vec2 vTextureCoord; diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index 062cc0b..c77cb50 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -26,7 +26,7 @@ while(true) { - var fragmentSrc = fragTemplate.replace(/\%forloop\%/gi, generateIfTestSrc(maxIfs)); + var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs)); gl.shaderSource(shader, fragmentSrc); gl.compileShader(shader); diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index e749168..1ac5853 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,8 +1,9 @@ var Shader = require('pixi-gl-core').GLShader; var glslify = require('glslify'); +var Const = require('../../const'); var fragTemplate = [ - 'precision lowp float;', + 'precision %PRECISION% float;', 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -17,11 +18,11 @@ function generateMultiTextureShader(gl, maxTextures) { - var vertexSrc = glslify('./texture.vert'); - var fragmentSrc = fragTemplate; + var vertexSrc = glslify('./texture.vert').replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + var fragmentSrc = fragTemplate.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); - fragmentSrc = fragmentSrc.replace(/\%count\%/gi, maxTextures); - fragmentSrc = fragmentSrc.replace(/\%forloop\%/gi, generateSampleSrc(maxTextures)); + fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); + fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures)); var shader = new Shader(gl, vertexSrc, fragmentSrc); diff --git a/src/core/sprites/webgl/texture.vert b/src/core/sprites/webgl/texture.vert index 87a6199..56cf3d8 100644 --- a/src/core/sprites/webgl/texture.vert +++ b/src/core/sprites/webgl/texture.vert @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; attribute vec4 aColor; @@ -15,4 +15,4 @@ vTextureCoord = aTextureCoord; vTextureId = aTextureId; vColor = vec4(aColor.rgb * aColor.a, aColor.a); -} \ No newline at end of file +} diff --git a/src/extras/webgl/tilingSprite.frag b/src/extras/webgl/tilingSprite.frag index 21d8ee6..5da42e1 100644 --- a/src/extras/webgl/tilingSprite.frag +++ b/src/extras/webgl/tilingSprite.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vTextureCoord; varying vec4 vColor; @@ -15,4 +15,4 @@ coord += uFrame.xy; gl_FragColor = texture2D(uSampler, coord) ; -} \ No newline at end of file +} diff --git a/src/extras/webgl/tilingSprite.vert b/src/extras/webgl/tilingSprite.vert index 3f989ea..571f1f7 100644 --- a/src/extras/webgl/tilingSprite.vert +++ b/src/extras/webgl/tilingSprite.vert @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; @@ -16,11 +16,11 @@ void main(void) { gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); - + vec2 coord = aTextureCoord; coord -= uTransform.xy; coord /= uTransform.zw; vTextureCoord = coord; - + vColor = vec4(aColor.rgb * aColor.a, aColor.a); -} \ No newline at end of file +} diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 755ea02..8ba7d88 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,6 @@ var extractUniformsFromSrc = require('./extractUniformsFromSrc'), utils = require('../../../utils'), + Const = require('../../../const'), SOURCE_KEY_MAP = {}; // var math = require('../../../math'); @@ -28,6 +29,10 @@ */ this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; + this.vertexSrc = this.vertexSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + + this.fragmentSrc = this.fragmentSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); diff --git a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag index 690dab0..951f03f 100644 --- a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag +++ b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vMaskCoord; varying vec2 vTextureCoord; diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index 062cc0b..c77cb50 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -26,7 +26,7 @@ while(true) { - var fragmentSrc = fragTemplate.replace(/\%forloop\%/gi, generateIfTestSrc(maxIfs)); + var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs)); gl.shaderSource(shader, fragmentSrc); gl.compileShader(shader); diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index e749168..1ac5853 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,8 +1,9 @@ var Shader = require('pixi-gl-core').GLShader; var glslify = require('glslify'); +var Const = require('../../const'); var fragTemplate = [ - 'precision lowp float;', + 'precision %PRECISION% float;', 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -17,11 +18,11 @@ function generateMultiTextureShader(gl, maxTextures) { - var vertexSrc = glslify('./texture.vert'); - var fragmentSrc = fragTemplate; + var vertexSrc = glslify('./texture.vert').replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + var fragmentSrc = fragTemplate.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); - fragmentSrc = fragmentSrc.replace(/\%count\%/gi, maxTextures); - fragmentSrc = fragmentSrc.replace(/\%forloop\%/gi, generateSampleSrc(maxTextures)); + fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); + fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures)); var shader = new Shader(gl, vertexSrc, fragmentSrc); diff --git a/src/core/sprites/webgl/texture.vert b/src/core/sprites/webgl/texture.vert index 87a6199..56cf3d8 100644 --- a/src/core/sprites/webgl/texture.vert +++ b/src/core/sprites/webgl/texture.vert @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; attribute vec4 aColor; @@ -15,4 +15,4 @@ vTextureCoord = aTextureCoord; vTextureId = aTextureId; vColor = vec4(aColor.rgb * aColor.a, aColor.a); -} \ No newline at end of file +} diff --git a/src/extras/webgl/tilingSprite.frag b/src/extras/webgl/tilingSprite.frag index 21d8ee6..5da42e1 100644 --- a/src/extras/webgl/tilingSprite.frag +++ b/src/extras/webgl/tilingSprite.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vTextureCoord; varying vec4 vColor; @@ -15,4 +15,4 @@ coord += uFrame.xy; gl_FragColor = texture2D(uSampler, coord) ; -} \ No newline at end of file +} diff --git a/src/extras/webgl/tilingSprite.vert b/src/extras/webgl/tilingSprite.vert index 3f989ea..571f1f7 100644 --- a/src/extras/webgl/tilingSprite.vert +++ b/src/extras/webgl/tilingSprite.vert @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; @@ -16,11 +16,11 @@ void main(void) { gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); - + vec2 coord = aTextureCoord; coord -= uTransform.xy; coord /= uTransform.zw; vTextureCoord = coord; - + vColor = vec4(aColor.rgb * aColor.a, aColor.a); -} \ No newline at end of file +} diff --git a/src/filters/FXAA/FXAA.frag b/src/filters/FXAA/FXAA.frag index 2f3b3ae..4dd287d 100755 --- a/src/filters/FXAA/FXAA.frag +++ b/src/filters/FXAA/FXAA.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; /** diff --git a/src/core/const.js b/src/core/const.js index 470852b..198f528 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -16,7 +16,7 @@ /** * Two Pi. - * + * * @property {number} PI_2 * @constant * @static @@ -25,7 +25,7 @@ /** * Conversion factor for converting radians to degrees. - * + * * @property {number} RAD_TO_DEG * @constant * @static @@ -34,7 +34,7 @@ /** * Conversion factor for converting degrees to radians. - * + * * @property {number} DEG_TO_RAD * @constant * @static @@ -68,7 +68,7 @@ /** * Various blend modes supported by PIXI. - * + * * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. * Anything else will silently act like NORMAL. * @@ -164,7 +164,7 @@ * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. * This property only affects WebGL. - * + * * @static * @constant * @property {object} WRAP_MODES @@ -190,7 +190,7 @@ * This property only affects WebGL * Handy for mobile devices! * This property only affects WebGL. - * + * * @static * @constant * @property {object} GC_MODES @@ -207,7 +207,7 @@ /** * If set to true WebGL will attempt make textures mimpaped by default. * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. - * + * * @static * @constant * @property {bool} MIPMAP_TEXTURES @@ -226,7 +226,7 @@ /** * Default resolution of the renderer. - * + * * @property {number} RESOLUTION * @constant * @static @@ -235,7 +235,7 @@ /** * Default filter resolution. - * + * * @property {number} FILTER_RESOLUTION * @constant * @static @@ -293,11 +293,29 @@ RREC: 4 }, + /** + * Constants that specify float precision in shaders. + * + * @static + * @constant + * @property {object} PRECISION + * @property {number} PRECISION.DEFAULT='mediump' + * @property {number} PRECISION.LOW='lowp' + * @property {number} PRECISION.MEDIUM='mediump' + * @property {number} PRECISION.HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. - TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed + TEXT_STYLE_CHANGED: 'changed' //Name of the event that fires when a text style is changed }; module.exports = CONST; diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 755ea02..8ba7d88 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,6 @@ var extractUniformsFromSrc = require('./extractUniformsFromSrc'), utils = require('../../../utils'), + Const = require('../../../const'), SOURCE_KEY_MAP = {}; // var math = require('../../../math'); @@ -28,6 +29,10 @@ */ this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; + this.vertexSrc = this.vertexSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + + this.fragmentSrc = this.fragmentSrc.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); diff --git a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag index 690dab0..951f03f 100644 --- a/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag +++ b/src/core/renderers/webgl/filters/spriteMask/spriteMaskFilter.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vMaskCoord; varying vec2 vTextureCoord; diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index 062cc0b..c77cb50 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -26,7 +26,7 @@ while(true) { - var fragmentSrc = fragTemplate.replace(/\%forloop\%/gi, generateIfTestSrc(maxIfs)); + var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs)); gl.shaderSource(shader, fragmentSrc); gl.compileShader(shader); diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index e749168..1ac5853 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,8 +1,9 @@ var Shader = require('pixi-gl-core').GLShader; var glslify = require('glslify'); +var Const = require('../../const'); var fragTemplate = [ - 'precision lowp float;', + 'precision %PRECISION% float;', 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -17,11 +18,11 @@ function generateMultiTextureShader(gl, maxTextures) { - var vertexSrc = glslify('./texture.vert'); - var fragmentSrc = fragTemplate; + var vertexSrc = glslify('./texture.vert').replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); + var fragmentSrc = fragTemplate.replace(/%PRECISION%/gi, Const.PRECISION.DEFAULT); - fragmentSrc = fragmentSrc.replace(/\%count\%/gi, maxTextures); - fragmentSrc = fragmentSrc.replace(/\%forloop\%/gi, generateSampleSrc(maxTextures)); + fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); + fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures)); var shader = new Shader(gl, vertexSrc, fragmentSrc); diff --git a/src/core/sprites/webgl/texture.vert b/src/core/sprites/webgl/texture.vert index 87a6199..56cf3d8 100644 --- a/src/core/sprites/webgl/texture.vert +++ b/src/core/sprites/webgl/texture.vert @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; attribute vec4 aColor; @@ -15,4 +15,4 @@ vTextureCoord = aTextureCoord; vTextureId = aTextureId; vColor = vec4(aColor.rgb * aColor.a, aColor.a); -} \ No newline at end of file +} diff --git a/src/extras/webgl/tilingSprite.frag b/src/extras/webgl/tilingSprite.frag index 21d8ee6..5da42e1 100644 --- a/src/extras/webgl/tilingSprite.frag +++ b/src/extras/webgl/tilingSprite.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; varying vec2 vTextureCoord; varying vec4 vColor; @@ -15,4 +15,4 @@ coord += uFrame.xy; gl_FragColor = texture2D(uSampler, coord) ; -} \ No newline at end of file +} diff --git a/src/extras/webgl/tilingSprite.vert b/src/extras/webgl/tilingSprite.vert index 3f989ea..571f1f7 100644 --- a/src/extras/webgl/tilingSprite.vert +++ b/src/extras/webgl/tilingSprite.vert @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; @@ -16,11 +16,11 @@ void main(void) { gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); - + vec2 coord = aTextureCoord; coord -= uTransform.xy; coord /= uTransform.zw; vTextureCoord = coord; - + vColor = vec4(aColor.rgb * aColor.a, aColor.a); -} \ No newline at end of file +} diff --git a/src/filters/FXAA/FXAA.frag b/src/filters/FXAA/FXAA.frag index 2f3b3ae..4dd287d 100755 --- a/src/filters/FXAA/FXAA.frag +++ b/src/filters/FXAA/FXAA.frag @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; /** diff --git a/src/filters/gray/gray.vert b/src/filters/gray/gray.vert index e79970e..3df85a3 100644 --- a/src/filters/gray/gray.vert +++ b/src/filters/gray/gray.vert @@ -1,4 +1,4 @@ -precision lowp float; +precision %PRECISION% float; attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; @@ -9,4 +9,4 @@ void main(void){ gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); vTextureCoord = aTextureCoord; -} \ No newline at end of file +}