diff --git a/src/core/const.js b/src/core/const.js index cced6c9..6b640ee 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -149,6 +149,8 @@ NEAREST: 1 }, + MIPMAP_TEXTURES:true, + /** * The prefix that denotes a URL is for a retina asset * diff --git a/src/core/const.js b/src/core/const.js index cced6c9..6b640ee 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -149,6 +149,8 @@ NEAREST: 1 }, + MIPMAP_TEXTURES:true, + /** * The prefix that denotes a URL is for a retina asset * diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index 65d462a..51cc899 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -74,6 +74,11 @@ //TODO check is power of two.. glTexture.enableWrapClamp(); + if(texture.mipmap && texture.isPowerOfTwo) + { + glTexture.enableMipmap(); + } + if(texture.scaleMode === CONST.SCALE_MODES.NEAREST) { glTexture.enableNearestScaling(); @@ -82,6 +87,8 @@ { glTexture.enableLinearScaling(); } + + } if(isRenderTexture) diff --git a/src/core/const.js b/src/core/const.js index cced6c9..6b640ee 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -149,6 +149,8 @@ NEAREST: 1 }, + MIPMAP_TEXTURES:true, + /** * The prefix that denotes a URL is for a retina asset * diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index 65d462a..51cc899 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -74,6 +74,11 @@ //TODO check is power of two.. glTexture.enableWrapClamp(); + if(texture.mipmap && texture.isPowerOfTwo) + { + glTexture.enableMipmap(); + } + if(texture.scaleMode === CONST.SCALE_MODES.NEAREST) { glTexture.enableNearestScaling(); @@ -82,6 +87,8 @@ { glTexture.enableLinearScaling(); } + + } if(isRenderTexture) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index bb3b10a..a6adeef 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,6 +1,7 @@ var utils = require('../utils'), CONST = require('../const'), - EventEmitter = require('eventemitter3'); + EventEmitter = require('eventemitter3'), + bitTwiddle = require('bit-twiddle'); /** * A texture stores the information that represents an image. All textures have a base texture. @@ -128,7 +129,7 @@ * * @member {boolean} */ - this.mipmap = false; + this.mipmap = CONST.MIPMAP_TEXTURES; /** * A map of renderer IDs to webgl textures @@ -180,7 +181,7 @@ this.width = this.realWidth / this.resolution; this.height = this.realHeight / this.resolution; - this.isPowerOfTwo = utils.isPowerOfTwo(this.realWidth, this.realHeight); + this.isPowerOfTwo = bitTwiddle.isPow2(this.realWidth) && bitTwiddle.isPow2(this.realHeight); this.emit('update', this); }; diff --git a/src/core/const.js b/src/core/const.js index cced6c9..6b640ee 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -149,6 +149,8 @@ NEAREST: 1 }, + MIPMAP_TEXTURES:true, + /** * The prefix that denotes a URL is for a retina asset * diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index 65d462a..51cc899 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -74,6 +74,11 @@ //TODO check is power of two.. glTexture.enableWrapClamp(); + if(texture.mipmap && texture.isPowerOfTwo) + { + glTexture.enableMipmap(); + } + if(texture.scaleMode === CONST.SCALE_MODES.NEAREST) { glTexture.enableNearestScaling(); @@ -82,6 +87,8 @@ { glTexture.enableLinearScaling(); } + + } if(isRenderTexture) diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index bb3b10a..a6adeef 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,6 +1,7 @@ var utils = require('../utils'), CONST = require('../const'), - EventEmitter = require('eventemitter3'); + EventEmitter = require('eventemitter3'), + bitTwiddle = require('bit-twiddle'); /** * A texture stores the information that represents an image. All textures have a base texture. @@ -128,7 +129,7 @@ * * @member {boolean} */ - this.mipmap = false; + this.mipmap = CONST.MIPMAP_TEXTURES; /** * A map of renderer IDs to webgl textures @@ -180,7 +181,7 @@ this.width = this.realWidth / this.resolution; this.height = this.realHeight / this.resolution; - this.isPowerOfTwo = utils.isPowerOfTwo(this.realWidth, this.realHeight); + this.isPowerOfTwo = bitTwiddle.isPow2(this.realWidth) && bitTwiddle.isPow2(this.realHeight); this.emit('update', this); }; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 241c91a..07d43bb 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -64,46 +64,6 @@ return ((rgb[0]*255 << 16) + (rgb[1]*255 << 8) + rgb[2]*255); }, - - - /** - * Given a number, this function returns the closest number that is a power of two - * this function is taken from Starling Framework as its pretty neat ;) - * - * @param number {number} - * @return {number} the closest number that is a power of two - */ - getNextPowerOfTwo: function (number) - { - // see: http://en.wikipedia.org/wiki/Power_of_two#Fast_algorithm_to_check_if_a_positive_number_is_a_power_of_two - if (number > 0 && (number & (number - 1)) === 0) - { - return number; - } - else - { - var result = 1; - - while (result < number) - { - result <<= 1; - } - - return result; - } - }, - - /** - * checks if the given width and height make a power of two rectangle - * - * @param width {number} - * @param height {number} - * @return {boolean} - */ - isPowerOfTwo: function (width, height) - { - return (width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0); - }, /** * get the resolution of an asset by looking for the prefix