diff --git a/src/core/Shader.js b/src/core/Shader.js deleted file mode 100644 index 81e076b..0000000 --- a/src/core/Shader.js +++ /dev/null @@ -1,47 +0,0 @@ -import { GLShader } from 'pixi-gl-core'; -import settings from './settings'; - -const { PRECISION } = settings; - -function checkPrecision(src) -{ - if (src instanceof Array) - { - if (src[0].substring(0, 9) !== 'precision') - { - const copy = src.slice(0); - - copy.unshift(`precision ${PRECISION} float;`); - - return copy; - } - } - else if (src.substring(0, 9) !== 'precision') - { - return `precision ${PRECISION} float;\n${src}`; - } - - return src; -} - -/** - * Wrapper class, webGL Shader for Pixi. - * Adds precision string if vertexSrc or fragmentSrc have no mention of it. - * - * @class - * @extends GLShader - * @memberof PIXI - */ -export default class Shader extends GLShader -{ - /** - * - * @param {WebGLRenderingContext} gl - The current WebGL rendering context - * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. - * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. - */ - constructor(gl, vertexSrc, fragmentSrc) - { - super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); - } -} diff --git a/src/core/Shader.js b/src/core/Shader.js deleted file mode 100644 index 81e076b..0000000 --- a/src/core/Shader.js +++ /dev/null @@ -1,47 +0,0 @@ -import { GLShader } from 'pixi-gl-core'; -import settings from './settings'; - -const { PRECISION } = settings; - -function checkPrecision(src) -{ - if (src instanceof Array) - { - if (src[0].substring(0, 9) !== 'precision') - { - const copy = src.slice(0); - - copy.unshift(`precision ${PRECISION} float;`); - - return copy; - } - } - else if (src.substring(0, 9) !== 'precision') - { - return `precision ${PRECISION} float;\n${src}`; - } - - return src; -} - -/** - * Wrapper class, webGL Shader for Pixi. - * Adds precision string if vertexSrc or fragmentSrc have no mention of it. - * - * @class - * @extends GLShader - * @memberof PIXI - */ -export default class Shader extends GLShader -{ - /** - * - * @param {WebGLRenderingContext} gl - The current WebGL rendering context - * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. - * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. - */ - constructor(gl, vertexSrc, fragmentSrc) - { - super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); - } -} diff --git a/src/core/const.js b/src/core/const.js index e4f0f81..5e3aff8 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -134,6 +134,12 @@ TRIANGLE_FAN: 6, }; +export const TYPES = { + FLOAT: 5126, + UNSIGNED_SHORT:5123, + UNSIGNED_BYTE: 5121 +}; + /** * The scale modes that are supported by pixi. * diff --git a/src/core/Shader.js b/src/core/Shader.js deleted file mode 100644 index 81e076b..0000000 --- a/src/core/Shader.js +++ /dev/null @@ -1,47 +0,0 @@ -import { GLShader } from 'pixi-gl-core'; -import settings from './settings'; - -const { PRECISION } = settings; - -function checkPrecision(src) -{ - if (src instanceof Array) - { - if (src[0].substring(0, 9) !== 'precision') - { - const copy = src.slice(0); - - copy.unshift(`precision ${PRECISION} float;`); - - return copy; - } - } - else if (src.substring(0, 9) !== 'precision') - { - return `precision ${PRECISION} float;\n${src}`; - } - - return src; -} - -/** - * Wrapper class, webGL Shader for Pixi. - * Adds precision string if vertexSrc or fragmentSrc have no mention of it. - * - * @class - * @extends GLShader - * @memberof PIXI - */ -export default class Shader extends GLShader -{ - /** - * - * @param {WebGLRenderingContext} gl - The current WebGL rendering context - * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. - * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. - */ - constructor(gl, vertexSrc, fragmentSrc) - { - super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); - } -} diff --git a/src/core/const.js b/src/core/const.js index e4f0f81..5e3aff8 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -134,6 +134,12 @@ TRIANGLE_FAN: 6, }; +export const TYPES = { + FLOAT: 5126, + UNSIGNED_SHORT:5123, + UNSIGNED_BYTE: 5121 +}; + /** * The scale modes that are supported by pixi. * diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 3d2b5da..5f7f584 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -60,6 +60,7 @@ this.defaultState = new WebGLState(); this.defaultState.blend = true; + this.defaultState.depth = true; this.setState(this.defaultState); } diff --git a/src/core/Shader.js b/src/core/Shader.js deleted file mode 100644 index 81e076b..0000000 --- a/src/core/Shader.js +++ /dev/null @@ -1,47 +0,0 @@ -import { GLShader } from 'pixi-gl-core'; -import settings from './settings'; - -const { PRECISION } = settings; - -function checkPrecision(src) -{ - if (src instanceof Array) - { - if (src[0].substring(0, 9) !== 'precision') - { - const copy = src.slice(0); - - copy.unshift(`precision ${PRECISION} float;`); - - return copy; - } - } - else if (src.substring(0, 9) !== 'precision') - { - return `precision ${PRECISION} float;\n${src}`; - } - - return src; -} - -/** - * Wrapper class, webGL Shader for Pixi. - * Adds precision string if vertexSrc or fragmentSrc have no mention of it. - * - * @class - * @extends GLShader - * @memberof PIXI - */ -export default class Shader extends GLShader -{ - /** - * - * @param {WebGLRenderingContext} gl - The current WebGL rendering context - * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. - * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. - */ - constructor(gl, vertexSrc, fragmentSrc) - { - super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); - } -} diff --git a/src/core/const.js b/src/core/const.js index e4f0f81..5e3aff8 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -134,6 +134,12 @@ TRIANGLE_FAN: 6, }; +export const TYPES = { + FLOAT: 5126, + UNSIGNED_SHORT:5123, + UNSIGNED_BYTE: 5121 +}; + /** * The scale modes that are supported by pixi. * diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 3d2b5da..5f7f584 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -60,6 +60,7 @@ this.defaultState = new WebGLState(); this.defaultState.blend = true; + this.defaultState.depth = true; this.setState(this.defaultState); } diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 5a0fc88..74f06a2 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -31,8 +31,8 @@ readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); } - geometry.addAttribute('aVertexPosition', vertices, 2) - .addAttribute('aTextureCoord', uvs, 2) + geometry.addAttribute('aVertexPosition', vertices, 2 * 4) + .addAttribute('aTextureCoord', uvs, 2 * 4) .addIndex(indices); const uniforms = { diff --git a/src/core/Shader.js b/src/core/Shader.js deleted file mode 100644 index 81e076b..0000000 --- a/src/core/Shader.js +++ /dev/null @@ -1,47 +0,0 @@ -import { GLShader } from 'pixi-gl-core'; -import settings from './settings'; - -const { PRECISION } = settings; - -function checkPrecision(src) -{ - if (src instanceof Array) - { - if (src[0].substring(0, 9) !== 'precision') - { - const copy = src.slice(0); - - copy.unshift(`precision ${PRECISION} float;`); - - return copy; - } - } - else if (src.substring(0, 9) !== 'precision') - { - return `precision ${PRECISION} float;\n${src}`; - } - - return src; -} - -/** - * Wrapper class, webGL Shader for Pixi. - * Adds precision string if vertexSrc or fragmentSrc have no mention of it. - * - * @class - * @extends GLShader - * @memberof PIXI - */ -export default class Shader extends GLShader -{ - /** - * - * @param {WebGLRenderingContext} gl - The current WebGL rendering context - * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. - * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. - */ - constructor(gl, vertexSrc, fragmentSrc) - { - super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); - } -} diff --git a/src/core/const.js b/src/core/const.js index e4f0f81..5e3aff8 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -134,6 +134,12 @@ TRIANGLE_FAN: 6, }; +export const TYPES = { + FLOAT: 5126, + UNSIGNED_SHORT:5123, + UNSIGNED_BYTE: 5121 +}; + /** * The scale modes that are supported by pixi. * diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 3d2b5da..5f7f584 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -60,6 +60,7 @@ this.defaultState = new WebGLState(); this.defaultState.blend = true; + this.defaultState.depth = true; this.setState(this.defaultState); } diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 5a0fc88..74f06a2 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -31,8 +31,8 @@ readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); } - geometry.addAttribute('aVertexPosition', vertices, 2) - .addAttribute('aTextureCoord', uvs, 2) + geometry.addAttribute('aVertexPosition', vertices, 2 * 4) + .addAttribute('aTextureCoord', uvs, 2 * 4) .addIndex(indices); const uniforms = { diff --git a/src/mesh/RawMesh.js b/src/mesh/RawMesh.js index 761aa69..f4d59b9 100644 --- a/src/mesh/RawMesh.js +++ b/src/mesh/RawMesh.js @@ -59,8 +59,8 @@ * @default PIXI.BLEND_MODES.NORMAL * @see PIXI.BLEND_MODES */ - this.blendMode = core.BLEND_MODES.NORMAL; - this.state.blendMode = this.blendMode; + //this.blendMode = core.BLEND_MODES.NORMAL; + //this.state.blendMode = this.blendMode; /** * The way the Mesh should be drawn, can be any of the {@link PIXI.mesh.RawMesh.DRAW_MODES} consts diff --git a/src/core/Shader.js b/src/core/Shader.js deleted file mode 100644 index 81e076b..0000000 --- a/src/core/Shader.js +++ /dev/null @@ -1,47 +0,0 @@ -import { GLShader } from 'pixi-gl-core'; -import settings from './settings'; - -const { PRECISION } = settings; - -function checkPrecision(src) -{ - if (src instanceof Array) - { - if (src[0].substring(0, 9) !== 'precision') - { - const copy = src.slice(0); - - copy.unshift(`precision ${PRECISION} float;`); - - return copy; - } - } - else if (src.substring(0, 9) !== 'precision') - { - return `precision ${PRECISION} float;\n${src}`; - } - - return src; -} - -/** - * Wrapper class, webGL Shader for Pixi. - * Adds precision string if vertexSrc or fragmentSrc have no mention of it. - * - * @class - * @extends GLShader - * @memberof PIXI - */ -export default class Shader extends GLShader -{ - /** - * - * @param {WebGLRenderingContext} gl - The current WebGL rendering context - * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. - * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. - */ - constructor(gl, vertexSrc, fragmentSrc) - { - super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); - } -} diff --git a/src/core/const.js b/src/core/const.js index e4f0f81..5e3aff8 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -134,6 +134,12 @@ TRIANGLE_FAN: 6, }; +export const TYPES = { + FLOAT: 5126, + UNSIGNED_SHORT:5123, + UNSIGNED_BYTE: 5121 +}; + /** * The scale modes that are supported by pixi. * diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 3d2b5da..5f7f584 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -60,6 +60,7 @@ this.defaultState = new WebGLState(); this.defaultState.blend = true; + this.defaultState.depth = true; this.setState(this.defaultState); } diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 5a0fc88..74f06a2 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -31,8 +31,8 @@ readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); } - geometry.addAttribute('aVertexPosition', vertices, 2) - .addAttribute('aTextureCoord', uvs, 2) + geometry.addAttribute('aVertexPosition', vertices, 2 * 4) + .addAttribute('aTextureCoord', uvs, 2 * 4) .addIndex(indices); const uniforms = { diff --git a/src/mesh/RawMesh.js b/src/mesh/RawMesh.js index 761aa69..f4d59b9 100644 --- a/src/mesh/RawMesh.js +++ b/src/mesh/RawMesh.js @@ -59,8 +59,8 @@ * @default PIXI.BLEND_MODES.NORMAL * @see PIXI.BLEND_MODES */ - this.blendMode = core.BLEND_MODES.NORMAL; - this.state.blendMode = this.blendMode; + //this.blendMode = core.BLEND_MODES.NORMAL; + //this.state.blendMode = this.blendMode; /** * The way the Mesh should be drawn, can be any of the {@link PIXI.mesh.RawMesh.DRAW_MODES} consts diff --git a/src/mesh/geometry/Attribute.js b/src/mesh/geometry/Attribute.js index c2db4b5..f414439 100644 --- a/src/mesh/geometry/Attribute.js +++ b/src/mesh/geometry/Attribute.js @@ -17,14 +17,13 @@ * @param {Number} [start=0] How far into the array to start reading values (used for interleaving data) * @param {Boolean} [normalised=false] should the data be normalised. */ - constructor(buffer, size = 2, stride = 0, start = 0, normalised = false) + constructor(buffer, normalised = false, type, stride, start) { this.buffer = buffer; this.normalized = normalised; - this.size = size; + this.type = type; this.stride = stride; this.start = start; - this.type = null; } /** diff --git a/src/core/Shader.js b/src/core/Shader.js deleted file mode 100644 index 81e076b..0000000 --- a/src/core/Shader.js +++ /dev/null @@ -1,47 +0,0 @@ -import { GLShader } from 'pixi-gl-core'; -import settings from './settings'; - -const { PRECISION } = settings; - -function checkPrecision(src) -{ - if (src instanceof Array) - { - if (src[0].substring(0, 9) !== 'precision') - { - const copy = src.slice(0); - - copy.unshift(`precision ${PRECISION} float;`); - - return copy; - } - } - else if (src.substring(0, 9) !== 'precision') - { - return `precision ${PRECISION} float;\n${src}`; - } - - return src; -} - -/** - * Wrapper class, webGL Shader for Pixi. - * Adds precision string if vertexSrc or fragmentSrc have no mention of it. - * - * @class - * @extends GLShader - * @memberof PIXI - */ -export default class Shader extends GLShader -{ - /** - * - * @param {WebGLRenderingContext} gl - The current WebGL rendering context - * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. - * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. - */ - constructor(gl, vertexSrc, fragmentSrc) - { - super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); - } -} diff --git a/src/core/const.js b/src/core/const.js index e4f0f81..5e3aff8 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -134,6 +134,12 @@ TRIANGLE_FAN: 6, }; +export const TYPES = { + FLOAT: 5126, + UNSIGNED_SHORT:5123, + UNSIGNED_BYTE: 5121 +}; + /** * The scale modes that are supported by pixi. * diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 3d2b5da..5f7f584 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -60,6 +60,7 @@ this.defaultState = new WebGLState(); this.defaultState.blend = true; + this.defaultState.depth = true; this.setState(this.defaultState); } diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 5a0fc88..74f06a2 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -31,8 +31,8 @@ readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); } - geometry.addAttribute('aVertexPosition', vertices, 2) - .addAttribute('aTextureCoord', uvs, 2) + geometry.addAttribute('aVertexPosition', vertices, 2 * 4) + .addAttribute('aTextureCoord', uvs, 2 * 4) .addIndex(indices); const uniforms = { diff --git a/src/mesh/RawMesh.js b/src/mesh/RawMesh.js index 761aa69..f4d59b9 100644 --- a/src/mesh/RawMesh.js +++ b/src/mesh/RawMesh.js @@ -59,8 +59,8 @@ * @default PIXI.BLEND_MODES.NORMAL * @see PIXI.BLEND_MODES */ - this.blendMode = core.BLEND_MODES.NORMAL; - this.state.blendMode = this.blendMode; + //this.blendMode = core.BLEND_MODES.NORMAL; + //this.state.blendMode = this.blendMode; /** * The way the Mesh should be drawn, can be any of the {@link PIXI.mesh.RawMesh.DRAW_MODES} consts diff --git a/src/mesh/geometry/Attribute.js b/src/mesh/geometry/Attribute.js index c2db4b5..f414439 100644 --- a/src/mesh/geometry/Attribute.js +++ b/src/mesh/geometry/Attribute.js @@ -17,14 +17,13 @@ * @param {Number} [start=0] How far into the array to start reading values (used for interleaving data) * @param {Boolean} [normalised=false] should the data be normalised. */ - constructor(buffer, size = 2, stride = 0, start = 0, normalised = false) + constructor(buffer, normalised = false, type, stride, start) { this.buffer = buffer; this.normalized = normalised; - this.size = size; + this.type = type; this.stride = stride; this.start = start; - this.type = null; } /** diff --git a/src/mesh/geometry/Geometry.js b/src/mesh/geometry/Geometry.js index 51aea50..3458ac2 100644 --- a/src/mesh/geometry/Geometry.js +++ b/src/mesh/geometry/Geometry.js @@ -1,7 +1,5 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import GeometryStyle from './GeometryStyle'; -import GeometryData from './GeometryData'; /* eslint-disable max-len */ @@ -28,22 +26,16 @@ export default class Geometry { /** - * @param {PIXI.mesh.GeometryData} data optional structure of the model such as the attributes layout - * @param {PIXI.mesh.GeometryStyle} style optional data of the model, this consists of buffers. + * @param {array} data this consists of buffers. optional. + * @param {object} attributes of the geometry, optional structure of the attributes layout */ - constructor(data, style) + constructor(buffers, attributes) { - /** - * the style of the geometry - * @type {PIXI.mesh.GeometryStyle} - */ - this.style = style || new GeometryStyle(); + this.buffers = buffers || []; - /** - * the data of the geometry - * @type {PIXI.mesh.GeometryData} - */ - this.data = data || new GeometryData(); + this.indexBuffer = null; + + this.attributes = attributes || {}; /** * A map of renderer IDs to webgl VAOs @@ -67,7 +59,7 @@ * * @return {PIXI.mesh.Geometry} returns self, useful for chaining. */ - addAttribute(id, buffer, size = 2, stride = 0, start = 0, normalised = false) + addAttribute(id, buffer, normalised = false, type, stride, start) { // check if this is a buffer! if (!buffer.data) @@ -81,12 +73,27 @@ buffer = new Buffer(buffer); } - this.style.addAttribute(id, new Attribute(buffer.id, size, stride, start, normalised)); - this.data.add(buffer.id, buffer); + var ids = id.split('|'); - // dynamically create an access point.. - // TODO - is this good or Bad? - this[id] = buffer; + if(ids.length > 1) + { + for (var i = 0; i < ids.length; i++) + { + this.addAttribute(ids[i], buffer, normalised, type) + } + + return this; + } + + let bufferIndex = this.buffers.indexOf(buffer); + + if (bufferIndex === -1) + { + this.buffers.push(buffer); + bufferIndex = this.buffers.length-1 + } + + this.attributes[id] = new Attribute(bufferIndex, normalised, type, stride, start); return this; } @@ -99,7 +106,7 @@ */ getAttribute(id) { - return this.data[this.style.attributes[id].buffer]; + return this.buffers[this.attributes[id].buffer]; } /** @@ -112,7 +119,24 @@ */ addIndex(buffer) { - this.data.addIndex(buffer); + if (!buffer.data) + { + // its an array! + if (buffer instanceof Array) + { + buffer = new Uint16Array(buffer); + } + + buffer = new Buffer(buffer); + } + + buffer.index = true; + this.indexBuffer = buffer; + + if (this.buffers.indexOf(buffer) === -1) + { + this.buffers.push(buffer); + } return this; } @@ -124,7 +148,7 @@ */ getIndex() { - return this.data.indexBuffer; + return this.indexBuffer; } /** @@ -139,7 +163,14 @@ this.glVertexArrayObjects = null; - this.data.destroy(); - this.style.destroy(); + for (let i = 0; i < this.buffers.length; i++) + { + this.buffers[i].destroy(); + } + + this.buffers = null; + this.indexBuffer.destroy(); + + this.attributes = null; } } diff --git a/src/core/Shader.js b/src/core/Shader.js deleted file mode 100644 index 81e076b..0000000 --- a/src/core/Shader.js +++ /dev/null @@ -1,47 +0,0 @@ -import { GLShader } from 'pixi-gl-core'; -import settings from './settings'; - -const { PRECISION } = settings; - -function checkPrecision(src) -{ - if (src instanceof Array) - { - if (src[0].substring(0, 9) !== 'precision') - { - const copy = src.slice(0); - - copy.unshift(`precision ${PRECISION} float;`); - - return copy; - } - } - else if (src.substring(0, 9) !== 'precision') - { - return `precision ${PRECISION} float;\n${src}`; - } - - return src; -} - -/** - * Wrapper class, webGL Shader for Pixi. - * Adds precision string if vertexSrc or fragmentSrc have no mention of it. - * - * @class - * @extends GLShader - * @memberof PIXI - */ -export default class Shader extends GLShader -{ - /** - * - * @param {WebGLRenderingContext} gl - The current WebGL rendering context - * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. - * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. - */ - constructor(gl, vertexSrc, fragmentSrc) - { - super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); - } -} diff --git a/src/core/const.js b/src/core/const.js index e4f0f81..5e3aff8 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -134,6 +134,12 @@ TRIANGLE_FAN: 6, }; +export const TYPES = { + FLOAT: 5126, + UNSIGNED_SHORT:5123, + UNSIGNED_BYTE: 5121 +}; + /** * The scale modes that are supported by pixi. * diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 3d2b5da..5f7f584 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -60,6 +60,7 @@ this.defaultState = new WebGLState(); this.defaultState.blend = true; + this.defaultState.depth = true; this.setState(this.defaultState); } diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 5a0fc88..74f06a2 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -31,8 +31,8 @@ readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); } - geometry.addAttribute('aVertexPosition', vertices, 2) - .addAttribute('aTextureCoord', uvs, 2) + geometry.addAttribute('aVertexPosition', vertices, 2 * 4) + .addAttribute('aTextureCoord', uvs, 2 * 4) .addIndex(indices); const uniforms = { diff --git a/src/mesh/RawMesh.js b/src/mesh/RawMesh.js index 761aa69..f4d59b9 100644 --- a/src/mesh/RawMesh.js +++ b/src/mesh/RawMesh.js @@ -59,8 +59,8 @@ * @default PIXI.BLEND_MODES.NORMAL * @see PIXI.BLEND_MODES */ - this.blendMode = core.BLEND_MODES.NORMAL; - this.state.blendMode = this.blendMode; + //this.blendMode = core.BLEND_MODES.NORMAL; + //this.state.blendMode = this.blendMode; /** * The way the Mesh should be drawn, can be any of the {@link PIXI.mesh.RawMesh.DRAW_MODES} consts diff --git a/src/mesh/geometry/Attribute.js b/src/mesh/geometry/Attribute.js index c2db4b5..f414439 100644 --- a/src/mesh/geometry/Attribute.js +++ b/src/mesh/geometry/Attribute.js @@ -17,14 +17,13 @@ * @param {Number} [start=0] How far into the array to start reading values (used for interleaving data) * @param {Boolean} [normalised=false] should the data be normalised. */ - constructor(buffer, size = 2, stride = 0, start = 0, normalised = false) + constructor(buffer, normalised = false, type, stride, start) { this.buffer = buffer; this.normalized = normalised; - this.size = size; + this.type = type; this.stride = stride; this.start = start; - this.type = null; } /** diff --git a/src/mesh/geometry/Geometry.js b/src/mesh/geometry/Geometry.js index 51aea50..3458ac2 100644 --- a/src/mesh/geometry/Geometry.js +++ b/src/mesh/geometry/Geometry.js @@ -1,7 +1,5 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import GeometryStyle from './GeometryStyle'; -import GeometryData from './GeometryData'; /* eslint-disable max-len */ @@ -28,22 +26,16 @@ export default class Geometry { /** - * @param {PIXI.mesh.GeometryData} data optional structure of the model such as the attributes layout - * @param {PIXI.mesh.GeometryStyle} style optional data of the model, this consists of buffers. + * @param {array} data this consists of buffers. optional. + * @param {object} attributes of the geometry, optional structure of the attributes layout */ - constructor(data, style) + constructor(buffers, attributes) { - /** - * the style of the geometry - * @type {PIXI.mesh.GeometryStyle} - */ - this.style = style || new GeometryStyle(); + this.buffers = buffers || []; - /** - * the data of the geometry - * @type {PIXI.mesh.GeometryData} - */ - this.data = data || new GeometryData(); + this.indexBuffer = null; + + this.attributes = attributes || {}; /** * A map of renderer IDs to webgl VAOs @@ -67,7 +59,7 @@ * * @return {PIXI.mesh.Geometry} returns self, useful for chaining. */ - addAttribute(id, buffer, size = 2, stride = 0, start = 0, normalised = false) + addAttribute(id, buffer, normalised = false, type, stride, start) { // check if this is a buffer! if (!buffer.data) @@ -81,12 +73,27 @@ buffer = new Buffer(buffer); } - this.style.addAttribute(id, new Attribute(buffer.id, size, stride, start, normalised)); - this.data.add(buffer.id, buffer); + var ids = id.split('|'); - // dynamically create an access point.. - // TODO - is this good or Bad? - this[id] = buffer; + if(ids.length > 1) + { + for (var i = 0; i < ids.length; i++) + { + this.addAttribute(ids[i], buffer, normalised, type) + } + + return this; + } + + let bufferIndex = this.buffers.indexOf(buffer); + + if (bufferIndex === -1) + { + this.buffers.push(buffer); + bufferIndex = this.buffers.length-1 + } + + this.attributes[id] = new Attribute(bufferIndex, normalised, type, stride, start); return this; } @@ -99,7 +106,7 @@ */ getAttribute(id) { - return this.data[this.style.attributes[id].buffer]; + return this.buffers[this.attributes[id].buffer]; } /** @@ -112,7 +119,24 @@ */ addIndex(buffer) { - this.data.addIndex(buffer); + if (!buffer.data) + { + // its an array! + if (buffer instanceof Array) + { + buffer = new Uint16Array(buffer); + } + + buffer = new Buffer(buffer); + } + + buffer.index = true; + this.indexBuffer = buffer; + + if (this.buffers.indexOf(buffer) === -1) + { + this.buffers.push(buffer); + } return this; } @@ -124,7 +148,7 @@ */ getIndex() { - return this.data.indexBuffer; + return this.indexBuffer; } /** @@ -139,7 +163,14 @@ this.glVertexArrayObjects = null; - this.data.destroy(); - this.style.destroy(); + for (let i = 0; i < this.buffers.length; i++) + { + this.buffers[i].destroy(); + } + + this.buffers = null; + this.indexBuffer.destroy(); + + this.attributes = null; } } diff --git a/src/mesh/geometry/GeometryStyle.js b/src/mesh/geometry/GeometryStyle.js deleted file mode 100644 index a2efa88..0000000 --- a/src/mesh/geometry/GeometryStyle.js +++ /dev/null @@ -1,84 +0,0 @@ -/** - * GeometryStyle represents the structure of the geometry such as the attributes layout. - * - * ```js - * let geometryStyle = new PIXI.mesh.GeometryStyle(); - * - * geometryStyle.addAttribute('positions, new PIXI.mesh.Attribute('positionBuffer', 2)); - * geometryStyle.addAttribute('uvs', new PIXI.mesh.Attribute('uvsBuffer', 2); - * - * ``` - * @class - * @memberof PIXI.mesh.GeometryStyle - */ -export default class GeometryStyle -{ - /** - * - */ - constructor() - { - /** - * key-value pair contains all the attributes for this style - * - * @member {Object} - */ - this.attributes = {}; - } - - // TODO rename this to add? - - /** - * - * Adds an attribute to the geometryStyle - * - * @param {String} id - the name of the attribute (matching up to a shader) - * @param {PIXI.mesh.Attribute} [attribute] the Attribute that you would like to add to the style. - * - * @return {PIXI.mesh.GeometryStyle} returns self, useful for chaining. - */ - addAttribute(id, attribute) - { - this.attributes[id] = attribute; - - return this; - } - - /** - * generates a map of what the locations of the attributes will be. - * All attributes locations are assigned in alphabetical order just like the {PIXI.Shader} attribute locations. - * This ensures that all geometries and shaders will be compatible if they have the same attributes. - * - * @private - * @return {object} map with key-value pairs mapping attribute names to locations (ints). - */ - generateAttributeLocations() - { - const array = []; - let i; - - for (i in this.attributes) - { - array.push(i); - } - - array.sort(); - - const map = {}; - - for (i = 0; i < array.length; i++) - { - map[array[i]] = i; - } - - return map; - } - - /** - * Destroys the geometryStyle. - */ - destroy() - { - this.attributes = null; - } -} diff --git a/src/core/Shader.js b/src/core/Shader.js deleted file mode 100644 index 81e076b..0000000 --- a/src/core/Shader.js +++ /dev/null @@ -1,47 +0,0 @@ -import { GLShader } from 'pixi-gl-core'; -import settings from './settings'; - -const { PRECISION } = settings; - -function checkPrecision(src) -{ - if (src instanceof Array) - { - if (src[0].substring(0, 9) !== 'precision') - { - const copy = src.slice(0); - - copy.unshift(`precision ${PRECISION} float;`); - - return copy; - } - } - else if (src.substring(0, 9) !== 'precision') - { - return `precision ${PRECISION} float;\n${src}`; - } - - return src; -} - -/** - * Wrapper class, webGL Shader for Pixi. - * Adds precision string if vertexSrc or fragmentSrc have no mention of it. - * - * @class - * @extends GLShader - * @memberof PIXI - */ -export default class Shader extends GLShader -{ - /** - * - * @param {WebGLRenderingContext} gl - The current WebGL rendering context - * @param {string|string[]} vertexSrc - The vertex shader source as an array of strings. - * @param {string|string[]} fragmentSrc - The fragment shader source as an array of strings. - */ - constructor(gl, vertexSrc, fragmentSrc) - { - super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); - } -} diff --git a/src/core/const.js b/src/core/const.js index e4f0f81..5e3aff8 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -134,6 +134,12 @@ TRIANGLE_FAN: 6, }; +export const TYPES = { + FLOAT: 5126, + UNSIGNED_SHORT:5123, + UNSIGNED_BYTE: 5121 +}; + /** * The scale modes that are supported by pixi. * diff --git a/src/core/renderers/webgl/managers/StateManager.js b/src/core/renderers/webgl/managers/StateManager.js index 3d2b5da..5f7f584 100755 --- a/src/core/renderers/webgl/managers/StateManager.js +++ b/src/core/renderers/webgl/managers/StateManager.js @@ -60,6 +60,7 @@ this.defaultState = new WebGLState(); this.defaultState.blend = true; + this.defaultState.depth = true; this.setState(this.defaultState); } diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 5a0fc88..74f06a2 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -31,8 +31,8 @@ readFileSync(join(__dirname, './webgl/mesh.frag'), 'utf8')); } - geometry.addAttribute('aVertexPosition', vertices, 2) - .addAttribute('aTextureCoord', uvs, 2) + geometry.addAttribute('aVertexPosition', vertices, 2 * 4) + .addAttribute('aTextureCoord', uvs, 2 * 4) .addIndex(indices); const uniforms = { diff --git a/src/mesh/RawMesh.js b/src/mesh/RawMesh.js index 761aa69..f4d59b9 100644 --- a/src/mesh/RawMesh.js +++ b/src/mesh/RawMesh.js @@ -59,8 +59,8 @@ * @default PIXI.BLEND_MODES.NORMAL * @see PIXI.BLEND_MODES */ - this.blendMode = core.BLEND_MODES.NORMAL; - this.state.blendMode = this.blendMode; + //this.blendMode = core.BLEND_MODES.NORMAL; + //this.state.blendMode = this.blendMode; /** * The way the Mesh should be drawn, can be any of the {@link PIXI.mesh.RawMesh.DRAW_MODES} consts diff --git a/src/mesh/geometry/Attribute.js b/src/mesh/geometry/Attribute.js index c2db4b5..f414439 100644 --- a/src/mesh/geometry/Attribute.js +++ b/src/mesh/geometry/Attribute.js @@ -17,14 +17,13 @@ * @param {Number} [start=0] How far into the array to start reading values (used for interleaving data) * @param {Boolean} [normalised=false] should the data be normalised. */ - constructor(buffer, size = 2, stride = 0, start = 0, normalised = false) + constructor(buffer, normalised = false, type, stride, start) { this.buffer = buffer; this.normalized = normalised; - this.size = size; + this.type = type; this.stride = stride; this.start = start; - this.type = null; } /** diff --git a/src/mesh/geometry/Geometry.js b/src/mesh/geometry/Geometry.js index 51aea50..3458ac2 100644 --- a/src/mesh/geometry/Geometry.js +++ b/src/mesh/geometry/Geometry.js @@ -1,7 +1,5 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import GeometryStyle from './GeometryStyle'; -import GeometryData from './GeometryData'; /* eslint-disable max-len */ @@ -28,22 +26,16 @@ export default class Geometry { /** - * @param {PIXI.mesh.GeometryData} data optional structure of the model such as the attributes layout - * @param {PIXI.mesh.GeometryStyle} style optional data of the model, this consists of buffers. + * @param {array} data this consists of buffers. optional. + * @param {object} attributes of the geometry, optional structure of the attributes layout */ - constructor(data, style) + constructor(buffers, attributes) { - /** - * the style of the geometry - * @type {PIXI.mesh.GeometryStyle} - */ - this.style = style || new GeometryStyle(); + this.buffers = buffers || []; - /** - * the data of the geometry - * @type {PIXI.mesh.GeometryData} - */ - this.data = data || new GeometryData(); + this.indexBuffer = null; + + this.attributes = attributes || {}; /** * A map of renderer IDs to webgl VAOs @@ -67,7 +59,7 @@ * * @return {PIXI.mesh.Geometry} returns self, useful for chaining. */ - addAttribute(id, buffer, size = 2, stride = 0, start = 0, normalised = false) + addAttribute(id, buffer, normalised = false, type, stride, start) { // check if this is a buffer! if (!buffer.data) @@ -81,12 +73,27 @@ buffer = new Buffer(buffer); } - this.style.addAttribute(id, new Attribute(buffer.id, size, stride, start, normalised)); - this.data.add(buffer.id, buffer); + var ids = id.split('|'); - // dynamically create an access point.. - // TODO - is this good or Bad? - this[id] = buffer; + if(ids.length > 1) + { + for (var i = 0; i < ids.length; i++) + { + this.addAttribute(ids[i], buffer, normalised, type) + } + + return this; + } + + let bufferIndex = this.buffers.indexOf(buffer); + + if (bufferIndex === -1) + { + this.buffers.push(buffer); + bufferIndex = this.buffers.length-1 + } + + this.attributes[id] = new Attribute(bufferIndex, normalised, type, stride, start); return this; } @@ -99,7 +106,7 @@ */ getAttribute(id) { - return this.data[this.style.attributes[id].buffer]; + return this.buffers[this.attributes[id].buffer]; } /** @@ -112,7 +119,24 @@ */ addIndex(buffer) { - this.data.addIndex(buffer); + if (!buffer.data) + { + // its an array! + if (buffer instanceof Array) + { + buffer = new Uint16Array(buffer); + } + + buffer = new Buffer(buffer); + } + + buffer.index = true; + this.indexBuffer = buffer; + + if (this.buffers.indexOf(buffer) === -1) + { + this.buffers.push(buffer); + } return this; } @@ -124,7 +148,7 @@ */ getIndex() { - return this.data.indexBuffer; + return this.indexBuffer; } /** @@ -139,7 +163,14 @@ this.glVertexArrayObjects = null; - this.data.destroy(); - this.style.destroy(); + for (let i = 0; i < this.buffers.length; i++) + { + this.buffers[i].destroy(); + } + + this.buffers = null; + this.indexBuffer.destroy(); + + this.attributes = null; } } diff --git a/src/mesh/geometry/GeometryStyle.js b/src/mesh/geometry/GeometryStyle.js deleted file mode 100644 index a2efa88..0000000 --- a/src/mesh/geometry/GeometryStyle.js +++ /dev/null @@ -1,84 +0,0 @@ -/** - * GeometryStyle represents the structure of the geometry such as the attributes layout. - * - * ```js - * let geometryStyle = new PIXI.mesh.GeometryStyle(); - * - * geometryStyle.addAttribute('positions, new PIXI.mesh.Attribute('positionBuffer', 2)); - * geometryStyle.addAttribute('uvs', new PIXI.mesh.Attribute('uvsBuffer', 2); - * - * ``` - * @class - * @memberof PIXI.mesh.GeometryStyle - */ -export default class GeometryStyle -{ - /** - * - */ - constructor() - { - /** - * key-value pair contains all the attributes for this style - * - * @member {Object} - */ - this.attributes = {}; - } - - // TODO rename this to add? - - /** - * - * Adds an attribute to the geometryStyle - * - * @param {String} id - the name of the attribute (matching up to a shader) - * @param {PIXI.mesh.Attribute} [attribute] the Attribute that you would like to add to the style. - * - * @return {PIXI.mesh.GeometryStyle} returns self, useful for chaining. - */ - addAttribute(id, attribute) - { - this.attributes[id] = attribute; - - return this; - } - - /** - * generates a map of what the locations of the attributes will be. - * All attributes locations are assigned in alphabetical order just like the {PIXI.Shader} attribute locations. - * This ensures that all geometries and shaders will be compatible if they have the same attributes. - * - * @private - * @return {object} map with key-value pairs mapping attribute names to locations (ints). - */ - generateAttributeLocations() - { - const array = []; - let i; - - for (i in this.attributes) - { - array.push(i); - } - - array.sort(); - - const map = {}; - - for (i = 0; i < array.length; i++) - { - map[array[i]] = i; - } - - return map; - } - - /** - * Destroys the geometryStyle. - */ - destroy() - { - this.attributes = null; - } -} diff --git a/src/mesh/webgl/MeshRenderer.js b/src/mesh/webgl/MeshRenderer.js index 2eff855..30507eb 100644 --- a/src/mesh/webgl/MeshRenderer.js +++ b/src/mesh/webgl/MeshRenderer.js @@ -57,7 +57,7 @@ this.renderer.state.setState(mesh.state); // bind the geometry... - this.bindGeometry(mesh.geometry); + this.bindGeometry(mesh.geometry, glShader); // then render it.. mesh.geometry.glVertexArrayObjects[this.CONTEXT_UID].draw(mesh.drawMode, mesh.size, mesh.start); @@ -68,20 +68,18 @@ * @private * @param {PIXI.mesh.Geometry} geometry instance of geometry to bind */ - bindGeometry(geometry) + bindGeometry(geometry, glShader) { - const vao = geometry.glVertexArrayObjects[this.CONTEXT_UID] || this.initGeometryVao(geometry); + const vao = geometry.glVertexArrayObjects[this.CONTEXT_UID] || this.initGeometryVao(geometry, glShader); this.renderer.bindVao(vao); - const data = geometry.data; - // TODO - optimise later! // don't need to loop through if nothing changed! // maybe look to add an 'autoupdate' to geometry? - for (let i = 0; i < data.buffers.length; i++) + for (let i = 0; i < geometry.buffers.length; i++) { - const buffer = data.buffers[i]; + const buffer = geometry.buffers[i]; const glBuffer = buffer._glBuffers[this.CONTEXT_UID]; @@ -100,7 +98,7 @@ * @param {PIXI.mesh.Geometry} geometry instance of geometry to to generate Vao for * @return {PIXI.glCore.VertexArrayObject} Returns a fresh vao. */ - initGeometryVao(geometry) + initGeometryVao(geometry, glShader) { const gl = this.gl; @@ -108,7 +106,9 @@ const vao = this.renderer.createVao(); - const buffers = geometry.data.buffers; + const buffers = geometry.buffers; + const attributes = geometry.attributes; + // first update - and creat the buffers! for (let i = 0; i < buffers.length; i++) @@ -128,30 +128,53 @@ } } - if (geometry.data.indexBuffer) + + if (geometry.indexBuffer) { // first update the index buffer if we have one.. - vao.addIndex(geometry.data.indexBuffer._glBuffers[this.CONTEXT_UID]); + vao.addIndex(geometry.indexBuffer._glBuffers[this.CONTEXT_UID]); } - const map = geometry.style.generateAttributeLocations(); + var stride = 0; + const tempStride = {}; + const tempStart = {}; + + for(const j in buffers) + { + tempStride[buffers[j].id] = 0; + tempStart[buffers[j].id] = 0; + } + + for (const j in attributes) + { + // calculate stride.. + tempStride[attributes[j].buffer] += glShader.attributes[j].size; + //assuming float for now! + } + + let start = 0; + + + console.log(buffers) + console.log(attributes) // next update the attributes buffer.. - for (const j in geometry.style.attributes) + for (const j in attributes) { - const attribute = geometry.style.attributes[j]; - const buffer = geometry.data[attribute.buffer]; + const attribute = attributes[j]; + const buffer = buffers[attribute.buffer]; - // need to know the shader.. - // or DO we... NOPE! const glBuffer = buffer._glBuffers[this.CONTEXT_UID]; - vao.addAttribute(glBuffer, { - size: attribute.size, - location: map[j], - }, gl.FLOAT, false, attribute.stride, attribute.start); + // need to know the shader as it means we can be lazy and let pixi do the work for us.. + // stride, start, type? + vao.addAttribute(glBuffer, glShader.attributes[j], attribute.type || 5126, attribute.normalized, 0, 0)//, tempStride[attribute.buffer] * 4, tempStart[attribute.buffer] * 4); + + tempStart[attribute.buffer] += glShader.attributes[j].size } + console.log(vao); + geometry.glVertexArrayObjects[this.CONTEXT_UID] = vao; return vao;