diff --git a/src/core/shader/Program.js b/src/core/shader/Program.js index da7bcf1..1828d86 100644 --- a/src/core/shader/Program.js +++ b/src/core/shader/Program.js @@ -23,14 +23,14 @@ * * @member {string} */ - this.vertexSrc = vertexSrc || Shader.defaultVertexSrc; + this.vertexSrc = vertexSrc || Program.defaultVertexSrc; /** * The fragment shader. * * @member {string} */ - this.fragmentSrc = fragmentSrc || Shader.defaultFragmentSrc; + this.fragmentSrc = fragmentSrc || Program.defaultFragmentSrc; // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types diff --git a/src/core/shader/Program.js b/src/core/shader/Program.js index da7bcf1..1828d86 100644 --- a/src/core/shader/Program.js +++ b/src/core/shader/Program.js @@ -23,14 +23,14 @@ * * @member {string} */ - this.vertexSrc = vertexSrc || Shader.defaultVertexSrc; + this.vertexSrc = vertexSrc || Program.defaultVertexSrc; /** * The fragment shader. * * @member {string} */ - this.fragmentSrc = fragmentSrc || Shader.defaultFragmentSrc; + this.fragmentSrc = fragmentSrc || Program.defaultFragmentSrc; // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index e488400..2a8cc78 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -1,11 +1,6 @@ -import extractUniformsFromSrc from './extractUniformsFromSrc'; -import extractAttributesFromSrc from './extractAttributesFromSrc'; -import generateUniformsSync from './generateUniformsSync'; import Program from './Program'; import { ProgramCache } from '../utils'; -let UID = 0; - // let math = require('../../../math'); /** * @class @@ -15,8 +10,7 @@ class Shader { /** - * @param {string} [vertexSrc] - The source of the vertex shader. - * @param {string} [fragmentSrc] - The source of the fragment shader. + * @param {PIXI.Program} [program] - The program the shader will use. * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones. */ constructor(program, uniforms) @@ -33,28 +27,33 @@ if (!uniform) { - this.uniforms[i] = program.uniformData[i].value; } - else + else if (uniform instanceof Array) { - if(uniform instanceof Array) - { - this.uniforms[i] = new Float32Array(uniform) - } + this.uniforms[i] = new Float32Array(uniform); } } } + /** + * A short hand function to create a shader based of a vertex and fragment shader + * + * @param {string} [vertexSrc] - The source of the vertex shader. + * @param {string} [fragmentSrc] - The source of the fragment shader. + * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones. + * + * @returns {PIXI.Shader} an shiney new pixi shader. + */ static from(vertexSrc, fragmentSrc, uniforms) { const key = vertexSrc + fragmentSrc; let program = ProgramCache[key]; - if(!program) + if (!program) { - ProgramCache[key] = program = new Program(vertexSrc,fragmentSrc); + ProgramCache[key] = program = new Program(vertexSrc, fragmentSrc); } return new Shader(program, uniforms); diff --git a/src/core/shader/Program.js b/src/core/shader/Program.js index da7bcf1..1828d86 100644 --- a/src/core/shader/Program.js +++ b/src/core/shader/Program.js @@ -23,14 +23,14 @@ * * @member {string} */ - this.vertexSrc = vertexSrc || Shader.defaultVertexSrc; + this.vertexSrc = vertexSrc || Program.defaultVertexSrc; /** * The fragment shader. * * @member {string} */ - this.fragmentSrc = fragmentSrc || Shader.defaultFragmentSrc; + this.fragmentSrc = fragmentSrc || Program.defaultFragmentSrc; // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index e488400..2a8cc78 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -1,11 +1,6 @@ -import extractUniformsFromSrc from './extractUniformsFromSrc'; -import extractAttributesFromSrc from './extractAttributesFromSrc'; -import generateUniformsSync from './generateUniformsSync'; import Program from './Program'; import { ProgramCache } from '../utils'; -let UID = 0; - // let math = require('../../../math'); /** * @class @@ -15,8 +10,7 @@ class Shader { /** - * @param {string} [vertexSrc] - The source of the vertex shader. - * @param {string} [fragmentSrc] - The source of the fragment shader. + * @param {PIXI.Program} [program] - The program the shader will use. * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones. */ constructor(program, uniforms) @@ -33,28 +27,33 @@ if (!uniform) { - this.uniforms[i] = program.uniformData[i].value; } - else + else if (uniform instanceof Array) { - if(uniform instanceof Array) - { - this.uniforms[i] = new Float32Array(uniform) - } + this.uniforms[i] = new Float32Array(uniform); } } } + /** + * A short hand function to create a shader based of a vertex and fragment shader + * + * @param {string} [vertexSrc] - The source of the vertex shader. + * @param {string} [fragmentSrc] - The source of the fragment shader. + * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones. + * + * @returns {PIXI.Shader} an shiney new pixi shader. + */ static from(vertexSrc, fragmentSrc, uniforms) { const key = vertexSrc + fragmentSrc; let program = ProgramCache[key]; - if(!program) + if (!program) { - ProgramCache[key] = program = new Program(vertexSrc,fragmentSrc); + ProgramCache[key] = program = new Program(vertexSrc, fragmentSrc); } return new Shader(program, uniforms); diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 49f7f31..8ff73f7 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -28,7 +28,7 @@ if (!meshProgram) { meshProgram = new core.Program(readFileSync(join(__dirname, './webgl/mesh.vert'), 'utf8'), - readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); + readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); } geometry.addAttribute('aVertexPosition', vertices) @@ -43,8 +43,7 @@ tint: new Float32Array([1, 1, 1]), }; - - super(geometry, new core.Shader(meshProgram,uniforms), null, drawMode); + super(geometry, new core.Shader(meshProgram, uniforms), null, drawMode); this.uniforms = uniforms; this.texture = texture; diff --git a/src/core/shader/Program.js b/src/core/shader/Program.js index da7bcf1..1828d86 100644 --- a/src/core/shader/Program.js +++ b/src/core/shader/Program.js @@ -23,14 +23,14 @@ * * @member {string} */ - this.vertexSrc = vertexSrc || Shader.defaultVertexSrc; + this.vertexSrc = vertexSrc || Program.defaultVertexSrc; /** * The fragment shader. * * @member {string} */ - this.fragmentSrc = fragmentSrc || Shader.defaultFragmentSrc; + this.fragmentSrc = fragmentSrc || Program.defaultFragmentSrc; // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index e488400..2a8cc78 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -1,11 +1,6 @@ -import extractUniformsFromSrc from './extractUniformsFromSrc'; -import extractAttributesFromSrc from './extractAttributesFromSrc'; -import generateUniformsSync from './generateUniformsSync'; import Program from './Program'; import { ProgramCache } from '../utils'; -let UID = 0; - // let math = require('../../../math'); /** * @class @@ -15,8 +10,7 @@ class Shader { /** - * @param {string} [vertexSrc] - The source of the vertex shader. - * @param {string} [fragmentSrc] - The source of the fragment shader. + * @param {PIXI.Program} [program] - The program the shader will use. * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones. */ constructor(program, uniforms) @@ -33,28 +27,33 @@ if (!uniform) { - this.uniforms[i] = program.uniformData[i].value; } - else + else if (uniform instanceof Array) { - if(uniform instanceof Array) - { - this.uniforms[i] = new Float32Array(uniform) - } + this.uniforms[i] = new Float32Array(uniform); } } } + /** + * A short hand function to create a shader based of a vertex and fragment shader + * + * @param {string} [vertexSrc] - The source of the vertex shader. + * @param {string} [fragmentSrc] - The source of the fragment shader. + * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones. + * + * @returns {PIXI.Shader} an shiney new pixi shader. + */ static from(vertexSrc, fragmentSrc, uniforms) { const key = vertexSrc + fragmentSrc; let program = ProgramCache[key]; - if(!program) + if (!program) { - ProgramCache[key] = program = new Program(vertexSrc,fragmentSrc); + ProgramCache[key] = program = new Program(vertexSrc, fragmentSrc); } return new Shader(program, uniforms); diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 49f7f31..8ff73f7 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -28,7 +28,7 @@ if (!meshProgram) { meshProgram = new core.Program(readFileSync(join(__dirname, './webgl/mesh.vert'), 'utf8'), - readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); + readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); } geometry.addAttribute('aVertexPosition', vertices) @@ -43,8 +43,7 @@ tint: new Float32Array([1, 1, 1]), }; - - super(geometry, new core.Shader(meshProgram,uniforms), null, drawMode); + super(geometry, new core.Shader(meshProgram, uniforms), null, drawMode); this.uniforms = uniforms; this.texture = texture; diff --git a/src/mesh/RawMesh.js b/src/mesh/RawMesh.js index 17a969d..2f68e6b 100644 --- a/src/mesh/RawMesh.js +++ b/src/mesh/RawMesh.js @@ -25,8 +25,6 @@ /** * @param {PIXI.mesh.Geometry} geometry the geometry the mesh will use * @param {PIXI.Shader} shader the shader the mesh will use - * @param {Object} uniforms the uniform values that this mesh will specifically use - * (will automatically be generated of not supplied) * @param {PIXI.State} state the state that the webGL context is required to be in to render the mesh * @param {number} drawMode the drawMode, can be any of the PIXI.DRAW_MODES consts */ diff --git a/src/core/shader/Program.js b/src/core/shader/Program.js index da7bcf1..1828d86 100644 --- a/src/core/shader/Program.js +++ b/src/core/shader/Program.js @@ -23,14 +23,14 @@ * * @member {string} */ - this.vertexSrc = vertexSrc || Shader.defaultVertexSrc; + this.vertexSrc = vertexSrc || Program.defaultVertexSrc; /** * The fragment shader. * * @member {string} */ - this.fragmentSrc = fragmentSrc || Shader.defaultFragmentSrc; + this.fragmentSrc = fragmentSrc || Program.defaultFragmentSrc; // pull out the vertex and shader uniforms if they are not specified.. // currently this does not extract structs only default types diff --git a/src/core/shader/Shader.js b/src/core/shader/Shader.js index e488400..2a8cc78 100644 --- a/src/core/shader/Shader.js +++ b/src/core/shader/Shader.js @@ -1,11 +1,6 @@ -import extractUniformsFromSrc from './extractUniformsFromSrc'; -import extractAttributesFromSrc from './extractAttributesFromSrc'; -import generateUniformsSync from './generateUniformsSync'; import Program from './Program'; import { ProgramCache } from '../utils'; -let UID = 0; - // let math = require('../../../math'); /** * @class @@ -15,8 +10,7 @@ class Shader { /** - * @param {string} [vertexSrc] - The source of the vertex shader. - * @param {string} [fragmentSrc] - The source of the fragment shader. + * @param {PIXI.Program} [program] - The program the shader will use. * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones. */ constructor(program, uniforms) @@ -33,28 +27,33 @@ if (!uniform) { - this.uniforms[i] = program.uniformData[i].value; } - else + else if (uniform instanceof Array) { - if(uniform instanceof Array) - { - this.uniforms[i] = new Float32Array(uniform) - } + this.uniforms[i] = new Float32Array(uniform); } } } + /** + * A short hand function to create a shader based of a vertex and fragment shader + * + * @param {string} [vertexSrc] - The source of the vertex shader. + * @param {string} [fragmentSrc] - The source of the fragment shader. + * @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones. + * + * @returns {PIXI.Shader} an shiney new pixi shader. + */ static from(vertexSrc, fragmentSrc, uniforms) { const key = vertexSrc + fragmentSrc; let program = ProgramCache[key]; - if(!program) + if (!program) { - ProgramCache[key] = program = new Program(vertexSrc,fragmentSrc); + ProgramCache[key] = program = new Program(vertexSrc, fragmentSrc); } return new Shader(program, uniforms); diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 49f7f31..8ff73f7 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -28,7 +28,7 @@ if (!meshProgram) { meshProgram = new core.Program(readFileSync(join(__dirname, './webgl/mesh.vert'), 'utf8'), - readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); + readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); } geometry.addAttribute('aVertexPosition', vertices) @@ -43,8 +43,7 @@ tint: new Float32Array([1, 1, 1]), }; - - super(geometry, new core.Shader(meshProgram,uniforms), null, drawMode); + super(geometry, new core.Shader(meshProgram, uniforms), null, drawMode); this.uniforms = uniforms; this.texture = texture; diff --git a/src/mesh/RawMesh.js b/src/mesh/RawMesh.js index 17a969d..2f68e6b 100644 --- a/src/mesh/RawMesh.js +++ b/src/mesh/RawMesh.js @@ -25,8 +25,6 @@ /** * @param {PIXI.mesh.Geometry} geometry the geometry the mesh will use * @param {PIXI.Shader} shader the shader the mesh will use - * @param {Object} uniforms the uniform values that this mesh will specifically use - * (will automatically be generated of not supplied) * @param {PIXI.State} state the state that the webGL context is required to be in to render the mesh * @param {number} drawMode the drawMode, can be any of the PIXI.DRAW_MODES consts */ diff --git a/src/mesh/webgl/MeshRenderer.js b/src/mesh/webgl/MeshRenderer.js index a3a5d35..d657548 100644 --- a/src/mesh/webgl/MeshRenderer.js +++ b/src/mesh/webgl/MeshRenderer.js @@ -66,6 +66,10 @@ mesh.geometry.glVertexArrayObjects[this.CONTEXT_UID].draw(mesh.drawMode, mesh.size, mesh.start); } + /** + * draws mesh + * @param {PIXI.mesh.RawMesh} mesh mesh instance + */ draw(mesh) { mesh.geometry.glVertexArrayObjects[this.CONTEXT_UID].draw(mesh.drawMode, mesh.size, mesh.start); @@ -111,7 +115,6 @@ */ initGeometryVao(geometry, glShader) { - const gl = this.gl; this.renderer.bindVao(null); @@ -134,7 +137,8 @@ } else { - buffer._glBuffers[this.CONTEXT_UID] = glCore.GLBuffer.createVertexBuffer(gl, buffer.data, buffer.static ? gl.STATIC_DRAW : gl.DYNAMIC_DRAW ); + /* eslint-disable max-len */ + buffer._glBuffers[this.CONTEXT_UID] = glCore.GLBuffer.createVertexBuffer(gl, buffer.data, buffer.static ? gl.STATIC_DRAW : gl.DYNAMIC_DRAW); } } }