diff --git a/packages/constants/src/index.js b/packages/constants/src/index.js index c92ea55..64a3a0a 100644 --- a/packages/constants/src/index.js +++ b/packages/constants/src/index.js @@ -212,43 +212,6 @@ UNSIGNED_SHORT_5_5_5_1: 32820, FLOAT: 5126, HALF_FLOAT: 36193, - - /** - * Returns if any type in the `TYPES` enum is of integer - * nature. - * - * @param {number} glint - `TYPES` types - * @return if `glint` is an integral type - */ - isInteger(glint) - { - return (glint !== TYPES.FLOAT) && (glint !== TYPES.HALF_FLOAT); - }, - - /** - * Returns the size of any type in the `TYPES` enum. - * - * @param {number} glint - TYPES enum constant - * @return size of `glint` in bytes - */ - sizeOf(glint) - { - switch (glint) - { - case TYPES.FLOAT: - return 4; - case TYPES.HALF_FLOAT: - case TYPES.UNSIGNED_SHORT_5_5_5_1: - case TYPES.UNSIGNED_SHORT_4_4_4_4: - case TYPES.UNSIGNED_SHORT_5_6_5: - case TYPES.UNSIGNED_SHORT: - return 2; - case TYPES.UNSIGNED_BYTE: - return 1; - default: - throw new Error(`{$glint} isn't a TYPES enum!`); - } - }, }; /** diff --git a/packages/constants/src/index.js b/packages/constants/src/index.js index c92ea55..64a3a0a 100644 --- a/packages/constants/src/index.js +++ b/packages/constants/src/index.js @@ -212,43 +212,6 @@ UNSIGNED_SHORT_5_5_5_1: 32820, FLOAT: 5126, HALF_FLOAT: 36193, - - /** - * Returns if any type in the `TYPES` enum is of integer - * nature. - * - * @param {number} glint - `TYPES` types - * @return if `glint` is an integral type - */ - isInteger(glint) - { - return (glint !== TYPES.FLOAT) && (glint !== TYPES.HALF_FLOAT); - }, - - /** - * Returns the size of any type in the `TYPES` enum. - * - * @param {number} glint - TYPES enum constant - * @return size of `glint` in bytes - */ - sizeOf(glint) - { - switch (glint) - { - case TYPES.FLOAT: - return 4; - case TYPES.HALF_FLOAT: - case TYPES.UNSIGNED_SHORT_5_5_5_1: - case TYPES.UNSIGNED_SHORT_4_4_4_4: - case TYPES.UNSIGNED_SHORT_5_6_5: - case TYPES.UNSIGNED_SHORT: - return 2; - case TYPES.UNSIGNED_BYTE: - return 1; - default: - throw new Error(`{$glint} isn't a TYPES enum!`); - } - }, }; /** diff --git a/packages/core/src/batch/AbstractBatchRenderer.js b/packages/core/src/batch/AbstractBatchRenderer.js index 104f521..6cea4b8 100644 --- a/packages/core/src/batch/AbstractBatchRenderer.js +++ b/packages/core/src/batch/AbstractBatchRenderer.js @@ -11,6 +11,28 @@ import { ENV } from '@pixi/constants'; /** + * @typedef Object AttributeDefinition + * @memberof PIXI + * + * @description + * Holds the information required to pass attributes from + * renderable objects to the WebGL vertex shader. + * + * @property {string} property - the property of rendered objects + * that hold the attributes. + * @property {string} name - attribute identifier in the GLSL + * vertex shader. + * @property {string} type - type of the attribute. It can be + * any of the view types of `PIXI.ViewableBuffer`. + * @property {number} size - number of elements in the property + * array that compose one attribute. + * @property {PIXI.TYPES} glType - type of the attribute as given + * to the geometry. + * @property {number} glSize - number of elements as glType which + * compose one attribute. + */ + +/** * Renderer dedicated to drawing and batching sprites. * * This is the default batch renderer. It buffers objects @@ -62,33 +84,9 @@ this.geometryClass = null; /** - * Array of attribute definitions that are described - * below. These are used to pass attribute data - * from your objects to the vertex shader. - * - * An attribute definition is an object with the - * following properties: - * - * | Property | Description | - * |------------|-----------------------------------------------| - * | property | Property name in objects for attribute data | - * | name | Name of attribute variable used in the shader | - * | size | Size of each attribute element in floats | - * - * `BatchRenderer` provides a few built-in attributes - * that you can use like `aColor`. Instead of the - * attribute definition, just give the name to - * use them. - * - * The `attribute float aTextureId` attribute should - * _always_ be present in your shader. See - * `PIXI.BatchShaderGenerator` for more details. - * - * NOTE: It is expected that the attribute buffers - * store an equal number of elements. For example, - * `object.vertexData.length = object.uvs.length`. Otherwise, - * wrapping will occur so that the attribute data is repeated - * for each vertex. + * Array of attribute definitions that are used to + * pass attribute data from your objects to the vertex + * shader. * * @default * | Index | property | name | type | size | glType | glSize | @@ -98,6 +96,7 @@ * | 3 | undefined | aColor | `uint32` | 1 | TYPES.UNSIGNED_BYTE | 4 | * | 4 | undefined | aTextureId | `float32` | 1 | TYPES.FLOAT | 1 | * + * @type {PIXI.AttributeDefinitions[]} * @readonly */ this.attributeDefinitions = null; @@ -747,9 +746,7 @@ * definitions. It also accounts for built-in attributes. * * @param {Array} attributeDefinitions - attribute definitions - * @return sum of all attribute sizes\ - * @function - * @memberof PIXI.AbstractBatchRenderer + * @return sum of all attribute sizes * @static */ static vertexSizeOf(attributeDefinitions) diff --git a/packages/constants/src/index.js b/packages/constants/src/index.js index c92ea55..64a3a0a 100644 --- a/packages/constants/src/index.js +++ b/packages/constants/src/index.js @@ -212,43 +212,6 @@ UNSIGNED_SHORT_5_5_5_1: 32820, FLOAT: 5126, HALF_FLOAT: 36193, - - /** - * Returns if any type in the `TYPES` enum is of integer - * nature. - * - * @param {number} glint - `TYPES` types - * @return if `glint` is an integral type - */ - isInteger(glint) - { - return (glint !== TYPES.FLOAT) && (glint !== TYPES.HALF_FLOAT); - }, - - /** - * Returns the size of any type in the `TYPES` enum. - * - * @param {number} glint - TYPES enum constant - * @return size of `glint` in bytes - */ - sizeOf(glint) - { - switch (glint) - { - case TYPES.FLOAT: - return 4; - case TYPES.HALF_FLOAT: - case TYPES.UNSIGNED_SHORT_5_5_5_1: - case TYPES.UNSIGNED_SHORT_4_4_4_4: - case TYPES.UNSIGNED_SHORT_5_6_5: - case TYPES.UNSIGNED_SHORT: - return 2; - case TYPES.UNSIGNED_BYTE: - return 1; - default: - throw new Error(`{$glint} isn't a TYPES enum!`); - } - }, }; /** diff --git a/packages/core/src/batch/AbstractBatchRenderer.js b/packages/core/src/batch/AbstractBatchRenderer.js index 104f521..6cea4b8 100644 --- a/packages/core/src/batch/AbstractBatchRenderer.js +++ b/packages/core/src/batch/AbstractBatchRenderer.js @@ -11,6 +11,28 @@ import { ENV } from '@pixi/constants'; /** + * @typedef Object AttributeDefinition + * @memberof PIXI + * + * @description + * Holds the information required to pass attributes from + * renderable objects to the WebGL vertex shader. + * + * @property {string} property - the property of rendered objects + * that hold the attributes. + * @property {string} name - attribute identifier in the GLSL + * vertex shader. + * @property {string} type - type of the attribute. It can be + * any of the view types of `PIXI.ViewableBuffer`. + * @property {number} size - number of elements in the property + * array that compose one attribute. + * @property {PIXI.TYPES} glType - type of the attribute as given + * to the geometry. + * @property {number} glSize - number of elements as glType which + * compose one attribute. + */ + +/** * Renderer dedicated to drawing and batching sprites. * * This is the default batch renderer. It buffers objects @@ -62,33 +84,9 @@ this.geometryClass = null; /** - * Array of attribute definitions that are described - * below. These are used to pass attribute data - * from your objects to the vertex shader. - * - * An attribute definition is an object with the - * following properties: - * - * | Property | Description | - * |------------|-----------------------------------------------| - * | property | Property name in objects for attribute data | - * | name | Name of attribute variable used in the shader | - * | size | Size of each attribute element in floats | - * - * `BatchRenderer` provides a few built-in attributes - * that you can use like `aColor`. Instead of the - * attribute definition, just give the name to - * use them. - * - * The `attribute float aTextureId` attribute should - * _always_ be present in your shader. See - * `PIXI.BatchShaderGenerator` for more details. - * - * NOTE: It is expected that the attribute buffers - * store an equal number of elements. For example, - * `object.vertexData.length = object.uvs.length`. Otherwise, - * wrapping will occur so that the attribute data is repeated - * for each vertex. + * Array of attribute definitions that are used to + * pass attribute data from your objects to the vertex + * shader. * * @default * | Index | property | name | type | size | glType | glSize | @@ -98,6 +96,7 @@ * | 3 | undefined | aColor | `uint32` | 1 | TYPES.UNSIGNED_BYTE | 4 | * | 4 | undefined | aTextureId | `float32` | 1 | TYPES.FLOAT | 1 | * + * @type {PIXI.AttributeDefinitions[]} * @readonly */ this.attributeDefinitions = null; @@ -747,9 +746,7 @@ * definitions. It also accounts for built-in attributes. * * @param {Array} attributeDefinitions - attribute definitions - * @return sum of all attribute sizes\ - * @function - * @memberof PIXI.AbstractBatchRenderer + * @return sum of all attribute sizes * @static */ static vertexSizeOf(attributeDefinitions) diff --git a/packages/core/src/batch/BatchPluginFactory.js b/packages/core/src/batch/BatchPluginFactory.js index 455e29a..aad5e68 100644 --- a/packages/core/src/batch/BatchPluginFactory.js +++ b/packages/core/src/batch/BatchPluginFactory.js @@ -2,6 +2,8 @@ import BatchGeometry from './BatchGeometry'; import AbstractBatchRenderer from './AbstractBatchRenderer'; import ViewableBuffer from '../geometry/ViewableBuffer'; + +import { sizeOfType } from '@pixi/utils'; import { TYPES } from '@pixi/constants'; import defaultVertex from './texture.vert'; @@ -140,7 +142,7 @@ + 'your elements with additional bytes.'); } - const outputSize = TYPES.sizeOf(def.glType) * def.glSize; + const outputSize = sizeOfType(def.glType) * def.glSize; if (outputSize !== inputSize) { diff --git a/packages/constants/src/index.js b/packages/constants/src/index.js index c92ea55..64a3a0a 100644 --- a/packages/constants/src/index.js +++ b/packages/constants/src/index.js @@ -212,43 +212,6 @@ UNSIGNED_SHORT_5_5_5_1: 32820, FLOAT: 5126, HALF_FLOAT: 36193, - - /** - * Returns if any type in the `TYPES` enum is of integer - * nature. - * - * @param {number} glint - `TYPES` types - * @return if `glint` is an integral type - */ - isInteger(glint) - { - return (glint !== TYPES.FLOAT) && (glint !== TYPES.HALF_FLOAT); - }, - - /** - * Returns the size of any type in the `TYPES` enum. - * - * @param {number} glint - TYPES enum constant - * @return size of `glint` in bytes - */ - sizeOf(glint) - { - switch (glint) - { - case TYPES.FLOAT: - return 4; - case TYPES.HALF_FLOAT: - case TYPES.UNSIGNED_SHORT_5_5_5_1: - case TYPES.UNSIGNED_SHORT_4_4_4_4: - case TYPES.UNSIGNED_SHORT_5_6_5: - case TYPES.UNSIGNED_SHORT: - return 2; - case TYPES.UNSIGNED_BYTE: - return 1; - default: - throw new Error(`{$glint} isn't a TYPES enum!`); - } - }, }; /** diff --git a/packages/core/src/batch/AbstractBatchRenderer.js b/packages/core/src/batch/AbstractBatchRenderer.js index 104f521..6cea4b8 100644 --- a/packages/core/src/batch/AbstractBatchRenderer.js +++ b/packages/core/src/batch/AbstractBatchRenderer.js @@ -11,6 +11,28 @@ import { ENV } from '@pixi/constants'; /** + * @typedef Object AttributeDefinition + * @memberof PIXI + * + * @description + * Holds the information required to pass attributes from + * renderable objects to the WebGL vertex shader. + * + * @property {string} property - the property of rendered objects + * that hold the attributes. + * @property {string} name - attribute identifier in the GLSL + * vertex shader. + * @property {string} type - type of the attribute. It can be + * any of the view types of `PIXI.ViewableBuffer`. + * @property {number} size - number of elements in the property + * array that compose one attribute. + * @property {PIXI.TYPES} glType - type of the attribute as given + * to the geometry. + * @property {number} glSize - number of elements as glType which + * compose one attribute. + */ + +/** * Renderer dedicated to drawing and batching sprites. * * This is the default batch renderer. It buffers objects @@ -62,33 +84,9 @@ this.geometryClass = null; /** - * Array of attribute definitions that are described - * below. These are used to pass attribute data - * from your objects to the vertex shader. - * - * An attribute definition is an object with the - * following properties: - * - * | Property | Description | - * |------------|-----------------------------------------------| - * | property | Property name in objects for attribute data | - * | name | Name of attribute variable used in the shader | - * | size | Size of each attribute element in floats | - * - * `BatchRenderer` provides a few built-in attributes - * that you can use like `aColor`. Instead of the - * attribute definition, just give the name to - * use them. - * - * The `attribute float aTextureId` attribute should - * _always_ be present in your shader. See - * `PIXI.BatchShaderGenerator` for more details. - * - * NOTE: It is expected that the attribute buffers - * store an equal number of elements. For example, - * `object.vertexData.length = object.uvs.length`. Otherwise, - * wrapping will occur so that the attribute data is repeated - * for each vertex. + * Array of attribute definitions that are used to + * pass attribute data from your objects to the vertex + * shader. * * @default * | Index | property | name | type | size | glType | glSize | @@ -98,6 +96,7 @@ * | 3 | undefined | aColor | `uint32` | 1 | TYPES.UNSIGNED_BYTE | 4 | * | 4 | undefined | aTextureId | `float32` | 1 | TYPES.FLOAT | 1 | * + * @type {PIXI.AttributeDefinitions[]} * @readonly */ this.attributeDefinitions = null; @@ -747,9 +746,7 @@ * definitions. It also accounts for built-in attributes. * * @param {Array} attributeDefinitions - attribute definitions - * @return sum of all attribute sizes\ - * @function - * @memberof PIXI.AbstractBatchRenderer + * @return sum of all attribute sizes * @static */ static vertexSizeOf(attributeDefinitions) diff --git a/packages/core/src/batch/BatchPluginFactory.js b/packages/core/src/batch/BatchPluginFactory.js index 455e29a..aad5e68 100644 --- a/packages/core/src/batch/BatchPluginFactory.js +++ b/packages/core/src/batch/BatchPluginFactory.js @@ -2,6 +2,8 @@ import BatchGeometry from './BatchGeometry'; import AbstractBatchRenderer from './AbstractBatchRenderer'; import ViewableBuffer from '../geometry/ViewableBuffer'; + +import { sizeOfType } from '@pixi/utils'; import { TYPES } from '@pixi/constants'; import defaultVertex from './texture.vert'; @@ -140,7 +142,7 @@ + 'your elements with additional bytes.'); } - const outputSize = TYPES.sizeOf(def.glType) * def.glSize; + const outputSize = sizeOfType(def.glType) * def.glSize; if (outputSize !== inputSize) { diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index e77949c..6e78c02 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -2,4 +2,5 @@ export * from './removeItems'; export * from './uid'; export * from './sign'; +export * from './sizeOfType'; export * from './pow2'; diff --git a/packages/constants/src/index.js b/packages/constants/src/index.js index c92ea55..64a3a0a 100644 --- a/packages/constants/src/index.js +++ b/packages/constants/src/index.js @@ -212,43 +212,6 @@ UNSIGNED_SHORT_5_5_5_1: 32820, FLOAT: 5126, HALF_FLOAT: 36193, - - /** - * Returns if any type in the `TYPES` enum is of integer - * nature. - * - * @param {number} glint - `TYPES` types - * @return if `glint` is an integral type - */ - isInteger(glint) - { - return (glint !== TYPES.FLOAT) && (glint !== TYPES.HALF_FLOAT); - }, - - /** - * Returns the size of any type in the `TYPES` enum. - * - * @param {number} glint - TYPES enum constant - * @return size of `glint` in bytes - */ - sizeOf(glint) - { - switch (glint) - { - case TYPES.FLOAT: - return 4; - case TYPES.HALF_FLOAT: - case TYPES.UNSIGNED_SHORT_5_5_5_1: - case TYPES.UNSIGNED_SHORT_4_4_4_4: - case TYPES.UNSIGNED_SHORT_5_6_5: - case TYPES.UNSIGNED_SHORT: - return 2; - case TYPES.UNSIGNED_BYTE: - return 1; - default: - throw new Error(`{$glint} isn't a TYPES enum!`); - } - }, }; /** diff --git a/packages/core/src/batch/AbstractBatchRenderer.js b/packages/core/src/batch/AbstractBatchRenderer.js index 104f521..6cea4b8 100644 --- a/packages/core/src/batch/AbstractBatchRenderer.js +++ b/packages/core/src/batch/AbstractBatchRenderer.js @@ -11,6 +11,28 @@ import { ENV } from '@pixi/constants'; /** + * @typedef Object AttributeDefinition + * @memberof PIXI + * + * @description + * Holds the information required to pass attributes from + * renderable objects to the WebGL vertex shader. + * + * @property {string} property - the property of rendered objects + * that hold the attributes. + * @property {string} name - attribute identifier in the GLSL + * vertex shader. + * @property {string} type - type of the attribute. It can be + * any of the view types of `PIXI.ViewableBuffer`. + * @property {number} size - number of elements in the property + * array that compose one attribute. + * @property {PIXI.TYPES} glType - type of the attribute as given + * to the geometry. + * @property {number} glSize - number of elements as glType which + * compose one attribute. + */ + +/** * Renderer dedicated to drawing and batching sprites. * * This is the default batch renderer. It buffers objects @@ -62,33 +84,9 @@ this.geometryClass = null; /** - * Array of attribute definitions that are described - * below. These are used to pass attribute data - * from your objects to the vertex shader. - * - * An attribute definition is an object with the - * following properties: - * - * | Property | Description | - * |------------|-----------------------------------------------| - * | property | Property name in objects for attribute data | - * | name | Name of attribute variable used in the shader | - * | size | Size of each attribute element in floats | - * - * `BatchRenderer` provides a few built-in attributes - * that you can use like `aColor`. Instead of the - * attribute definition, just give the name to - * use them. - * - * The `attribute float aTextureId` attribute should - * _always_ be present in your shader. See - * `PIXI.BatchShaderGenerator` for more details. - * - * NOTE: It is expected that the attribute buffers - * store an equal number of elements. For example, - * `object.vertexData.length = object.uvs.length`. Otherwise, - * wrapping will occur so that the attribute data is repeated - * for each vertex. + * Array of attribute definitions that are used to + * pass attribute data from your objects to the vertex + * shader. * * @default * | Index | property | name | type | size | glType | glSize | @@ -98,6 +96,7 @@ * | 3 | undefined | aColor | `uint32` | 1 | TYPES.UNSIGNED_BYTE | 4 | * | 4 | undefined | aTextureId | `float32` | 1 | TYPES.FLOAT | 1 | * + * @type {PIXI.AttributeDefinitions[]} * @readonly */ this.attributeDefinitions = null; @@ -747,9 +746,7 @@ * definitions. It also accounts for built-in attributes. * * @param {Array} attributeDefinitions - attribute definitions - * @return sum of all attribute sizes\ - * @function - * @memberof PIXI.AbstractBatchRenderer + * @return sum of all attribute sizes * @static */ static vertexSizeOf(attributeDefinitions) diff --git a/packages/core/src/batch/BatchPluginFactory.js b/packages/core/src/batch/BatchPluginFactory.js index 455e29a..aad5e68 100644 --- a/packages/core/src/batch/BatchPluginFactory.js +++ b/packages/core/src/batch/BatchPluginFactory.js @@ -2,6 +2,8 @@ import BatchGeometry from './BatchGeometry'; import AbstractBatchRenderer from './AbstractBatchRenderer'; import ViewableBuffer from '../geometry/ViewableBuffer'; + +import { sizeOfType } from '@pixi/utils'; import { TYPES } from '@pixi/constants'; import defaultVertex from './texture.vert'; @@ -140,7 +142,7 @@ + 'your elements with additional bytes.'); } - const outputSize = TYPES.sizeOf(def.glType) * def.glSize; + const outputSize = sizeOfType(def.glType) * def.glSize; if (outputSize !== inputSize) { diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index e77949c..6e78c02 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -2,4 +2,5 @@ export * from './removeItems'; export * from './uid'; export * from './sign'; +export * from './sizeOfType'; export * from './pow2'; diff --git a/packages/utils/src/data/sizeOfType.js b/packages/utils/src/data/sizeOfType.js new file mode 100644 index 0000000..cbc8e0f --- /dev/null +++ b/packages/utils/src/data/sizeOfType.js @@ -0,0 +1,26 @@ +import { TYPES } from '@pixi/constants'; + +/** + * Returns the size of any type in the `TYPES` enum. + * + * @param {number} glint - TYPES enum constant + * @return size of `glint` in bytes + */ +export function sizeOfType(glint) +{ + switch (glint) + { + case TYPES.FLOAT: + return 4; + case TYPES.HALF_FLOAT: + case TYPES.UNSIGNED_SHORT_5_5_5_1: + case TYPES.UNSIGNED_SHORT_4_4_4_4: + case TYPES.UNSIGNED_SHORT_5_6_5: + case TYPES.UNSIGNED_SHORT: + return 2; + case TYPES.UNSIGNED_BYTE: + return 1; + default: + throw new Error(`{$glint} isn't a TYPES enum!`); + } +}