diff --git a/package.json b/package.json index 2466363..829456f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.5.0", + "version": "5.0.0", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ diff --git a/package.json b/package.json index 2466363..829456f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.5.0", + "version": "5.0.0", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a41e1e5..43c8c79 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -93,8 +93,8 @@ this._backgroundColorRgba[3] = this.transparent ? 0 : 1; this.globalUniforms = new UniformGroup({ - projectionMatrix:new Matrix() - }, false) + projectionMatrix:new Matrix(), + }, true) this.addSystem(MaskSystem, 'mask') .addSystem(ContextSystem, 'context') diff --git a/package.json b/package.json index 2466363..829456f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.5.0", + "version": "5.0.0", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a41e1e5..43c8c79 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -93,8 +93,8 @@ this._backgroundColorRgba[3] = this.transparent ? 0 : 1; this.globalUniforms = new UniformGroup({ - projectionMatrix:new Matrix() - }, false) + projectionMatrix:new Matrix(), + }, true) this.addSystem(MaskSystem, 'mask') .addSystem(ContextSystem, 'context') diff --git a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js index b07837f..b76082e 100644 --- a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js +++ b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js @@ -43,13 +43,12 @@ * @private * @param {PIXI.mesh.Geometry} geometry instance of geometry to bind */ - bind(geometry, glShader) + bind(geometry, shader) { - glShader = glShader || this.renderer.shader.getGLShader(); + shader = shader || this.renderer.shader.shader; const gl = this.gl; - // not sure the best way to address this.. // currently different shaders require different VAOs for the same geometry // Still mulling over the best way to solve this one.. @@ -61,7 +60,7 @@ vaos = geometry.glVertexArrayObjects[this.CONTEXT_UID] = {}; } - const vao = vaos[glShader.id] || this.initGeometryVao(geometry, glShader); + const vao = vaos[shader.program.id] || this.initGeometryVao(geometry, shader.program); this._activeGeometry = geometry; @@ -114,11 +113,11 @@ } } - checkCompatability(geometry, glShader) + checkCompatability(geometry, program) { // geometry must have at least all the attributes that the shader requires. const geometryAttributes = geometry.attributes; - const shaderAttributes = glShader.attributes; + const shaderAttributes = program.attributeData; for (const j in shaderAttributes) { @@ -135,9 +134,9 @@ * @param {PIXI.mesh.Geometry} geometry instance of geometry to to generate Vao for * @return {PIXI.VertexArrayObject} Returns a fresh vao. */ - initGeometryVao(geometry, glShader) + initGeometryVao(geometry, program) { - this.checkCompatability(geometry, glShader); + this.checkCompatability(geometry, program); const gl = this.gl; const CONTEXT_UID = this.CONTEXT_UID; @@ -166,9 +165,9 @@ for (const j in attributes) { - if(!attributes[j].size && glShader.attributes[j]) + if(!attributes[j].size && program.attributeData[j]) { - attributes[j].size = glShader.attributes[j].size; + attributes[j].size = program.attributeData[j].size; } tempStride[attributes[j].buffer] += attributes[j].size * byteSizeMap[attributes[j].type]; @@ -221,7 +220,7 @@ const buffer = buffers[attribute.buffer]; const glBuffer = buffer._glBuffers[CONTEXT_UID]; - if(glShader.attributes[j]) + if(program.attributeData[j]) { if(lastBuffer !== glBuffer) { @@ -230,7 +229,7 @@ lastBuffer = glBuffer; } - const location = glShader.attributes[j].location; + const location = program.attributeData[j].location; gl.enableVertexAttribArray(location); @@ -250,7 +249,7 @@ // TODO - maybe make this a data object? // lets wait to see if we need to first! - geometry.glVertexArrayObjects[CONTEXT_UID][glShader.id] = vao; + geometry.glVertexArrayObjects[CONTEXT_UID][program.id] = vao; gl.bindVertexArray(null); diff --git a/package.json b/package.json index 2466363..829456f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.5.0", + "version": "5.0.0", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a41e1e5..43c8c79 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -93,8 +93,8 @@ this._backgroundColorRgba[3] = this.transparent ? 0 : 1; this.globalUniforms = new UniformGroup({ - projectionMatrix:new Matrix() - }, false) + projectionMatrix:new Matrix(), + }, true) this.addSystem(MaskSystem, 'mask') .addSystem(ContextSystem, 'context') diff --git a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js index b07837f..b76082e 100644 --- a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js +++ b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js @@ -43,13 +43,12 @@ * @private * @param {PIXI.mesh.Geometry} geometry instance of geometry to bind */ - bind(geometry, glShader) + bind(geometry, shader) { - glShader = glShader || this.renderer.shader.getGLShader(); + shader = shader || this.renderer.shader.shader; const gl = this.gl; - // not sure the best way to address this.. // currently different shaders require different VAOs for the same geometry // Still mulling over the best way to solve this one.. @@ -61,7 +60,7 @@ vaos = geometry.glVertexArrayObjects[this.CONTEXT_UID] = {}; } - const vao = vaos[glShader.id] || this.initGeometryVao(geometry, glShader); + const vao = vaos[shader.program.id] || this.initGeometryVao(geometry, shader.program); this._activeGeometry = geometry; @@ -114,11 +113,11 @@ } } - checkCompatability(geometry, glShader) + checkCompatability(geometry, program) { // geometry must have at least all the attributes that the shader requires. const geometryAttributes = geometry.attributes; - const shaderAttributes = glShader.attributes; + const shaderAttributes = program.attributeData; for (const j in shaderAttributes) { @@ -135,9 +134,9 @@ * @param {PIXI.mesh.Geometry} geometry instance of geometry to to generate Vao for * @return {PIXI.VertexArrayObject} Returns a fresh vao. */ - initGeometryVao(geometry, glShader) + initGeometryVao(geometry, program) { - this.checkCompatability(geometry, glShader); + this.checkCompatability(geometry, program); const gl = this.gl; const CONTEXT_UID = this.CONTEXT_UID; @@ -166,9 +165,9 @@ for (const j in attributes) { - if(!attributes[j].size && glShader.attributes[j]) + if(!attributes[j].size && program.attributeData[j]) { - attributes[j].size = glShader.attributes[j].size; + attributes[j].size = program.attributeData[j].size; } tempStride[attributes[j].buffer] += attributes[j].size * byteSizeMap[attributes[j].type]; @@ -221,7 +220,7 @@ const buffer = buffers[attribute.buffer]; const glBuffer = buffer._glBuffers[CONTEXT_UID]; - if(glShader.attributes[j]) + if(program.attributeData[j]) { if(lastBuffer !== glBuffer) { @@ -230,7 +229,7 @@ lastBuffer = glBuffer; } - const location = glShader.attributes[j].location; + const location = program.attributeData[j].location; gl.enableVertexAttribArray(location); @@ -250,7 +249,7 @@ // TODO - maybe make this a data object? // lets wait to see if we need to first! - geometry.glVertexArrayObjects[CONTEXT_UID][glShader.id] = vao; + geometry.glVertexArrayObjects[CONTEXT_UID][program.id] = vao; gl.bindVertexArray(null); diff --git a/src/core/renderers/webgl/systems/shader/ShaderSystem.js b/src/core/renderers/webgl/systems/shader/ShaderSystem.js index 4c39c7e..0ee6743 100644 --- a/src/core/renderers/webgl/systems/shader/ShaderSystem.js +++ b/src/core/renderers/webgl/systems/shader/ShaderSystem.js @@ -47,12 +47,13 @@ */ bind(shader, dontSync) { + // maybe a better place for this... + shader.uniforms.globals = this.renderer.globalUniforms; + const program = shader.program; const glShader = program.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); // TODO - some current pixi plugins bypass this.. so it not safe to use yet.. - // if (this.shader !== shader) - // { if (this.shader !== shader) { this.shader = shader; @@ -87,19 +88,20 @@ if(!group.static || group.dirtyId !== glShader.uniformGroups[group.id]) { glShader.uniformGroups[group.id] = group.dirtyId; - const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSynGroups(group); + const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSyncGroups(group); syncFunc(glShader.uniformData, group.uniforms, this.renderer); } } - createSynGroups(group) + createSyncGroups(group) { group.syncUniforms[this.shader.program.id] = generateUniformsSync(group, this.shader.program.uniformData); return group.syncUniforms[this.shader.program.id]; } + /** * Returns the underlying GLShade rof the currently bound shader. * This can be handy for when you to have a little more control over the setting of your uniforms. @@ -130,6 +132,8 @@ const program = shader.program; const attribMap = {}; + // insert the global properties too! + for (const i in program.attributeData) { attribMap[i] = program.attributeData[i].location; diff --git a/package.json b/package.json index 2466363..829456f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.5.0", + "version": "5.0.0", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a41e1e5..43c8c79 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -93,8 +93,8 @@ this._backgroundColorRgba[3] = this.transparent ? 0 : 1; this.globalUniforms = new UniformGroup({ - projectionMatrix:new Matrix() - }, false) + projectionMatrix:new Matrix(), + }, true) this.addSystem(MaskSystem, 'mask') .addSystem(ContextSystem, 'context') diff --git a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js index b07837f..b76082e 100644 --- a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js +++ b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js @@ -43,13 +43,12 @@ * @private * @param {PIXI.mesh.Geometry} geometry instance of geometry to bind */ - bind(geometry, glShader) + bind(geometry, shader) { - glShader = glShader || this.renderer.shader.getGLShader(); + shader = shader || this.renderer.shader.shader; const gl = this.gl; - // not sure the best way to address this.. // currently different shaders require different VAOs for the same geometry // Still mulling over the best way to solve this one.. @@ -61,7 +60,7 @@ vaos = geometry.glVertexArrayObjects[this.CONTEXT_UID] = {}; } - const vao = vaos[glShader.id] || this.initGeometryVao(geometry, glShader); + const vao = vaos[shader.program.id] || this.initGeometryVao(geometry, shader.program); this._activeGeometry = geometry; @@ -114,11 +113,11 @@ } } - checkCompatability(geometry, glShader) + checkCompatability(geometry, program) { // geometry must have at least all the attributes that the shader requires. const geometryAttributes = geometry.attributes; - const shaderAttributes = glShader.attributes; + const shaderAttributes = program.attributeData; for (const j in shaderAttributes) { @@ -135,9 +134,9 @@ * @param {PIXI.mesh.Geometry} geometry instance of geometry to to generate Vao for * @return {PIXI.VertexArrayObject} Returns a fresh vao. */ - initGeometryVao(geometry, glShader) + initGeometryVao(geometry, program) { - this.checkCompatability(geometry, glShader); + this.checkCompatability(geometry, program); const gl = this.gl; const CONTEXT_UID = this.CONTEXT_UID; @@ -166,9 +165,9 @@ for (const j in attributes) { - if(!attributes[j].size && glShader.attributes[j]) + if(!attributes[j].size && program.attributeData[j]) { - attributes[j].size = glShader.attributes[j].size; + attributes[j].size = program.attributeData[j].size; } tempStride[attributes[j].buffer] += attributes[j].size * byteSizeMap[attributes[j].type]; @@ -221,7 +220,7 @@ const buffer = buffers[attribute.buffer]; const glBuffer = buffer._glBuffers[CONTEXT_UID]; - if(glShader.attributes[j]) + if(program.attributeData[j]) { if(lastBuffer !== glBuffer) { @@ -230,7 +229,7 @@ lastBuffer = glBuffer; } - const location = glShader.attributes[j].location; + const location = program.attributeData[j].location; gl.enableVertexAttribArray(location); @@ -250,7 +249,7 @@ // TODO - maybe make this a data object? // lets wait to see if we need to first! - geometry.glVertexArrayObjects[CONTEXT_UID][glShader.id] = vao; + geometry.glVertexArrayObjects[CONTEXT_UID][program.id] = vao; gl.bindVertexArray(null); diff --git a/src/core/renderers/webgl/systems/shader/ShaderSystem.js b/src/core/renderers/webgl/systems/shader/ShaderSystem.js index 4c39c7e..0ee6743 100644 --- a/src/core/renderers/webgl/systems/shader/ShaderSystem.js +++ b/src/core/renderers/webgl/systems/shader/ShaderSystem.js @@ -47,12 +47,13 @@ */ bind(shader, dontSync) { + // maybe a better place for this... + shader.uniforms.globals = this.renderer.globalUniforms; + const program = shader.program; const glShader = program.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); // TODO - some current pixi plugins bypass this.. so it not safe to use yet.. - // if (this.shader !== shader) - // { if (this.shader !== shader) { this.shader = shader; @@ -87,19 +88,20 @@ if(!group.static || group.dirtyId !== glShader.uniformGroups[group.id]) { glShader.uniformGroups[group.id] = group.dirtyId; - const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSynGroups(group); + const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSyncGroups(group); syncFunc(glShader.uniformData, group.uniforms, this.renderer); } } - createSynGroups(group) + createSyncGroups(group) { group.syncUniforms[this.shader.program.id] = generateUniformsSync(group, this.shader.program.uniformData); return group.syncUniforms[this.shader.program.id]; } + /** * Returns the underlying GLShade rof the currently bound shader. * This can be handy for when you to have a little more control over the setting of your uniforms. @@ -130,6 +132,8 @@ const program = shader.program; const attribMap = {}; + // insert the global properties too! + for (const i in program.attributeData) { attribMap[i] = program.attributeData[i].location; diff --git a/src/core/settings.js b/src/core/settings.js index 38ef45c..bb636aa 100644 --- a/src/core/settings.js +++ b/src/core/settings.js @@ -137,7 +137,7 @@ * @type {PIXI.TRANSFORM_MODE} * @default PIXI.TRANSFORM_MODE.STATIC */ - TRANSFORM_MODE: 0, + TRANSFORM_MODE: 1, /** * Default Garbage Collection mode. @@ -187,7 +187,7 @@ * @type {PIXI.SCALE_MODES} * @default PIXI.SCALE_MODES.LINEAR */ - SCALE_MODE: 1, + SCALE_MODE: 0, /** * Default specify float precision in vertex shader. diff --git a/package.json b/package.json index 2466363..829456f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.5.0", + "version": "5.0.0", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a41e1e5..43c8c79 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -93,8 +93,8 @@ this._backgroundColorRgba[3] = this.transparent ? 0 : 1; this.globalUniforms = new UniformGroup({ - projectionMatrix:new Matrix() - }, false) + projectionMatrix:new Matrix(), + }, true) this.addSystem(MaskSystem, 'mask') .addSystem(ContextSystem, 'context') diff --git a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js index b07837f..b76082e 100644 --- a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js +++ b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js @@ -43,13 +43,12 @@ * @private * @param {PIXI.mesh.Geometry} geometry instance of geometry to bind */ - bind(geometry, glShader) + bind(geometry, shader) { - glShader = glShader || this.renderer.shader.getGLShader(); + shader = shader || this.renderer.shader.shader; const gl = this.gl; - // not sure the best way to address this.. // currently different shaders require different VAOs for the same geometry // Still mulling over the best way to solve this one.. @@ -61,7 +60,7 @@ vaos = geometry.glVertexArrayObjects[this.CONTEXT_UID] = {}; } - const vao = vaos[glShader.id] || this.initGeometryVao(geometry, glShader); + const vao = vaos[shader.program.id] || this.initGeometryVao(geometry, shader.program); this._activeGeometry = geometry; @@ -114,11 +113,11 @@ } } - checkCompatability(geometry, glShader) + checkCompatability(geometry, program) { // geometry must have at least all the attributes that the shader requires. const geometryAttributes = geometry.attributes; - const shaderAttributes = glShader.attributes; + const shaderAttributes = program.attributeData; for (const j in shaderAttributes) { @@ -135,9 +134,9 @@ * @param {PIXI.mesh.Geometry} geometry instance of geometry to to generate Vao for * @return {PIXI.VertexArrayObject} Returns a fresh vao. */ - initGeometryVao(geometry, glShader) + initGeometryVao(geometry, program) { - this.checkCompatability(geometry, glShader); + this.checkCompatability(geometry, program); const gl = this.gl; const CONTEXT_UID = this.CONTEXT_UID; @@ -166,9 +165,9 @@ for (const j in attributes) { - if(!attributes[j].size && glShader.attributes[j]) + if(!attributes[j].size && program.attributeData[j]) { - attributes[j].size = glShader.attributes[j].size; + attributes[j].size = program.attributeData[j].size; } tempStride[attributes[j].buffer] += attributes[j].size * byteSizeMap[attributes[j].type]; @@ -221,7 +220,7 @@ const buffer = buffers[attribute.buffer]; const glBuffer = buffer._glBuffers[CONTEXT_UID]; - if(glShader.attributes[j]) + if(program.attributeData[j]) { if(lastBuffer !== glBuffer) { @@ -230,7 +229,7 @@ lastBuffer = glBuffer; } - const location = glShader.attributes[j].location; + const location = program.attributeData[j].location; gl.enableVertexAttribArray(location); @@ -250,7 +249,7 @@ // TODO - maybe make this a data object? // lets wait to see if we need to first! - geometry.glVertexArrayObjects[CONTEXT_UID][glShader.id] = vao; + geometry.glVertexArrayObjects[CONTEXT_UID][program.id] = vao; gl.bindVertexArray(null); diff --git a/src/core/renderers/webgl/systems/shader/ShaderSystem.js b/src/core/renderers/webgl/systems/shader/ShaderSystem.js index 4c39c7e..0ee6743 100644 --- a/src/core/renderers/webgl/systems/shader/ShaderSystem.js +++ b/src/core/renderers/webgl/systems/shader/ShaderSystem.js @@ -47,12 +47,13 @@ */ bind(shader, dontSync) { + // maybe a better place for this... + shader.uniforms.globals = this.renderer.globalUniforms; + const program = shader.program; const glShader = program.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); // TODO - some current pixi plugins bypass this.. so it not safe to use yet.. - // if (this.shader !== shader) - // { if (this.shader !== shader) { this.shader = shader; @@ -87,19 +88,20 @@ if(!group.static || group.dirtyId !== glShader.uniformGroups[group.id]) { glShader.uniformGroups[group.id] = group.dirtyId; - const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSynGroups(group); + const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSyncGroups(group); syncFunc(glShader.uniformData, group.uniforms, this.renderer); } } - createSynGroups(group) + createSyncGroups(group) { group.syncUniforms[this.shader.program.id] = generateUniformsSync(group, this.shader.program.uniformData); return group.syncUniforms[this.shader.program.id]; } + /** * Returns the underlying GLShade rof the currently bound shader. * This can be handy for when you to have a little more control over the setting of your uniforms. @@ -130,6 +132,8 @@ const program = shader.program; const attribMap = {}; + // insert the global properties too! + for (const i in program.attributeData) { attribMap[i] = program.attributeData[i].location; diff --git a/src/core/settings.js b/src/core/settings.js index 38ef45c..bb636aa 100644 --- a/src/core/settings.js +++ b/src/core/settings.js @@ -137,7 +137,7 @@ * @type {PIXI.TRANSFORM_MODE} * @default PIXI.TRANSFORM_MODE.STATIC */ - TRANSFORM_MODE: 0, + TRANSFORM_MODE: 1, /** * Default Garbage Collection mode. @@ -187,7 +187,7 @@ * @type {PIXI.SCALE_MODES} * @default PIXI.SCALE_MODES.LINEAR */ - SCALE_MODE: 1, + SCALE_MODE: 0, /** * Default specify float precision in vertex shader. diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index 426baa6..005402d 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -40,17 +40,7 @@ // does the trick for now though! for (const i in program.uniformData) { - const exists = this.checkUniformExists(i, this.uniformGroup);//this.uniformGroup.uniforms[i]; - - if (!exists) // bad as we need check wher ethe uniforms are.. - { - //console.log("uniform does not exist " + i) - // search within other groups to find the property - // failing that, create it on the root uniform object - this.uniformGroup.uniforms[i] = program.uniformData[i].value; - - } - else if (this.uniformGroup.uniforms[i] instanceof Array) + if (this.uniformGroup.uniforms[i] instanceof Array) { this.uniformGroup.uniforms[i] = new Float32Array(uniform); } diff --git a/package.json b/package.json index 2466363..829456f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.5.0", + "version": "5.0.0", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a41e1e5..43c8c79 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -93,8 +93,8 @@ this._backgroundColorRgba[3] = this.transparent ? 0 : 1; this.globalUniforms = new UniformGroup({ - projectionMatrix:new Matrix() - }, false) + projectionMatrix:new Matrix(), + }, true) this.addSystem(MaskSystem, 'mask') .addSystem(ContextSystem, 'context') diff --git a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js index b07837f..b76082e 100644 --- a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js +++ b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js @@ -43,13 +43,12 @@ * @private * @param {PIXI.mesh.Geometry} geometry instance of geometry to bind */ - bind(geometry, glShader) + bind(geometry, shader) { - glShader = glShader || this.renderer.shader.getGLShader(); + shader = shader || this.renderer.shader.shader; const gl = this.gl; - // not sure the best way to address this.. // currently different shaders require different VAOs for the same geometry // Still mulling over the best way to solve this one.. @@ -61,7 +60,7 @@ vaos = geometry.glVertexArrayObjects[this.CONTEXT_UID] = {}; } - const vao = vaos[glShader.id] || this.initGeometryVao(geometry, glShader); + const vao = vaos[shader.program.id] || this.initGeometryVao(geometry, shader.program); this._activeGeometry = geometry; @@ -114,11 +113,11 @@ } } - checkCompatability(geometry, glShader) + checkCompatability(geometry, program) { // geometry must have at least all the attributes that the shader requires. const geometryAttributes = geometry.attributes; - const shaderAttributes = glShader.attributes; + const shaderAttributes = program.attributeData; for (const j in shaderAttributes) { @@ -135,9 +134,9 @@ * @param {PIXI.mesh.Geometry} geometry instance of geometry to to generate Vao for * @return {PIXI.VertexArrayObject} Returns a fresh vao. */ - initGeometryVao(geometry, glShader) + initGeometryVao(geometry, program) { - this.checkCompatability(geometry, glShader); + this.checkCompatability(geometry, program); const gl = this.gl; const CONTEXT_UID = this.CONTEXT_UID; @@ -166,9 +165,9 @@ for (const j in attributes) { - if(!attributes[j].size && glShader.attributes[j]) + if(!attributes[j].size && program.attributeData[j]) { - attributes[j].size = glShader.attributes[j].size; + attributes[j].size = program.attributeData[j].size; } tempStride[attributes[j].buffer] += attributes[j].size * byteSizeMap[attributes[j].type]; @@ -221,7 +220,7 @@ const buffer = buffers[attribute.buffer]; const glBuffer = buffer._glBuffers[CONTEXT_UID]; - if(glShader.attributes[j]) + if(program.attributeData[j]) { if(lastBuffer !== glBuffer) { @@ -230,7 +229,7 @@ lastBuffer = glBuffer; } - const location = glShader.attributes[j].location; + const location = program.attributeData[j].location; gl.enableVertexAttribArray(location); @@ -250,7 +249,7 @@ // TODO - maybe make this a data object? // lets wait to see if we need to first! - geometry.glVertexArrayObjects[CONTEXT_UID][glShader.id] = vao; + geometry.glVertexArrayObjects[CONTEXT_UID][program.id] = vao; gl.bindVertexArray(null); diff --git a/src/core/renderers/webgl/systems/shader/ShaderSystem.js b/src/core/renderers/webgl/systems/shader/ShaderSystem.js index 4c39c7e..0ee6743 100644 --- a/src/core/renderers/webgl/systems/shader/ShaderSystem.js +++ b/src/core/renderers/webgl/systems/shader/ShaderSystem.js @@ -47,12 +47,13 @@ */ bind(shader, dontSync) { + // maybe a better place for this... + shader.uniforms.globals = this.renderer.globalUniforms; + const program = shader.program; const glShader = program.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); // TODO - some current pixi plugins bypass this.. so it not safe to use yet.. - // if (this.shader !== shader) - // { if (this.shader !== shader) { this.shader = shader; @@ -87,19 +88,20 @@ if(!group.static || group.dirtyId !== glShader.uniformGroups[group.id]) { glShader.uniformGroups[group.id] = group.dirtyId; - const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSynGroups(group); + const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSyncGroups(group); syncFunc(glShader.uniformData, group.uniforms, this.renderer); } } - createSynGroups(group) + createSyncGroups(group) { group.syncUniforms[this.shader.program.id] = generateUniformsSync(group, this.shader.program.uniformData); return group.syncUniforms[this.shader.program.id]; } + /** * Returns the underlying GLShade rof the currently bound shader. * This can be handy for when you to have a little more control over the setting of your uniforms. @@ -130,6 +132,8 @@ const program = shader.program; const attribMap = {}; + // insert the global properties too! + for (const i in program.attributeData) { attribMap[i] = program.attributeData[i].location; diff --git a/src/core/settings.js b/src/core/settings.js index 38ef45c..bb636aa 100644 --- a/src/core/settings.js +++ b/src/core/settings.js @@ -137,7 +137,7 @@ * @type {PIXI.TRANSFORM_MODE} * @default PIXI.TRANSFORM_MODE.STATIC */ - TRANSFORM_MODE: 0, + TRANSFORM_MODE: 1, /** * Default Garbage Collection mode. @@ -187,7 +187,7 @@ * @type {PIXI.SCALE_MODES} * @default PIXI.SCALE_MODES.LINEAR */ - SCALE_MODE: 1, + SCALE_MODE: 0, /** * Default specify float precision in vertex shader. diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index 426baa6..005402d 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -40,17 +40,7 @@ // does the trick for now though! for (const i in program.uniformData) { - const exists = this.checkUniformExists(i, this.uniformGroup);//this.uniformGroup.uniforms[i]; - - if (!exists) // bad as we need check wher ethe uniforms are.. - { - //console.log("uniform does not exist " + i) - // search within other groups to find the property - // failing that, create it on the root uniform object - this.uniformGroup.uniforms[i] = program.uniformData[i].value; - - } - else if (this.uniformGroup.uniforms[i] instanceof Array) + if (this.uniformGroup.uniforms[i] instanceof Array) { this.uniformGroup.uniforms[i] = new Float32Array(uniform); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index dc9d8bf..940593f 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -9,7 +9,7 @@ import bitTwiddle from 'bit-twiddle'; import Geometry from '../../geometry/Geometry'; import Buffer_GEOM from '../../geometry/Buffer'; -import UniformGroup from '../../shader/UniformGroup'; + let TICK = 0; let TEXTURE_TICK = 0; @@ -106,7 +106,7 @@ { const gl = this.renderer.gl; - if (true)//this.renderer.legacy) + if (this.renderer.legacy) { this.MAX_TEXTURES = 1; } @@ -119,20 +119,9 @@ this.MAX_TEXTURES = checkMaxIfStatmentsInShader(this.MAX_TEXTURES, gl); } - const sampleValues = new Int32Array(this.MAX_TEXTURES); - - for (let i = 0; i < this.MAX_TEXTURES; i++) - { - sampleValues[i] = i; - } - - const uniforms = { - default:UniformGroup.from({uSamplers:sampleValues}, true), - globals:this.renderer.globalUniforms - } // generate generateMultiTextureProgram, may be a better move? - this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES, uniforms); + this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES); // we use the second shader as the first one depending on your browser may omit aTextureId // as it is not used by the shader so is optimized out. diff --git a/package.json b/package.json index 2466363..829456f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.5.0", + "version": "5.0.0", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a41e1e5..43c8c79 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -93,8 +93,8 @@ this._backgroundColorRgba[3] = this.transparent ? 0 : 1; this.globalUniforms = new UniformGroup({ - projectionMatrix:new Matrix() - }, false) + projectionMatrix:new Matrix(), + }, true) this.addSystem(MaskSystem, 'mask') .addSystem(ContextSystem, 'context') diff --git a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js index b07837f..b76082e 100644 --- a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js +++ b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js @@ -43,13 +43,12 @@ * @private * @param {PIXI.mesh.Geometry} geometry instance of geometry to bind */ - bind(geometry, glShader) + bind(geometry, shader) { - glShader = glShader || this.renderer.shader.getGLShader(); + shader = shader || this.renderer.shader.shader; const gl = this.gl; - // not sure the best way to address this.. // currently different shaders require different VAOs for the same geometry // Still mulling over the best way to solve this one.. @@ -61,7 +60,7 @@ vaos = geometry.glVertexArrayObjects[this.CONTEXT_UID] = {}; } - const vao = vaos[glShader.id] || this.initGeometryVao(geometry, glShader); + const vao = vaos[shader.program.id] || this.initGeometryVao(geometry, shader.program); this._activeGeometry = geometry; @@ -114,11 +113,11 @@ } } - checkCompatability(geometry, glShader) + checkCompatability(geometry, program) { // geometry must have at least all the attributes that the shader requires. const geometryAttributes = geometry.attributes; - const shaderAttributes = glShader.attributes; + const shaderAttributes = program.attributeData; for (const j in shaderAttributes) { @@ -135,9 +134,9 @@ * @param {PIXI.mesh.Geometry} geometry instance of geometry to to generate Vao for * @return {PIXI.VertexArrayObject} Returns a fresh vao. */ - initGeometryVao(geometry, glShader) + initGeometryVao(geometry, program) { - this.checkCompatability(geometry, glShader); + this.checkCompatability(geometry, program); const gl = this.gl; const CONTEXT_UID = this.CONTEXT_UID; @@ -166,9 +165,9 @@ for (const j in attributes) { - if(!attributes[j].size && glShader.attributes[j]) + if(!attributes[j].size && program.attributeData[j]) { - attributes[j].size = glShader.attributes[j].size; + attributes[j].size = program.attributeData[j].size; } tempStride[attributes[j].buffer] += attributes[j].size * byteSizeMap[attributes[j].type]; @@ -221,7 +220,7 @@ const buffer = buffers[attribute.buffer]; const glBuffer = buffer._glBuffers[CONTEXT_UID]; - if(glShader.attributes[j]) + if(program.attributeData[j]) { if(lastBuffer !== glBuffer) { @@ -230,7 +229,7 @@ lastBuffer = glBuffer; } - const location = glShader.attributes[j].location; + const location = program.attributeData[j].location; gl.enableVertexAttribArray(location); @@ -250,7 +249,7 @@ // TODO - maybe make this a data object? // lets wait to see if we need to first! - geometry.glVertexArrayObjects[CONTEXT_UID][glShader.id] = vao; + geometry.glVertexArrayObjects[CONTEXT_UID][program.id] = vao; gl.bindVertexArray(null); diff --git a/src/core/renderers/webgl/systems/shader/ShaderSystem.js b/src/core/renderers/webgl/systems/shader/ShaderSystem.js index 4c39c7e..0ee6743 100644 --- a/src/core/renderers/webgl/systems/shader/ShaderSystem.js +++ b/src/core/renderers/webgl/systems/shader/ShaderSystem.js @@ -47,12 +47,13 @@ */ bind(shader, dontSync) { + // maybe a better place for this... + shader.uniforms.globals = this.renderer.globalUniforms; + const program = shader.program; const glShader = program.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); // TODO - some current pixi plugins bypass this.. so it not safe to use yet.. - // if (this.shader !== shader) - // { if (this.shader !== shader) { this.shader = shader; @@ -87,19 +88,20 @@ if(!group.static || group.dirtyId !== glShader.uniformGroups[group.id]) { glShader.uniformGroups[group.id] = group.dirtyId; - const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSynGroups(group); + const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSyncGroups(group); syncFunc(glShader.uniformData, group.uniforms, this.renderer); } } - createSynGroups(group) + createSyncGroups(group) { group.syncUniforms[this.shader.program.id] = generateUniformsSync(group, this.shader.program.uniformData); return group.syncUniforms[this.shader.program.id]; } + /** * Returns the underlying GLShade rof the currently bound shader. * This can be handy for when you to have a little more control over the setting of your uniforms. @@ -130,6 +132,8 @@ const program = shader.program; const attribMap = {}; + // insert the global properties too! + for (const i in program.attributeData) { attribMap[i] = program.attributeData[i].location; diff --git a/src/core/settings.js b/src/core/settings.js index 38ef45c..bb636aa 100644 --- a/src/core/settings.js +++ b/src/core/settings.js @@ -137,7 +137,7 @@ * @type {PIXI.TRANSFORM_MODE} * @default PIXI.TRANSFORM_MODE.STATIC */ - TRANSFORM_MODE: 0, + TRANSFORM_MODE: 1, /** * Default Garbage Collection mode. @@ -187,7 +187,7 @@ * @type {PIXI.SCALE_MODES} * @default PIXI.SCALE_MODES.LINEAR */ - SCALE_MODE: 1, + SCALE_MODE: 0, /** * Default specify float precision in vertex shader. diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index 426baa6..005402d 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -40,17 +40,7 @@ // does the trick for now though! for (const i in program.uniformData) { - const exists = this.checkUniformExists(i, this.uniformGroup);//this.uniformGroup.uniforms[i]; - - if (!exists) // bad as we need check wher ethe uniforms are.. - { - //console.log("uniform does not exist " + i) - // search within other groups to find the property - // failing that, create it on the root uniform object - this.uniformGroup.uniforms[i] = program.uniformData[i].value; - - } - else if (this.uniformGroup.uniforms[i] instanceof Array) + if (this.uniformGroup.uniforms[i] instanceof Array) { this.uniformGroup.uniforms[i] = new Float32Array(uniform); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index dc9d8bf..940593f 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -9,7 +9,7 @@ import bitTwiddle from 'bit-twiddle'; import Geometry from '../../geometry/Geometry'; import Buffer_GEOM from '../../geometry/Buffer'; -import UniformGroup from '../../shader/UniformGroup'; + let TICK = 0; let TEXTURE_TICK = 0; @@ -106,7 +106,7 @@ { const gl = this.renderer.gl; - if (true)//this.renderer.legacy) + if (this.renderer.legacy) { this.MAX_TEXTURES = 1; } @@ -119,20 +119,9 @@ this.MAX_TEXTURES = checkMaxIfStatmentsInShader(this.MAX_TEXTURES, gl); } - const sampleValues = new Int32Array(this.MAX_TEXTURES); - - for (let i = 0; i < this.MAX_TEXTURES; i++) - { - sampleValues[i] = i; - } - - const uniforms = { - default:UniformGroup.from({uSamplers:sampleValues}, true), - globals:this.renderer.globalUniforms - } // generate generateMultiTextureProgram, may be a better move? - this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES, uniforms); + this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES); // we use the second shader as the first one depending on your browser may omit aTextureId // as it is not used by the shader so is optimized out. diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 0d555ce..2adf34e 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,5 +1,5 @@ -import { GLShader } from 'pixi-gl-core'; import Shader from '../../shader/Shader'; +import UniformGroup from '../../shader/UniformGroup'; import { PRECISION } from '../../const'; import { readFileSync } from 'fs'; import { join } from 'path'; @@ -18,8 +18,20 @@ '}', ].join('\n'); -export default function generateMultiTextureShader(gl, maxTextures, uniforms) +export default function generateMultiTextureShader(gl, maxTextures) { + const sampleValues = new Int32Array(maxTextures); + + for (let i = 0; i < maxTextures; i++) + { + sampleValues[i] = i; + } + + const uniforms = { + default:UniformGroup.from({uSamplers:sampleValues}, true), + } + + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; diff --git a/package.json b/package.json index 2466363..829456f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pixi.js", - "version": "4.5.0", + "version": "5.0.0", "description": "Pixi.js is a fast lightweight 2D library that works across all devices.", "author": "Mat Groves", "contributors": [ diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index a41e1e5..43c8c79 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -93,8 +93,8 @@ this._backgroundColorRgba[3] = this.transparent ? 0 : 1; this.globalUniforms = new UniformGroup({ - projectionMatrix:new Matrix() - }, false) + projectionMatrix:new Matrix(), + }, true) this.addSystem(MaskSystem, 'mask') .addSystem(ContextSystem, 'context') diff --git a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js index b07837f..b76082e 100644 --- a/src/core/renderers/webgl/systems/geometry/GeometrySystem.js +++ b/src/core/renderers/webgl/systems/geometry/GeometrySystem.js @@ -43,13 +43,12 @@ * @private * @param {PIXI.mesh.Geometry} geometry instance of geometry to bind */ - bind(geometry, glShader) + bind(geometry, shader) { - glShader = glShader || this.renderer.shader.getGLShader(); + shader = shader || this.renderer.shader.shader; const gl = this.gl; - // not sure the best way to address this.. // currently different shaders require different VAOs for the same geometry // Still mulling over the best way to solve this one.. @@ -61,7 +60,7 @@ vaos = geometry.glVertexArrayObjects[this.CONTEXT_UID] = {}; } - const vao = vaos[glShader.id] || this.initGeometryVao(geometry, glShader); + const vao = vaos[shader.program.id] || this.initGeometryVao(geometry, shader.program); this._activeGeometry = geometry; @@ -114,11 +113,11 @@ } } - checkCompatability(geometry, glShader) + checkCompatability(geometry, program) { // geometry must have at least all the attributes that the shader requires. const geometryAttributes = geometry.attributes; - const shaderAttributes = glShader.attributes; + const shaderAttributes = program.attributeData; for (const j in shaderAttributes) { @@ -135,9 +134,9 @@ * @param {PIXI.mesh.Geometry} geometry instance of geometry to to generate Vao for * @return {PIXI.VertexArrayObject} Returns a fresh vao. */ - initGeometryVao(geometry, glShader) + initGeometryVao(geometry, program) { - this.checkCompatability(geometry, glShader); + this.checkCompatability(geometry, program); const gl = this.gl; const CONTEXT_UID = this.CONTEXT_UID; @@ -166,9 +165,9 @@ for (const j in attributes) { - if(!attributes[j].size && glShader.attributes[j]) + if(!attributes[j].size && program.attributeData[j]) { - attributes[j].size = glShader.attributes[j].size; + attributes[j].size = program.attributeData[j].size; } tempStride[attributes[j].buffer] += attributes[j].size * byteSizeMap[attributes[j].type]; @@ -221,7 +220,7 @@ const buffer = buffers[attribute.buffer]; const glBuffer = buffer._glBuffers[CONTEXT_UID]; - if(glShader.attributes[j]) + if(program.attributeData[j]) { if(lastBuffer !== glBuffer) { @@ -230,7 +229,7 @@ lastBuffer = glBuffer; } - const location = glShader.attributes[j].location; + const location = program.attributeData[j].location; gl.enableVertexAttribArray(location); @@ -250,7 +249,7 @@ // TODO - maybe make this a data object? // lets wait to see if we need to first! - geometry.glVertexArrayObjects[CONTEXT_UID][glShader.id] = vao; + geometry.glVertexArrayObjects[CONTEXT_UID][program.id] = vao; gl.bindVertexArray(null); diff --git a/src/core/renderers/webgl/systems/shader/ShaderSystem.js b/src/core/renderers/webgl/systems/shader/ShaderSystem.js index 4c39c7e..0ee6743 100644 --- a/src/core/renderers/webgl/systems/shader/ShaderSystem.js +++ b/src/core/renderers/webgl/systems/shader/ShaderSystem.js @@ -47,12 +47,13 @@ */ bind(shader, dontSync) { + // maybe a better place for this... + shader.uniforms.globals = this.renderer.globalUniforms; + const program = shader.program; const glShader = program.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); // TODO - some current pixi plugins bypass this.. so it not safe to use yet.. - // if (this.shader !== shader) - // { if (this.shader !== shader) { this.shader = shader; @@ -87,19 +88,20 @@ if(!group.static || group.dirtyId !== glShader.uniformGroups[group.id]) { glShader.uniformGroups[group.id] = group.dirtyId; - const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSynGroups(group); + const syncFunc = group.syncUniforms[this.shader.program.id] || this.createSyncGroups(group); syncFunc(glShader.uniformData, group.uniforms, this.renderer); } } - createSynGroups(group) + createSyncGroups(group) { group.syncUniforms[this.shader.program.id] = generateUniformsSync(group, this.shader.program.uniformData); return group.syncUniforms[this.shader.program.id]; } + /** * Returns the underlying GLShade rof the currently bound shader. * This can be handy for when you to have a little more control over the setting of your uniforms. @@ -130,6 +132,8 @@ const program = shader.program; const attribMap = {}; + // insert the global properties too! + for (const i in program.attributeData) { attribMap[i] = program.attributeData[i].location; diff --git a/src/core/settings.js b/src/core/settings.js index 38ef45c..bb636aa 100644 --- a/src/core/settings.js +++ b/src/core/settings.js @@ -137,7 +137,7 @@ * @type {PIXI.TRANSFORM_MODE} * @default PIXI.TRANSFORM_MODE.STATIC */ - TRANSFORM_MODE: 0, + TRANSFORM_MODE: 1, /** * Default Garbage Collection mode. @@ -187,7 +187,7 @@ * @type {PIXI.SCALE_MODES} * @default PIXI.SCALE_MODES.LINEAR */ - SCALE_MODE: 1, + SCALE_MODE: 0, /** * Default specify float precision in vertex shader. diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index 426baa6..005402d 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -40,17 +40,7 @@ // does the trick for now though! for (const i in program.uniformData) { - const exists = this.checkUniformExists(i, this.uniformGroup);//this.uniformGroup.uniforms[i]; - - if (!exists) // bad as we need check wher ethe uniforms are.. - { - //console.log("uniform does not exist " + i) - // search within other groups to find the property - // failing that, create it on the root uniform object - this.uniformGroup.uniforms[i] = program.uniformData[i].value; - - } - else if (this.uniformGroup.uniforms[i] instanceof Array) + if (this.uniformGroup.uniforms[i] instanceof Array) { this.uniformGroup.uniforms[i] = new Float32Array(uniform); } diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index dc9d8bf..940593f 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -9,7 +9,7 @@ import bitTwiddle from 'bit-twiddle'; import Geometry from '../../geometry/Geometry'; import Buffer_GEOM from '../../geometry/Buffer'; -import UniformGroup from '../../shader/UniformGroup'; + let TICK = 0; let TEXTURE_TICK = 0; @@ -106,7 +106,7 @@ { const gl = this.renderer.gl; - if (true)//this.renderer.legacy) + if (this.renderer.legacy) { this.MAX_TEXTURES = 1; } @@ -119,20 +119,9 @@ this.MAX_TEXTURES = checkMaxIfStatmentsInShader(this.MAX_TEXTURES, gl); } - const sampleValues = new Int32Array(this.MAX_TEXTURES); - - for (let i = 0; i < this.MAX_TEXTURES; i++) - { - sampleValues[i] = i; - } - - const uniforms = { - default:UniformGroup.from({uSamplers:sampleValues}, true), - globals:this.renderer.globalUniforms - } // generate generateMultiTextureProgram, may be a better move? - this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES, uniforms); + this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES); // we use the second shader as the first one depending on your browser may omit aTextureId // as it is not used by the shader so is optimized out. diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 0d555ce..2adf34e 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,5 +1,5 @@ -import { GLShader } from 'pixi-gl-core'; import Shader from '../../shader/Shader'; +import UniformGroup from '../../shader/UniformGroup'; import { PRECISION } from '../../const'; import { readFileSync } from 'fs'; import { join } from 'path'; @@ -18,8 +18,20 @@ '}', ].join('\n'); -export default function generateMultiTextureShader(gl, maxTextures, uniforms) +export default function generateMultiTextureShader(gl, maxTextures) { + const sampleValues = new Int32Array(maxTextures); + + for (let i = 0; i < maxTextures; i++) + { + sampleValues[i] = i; + } + + const uniforms = { + default:UniformGroup.from({uSamplers:sampleValues}, true), + } + + const vertexSrc = readFileSync(join(__dirname, './texture.vert'), 'utf8'); let fragmentSrc = fragTemplate; diff --git a/src/mesh/webgl/MeshRenderer.js b/src/mesh/webgl/MeshRenderer.js index 30b85f1..1089c3c 100644 --- a/src/mesh/webgl/MeshRenderer.js +++ b/src/mesh/webgl/MeshRenderer.js @@ -46,23 +46,24 @@ { // bind the shader.. + // TODO // set the shader props.. - if (mesh.shader.uniforms.translationMatrix) + // probably only need to set once! + // as its then a refference.. + if (mesh.shader.program.uniformData.translationMatrix) { // the transform! mesh.shader.uniforms.translationMatrix = mesh.transform.worldTransform.toArray(true); } - const glShader = this.renderer.shader.bind(mesh.shader, true); + // bind and sync uniforms.. + this.renderer.shader.bind(mesh.shader); - // set unifomrs.. - this.renderer.shader.syncUniformGroup(mesh.shader.uniformGroup); - - // sync uniforms.. + // set state.. this.renderer.state.setState(mesh.state); // bind the geometry... - this.renderer.geometry.bind(mesh.geometry, glShader); + this.renderer.geometry.bind(mesh.geometry, mesh.shader); // then render it this.renderer.geometry.draw(mesh.drawMode, mesh.size, mesh.start, mesh.geometry.instanceCount); }