diff --git a/packages/constants/src/index.js b/packages/constants/src/index.js index d29f4d9..64a3a0a 100644 --- a/packages/constants/src/index.js +++ b/packages/constants/src/index.js @@ -257,6 +257,30 @@ }; /** + * Mipmap filtering modes that are supported by pixi. + * + * The {@link PIXI.settings.MIPMAP_TEXTURES} affects default texture filtering. + * Mipmaps are generated for a baseTexture if its `mipmap` field is `ON`, + * or its `POW2` and texture dimensions are powers of 2. + * Due to platform restriction, `ON` option will work like `POW2` for webgl-1. + * + * This property only affects WebGL. + * + * @name MIPMAP_MODES + * @memberof PIXI + * @static + * @enum {number} + * @property {number} OFF - No mipmaps + * @property {number} POW2 - Generate mipmaps if texture dimensions are pow2 + * @property {number} ON - Always generate mipmaps + */ +export const MIPMAP_MODES = { + OFF: 0, + POW2: 1, + ON: 2, +}; + +/** * The gc modes that are supported by pixi. * * The {@link PIXI.settings.GC_MODE} Garbage Collection mode for PixiJS textures is AUTO diff --git a/packages/constants/src/index.js b/packages/constants/src/index.js index d29f4d9..64a3a0a 100644 --- a/packages/constants/src/index.js +++ b/packages/constants/src/index.js @@ -257,6 +257,30 @@ }; /** + * Mipmap filtering modes that are supported by pixi. + * + * The {@link PIXI.settings.MIPMAP_TEXTURES} affects default texture filtering. + * Mipmaps are generated for a baseTexture if its `mipmap` field is `ON`, + * or its `POW2` and texture dimensions are powers of 2. + * Due to platform restriction, `ON` option will work like `POW2` for webgl-1. + * + * This property only affects WebGL. + * + * @name MIPMAP_MODES + * @memberof PIXI + * @static + * @enum {number} + * @property {number} OFF - No mipmaps + * @property {number} POW2 - Generate mipmaps if texture dimensions are pow2 + * @property {number} ON - Always generate mipmaps + */ +export const MIPMAP_MODES = { + OFF: 0, + POW2: 1, + ON: 2, +}; + +/** * The gc modes that are supported by pixi. * * The {@link PIXI.settings.GC_MODE} Garbage Collection mode for PixiJS textures is AUTO diff --git a/packages/core/src/textures/BaseTexture.js b/packages/core/src/textures/BaseTexture.js index f31479d..8798d39 100644 --- a/packages/core/src/textures/BaseTexture.js +++ b/packages/core/src/textures/BaseTexture.js @@ -26,7 +26,7 @@ * The current resource to use, for things that aren't Resource objects, will be converted * into a Resource. * @param {Object} [options] - Collection of options - * @param {boolean} [options.mipmap=PIXI.settings.MIPMAP_TEXTURES] - If mipmapping is enabled for texture + * @param {PIXI.MIPMAP_MODES} [options.mipmap=PIXI.settings.MIPMAP_TEXTURES] - If mipmapping is enabled for texture * @param {PIXI.WRAP_MODES} [options.wrapMode=PIXI.settings.WRAP_MODE] - Wrap mode for textures * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.settings.SCALE_MODE] - Default scale mode, linear, nearest * @param {PIXI.FORMATS} [options.format=PIXI.FORMATS.RGBA] - GL format type @@ -81,9 +81,10 @@ this.resolution = resolution || settings.RESOLUTION; /** - * If mipmapping was used for this texture, enable and disable with enableMipmap() + * Mipmap mode of the texture, affects downscaled images * - * @member {boolean} + * @member {PIXI.MIPMAP_MODES} + * @default PIXI.settings.MIPMAP_TEXTURES */ this.mipmap = mipmap !== undefined ? mipmap : settings.MIPMAP_TEXTURES; @@ -96,9 +97,8 @@ /** * The scale mode to apply when scaling this texture * - * @member {number} + * @member {PIXI.SCALE_MODES} * @default PIXI.settings.SCALE_MODE - * @see PIXI.SCALE_MODES */ this.scaleMode = scaleMode !== undefined ? scaleMode : settings.SCALE_MODE; @@ -304,7 +304,7 @@ * Changes style options of BaseTexture * * @param {PIXI.SCALE_MODES} [scaleMode] - Pixi scalemode - * @param {boolean} [mipmap] - enable mipmaps + * @param {PIXI.MIPMAP_MODES} [mipmap] - enable mipmaps * @returns {BaseTexture} this */ setStyle(scaleMode, mipmap) diff --git a/packages/constants/src/index.js b/packages/constants/src/index.js index d29f4d9..64a3a0a 100644 --- a/packages/constants/src/index.js +++ b/packages/constants/src/index.js @@ -257,6 +257,30 @@ }; /** + * Mipmap filtering modes that are supported by pixi. + * + * The {@link PIXI.settings.MIPMAP_TEXTURES} affects default texture filtering. + * Mipmaps are generated for a baseTexture if its `mipmap` field is `ON`, + * or its `POW2` and texture dimensions are powers of 2. + * Due to platform restriction, `ON` option will work like `POW2` for webgl-1. + * + * This property only affects WebGL. + * + * @name MIPMAP_MODES + * @memberof PIXI + * @static + * @enum {number} + * @property {number} OFF - No mipmaps + * @property {number} POW2 - Generate mipmaps if texture dimensions are pow2 + * @property {number} ON - Always generate mipmaps + */ +export const MIPMAP_MODES = { + OFF: 0, + POW2: 1, + ON: 2, +}; + +/** * The gc modes that are supported by pixi. * * The {@link PIXI.settings.GC_MODE} Garbage Collection mode for PixiJS textures is AUTO diff --git a/packages/core/src/textures/BaseTexture.js b/packages/core/src/textures/BaseTexture.js index f31479d..8798d39 100644 --- a/packages/core/src/textures/BaseTexture.js +++ b/packages/core/src/textures/BaseTexture.js @@ -26,7 +26,7 @@ * The current resource to use, for things that aren't Resource objects, will be converted * into a Resource. * @param {Object} [options] - Collection of options - * @param {boolean} [options.mipmap=PIXI.settings.MIPMAP_TEXTURES] - If mipmapping is enabled for texture + * @param {PIXI.MIPMAP_MODES} [options.mipmap=PIXI.settings.MIPMAP_TEXTURES] - If mipmapping is enabled for texture * @param {PIXI.WRAP_MODES} [options.wrapMode=PIXI.settings.WRAP_MODE] - Wrap mode for textures * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.settings.SCALE_MODE] - Default scale mode, linear, nearest * @param {PIXI.FORMATS} [options.format=PIXI.FORMATS.RGBA] - GL format type @@ -81,9 +81,10 @@ this.resolution = resolution || settings.RESOLUTION; /** - * If mipmapping was used for this texture, enable and disable with enableMipmap() + * Mipmap mode of the texture, affects downscaled images * - * @member {boolean} + * @member {PIXI.MIPMAP_MODES} + * @default PIXI.settings.MIPMAP_TEXTURES */ this.mipmap = mipmap !== undefined ? mipmap : settings.MIPMAP_TEXTURES; @@ -96,9 +97,8 @@ /** * The scale mode to apply when scaling this texture * - * @member {number} + * @member {PIXI.SCALE_MODES} * @default PIXI.settings.SCALE_MODE - * @see PIXI.SCALE_MODES */ this.scaleMode = scaleMode !== undefined ? scaleMode : settings.SCALE_MODE; @@ -304,7 +304,7 @@ * Changes style options of BaseTexture * * @param {PIXI.SCALE_MODES} [scaleMode] - Pixi scalemode - * @param {boolean} [mipmap] - enable mipmaps + * @param {PIXI.MIPMAP_MODES} [mipmap] - enable mipmaps * @returns {BaseTexture} this */ setStyle(scaleMode, mipmap) diff --git a/packages/core/src/textures/TextureSystem.js b/packages/core/src/textures/TextureSystem.js index 109a76c..67aa26f 100644 --- a/packages/core/src/textures/TextureSystem.js +++ b/packages/core/src/textures/TextureSystem.js @@ -2,7 +2,7 @@ import BaseTexture from './BaseTexture'; import GLTexture from './GLTexture'; import { removeItems } from '@pixi/utils'; -import { WRAP_MODES } from '@pixi/constants'; +import { MIPMAP_MODES, WRAP_MODES } from '@pixi/constants'; /** * System plugin to the renderer to manage textures. @@ -329,14 +329,14 @@ return; } - if (this.webGLVersion !== 2 && !texture.isPowerOfTwo) + if ((texture.mipmap === MIPMAP_MODES.POW2 || this.webGLVersion !== 2) && !texture.isPowerOfTwo) { - glTexture.mipmap = false; + glTexture.mipmap = 0; glTexture.wrapMode = WRAP_MODES.CLAMP; } else { - glTexture.mipmap = texture.mipmap; + glTexture.mipmap = texture.mipmap >= 1; glTexture.wrapMode = texture.wrapMode; } diff --git a/packages/constants/src/index.js b/packages/constants/src/index.js index d29f4d9..64a3a0a 100644 --- a/packages/constants/src/index.js +++ b/packages/constants/src/index.js @@ -257,6 +257,30 @@ }; /** + * Mipmap filtering modes that are supported by pixi. + * + * The {@link PIXI.settings.MIPMAP_TEXTURES} affects default texture filtering. + * Mipmaps are generated for a baseTexture if its `mipmap` field is `ON`, + * or its `POW2` and texture dimensions are powers of 2. + * Due to platform restriction, `ON` option will work like `POW2` for webgl-1. + * + * This property only affects WebGL. + * + * @name MIPMAP_MODES + * @memberof PIXI + * @static + * @enum {number} + * @property {number} OFF - No mipmaps + * @property {number} POW2 - Generate mipmaps if texture dimensions are pow2 + * @property {number} ON - Always generate mipmaps + */ +export const MIPMAP_MODES = { + OFF: 0, + POW2: 1, + ON: 2, +}; + +/** * The gc modes that are supported by pixi. * * The {@link PIXI.settings.GC_MODE} Garbage Collection mode for PixiJS textures is AUTO diff --git a/packages/core/src/textures/BaseTexture.js b/packages/core/src/textures/BaseTexture.js index f31479d..8798d39 100644 --- a/packages/core/src/textures/BaseTexture.js +++ b/packages/core/src/textures/BaseTexture.js @@ -26,7 +26,7 @@ * The current resource to use, for things that aren't Resource objects, will be converted * into a Resource. * @param {Object} [options] - Collection of options - * @param {boolean} [options.mipmap=PIXI.settings.MIPMAP_TEXTURES] - If mipmapping is enabled for texture + * @param {PIXI.MIPMAP_MODES} [options.mipmap=PIXI.settings.MIPMAP_TEXTURES] - If mipmapping is enabled for texture * @param {PIXI.WRAP_MODES} [options.wrapMode=PIXI.settings.WRAP_MODE] - Wrap mode for textures * @param {PIXI.SCALE_MODES} [options.scaleMode=PIXI.settings.SCALE_MODE] - Default scale mode, linear, nearest * @param {PIXI.FORMATS} [options.format=PIXI.FORMATS.RGBA] - GL format type @@ -81,9 +81,10 @@ this.resolution = resolution || settings.RESOLUTION; /** - * If mipmapping was used for this texture, enable and disable with enableMipmap() + * Mipmap mode of the texture, affects downscaled images * - * @member {boolean} + * @member {PIXI.MIPMAP_MODES} + * @default PIXI.settings.MIPMAP_TEXTURES */ this.mipmap = mipmap !== undefined ? mipmap : settings.MIPMAP_TEXTURES; @@ -96,9 +97,8 @@ /** * The scale mode to apply when scaling this texture * - * @member {number} + * @member {PIXI.SCALE_MODES} * @default PIXI.settings.SCALE_MODE - * @see PIXI.SCALE_MODES */ this.scaleMode = scaleMode !== undefined ? scaleMode : settings.SCALE_MODE; @@ -304,7 +304,7 @@ * Changes style options of BaseTexture * * @param {PIXI.SCALE_MODES} [scaleMode] - Pixi scalemode - * @param {boolean} [mipmap] - enable mipmaps + * @param {PIXI.MIPMAP_MODES} [mipmap] - enable mipmaps * @returns {BaseTexture} this */ setStyle(scaleMode, mipmap) diff --git a/packages/core/src/textures/TextureSystem.js b/packages/core/src/textures/TextureSystem.js index 109a76c..67aa26f 100644 --- a/packages/core/src/textures/TextureSystem.js +++ b/packages/core/src/textures/TextureSystem.js @@ -2,7 +2,7 @@ import BaseTexture from './BaseTexture'; import GLTexture from './GLTexture'; import { removeItems } from '@pixi/utils'; -import { WRAP_MODES } from '@pixi/constants'; +import { MIPMAP_MODES, WRAP_MODES } from '@pixi/constants'; /** * System plugin to the renderer to manage textures. @@ -329,14 +329,14 @@ return; } - if (this.webGLVersion !== 2 && !texture.isPowerOfTwo) + if ((texture.mipmap === MIPMAP_MODES.POW2 || this.webGLVersion !== 2) && !texture.isPowerOfTwo) { - glTexture.mipmap = false; + glTexture.mipmap = 0; glTexture.wrapMode = WRAP_MODES.CLAMP; } else { - glTexture.mipmap = texture.mipmap; + glTexture.mipmap = texture.mipmap >= 1; glTexture.wrapMode = texture.wrapMode; } diff --git a/packages/settings/src/settings.js b/packages/settings/src/settings.js index c31b1bf..07b5b77 100644 --- a/packages/settings/src/settings.js +++ b/packages/settings/src/settings.js @@ -23,16 +23,16 @@ * @static * @name MIPMAP_TEXTURES * @memberof PIXI.settings - * @type {boolean} - * @default true + * @type {PIXI.MIPMAP_MODES} + * @default PIXI.MIPMAP_MODES.POW2 */ - MIPMAP_TEXTURES: true, + MIPMAP_TEXTURES: 1, /** * Default resolution / device pixel ratio of the renderer. * * @static - * @name RESOLTION + * @name RESOLUTION * @memberof PIXI.settings * @type {number} * @default 1