diff --git a/packages/core/src/batch/AbstractBatchRenderer.js b/packages/core/src/batch/AbstractBatchRenderer.js index 6e5f9d1..7b4d061 100644 --- a/packages/core/src/batch/AbstractBatchRenderer.js +++ b/packages/core/src/batch/AbstractBatchRenderer.js @@ -1,7 +1,6 @@ import builtinAttributeDefinitions from './utils/builtinAttributeDefinitions'; import BatchDrawCall from './BatchDrawCall'; import BaseTexture from '../textures/BaseTexture'; -import builtinAttributeSizes from './utils/builtinAttributeSizes'; import State from '../state/State'; import ObjectRenderer from './ObjectRenderer'; import checkMaxIfStatementsInShader from '../shader/utils/checkMaxIfStatementsInShader'; @@ -11,7 +10,7 @@ import { ENV } from '@pixi/constants'; /** - * @typedef Object AttributeDefinition + * @typedef {Object} AttributeDefinition * @memberof PIXI * * @description @@ -30,6 +29,8 @@ * to the geometry. * @property {number} glSize - number of elements as glType which * compose one attribute. + * + * @see PIXI.AbstractBatchRenderer#attributeDefinitions */ /** @@ -86,9 +87,8 @@ /** * Array of attribute definitions that are used to * pass attribute data from your objects to the vertex - * shader. + * shader. Default values are given below: * - * @default * | Index | property | name | type | size | glType | glSize | * |-------|------------|-----------------|-----------|------|----------------------|--------| * | 1 | vertexData | aVertexPosition | `float32` | 2 | TYPES.FLOAT | 1 | @@ -765,16 +765,16 @@ if (typeof definition !== 'string') { - vertexSize += attributeDefinitions[d].size; + vertexSize += attributeDefinitions[d]._wordSize; } else { - if (!builtinAttributeSizes[definition]) + if (!builtinAttributeDefinitions[definition]) { throw new Error(`${definition} is not a builtin attribute!`); } - vertexSize += builtinAttributeSizes[definition]; + vertexSize += builtinAttributeDefinitions[definition]._wordSize; } } diff --git a/packages/core/src/batch/AbstractBatchRenderer.js b/packages/core/src/batch/AbstractBatchRenderer.js index 6e5f9d1..7b4d061 100644 --- a/packages/core/src/batch/AbstractBatchRenderer.js +++ b/packages/core/src/batch/AbstractBatchRenderer.js @@ -1,7 +1,6 @@ import builtinAttributeDefinitions from './utils/builtinAttributeDefinitions'; import BatchDrawCall from './BatchDrawCall'; import BaseTexture from '../textures/BaseTexture'; -import builtinAttributeSizes from './utils/builtinAttributeSizes'; import State from '../state/State'; import ObjectRenderer from './ObjectRenderer'; import checkMaxIfStatementsInShader from '../shader/utils/checkMaxIfStatementsInShader'; @@ -11,7 +10,7 @@ import { ENV } from '@pixi/constants'; /** - * @typedef Object AttributeDefinition + * @typedef {Object} AttributeDefinition * @memberof PIXI * * @description @@ -30,6 +29,8 @@ * to the geometry. * @property {number} glSize - number of elements as glType which * compose one attribute. + * + * @see PIXI.AbstractBatchRenderer#attributeDefinitions */ /** @@ -86,9 +87,8 @@ /** * Array of attribute definitions that are used to * pass attribute data from your objects to the vertex - * shader. + * shader. Default values are given below: * - * @default * | Index | property | name | type | size | glType | glSize | * |-------|------------|-----------------|-----------|------|----------------------|--------| * | 1 | vertexData | aVertexPosition | `float32` | 2 | TYPES.FLOAT | 1 | @@ -765,16 +765,16 @@ if (typeof definition !== 'string') { - vertexSize += attributeDefinitions[d].size; + vertexSize += attributeDefinitions[d]._wordSize; } else { - if (!builtinAttributeSizes[definition]) + if (!builtinAttributeDefinitions[definition]) { throw new Error(`${definition} is not a builtin attribute!`); } - vertexSize += builtinAttributeSizes[definition]; + vertexSize += builtinAttributeDefinitions[definition]._wordSize; } } diff --git a/packages/core/src/batch/BatchGeometry.js b/packages/core/src/batch/BatchGeometry.js index 8154746..ad67273 100644 --- a/packages/core/src/batch/BatchGeometry.js +++ b/packages/core/src/batch/BatchGeometry.js @@ -1,8 +1,29 @@ import Buffer from '../geometry/Buffer'; -import builtinAttributeSizes from './utils/builtinAttributeSizes'; +import builtinAttributeDefinitions from './utils/builtinAttributeDefinitions'; import Geometry from '../geometry/Geometry'; import { TYPES } from '@pixi/constants'; +const defaultAttributes = [ + { + property: 'vertexData', + name: 'aVertexPosition', + type: 'float32', + size: 2, + glType: TYPES.FLOAT, + glSize: 2, + }, + { + property: 'uvs', + name: 'aTextureCoord', + type: 'float32', + size: 2, + glType: TYPES.FLOAT, + glSize: 2, + }, + 'aColor', // built-in attribute + 'aTextureId', +]; + /** * Geometry used to batch standard PIXI content (e.g. Mesh, Sprite, * Graphics objects). @@ -15,9 +36,9 @@ /** * @param {boolean} [_static=false] Optimization flag, where `false` * is updated every frame, `true` doesn't change frame-to-frame. - * @param {Object[]} attributeDefinitions - attribute definitions + * @param {Array} attributeDefinitions - attribute definitions */ - constructor(_static = false, attributeDefinitions) + constructor(_static = false, attributeDefinitions = defaultAttributes) { super(); @@ -38,21 +59,23 @@ this._indexBuffer = new Buffer(null, _static, true); /* These are automatically interleaved by GeometrySystem. */ - attributeDefinitions.forEach((def) => + for (let i = 0; i < attributeDefinitions.length; i++) { + const def = attributeDefinitions[i]; + if (def === 'aColor') { // special this.addAttribute('aColor', this._buffer, 4, true, TYPES.UNSIGNED_BYTE); - - return; + continue; } const isBuiltin = (typeof def === 'string'); const identifier = isBuiltin ? def : def.name; - const size = isBuiltin ? builtinAttributeSizes[identifier] : def.glSize; + const size = isBuiltin ? builtinAttributeDefinitions[identifier].glSize : def.glSize; + const type = isBuiltin ? builtinAttributeDefinitions[identifier].glType : def.glType; - this.addAttribute(identifier, this._buffer, size, def === 'aTextureId', def.glType); - }); + this.addAttribute(identifier, this._buffer, size, def === 'aTextureId', type); + } this.addIndex(this._indexBuffer); } diff --git a/packages/core/src/batch/AbstractBatchRenderer.js b/packages/core/src/batch/AbstractBatchRenderer.js index 6e5f9d1..7b4d061 100644 --- a/packages/core/src/batch/AbstractBatchRenderer.js +++ b/packages/core/src/batch/AbstractBatchRenderer.js @@ -1,7 +1,6 @@ import builtinAttributeDefinitions from './utils/builtinAttributeDefinitions'; import BatchDrawCall from './BatchDrawCall'; import BaseTexture from '../textures/BaseTexture'; -import builtinAttributeSizes from './utils/builtinAttributeSizes'; import State from '../state/State'; import ObjectRenderer from './ObjectRenderer'; import checkMaxIfStatementsInShader from '../shader/utils/checkMaxIfStatementsInShader'; @@ -11,7 +10,7 @@ import { ENV } from '@pixi/constants'; /** - * @typedef Object AttributeDefinition + * @typedef {Object} AttributeDefinition * @memberof PIXI * * @description @@ -30,6 +29,8 @@ * to the geometry. * @property {number} glSize - number of elements as glType which * compose one attribute. + * + * @see PIXI.AbstractBatchRenderer#attributeDefinitions */ /** @@ -86,9 +87,8 @@ /** * Array of attribute definitions that are used to * pass attribute data from your objects to the vertex - * shader. + * shader. Default values are given below: * - * @default * | Index | property | name | type | size | glType | glSize | * |-------|------------|-----------------|-----------|------|----------------------|--------| * | 1 | vertexData | aVertexPosition | `float32` | 2 | TYPES.FLOAT | 1 | @@ -765,16 +765,16 @@ if (typeof definition !== 'string') { - vertexSize += attributeDefinitions[d].size; + vertexSize += attributeDefinitions[d]._wordSize; } else { - if (!builtinAttributeSizes[definition]) + if (!builtinAttributeDefinitions[definition]) { throw new Error(`${definition} is not a builtin attribute!`); } - vertexSize += builtinAttributeSizes[definition]; + vertexSize += builtinAttributeDefinitions[definition]._wordSize; } } diff --git a/packages/core/src/batch/BatchGeometry.js b/packages/core/src/batch/BatchGeometry.js index 8154746..ad67273 100644 --- a/packages/core/src/batch/BatchGeometry.js +++ b/packages/core/src/batch/BatchGeometry.js @@ -1,8 +1,29 @@ import Buffer from '../geometry/Buffer'; -import builtinAttributeSizes from './utils/builtinAttributeSizes'; +import builtinAttributeDefinitions from './utils/builtinAttributeDefinitions'; import Geometry from '../geometry/Geometry'; import { TYPES } from '@pixi/constants'; +const defaultAttributes = [ + { + property: 'vertexData', + name: 'aVertexPosition', + type: 'float32', + size: 2, + glType: TYPES.FLOAT, + glSize: 2, + }, + { + property: 'uvs', + name: 'aTextureCoord', + type: 'float32', + size: 2, + glType: TYPES.FLOAT, + glSize: 2, + }, + 'aColor', // built-in attribute + 'aTextureId', +]; + /** * Geometry used to batch standard PIXI content (e.g. Mesh, Sprite, * Graphics objects). @@ -15,9 +36,9 @@ /** * @param {boolean} [_static=false] Optimization flag, where `false` * is updated every frame, `true` doesn't change frame-to-frame. - * @param {Object[]} attributeDefinitions - attribute definitions + * @param {Array} attributeDefinitions - attribute definitions */ - constructor(_static = false, attributeDefinitions) + constructor(_static = false, attributeDefinitions = defaultAttributes) { super(); @@ -38,21 +59,23 @@ this._indexBuffer = new Buffer(null, _static, true); /* These are automatically interleaved by GeometrySystem. */ - attributeDefinitions.forEach((def) => + for (let i = 0; i < attributeDefinitions.length; i++) { + const def = attributeDefinitions[i]; + if (def === 'aColor') { // special this.addAttribute('aColor', this._buffer, 4, true, TYPES.UNSIGNED_BYTE); - - return; + continue; } const isBuiltin = (typeof def === 'string'); const identifier = isBuiltin ? def : def.name; - const size = isBuiltin ? builtinAttributeSizes[identifier] : def.glSize; + const size = isBuiltin ? builtinAttributeDefinitions[identifier].glSize : def.glSize; + const type = isBuiltin ? builtinAttributeDefinitions[identifier].glType : def.glType; - this.addAttribute(identifier, this._buffer, size, def === 'aTextureId', def.glType); - }); + this.addAttribute(identifier, this._buffer, size, def === 'aTextureId', type); + } this.addIndex(this._indexBuffer); } diff --git a/packages/core/src/batch/utils/builtinAttributeSizes.js b/packages/core/src/batch/utils/builtinAttributeSizes.js deleted file mode 100644 index 2ffb06f..0000000 --- a/packages/core/src/batch/utils/builtinAttributeSizes.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Sizes of built-in attributes provided by `BatchRenderer`, - * which includes the required `aTextureId` attribute. - * - * @type Map - * @see {AbstractBatchRenderer#vertexSizeOf} - */ -export const builtinAttributeSizes = { - aColor: 1, - aTextureId: 1, -}; - -export default builtinAttributeSizes;