diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 3be2cf8..9606b76 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -1,7 +1,5 @@ import { GLShader } from 'pixi-gl-core'; -import { WRAP_MODES, SCALE_MODES, PRECISION} from '../../const'; -import RenderTarget from './utils/RenderTarget'; -import { removeItems } from '../../utils'; +import { PRECISION } from '../../const'; /** * Helper class to create a webGL Texture @@ -35,14 +33,15 @@ bindShader(shader, dontSync) { - // if(this.shader === shader)return; + const glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - this.shader = shader; + if (this.shader !== shader) + { + this.shader = shader; + this.renderer._bindGLShader(glShader); + } - let glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - - this.renderer._bindGLShader(glShader); - if(!dontSync) + if (!dontSync) { this.syncUniforms(glShader, shader); } @@ -58,8 +57,8 @@ generateShader(shader) { - const attribMap = {}; + for (const i in shader.attributeData) { attribMap[i] = shader.attributeData[i].location; @@ -67,17 +66,9 @@ const glShader = new GLShader(this.gl, shader.vertexSrc, shader.fragmentSrc, PRECISION.DEFAULT, attribMap); - //TODO should I add this a s a prototype - glShader.dirtyFlags = {}; - for (var i in shader.realUniforms) { - glShader.dirtyFlags[i] = 0; - }; - console.log(glShader.dirtyFlags) - shader.glShaders[this.renderer.CONTEXT_UID] = glShader; - - return glShader + return glShader; } /** @@ -89,8 +80,6 @@ syncUniforms(glShader, shader) { const uniformData = shader.uniformData; - const realUniforms = shader.realUniforms; - const dirtyFlags = glShader.dirtyFlags; // 0 is reserverd for the pixi texture so we start at 1! let textureCount = 1; @@ -98,23 +87,16 @@ // TODO don't need to use the uniform for (const i in uniformData) { - if(dirtyFlags[i] === uniformData[i].dirtyId) - { - //continue; - } - - dirtyFlags[i] = uniformData[i].dirtyId; - if (uniformData[i].type === 'sampler2D' && uniformData[i].value !== 0) { if (uniformData[i].value.baseTexture) { glShader.uniforms[i] = this.renderer.bindTexture(uniformData[i].value, textureCount, true); - // console.log( glShader.uniforms[i]) } else { glShader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably @@ -144,7 +126,7 @@ { // check if its a point.. if (uniformData[i].value.x !== undefined) - { + { const val = glShader.uniforms[i] || new Float32Array(2); val[0] = uniformData[i].value.x; @@ -152,7 +134,7 @@ glShader.uniforms[i] = val; } else - { + { glShader.uniforms[i] = uniformData[i].value; } } @@ -170,13 +152,12 @@ } } - - /** * Destroys this manager and removes all its textures */ destroy() { - + // TODO implement destroy method for ShaderManager + this.destroyed = true; } } diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 3be2cf8..9606b76 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -1,7 +1,5 @@ import { GLShader } from 'pixi-gl-core'; -import { WRAP_MODES, SCALE_MODES, PRECISION} from '../../const'; -import RenderTarget from './utils/RenderTarget'; -import { removeItems } from '../../utils'; +import { PRECISION } from '../../const'; /** * Helper class to create a webGL Texture @@ -35,14 +33,15 @@ bindShader(shader, dontSync) { - // if(this.shader === shader)return; + const glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - this.shader = shader; + if (this.shader !== shader) + { + this.shader = shader; + this.renderer._bindGLShader(glShader); + } - let glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - - this.renderer._bindGLShader(glShader); - if(!dontSync) + if (!dontSync) { this.syncUniforms(glShader, shader); } @@ -58,8 +57,8 @@ generateShader(shader) { - const attribMap = {}; + for (const i in shader.attributeData) { attribMap[i] = shader.attributeData[i].location; @@ -67,17 +66,9 @@ const glShader = new GLShader(this.gl, shader.vertexSrc, shader.fragmentSrc, PRECISION.DEFAULT, attribMap); - //TODO should I add this a s a prototype - glShader.dirtyFlags = {}; - for (var i in shader.realUniforms) { - glShader.dirtyFlags[i] = 0; - }; - console.log(glShader.dirtyFlags) - shader.glShaders[this.renderer.CONTEXT_UID] = glShader; - - return glShader + return glShader; } /** @@ -89,8 +80,6 @@ syncUniforms(glShader, shader) { const uniformData = shader.uniformData; - const realUniforms = shader.realUniforms; - const dirtyFlags = glShader.dirtyFlags; // 0 is reserverd for the pixi texture so we start at 1! let textureCount = 1; @@ -98,23 +87,16 @@ // TODO don't need to use the uniform for (const i in uniformData) { - if(dirtyFlags[i] === uniformData[i].dirtyId) - { - //continue; - } - - dirtyFlags[i] = uniformData[i].dirtyId; - if (uniformData[i].type === 'sampler2D' && uniformData[i].value !== 0) { if (uniformData[i].value.baseTexture) { glShader.uniforms[i] = this.renderer.bindTexture(uniformData[i].value, textureCount, true); - // console.log( glShader.uniforms[i]) } else { glShader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably @@ -144,7 +126,7 @@ { // check if its a point.. if (uniformData[i].value.x !== undefined) - { + { const val = glShader.uniforms[i] || new Float32Array(2); val[0] = uniformData[i].value.x; @@ -152,7 +134,7 @@ glShader.uniforms[i] = val; } else - { + { glShader.uniforms[i] = uniformData[i].value; } } @@ -170,13 +152,12 @@ } } - - /** * Destroys this manager and removes all its textures */ destroy() { - + // TODO implement destroy method for ShaderManager + this.destroyed = true; } } diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 026e741..3830e4c 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,7 +9,6 @@ import ShaderManager from './ShaderManager'; import BaseTexture from '../../textures/BaseTexture'; import TextureGarbageCollector from './TextureGarbageCollector'; -import WebGLState from './WebGLState'; import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; import validateContext from './utils/validateContext'; import { pluginTarget } from '../../utils'; @@ -100,7 +99,6 @@ */ this.stencilManager = new StencilManager(this); - /** * An empty renderer. * @@ -447,8 +445,6 @@ this.shaderManager.bindShader(shader, dontSync); } - - /** * Changes the current shader to the one given in parameter * diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 3be2cf8..9606b76 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -1,7 +1,5 @@ import { GLShader } from 'pixi-gl-core'; -import { WRAP_MODES, SCALE_MODES, PRECISION} from '../../const'; -import RenderTarget from './utils/RenderTarget'; -import { removeItems } from '../../utils'; +import { PRECISION } from '../../const'; /** * Helper class to create a webGL Texture @@ -35,14 +33,15 @@ bindShader(shader, dontSync) { - // if(this.shader === shader)return; + const glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - this.shader = shader; + if (this.shader !== shader) + { + this.shader = shader; + this.renderer._bindGLShader(glShader); + } - let glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - - this.renderer._bindGLShader(glShader); - if(!dontSync) + if (!dontSync) { this.syncUniforms(glShader, shader); } @@ -58,8 +57,8 @@ generateShader(shader) { - const attribMap = {}; + for (const i in shader.attributeData) { attribMap[i] = shader.attributeData[i].location; @@ -67,17 +66,9 @@ const glShader = new GLShader(this.gl, shader.vertexSrc, shader.fragmentSrc, PRECISION.DEFAULT, attribMap); - //TODO should I add this a s a prototype - glShader.dirtyFlags = {}; - for (var i in shader.realUniforms) { - glShader.dirtyFlags[i] = 0; - }; - console.log(glShader.dirtyFlags) - shader.glShaders[this.renderer.CONTEXT_UID] = glShader; - - return glShader + return glShader; } /** @@ -89,8 +80,6 @@ syncUniforms(glShader, shader) { const uniformData = shader.uniformData; - const realUniforms = shader.realUniforms; - const dirtyFlags = glShader.dirtyFlags; // 0 is reserverd for the pixi texture so we start at 1! let textureCount = 1; @@ -98,23 +87,16 @@ // TODO don't need to use the uniform for (const i in uniformData) { - if(dirtyFlags[i] === uniformData[i].dirtyId) - { - //continue; - } - - dirtyFlags[i] = uniformData[i].dirtyId; - if (uniformData[i].type === 'sampler2D' && uniformData[i].value !== 0) { if (uniformData[i].value.baseTexture) { glShader.uniforms[i] = this.renderer.bindTexture(uniformData[i].value, textureCount, true); - // console.log( glShader.uniforms[i]) } else { glShader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably @@ -144,7 +126,7 @@ { // check if its a point.. if (uniformData[i].value.x !== undefined) - { + { const val = glShader.uniforms[i] || new Float32Array(2); val[0] = uniformData[i].value.x; @@ -152,7 +134,7 @@ glShader.uniforms[i] = val; } else - { + { glShader.uniforms[i] = uniformData[i].value; } } @@ -170,13 +152,12 @@ } } - - /** * Destroys this manager and removes all its textures */ destroy() { - + // TODO implement destroy method for ShaderManager + this.destroyed = true; } } diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 026e741..3830e4c 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,7 +9,6 @@ import ShaderManager from './ShaderManager'; import BaseTexture from '../../textures/BaseTexture'; import TextureGarbageCollector from './TextureGarbageCollector'; -import WebGLState from './WebGLState'; import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; import validateContext from './utils/validateContext'; import { pluginTarget } from '../../utils'; @@ -100,7 +99,6 @@ */ this.stencilManager = new StencilManager(this); - /** * An empty renderer. * @@ -447,8 +445,6 @@ this.shaderManager.bindShader(shader, dontSync); } - - /** * Changes the current shader to the one given in parameter * diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 776fad3..93a5d2a 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,4 @@ import Shader from '../../../shader/Shader'; -import { uid } from '../../../utils'; import { BLEND_MODES } from '../../../const'; // let math = require('../../../math'); @@ -17,7 +16,7 @@ */ constructor(vertexSrc, fragmentSrc, uniforms) { - super(vertexSrc, fragmentSrc, uniforms) + super(vertexSrc, fragmentSrc, uniforms); this.blendMode = BLEND_MODES.NORMAL; diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 3be2cf8..9606b76 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -1,7 +1,5 @@ import { GLShader } from 'pixi-gl-core'; -import { WRAP_MODES, SCALE_MODES, PRECISION} from '../../const'; -import RenderTarget from './utils/RenderTarget'; -import { removeItems } from '../../utils'; +import { PRECISION } from '../../const'; /** * Helper class to create a webGL Texture @@ -35,14 +33,15 @@ bindShader(shader, dontSync) { - // if(this.shader === shader)return; + const glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - this.shader = shader; + if (this.shader !== shader) + { + this.shader = shader; + this.renderer._bindGLShader(glShader); + } - let glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - - this.renderer._bindGLShader(glShader); - if(!dontSync) + if (!dontSync) { this.syncUniforms(glShader, shader); } @@ -58,8 +57,8 @@ generateShader(shader) { - const attribMap = {}; + for (const i in shader.attributeData) { attribMap[i] = shader.attributeData[i].location; @@ -67,17 +66,9 @@ const glShader = new GLShader(this.gl, shader.vertexSrc, shader.fragmentSrc, PRECISION.DEFAULT, attribMap); - //TODO should I add this a s a prototype - glShader.dirtyFlags = {}; - for (var i in shader.realUniforms) { - glShader.dirtyFlags[i] = 0; - }; - console.log(glShader.dirtyFlags) - shader.glShaders[this.renderer.CONTEXT_UID] = glShader; - - return glShader + return glShader; } /** @@ -89,8 +80,6 @@ syncUniforms(glShader, shader) { const uniformData = shader.uniformData; - const realUniforms = shader.realUniforms; - const dirtyFlags = glShader.dirtyFlags; // 0 is reserverd for the pixi texture so we start at 1! let textureCount = 1; @@ -98,23 +87,16 @@ // TODO don't need to use the uniform for (const i in uniformData) { - if(dirtyFlags[i] === uniformData[i].dirtyId) - { - //continue; - } - - dirtyFlags[i] = uniformData[i].dirtyId; - if (uniformData[i].type === 'sampler2D' && uniformData[i].value !== 0) { if (uniformData[i].value.baseTexture) { glShader.uniforms[i] = this.renderer.bindTexture(uniformData[i].value, textureCount, true); - // console.log( glShader.uniforms[i]) } else { glShader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably @@ -144,7 +126,7 @@ { // check if its a point.. if (uniformData[i].value.x !== undefined) - { + { const val = glShader.uniforms[i] || new Float32Array(2); val[0] = uniformData[i].value.x; @@ -152,7 +134,7 @@ glShader.uniforms[i] = val; } else - { + { glShader.uniforms[i] = uniformData[i].value; } } @@ -170,13 +152,12 @@ } } - - /** * Destroys this manager and removes all its textures */ destroy() { - + // TODO implement destroy method for ShaderManager + this.destroyed = true; } } diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 026e741..3830e4c 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,7 +9,6 @@ import ShaderManager from './ShaderManager'; import BaseTexture from '../../textures/BaseTexture'; import TextureGarbageCollector from './TextureGarbageCollector'; -import WebGLState from './WebGLState'; import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; import validateContext from './utils/validateContext'; import { pluginTarget } from '../../utils'; @@ -100,7 +99,6 @@ */ this.stencilManager = new StencilManager(this); - /** * An empty renderer. * @@ -447,8 +445,6 @@ this.shaderManager.bindShader(shader, dontSync); } - - /** * Changes the current shader to the one given in parameter * diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 776fad3..93a5d2a 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,4 @@ import Shader from '../../../shader/Shader'; -import { uid } from '../../../utils'; import { BLEND_MODES } from '../../../const'; // let math = require('../../../math'); @@ -17,7 +16,7 @@ */ constructor(vertexSrc, fragmentSrc, uniforms) { - super(vertexSrc, fragmentSrc, uniforms) + super(vertexSrc, fragmentSrc, uniforms); this.blendMode = BLEND_MODES.NORMAL; diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 9466b50..157402a 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -19,7 +19,6 @@ */ constructor(gl) { - /** * The current WebGL rendering context * @@ -51,7 +50,7 @@ // map functions for when we set state.. this.map[BLEND] = this.setBlend; - this.map[OFFSET] = this.setPolygonOffset; + this.map[OFFSET] = this.setOffset; this.map[CULLING] = this.setCullFace; this.map[DEPTH_TEST] = this.setDepthTest; this.map[WINDING] = this.setFrontFace; @@ -67,18 +66,18 @@ setState(state) { // TODO maybe to an object check? ( this.state === state )? - if(this.stateId === state.data)return; + if (this.stateId === state.data) return; let diff = this.stateId ^ state.data; let i = 0; // order from least to most common - while(diff) + while (diff) { - if(diff & 1) + if (diff & 1) { // state change! - this.map[i].call(this, !!(state.data & (1 << i)) ); + this.map[i].call(this, !!(state.data & (1 << i))); } diff = diff >> 1; @@ -91,12 +90,11 @@ for (let i = 0; i < this.checks.length; i++) { this.checks[i](this, state); - }; + } this.stateId = state.data; } - /** * Enables or disabled blending. * @@ -109,7 +107,7 @@ this.gl[value ? 'enable' : 'disable'](this.gl.BLEND); } - setPolygonOffset(value) + setOffset(value) { this.gl[value ? 'enable' : 'disable'](this.gl.POLYGON_OFFSET_FILL); } @@ -209,26 +207,25 @@ this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false); - //TO DO? - //this.setState(this.defaultState); + // TODO? + // this.setState(this.defaultState); } updateCheck(func, value) { const index = this.checks.indexOf(func); - if(value && index === -1) + if (value && index === -1) { this.checks.push(func); } - else if(!value && index !== -1) + else if (!value && index !== -1) { this.checks.splice(index, 1); } - } - //static function maintains scope! + // static function maintains scope! static checkBlendMode(manager, state) { manager.setBlendMode(state.blendMode); diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 3be2cf8..9606b76 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -1,7 +1,5 @@ import { GLShader } from 'pixi-gl-core'; -import { WRAP_MODES, SCALE_MODES, PRECISION} from '../../const'; -import RenderTarget from './utils/RenderTarget'; -import { removeItems } from '../../utils'; +import { PRECISION } from '../../const'; /** * Helper class to create a webGL Texture @@ -35,14 +33,15 @@ bindShader(shader, dontSync) { - // if(this.shader === shader)return; + const glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - this.shader = shader; + if (this.shader !== shader) + { + this.shader = shader; + this.renderer._bindGLShader(glShader); + } - let glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - - this.renderer._bindGLShader(glShader); - if(!dontSync) + if (!dontSync) { this.syncUniforms(glShader, shader); } @@ -58,8 +57,8 @@ generateShader(shader) { - const attribMap = {}; + for (const i in shader.attributeData) { attribMap[i] = shader.attributeData[i].location; @@ -67,17 +66,9 @@ const glShader = new GLShader(this.gl, shader.vertexSrc, shader.fragmentSrc, PRECISION.DEFAULT, attribMap); - //TODO should I add this a s a prototype - glShader.dirtyFlags = {}; - for (var i in shader.realUniforms) { - glShader.dirtyFlags[i] = 0; - }; - console.log(glShader.dirtyFlags) - shader.glShaders[this.renderer.CONTEXT_UID] = glShader; - - return glShader + return glShader; } /** @@ -89,8 +80,6 @@ syncUniforms(glShader, shader) { const uniformData = shader.uniformData; - const realUniforms = shader.realUniforms; - const dirtyFlags = glShader.dirtyFlags; // 0 is reserverd for the pixi texture so we start at 1! let textureCount = 1; @@ -98,23 +87,16 @@ // TODO don't need to use the uniform for (const i in uniformData) { - if(dirtyFlags[i] === uniformData[i].dirtyId) - { - //continue; - } - - dirtyFlags[i] = uniformData[i].dirtyId; - if (uniformData[i].type === 'sampler2D' && uniformData[i].value !== 0) { if (uniformData[i].value.baseTexture) { glShader.uniforms[i] = this.renderer.bindTexture(uniformData[i].value, textureCount, true); - // console.log( glShader.uniforms[i]) } else { glShader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably @@ -144,7 +126,7 @@ { // check if its a point.. if (uniformData[i].value.x !== undefined) - { + { const val = glShader.uniforms[i] || new Float32Array(2); val[0] = uniformData[i].value.x; @@ -152,7 +134,7 @@ glShader.uniforms[i] = val; } else - { + { glShader.uniforms[i] = uniformData[i].value; } } @@ -170,13 +152,12 @@ } } - - /** * Destroys this manager and removes all its textures */ destroy() { - + // TODO implement destroy method for ShaderManager + this.destroyed = true; } } diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 026e741..3830e4c 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,7 +9,6 @@ import ShaderManager from './ShaderManager'; import BaseTexture from '../../textures/BaseTexture'; import TextureGarbageCollector from './TextureGarbageCollector'; -import WebGLState from './WebGLState'; import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; import validateContext from './utils/validateContext'; import { pluginTarget } from '../../utils'; @@ -100,7 +99,6 @@ */ this.stencilManager = new StencilManager(this); - /** * An empty renderer. * @@ -447,8 +445,6 @@ this.shaderManager.bindShader(shader, dontSync); } - - /** * Changes the current shader to the one given in parameter * diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 776fad3..93a5d2a 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,4 @@ import Shader from '../../../shader/Shader'; -import { uid } from '../../../utils'; import { BLEND_MODES } from '../../../const'; // let math = require('../../../math'); @@ -17,7 +16,7 @@ */ constructor(vertexSrc, fragmentSrc, uniforms) { - super(vertexSrc, fragmentSrc, uniforms) + super(vertexSrc, fragmentSrc, uniforms); this.blendMode = BLEND_MODES.NORMAL; diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 9466b50..157402a 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -19,7 +19,6 @@ */ constructor(gl) { - /** * The current WebGL rendering context * @@ -51,7 +50,7 @@ // map functions for when we set state.. this.map[BLEND] = this.setBlend; - this.map[OFFSET] = this.setPolygonOffset; + this.map[OFFSET] = this.setOffset; this.map[CULLING] = this.setCullFace; this.map[DEPTH_TEST] = this.setDepthTest; this.map[WINDING] = this.setFrontFace; @@ -67,18 +66,18 @@ setState(state) { // TODO maybe to an object check? ( this.state === state )? - if(this.stateId === state.data)return; + if (this.stateId === state.data) return; let diff = this.stateId ^ state.data; let i = 0; // order from least to most common - while(diff) + while (diff) { - if(diff & 1) + if (diff & 1) { // state change! - this.map[i].call(this, !!(state.data & (1 << i)) ); + this.map[i].call(this, !!(state.data & (1 << i))); } diff = diff >> 1; @@ -91,12 +90,11 @@ for (let i = 0; i < this.checks.length; i++) { this.checks[i](this, state); - }; + } this.stateId = state.data; } - /** * Enables or disabled blending. * @@ -109,7 +107,7 @@ this.gl[value ? 'enable' : 'disable'](this.gl.BLEND); } - setPolygonOffset(value) + setOffset(value) { this.gl[value ? 'enable' : 'disable'](this.gl.POLYGON_OFFSET_FILL); } @@ -209,26 +207,25 @@ this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false); - //TO DO? - //this.setState(this.defaultState); + // TODO? + // this.setState(this.defaultState); } updateCheck(func, value) { const index = this.checks.indexOf(func); - if(value && index === -1) + if (value && index === -1) { this.checks.push(func); } - else if(!value && index !== -1) + else if (!value && index !== -1) { this.checks.splice(index, 1); } - } - //static function maintains scope! + // static function maintains scope! static checkBlendMode(manager, state) { manager.setBlendMode(state.blendMode); diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index bf2620b..826e1b0 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -45,7 +45,10 @@ // does the trick for now though! for (const i in this.uniformData) { - this.uniforms[i] = this.uniformData[i].value; + if(!this.uniforms[i]) + { + this.uniforms[i] = this.uniformData[i].value; + } } // this is where we store shader references.. diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 3be2cf8..9606b76 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -1,7 +1,5 @@ import { GLShader } from 'pixi-gl-core'; -import { WRAP_MODES, SCALE_MODES, PRECISION} from '../../const'; -import RenderTarget from './utils/RenderTarget'; -import { removeItems } from '../../utils'; +import { PRECISION } from '../../const'; /** * Helper class to create a webGL Texture @@ -35,14 +33,15 @@ bindShader(shader, dontSync) { - // if(this.shader === shader)return; + const glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - this.shader = shader; + if (this.shader !== shader) + { + this.shader = shader; + this.renderer._bindGLShader(glShader); + } - let glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - - this.renderer._bindGLShader(glShader); - if(!dontSync) + if (!dontSync) { this.syncUniforms(glShader, shader); } @@ -58,8 +57,8 @@ generateShader(shader) { - const attribMap = {}; + for (const i in shader.attributeData) { attribMap[i] = shader.attributeData[i].location; @@ -67,17 +66,9 @@ const glShader = new GLShader(this.gl, shader.vertexSrc, shader.fragmentSrc, PRECISION.DEFAULT, attribMap); - //TODO should I add this a s a prototype - glShader.dirtyFlags = {}; - for (var i in shader.realUniforms) { - glShader.dirtyFlags[i] = 0; - }; - console.log(glShader.dirtyFlags) - shader.glShaders[this.renderer.CONTEXT_UID] = glShader; - - return glShader + return glShader; } /** @@ -89,8 +80,6 @@ syncUniforms(glShader, shader) { const uniformData = shader.uniformData; - const realUniforms = shader.realUniforms; - const dirtyFlags = glShader.dirtyFlags; // 0 is reserverd for the pixi texture so we start at 1! let textureCount = 1; @@ -98,23 +87,16 @@ // TODO don't need to use the uniform for (const i in uniformData) { - if(dirtyFlags[i] === uniformData[i].dirtyId) - { - //continue; - } - - dirtyFlags[i] = uniformData[i].dirtyId; - if (uniformData[i].type === 'sampler2D' && uniformData[i].value !== 0) { if (uniformData[i].value.baseTexture) { glShader.uniforms[i] = this.renderer.bindTexture(uniformData[i].value, textureCount, true); - // console.log( glShader.uniforms[i]) } else { glShader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably @@ -144,7 +126,7 @@ { // check if its a point.. if (uniformData[i].value.x !== undefined) - { + { const val = glShader.uniforms[i] || new Float32Array(2); val[0] = uniformData[i].value.x; @@ -152,7 +134,7 @@ glShader.uniforms[i] = val; } else - { + { glShader.uniforms[i] = uniformData[i].value; } } @@ -170,13 +152,12 @@ } } - - /** * Destroys this manager and removes all its textures */ destroy() { - + // TODO implement destroy method for ShaderManager + this.destroyed = true; } } diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 026e741..3830e4c 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,7 +9,6 @@ import ShaderManager from './ShaderManager'; import BaseTexture from '../../textures/BaseTexture'; import TextureGarbageCollector from './TextureGarbageCollector'; -import WebGLState from './WebGLState'; import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; import validateContext from './utils/validateContext'; import { pluginTarget } from '../../utils'; @@ -100,7 +99,6 @@ */ this.stencilManager = new StencilManager(this); - /** * An empty renderer. * @@ -447,8 +445,6 @@ this.shaderManager.bindShader(shader, dontSync); } - - /** * Changes the current shader to the one given in parameter * diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 776fad3..93a5d2a 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,4 @@ import Shader from '../../../shader/Shader'; -import { uid } from '../../../utils'; import { BLEND_MODES } from '../../../const'; // let math = require('../../../math'); @@ -17,7 +16,7 @@ */ constructor(vertexSrc, fragmentSrc, uniforms) { - super(vertexSrc, fragmentSrc, uniforms) + super(vertexSrc, fragmentSrc, uniforms); this.blendMode = BLEND_MODES.NORMAL; diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 9466b50..157402a 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -19,7 +19,6 @@ */ constructor(gl) { - /** * The current WebGL rendering context * @@ -51,7 +50,7 @@ // map functions for when we set state.. this.map[BLEND] = this.setBlend; - this.map[OFFSET] = this.setPolygonOffset; + this.map[OFFSET] = this.setOffset; this.map[CULLING] = this.setCullFace; this.map[DEPTH_TEST] = this.setDepthTest; this.map[WINDING] = this.setFrontFace; @@ -67,18 +66,18 @@ setState(state) { // TODO maybe to an object check? ( this.state === state )? - if(this.stateId === state.data)return; + if (this.stateId === state.data) return; let diff = this.stateId ^ state.data; let i = 0; // order from least to most common - while(diff) + while (diff) { - if(diff & 1) + if (diff & 1) { // state change! - this.map[i].call(this, !!(state.data & (1 << i)) ); + this.map[i].call(this, !!(state.data & (1 << i))); } diff = diff >> 1; @@ -91,12 +90,11 @@ for (let i = 0; i < this.checks.length; i++) { this.checks[i](this, state); - }; + } this.stateId = state.data; } - /** * Enables or disabled blending. * @@ -109,7 +107,7 @@ this.gl[value ? 'enable' : 'disable'](this.gl.BLEND); } - setPolygonOffset(value) + setOffset(value) { this.gl[value ? 'enable' : 'disable'](this.gl.POLYGON_OFFSET_FILL); } @@ -209,26 +207,25 @@ this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false); - //TO DO? - //this.setState(this.defaultState); + // TODO? + // this.setState(this.defaultState); } updateCheck(func, value) { const index = this.checks.indexOf(func); - if(value && index === -1) + if (value && index === -1) { this.checks.push(func); } - else if(!value && index !== -1) + else if (!value && index !== -1) { this.checks.splice(index, 1); } - } - //static function maintains scope! + // static function maintains scope! static checkBlendMode(manager, state) { manager.setBlendMode(state.blendMode); diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index bf2620b..826e1b0 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -45,7 +45,10 @@ // does the trick for now though! for (const i in this.uniformData) { - this.uniforms[i] = this.uniformData[i].value; + if(!this.uniforms[i]) + { + this.uniforms[i] = this.uniformData[i].value; + } } // this is where we store shader references.. diff --git a/src/core/shader/generateUniformsSync.js b/src/core/shader/generateUniformsSync.js index e9995d9..278e0f0 100644 --- a/src/core/shader/generateUniformsSync.js +++ b/src/core/shader/generateUniformsSync.js @@ -50,12 +50,14 @@ // TODO && uniformData[i].value !== 0 <-- do we still need this? if (data.type === 'sampler2D') { - func += `\ngl.uniform1iv(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len + func += `\n + + gl.uniform1i(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len } else if (data.type === 'mat3') { func += `\nvalue = uniformValues.${i}; -gl.uniformMatrix3fv(uniformData.${i}.location, false, (value.a !== undefined) ? value : value.toArray(true));\n`; +gl.uniformMatrix3fv(uniformData.${i}.location, false, (value.a === undefined) ? value : value.toArray(true));\n`; } else if (data.type === 'vec2') { diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 3be2cf8..9606b76 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -1,7 +1,5 @@ import { GLShader } from 'pixi-gl-core'; -import { WRAP_MODES, SCALE_MODES, PRECISION} from '../../const'; -import RenderTarget from './utils/RenderTarget'; -import { removeItems } from '../../utils'; +import { PRECISION } from '../../const'; /** * Helper class to create a webGL Texture @@ -35,14 +33,15 @@ bindShader(shader, dontSync) { - // if(this.shader === shader)return; + const glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - this.shader = shader; + if (this.shader !== shader) + { + this.shader = shader; + this.renderer._bindGLShader(glShader); + } - let glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - - this.renderer._bindGLShader(glShader); - if(!dontSync) + if (!dontSync) { this.syncUniforms(glShader, shader); } @@ -58,8 +57,8 @@ generateShader(shader) { - const attribMap = {}; + for (const i in shader.attributeData) { attribMap[i] = shader.attributeData[i].location; @@ -67,17 +66,9 @@ const glShader = new GLShader(this.gl, shader.vertexSrc, shader.fragmentSrc, PRECISION.DEFAULT, attribMap); - //TODO should I add this a s a prototype - glShader.dirtyFlags = {}; - for (var i in shader.realUniforms) { - glShader.dirtyFlags[i] = 0; - }; - console.log(glShader.dirtyFlags) - shader.glShaders[this.renderer.CONTEXT_UID] = glShader; - - return glShader + return glShader; } /** @@ -89,8 +80,6 @@ syncUniforms(glShader, shader) { const uniformData = shader.uniformData; - const realUniforms = shader.realUniforms; - const dirtyFlags = glShader.dirtyFlags; // 0 is reserverd for the pixi texture so we start at 1! let textureCount = 1; @@ -98,23 +87,16 @@ // TODO don't need to use the uniform for (const i in uniformData) { - if(dirtyFlags[i] === uniformData[i].dirtyId) - { - //continue; - } - - dirtyFlags[i] = uniformData[i].dirtyId; - if (uniformData[i].type === 'sampler2D' && uniformData[i].value !== 0) { if (uniformData[i].value.baseTexture) { glShader.uniforms[i] = this.renderer.bindTexture(uniformData[i].value, textureCount, true); - // console.log( glShader.uniforms[i]) } else { glShader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably @@ -144,7 +126,7 @@ { // check if its a point.. if (uniformData[i].value.x !== undefined) - { + { const val = glShader.uniforms[i] || new Float32Array(2); val[0] = uniformData[i].value.x; @@ -152,7 +134,7 @@ glShader.uniforms[i] = val; } else - { + { glShader.uniforms[i] = uniformData[i].value; } } @@ -170,13 +152,12 @@ } } - - /** * Destroys this manager and removes all its textures */ destroy() { - + // TODO implement destroy method for ShaderManager + this.destroyed = true; } } diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 026e741..3830e4c 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,7 +9,6 @@ import ShaderManager from './ShaderManager'; import BaseTexture from '../../textures/BaseTexture'; import TextureGarbageCollector from './TextureGarbageCollector'; -import WebGLState from './WebGLState'; import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; import validateContext from './utils/validateContext'; import { pluginTarget } from '../../utils'; @@ -100,7 +99,6 @@ */ this.stencilManager = new StencilManager(this); - /** * An empty renderer. * @@ -447,8 +445,6 @@ this.shaderManager.bindShader(shader, dontSync); } - - /** * Changes the current shader to the one given in parameter * diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 776fad3..93a5d2a 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,4 @@ import Shader from '../../../shader/Shader'; -import { uid } from '../../../utils'; import { BLEND_MODES } from '../../../const'; // let math = require('../../../math'); @@ -17,7 +16,7 @@ */ constructor(vertexSrc, fragmentSrc, uniforms) { - super(vertexSrc, fragmentSrc, uniforms) + super(vertexSrc, fragmentSrc, uniforms); this.blendMode = BLEND_MODES.NORMAL; diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 9466b50..157402a 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -19,7 +19,6 @@ */ constructor(gl) { - /** * The current WebGL rendering context * @@ -51,7 +50,7 @@ // map functions for when we set state.. this.map[BLEND] = this.setBlend; - this.map[OFFSET] = this.setPolygonOffset; + this.map[OFFSET] = this.setOffset; this.map[CULLING] = this.setCullFace; this.map[DEPTH_TEST] = this.setDepthTest; this.map[WINDING] = this.setFrontFace; @@ -67,18 +66,18 @@ setState(state) { // TODO maybe to an object check? ( this.state === state )? - if(this.stateId === state.data)return; + if (this.stateId === state.data) return; let diff = this.stateId ^ state.data; let i = 0; // order from least to most common - while(diff) + while (diff) { - if(diff & 1) + if (diff & 1) { // state change! - this.map[i].call(this, !!(state.data & (1 << i)) ); + this.map[i].call(this, !!(state.data & (1 << i))); } diff = diff >> 1; @@ -91,12 +90,11 @@ for (let i = 0; i < this.checks.length; i++) { this.checks[i](this, state); - }; + } this.stateId = state.data; } - /** * Enables or disabled blending. * @@ -109,7 +107,7 @@ this.gl[value ? 'enable' : 'disable'](this.gl.BLEND); } - setPolygonOffset(value) + setOffset(value) { this.gl[value ? 'enable' : 'disable'](this.gl.POLYGON_OFFSET_FILL); } @@ -209,26 +207,25 @@ this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false); - //TO DO? - //this.setState(this.defaultState); + // TODO? + // this.setState(this.defaultState); } updateCheck(func, value) { const index = this.checks.indexOf(func); - if(value && index === -1) + if (value && index === -1) { this.checks.push(func); } - else if(!value && index !== -1) + else if (!value && index !== -1) { this.checks.splice(index, 1); } - } - //static function maintains scope! + // static function maintains scope! static checkBlendMode(manager, state) { manager.setBlendMode(state.blendMode); diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index bf2620b..826e1b0 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -45,7 +45,10 @@ // does the trick for now though! for (const i in this.uniformData) { - this.uniforms[i] = this.uniformData[i].value; + if(!this.uniforms[i]) + { + this.uniforms[i] = this.uniformData[i].value; + } } // this is where we store shader references.. diff --git a/src/core/shader/generateUniformsSync.js b/src/core/shader/generateUniformsSync.js index e9995d9..278e0f0 100644 --- a/src/core/shader/generateUniformsSync.js +++ b/src/core/shader/generateUniformsSync.js @@ -50,12 +50,14 @@ // TODO && uniformData[i].value !== 0 <-- do we still need this? if (data.type === 'sampler2D') { - func += `\ngl.uniform1iv(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len + func += `\n + + gl.uniform1i(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len } else if (data.type === 'mat3') { func += `\nvalue = uniformValues.${i}; -gl.uniformMatrix3fv(uniformData.${i}.location, false, (value.a !== undefined) ? value : value.toArray(true));\n`; +gl.uniformMatrix3fv(uniformData.${i}.location, false, (value.a === undefined) ? value : value.toArray(true));\n`; } else if (data.type === 'vec2') { diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 0b07d77..c930e91 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -46,7 +46,7 @@ // TODO uniform auto generation? // make sure to add required feilds - this.uniforms = uniforms; + this.uniforms = uniforms || shader.uniforms; /** * The tint applied to the mesh. This is a [r,g,b] value. A value of [1,1,1] will remove any diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 3be2cf8..9606b76 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -1,7 +1,5 @@ import { GLShader } from 'pixi-gl-core'; -import { WRAP_MODES, SCALE_MODES, PRECISION} from '../../const'; -import RenderTarget from './utils/RenderTarget'; -import { removeItems } from '../../utils'; +import { PRECISION } from '../../const'; /** * Helper class to create a webGL Texture @@ -35,14 +33,15 @@ bindShader(shader, dontSync) { - // if(this.shader === shader)return; + const glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - this.shader = shader; + if (this.shader !== shader) + { + this.shader = shader; + this.renderer._bindGLShader(glShader); + } - let glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - - this.renderer._bindGLShader(glShader); - if(!dontSync) + if (!dontSync) { this.syncUniforms(glShader, shader); } @@ -58,8 +57,8 @@ generateShader(shader) { - const attribMap = {}; + for (const i in shader.attributeData) { attribMap[i] = shader.attributeData[i].location; @@ -67,17 +66,9 @@ const glShader = new GLShader(this.gl, shader.vertexSrc, shader.fragmentSrc, PRECISION.DEFAULT, attribMap); - //TODO should I add this a s a prototype - glShader.dirtyFlags = {}; - for (var i in shader.realUniforms) { - glShader.dirtyFlags[i] = 0; - }; - console.log(glShader.dirtyFlags) - shader.glShaders[this.renderer.CONTEXT_UID] = glShader; - - return glShader + return glShader; } /** @@ -89,8 +80,6 @@ syncUniforms(glShader, shader) { const uniformData = shader.uniformData; - const realUniforms = shader.realUniforms; - const dirtyFlags = glShader.dirtyFlags; // 0 is reserverd for the pixi texture so we start at 1! let textureCount = 1; @@ -98,23 +87,16 @@ // TODO don't need to use the uniform for (const i in uniformData) { - if(dirtyFlags[i] === uniformData[i].dirtyId) - { - //continue; - } - - dirtyFlags[i] = uniformData[i].dirtyId; - if (uniformData[i].type === 'sampler2D' && uniformData[i].value !== 0) { if (uniformData[i].value.baseTexture) { glShader.uniforms[i] = this.renderer.bindTexture(uniformData[i].value, textureCount, true); - // console.log( glShader.uniforms[i]) } else { glShader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably @@ -144,7 +126,7 @@ { // check if its a point.. if (uniformData[i].value.x !== undefined) - { + { const val = glShader.uniforms[i] || new Float32Array(2); val[0] = uniformData[i].value.x; @@ -152,7 +134,7 @@ glShader.uniforms[i] = val; } else - { + { glShader.uniforms[i] = uniformData[i].value; } } @@ -170,13 +152,12 @@ } } - - /** * Destroys this manager and removes all its textures */ destroy() { - + // TODO implement destroy method for ShaderManager + this.destroyed = true; } } diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 026e741..3830e4c 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,7 +9,6 @@ import ShaderManager from './ShaderManager'; import BaseTexture from '../../textures/BaseTexture'; import TextureGarbageCollector from './TextureGarbageCollector'; -import WebGLState from './WebGLState'; import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; import validateContext from './utils/validateContext'; import { pluginTarget } from '../../utils'; @@ -100,7 +99,6 @@ */ this.stencilManager = new StencilManager(this); - /** * An empty renderer. * @@ -447,8 +445,6 @@ this.shaderManager.bindShader(shader, dontSync); } - - /** * Changes the current shader to the one given in parameter * diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 776fad3..93a5d2a 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,4 @@ import Shader from '../../../shader/Shader'; -import { uid } from '../../../utils'; import { BLEND_MODES } from '../../../const'; // let math = require('../../../math'); @@ -17,7 +16,7 @@ */ constructor(vertexSrc, fragmentSrc, uniforms) { - super(vertexSrc, fragmentSrc, uniforms) + super(vertexSrc, fragmentSrc, uniforms); this.blendMode = BLEND_MODES.NORMAL; diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 9466b50..157402a 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -19,7 +19,6 @@ */ constructor(gl) { - /** * The current WebGL rendering context * @@ -51,7 +50,7 @@ // map functions for when we set state.. this.map[BLEND] = this.setBlend; - this.map[OFFSET] = this.setPolygonOffset; + this.map[OFFSET] = this.setOffset; this.map[CULLING] = this.setCullFace; this.map[DEPTH_TEST] = this.setDepthTest; this.map[WINDING] = this.setFrontFace; @@ -67,18 +66,18 @@ setState(state) { // TODO maybe to an object check? ( this.state === state )? - if(this.stateId === state.data)return; + if (this.stateId === state.data) return; let diff = this.stateId ^ state.data; let i = 0; // order from least to most common - while(diff) + while (diff) { - if(diff & 1) + if (diff & 1) { // state change! - this.map[i].call(this, !!(state.data & (1 << i)) ); + this.map[i].call(this, !!(state.data & (1 << i))); } diff = diff >> 1; @@ -91,12 +90,11 @@ for (let i = 0; i < this.checks.length; i++) { this.checks[i](this, state); - }; + } this.stateId = state.data; } - /** * Enables or disabled blending. * @@ -109,7 +107,7 @@ this.gl[value ? 'enable' : 'disable'](this.gl.BLEND); } - setPolygonOffset(value) + setOffset(value) { this.gl[value ? 'enable' : 'disable'](this.gl.POLYGON_OFFSET_FILL); } @@ -209,26 +207,25 @@ this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false); - //TO DO? - //this.setState(this.defaultState); + // TODO? + // this.setState(this.defaultState); } updateCheck(func, value) { const index = this.checks.indexOf(func); - if(value && index === -1) + if (value && index === -1) { this.checks.push(func); } - else if(!value && index !== -1) + else if (!value && index !== -1) { this.checks.splice(index, 1); } - } - //static function maintains scope! + // static function maintains scope! static checkBlendMode(manager, state) { manager.setBlendMode(state.blendMode); diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index bf2620b..826e1b0 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -45,7 +45,10 @@ // does the trick for now though! for (const i in this.uniformData) { - this.uniforms[i] = this.uniformData[i].value; + if(!this.uniforms[i]) + { + this.uniforms[i] = this.uniformData[i].value; + } } // this is where we store shader references.. diff --git a/src/core/shader/generateUniformsSync.js b/src/core/shader/generateUniformsSync.js index e9995d9..278e0f0 100644 --- a/src/core/shader/generateUniformsSync.js +++ b/src/core/shader/generateUniformsSync.js @@ -50,12 +50,14 @@ // TODO && uniformData[i].value !== 0 <-- do we still need this? if (data.type === 'sampler2D') { - func += `\ngl.uniform1iv(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len + func += `\n + + gl.uniform1i(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len } else if (data.type === 'mat3') { func += `\nvalue = uniformValues.${i}; -gl.uniformMatrix3fv(uniformData.${i}.location, false, (value.a !== undefined) ? value : value.toArray(true));\n`; +gl.uniformMatrix3fv(uniformData.${i}.location, false, (value.a === undefined) ? value : value.toArray(true));\n`; } else if (data.type === 'vec2') { diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 0b07d77..c930e91 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -46,7 +46,7 @@ // TODO uniform auto generation? // make sure to add required feilds - this.uniforms = uniforms; + this.uniforms = uniforms || shader.uniforms; /** * The tint applied to the mesh. This is a [r,g,b] value. A value of [1,1,1] will remove any diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index 0589890..752a070 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -42,7 +42,12 @@ .addAttribute('aTextureCoord', new Float32Array(points.length * 4), 2) .addIndex(new Uint16Array(points.length * 2)); - super(geometry, meshShader, {}, 5); + super(geometry, meshShader, { + uSample2:texture, + alpha:1, + tint:new Float32Array([0, 0, 0]), + translationMatrix:this.transform.worldTransform + }, null, 5); this.texture = texture; @@ -60,6 +65,7 @@ */ this._ready = true; + this._tint = 0xFFFFFF; this.tint = 0xFFFFFF; // wait for the texture to load @@ -139,6 +145,17 @@ 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 * @@ -218,19 +235,10 @@ lastPoint = point; } - this.shader.uniforms.alpha = 1; + this.shader.uniforms.alpha = this.alpha; this.shader.uniforms.uSampler2 = this.texture; this.geometry.getAttribute('aVertexPosition').update(); this.containerUpdateTransform(); } - - _renderWebGL(renderer) - { - this.shader.uniforms.tint = core.utils.hex2rgb(this.tint, temp); - this.shader.uniforms.uSampler2 = this.texture; - - renderer.setObjectRenderer(renderer.plugins.mesh); - renderer.plugins.mesh.render(this); - } } diff --git a/src/core/const.js b/src/core/const.js index f670fd8..e4f0f81 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -104,7 +104,7 @@ SATURATION: 14, COLOR: 15, LUMINOSITY: 16, - NONE: 17 + NONE: 17, }; /** diff --git a/src/core/renderers/webgl/ShaderManager.js b/src/core/renderers/webgl/ShaderManager.js index 3be2cf8..9606b76 100644 --- a/src/core/renderers/webgl/ShaderManager.js +++ b/src/core/renderers/webgl/ShaderManager.js @@ -1,7 +1,5 @@ import { GLShader } from 'pixi-gl-core'; -import { WRAP_MODES, SCALE_MODES, PRECISION} from '../../const'; -import RenderTarget from './utils/RenderTarget'; -import { removeItems } from '../../utils'; +import { PRECISION } from '../../const'; /** * Helper class to create a webGL Texture @@ -35,14 +33,15 @@ bindShader(shader, dontSync) { - // if(this.shader === shader)return; + const glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - this.shader = shader; + if (this.shader !== shader) + { + this.shader = shader; + this.renderer._bindGLShader(glShader); + } - let glShader = shader.glShaders[this.renderer.CONTEXT_UID] || this.generateShader(shader); - - this.renderer._bindGLShader(glShader); - if(!dontSync) + if (!dontSync) { this.syncUniforms(glShader, shader); } @@ -58,8 +57,8 @@ generateShader(shader) { - const attribMap = {}; + for (const i in shader.attributeData) { attribMap[i] = shader.attributeData[i].location; @@ -67,17 +66,9 @@ const glShader = new GLShader(this.gl, shader.vertexSrc, shader.fragmentSrc, PRECISION.DEFAULT, attribMap); - //TODO should I add this a s a prototype - glShader.dirtyFlags = {}; - for (var i in shader.realUniforms) { - glShader.dirtyFlags[i] = 0; - }; - console.log(glShader.dirtyFlags) - shader.glShaders[this.renderer.CONTEXT_UID] = glShader; - - return glShader + return glShader; } /** @@ -89,8 +80,6 @@ syncUniforms(glShader, shader) { const uniformData = shader.uniformData; - const realUniforms = shader.realUniforms; - const dirtyFlags = glShader.dirtyFlags; // 0 is reserverd for the pixi texture so we start at 1! let textureCount = 1; @@ -98,23 +87,16 @@ // TODO don't need to use the uniform for (const i in uniformData) { - if(dirtyFlags[i] === uniformData[i].dirtyId) - { - //continue; - } - - dirtyFlags[i] = uniformData[i].dirtyId; - if (uniformData[i].type === 'sampler2D' && uniformData[i].value !== 0) { if (uniformData[i].value.baseTexture) { glShader.uniforms[i] = this.renderer.bindTexture(uniformData[i].value, textureCount, true); - // console.log( glShader.uniforms[i]) } else { glShader.uniforms[i] = textureCount; + // TODO // this is helpful as renderTargets can also be set. // Although thinking about it, we could probably @@ -144,7 +126,7 @@ { // check if its a point.. if (uniformData[i].value.x !== undefined) - { + { const val = glShader.uniforms[i] || new Float32Array(2); val[0] = uniformData[i].value.x; @@ -152,7 +134,7 @@ glShader.uniforms[i] = val; } else - { + { glShader.uniforms[i] = uniformData[i].value; } } @@ -170,13 +152,12 @@ } } - - /** * Destroys this manager and removes all its textures */ destroy() { - + // TODO implement destroy method for ShaderManager + this.destroyed = true; } } diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 026e741..3830e4c 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -9,7 +9,6 @@ import ShaderManager from './ShaderManager'; import BaseTexture from '../../textures/BaseTexture'; import TextureGarbageCollector from './TextureGarbageCollector'; -import WebGLState from './WebGLState'; import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; import validateContext from './utils/validateContext'; import { pluginTarget } from '../../utils'; @@ -100,7 +99,6 @@ */ this.stencilManager = new StencilManager(this); - /** * An empty renderer. * @@ -447,8 +445,6 @@ this.shaderManager.bindShader(shader, dontSync); } - - /** * Changes the current shader to the one given in parameter * diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 776fad3..93a5d2a 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,5 +1,4 @@ import Shader from '../../../shader/Shader'; -import { uid } from '../../../utils'; import { BLEND_MODES } from '../../../const'; // let math = require('../../../math'); @@ -17,7 +16,7 @@ */ constructor(vertexSrc, fragmentSrc, uniforms) { - super(vertexSrc, fragmentSrc, uniforms) + super(vertexSrc, fragmentSrc, uniforms); this.blendMode = BLEND_MODES.NORMAL; diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 9466b50..157402a 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -19,7 +19,6 @@ */ constructor(gl) { - /** * The current WebGL rendering context * @@ -51,7 +50,7 @@ // map functions for when we set state.. this.map[BLEND] = this.setBlend; - this.map[OFFSET] = this.setPolygonOffset; + this.map[OFFSET] = this.setOffset; this.map[CULLING] = this.setCullFace; this.map[DEPTH_TEST] = this.setDepthTest; this.map[WINDING] = this.setFrontFace; @@ -67,18 +66,18 @@ setState(state) { // TODO maybe to an object check? ( this.state === state )? - if(this.stateId === state.data)return; + if (this.stateId === state.data) return; let diff = this.stateId ^ state.data; let i = 0; // order from least to most common - while(diff) + while (diff) { - if(diff & 1) + if (diff & 1) { // state change! - this.map[i].call(this, !!(state.data & (1 << i)) ); + this.map[i].call(this, !!(state.data & (1 << i))); } diff = diff >> 1; @@ -91,12 +90,11 @@ for (let i = 0; i < this.checks.length; i++) { this.checks[i](this, state); - }; + } this.stateId = state.data; } - /** * Enables or disabled blending. * @@ -109,7 +107,7 @@ this.gl[value ? 'enable' : 'disable'](this.gl.BLEND); } - setPolygonOffset(value) + setOffset(value) { this.gl[value ? 'enable' : 'disable'](this.gl.POLYGON_OFFSET_FILL); } @@ -209,26 +207,25 @@ this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL, false); - //TO DO? - //this.setState(this.defaultState); + // TODO? + // this.setState(this.defaultState); } updateCheck(func, value) { const index = this.checks.indexOf(func); - if(value && index === -1) + if (value && index === -1) { this.checks.push(func); } - else if(!value && index !== -1) + else if (!value && index !== -1) { this.checks.splice(index, 1); } - } - //static function maintains scope! + // static function maintains scope! static checkBlendMode(manager, state) { manager.setBlendMode(state.blendMode); diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index bf2620b..826e1b0 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -45,7 +45,10 @@ // does the trick for now though! for (const i in this.uniformData) { - this.uniforms[i] = this.uniformData[i].value; + if(!this.uniforms[i]) + { + this.uniforms[i] = this.uniformData[i].value; + } } // this is where we store shader references.. diff --git a/src/core/shader/generateUniformsSync.js b/src/core/shader/generateUniformsSync.js index e9995d9..278e0f0 100644 --- a/src/core/shader/generateUniformsSync.js +++ b/src/core/shader/generateUniformsSync.js @@ -50,12 +50,14 @@ // TODO && uniformData[i].value !== 0 <-- do we still need this? if (data.type === 'sampler2D') { - func += `\ngl.uniform1iv(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len + func += `\n + + gl.uniform1i(uniformData.${i}.location, renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true) );\n`; // eslint-disable-line max-len } else if (data.type === 'mat3') { func += `\nvalue = uniformValues.${i}; -gl.uniformMatrix3fv(uniformData.${i}.location, false, (value.a !== undefined) ? value : value.toArray(true));\n`; +gl.uniformMatrix3fv(uniformData.${i}.location, false, (value.a === undefined) ? value : value.toArray(true));\n`; } else if (data.type === 'vec2') { diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 0b07d77..c930e91 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -46,7 +46,7 @@ // TODO uniform auto generation? // make sure to add required feilds - this.uniforms = uniforms; + this.uniforms = uniforms || shader.uniforms; /** * The tint applied to the mesh. This is a [r,g,b] value. A value of [1,1,1] will remove any diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index 0589890..752a070 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -42,7 +42,12 @@ .addAttribute('aTextureCoord', new Float32Array(points.length * 4), 2) .addIndex(new Uint16Array(points.length * 2)); - super(geometry, meshShader, {}, 5); + super(geometry, meshShader, { + uSample2:texture, + alpha:1, + tint:new Float32Array([0, 0, 0]), + translationMatrix:this.transform.worldTransform + }, null, 5); this.texture = texture; @@ -60,6 +65,7 @@ */ this._ready = true; + this._tint = 0xFFFFFF; this.tint = 0xFFFFFF; // wait for the texture to load @@ -139,6 +145,17 @@ 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 * @@ -218,19 +235,10 @@ lastPoint = point; } - this.shader.uniforms.alpha = 1; + this.shader.uniforms.alpha = this.alpha; this.shader.uniforms.uSampler2 = this.texture; this.geometry.getAttribute('aVertexPosition').update(); this.containerUpdateTransform(); } - - _renderWebGL(renderer) - { - this.shader.uniforms.tint = core.utils.hex2rgb(this.tint, temp); - this.shader.uniforms.uSampler2 = this.texture; - - renderer.setObjectRenderer(renderer.plugins.mesh); - renderer.plugins.mesh.render(this); - } } diff --git a/src/mesh/webgl/MeshRenderer.js b/src/mesh/webgl/MeshRenderer.js index d6158fb..c7c0a33 100644 --- a/src/mesh/webgl/MeshRenderer.js +++ b/src/mesh/webgl/MeshRenderer.js @@ -37,10 +37,10 @@ render(mesh) { // set the shader props.. - if (mesh.shader.uniforms.translationMatrix) + if (mesh.uniforms.translationMatrix) { // the transform! - mesh.shader.uniforms.translationMatrix = mesh.transform.worldTransform.toArray(true); + mesh.uniforms.translationMatrix = mesh.transform.worldTransform.toArray(true); } // bind the shader..