diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 9606b76..99fd267 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -82,7 +82,7 @@ const uniformData = shader.uniformData; // 0 is reserverd for the pixi texture so we start at 1! - let textureCount = 1; + let textureCount = 0; // TODO don't need to use the uniform for (const i in uniformData) diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 9606b76..99fd267 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -82,7 +82,7 @@ const uniformData = shader.uniformData; // 0 is reserverd for the pixi texture so we start at 1! - let textureCount = 1; + let textureCount = 0; // TODO don't need to use the uniform for (const i in uniformData) diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 3830e4c..f7781fe 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -516,7 +516,12 @@ } else { - // bind the current texture + + if(this.boundTextures[location] === texture) + { + return location; + } + this.boundTextures[location] = texture; gl.activeTexture(gl.TEXTURE0 + location); gl.bindTexture(gl.TEXTURE_2D, glTexture.texture); diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 9606b76..99fd267 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -82,7 +82,7 @@ const uniformData = shader.uniformData; // 0 is reserverd for the pixi texture so we start at 1! - let textureCount = 1; + let textureCount = 0; // TODO don't need to use the uniform for (const i in uniformData) diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 3830e4c..f7781fe 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -516,7 +516,12 @@ } else { - // bind the current texture + + if(this.boundTextures[location] === texture) + { + return location; + } + this.boundTextures[location] = texture; gl.activeTexture(gl.TEXTURE0 + location); gl.bindTexture(gl.TEXTURE_2D, glTexture.texture); diff --git a/src/core/shader/generateUniformsSync.js b/src/core/shader/generateUniformsSync.js index 278e0f0..68b9c75 100644 --- a/src/core/shader/generateUniformsSync.js +++ b/src/core/shader/generateUniformsSync.js @@ -2,7 +2,7 @@ float: `if(cacheValue !== value) { - cacheValue = value; + cacheValue.value = value; gl.uniform1f(location, value) }`, @@ -48,11 +48,25 @@ const data = uniformData[i]; // TODO && uniformData[i].value !== 0 <-- do we still need this? - if (data.type === 'sampler2D') + if (data.type === 'float') { - func += `\n + //const template = GLSL_TO_SINGLE_SETTERS_CACHED[data.type].replace('location', `uniformData.${i}.location`); - gl.uniform1i(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len + func += `\nif(uniformValues.${i} !== uniformData.${i}.value) +{ + uniformData.${i}.value = uniformValues.${i} + gl.uniform1f(uniformData.${i}.location, uniformValues.${i}) +}\n`; + } + else if (data.type === 'sampler2D') + { + func += `\nvar location = renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true); + +if(uniformData.${i}.value !== location) +{ + uniformData.${i}.value = location; + gl.uniform1i(uniformData.${i}.location, location);\n; // eslint-disable-line max-len +}` } else if (data.type === 'mat3') { @@ -75,7 +89,8 @@ } } - // console.log(func); + console.log(' --------------- ') + console.log(func); return new Function('uniformData', 'uniformValues', 'gl', func); // eslint-disable-line no-new-func } diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 9606b76..99fd267 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -82,7 +82,7 @@ const uniformData = shader.uniformData; // 0 is reserverd for the pixi texture so we start at 1! - let textureCount = 1; + let textureCount = 0; // TODO don't need to use the uniform for (const i in uniformData) diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 3830e4c..f7781fe 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -516,7 +516,12 @@ } else { - // bind the current texture + + if(this.boundTextures[location] === texture) + { + return location; + } + this.boundTextures[location] = texture; gl.activeTexture(gl.TEXTURE0 + location); gl.bindTexture(gl.TEXTURE_2D, glTexture.texture); diff --git a/src/core/shader/generateUniformsSync.js b/src/core/shader/generateUniformsSync.js index 278e0f0..68b9c75 100644 --- a/src/core/shader/generateUniformsSync.js +++ b/src/core/shader/generateUniformsSync.js @@ -2,7 +2,7 @@ float: `if(cacheValue !== value) { - cacheValue = value; + cacheValue.value = value; gl.uniform1f(location, value) }`, @@ -48,11 +48,25 @@ const data = uniformData[i]; // TODO && uniformData[i].value !== 0 <-- do we still need this? - if (data.type === 'sampler2D') + if (data.type === 'float') { - func += `\n + //const template = GLSL_TO_SINGLE_SETTERS_CACHED[data.type].replace('location', `uniformData.${i}.location`); - gl.uniform1i(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len + func += `\nif(uniformValues.${i} !== uniformData.${i}.value) +{ + uniformData.${i}.value = uniformValues.${i} + gl.uniform1f(uniformData.${i}.location, uniformValues.${i}) +}\n`; + } + else if (data.type === 'sampler2D') + { + func += `\nvar location = renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true); + +if(uniformData.${i}.value !== location) +{ + uniformData.${i}.value = location; + gl.uniform1i(uniformData.${i}.location, location);\n; // eslint-disable-line max-len +}` } else if (data.type === 'mat3') { @@ -75,7 +89,8 @@ } } - // console.log(func); + console.log(' --------------- ') + console.log(func); return new Function('uniformData', 'uniformValues', 'gl', func); // eslint-disable-line no-new-func } diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index 752a070..1d28280 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -42,12 +42,16 @@ .addAttribute('aTextureCoord', new Float32Array(points.length * 4), 2) .addIndex(new Uint16Array(points.length * 2)); - super(geometry, meshShader, { - uSample2:texture, + const uniforms = { + uSampler2:texture, alpha:1, - tint:new Float32Array([0, 0, 0]), - translationMatrix:this.transform.worldTransform - }, null, 5); + translationMatrix:null, + tint:new Float32Array([1, 1, 1]) + } + + super(geometry, meshShader, uniforms, null, 5); + + uniforms.translationMatrix = this.transform.worldTransform; this.texture = texture; @@ -56,15 +60,6 @@ */ this.points = points; - /** - * Tracker for if the rope is ready to be drawn. Needed because Mesh ctor can - * call _onTextureUpdated which could call refresh too early. - * - * @member {boolean} - * @private - */ - this._ready = true; - this._tint = 0xFFFFFF; this.tint = 0xFFFFFF; @@ -79,6 +74,17 @@ } } + set tint(value) + { + this._tint = value; + core.utils.hex2rgb(this._tint, this.uniforms.tint); + } + + get tint() + { + return this._tint; + } + /** * Refreshes */ @@ -145,17 +151,6 @@ this.geometry.data.indexBuffer.update(); } - set tint(value) - { - this._tint = value; - core.utils.hex2rgb(this._tint, this.uniforms.tint); - } - - get tint() - { - return this._tint; - } - /** * Clear texture UVs when new texture is set * @@ -163,11 +158,7 @@ */ _onTextureUpdate() { - // wait for the Rope ctor to finish before calling refresh - if (this._ready) - { - this.refresh(); - } + this.refresh(); } /** @@ -235,10 +226,10 @@ lastPoint = point; } - this.shader.uniforms.alpha = this.alpha; - this.shader.uniforms.uSampler2 = this.texture; - this.geometry.getAttribute('aVertexPosition').update(); + + this.uniforms.alpha = this.worldAlpha; + this.containerUpdateTransform(); } }