From aac11c08fc7328c4f42a426aba12cf70e3849b36 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 7 Nov 2017 13:54:19 -0500 Subject: [PATCH] Improve doc and tests for imageyr layer texture filtering --- Source/Renderer/TextureMagnificationFilter.js | 8 ++--- Source/Renderer/TextureMinificationFilter.js | 35 +++++++++++++------ Source/Scene/ImageryLayer.js | 9 +++++ Specs/Scene/ImageryLayerSpec.js | 21 ++++++++++- 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/Source/Renderer/TextureMagnificationFilter.js b/Source/Renderer/TextureMagnificationFilter.js index edb9f3bf354d..a10ebacaefc2 100644 --- a/Source/Renderer/TextureMagnificationFilter.js +++ b/Source/Renderer/TextureMagnificationFilter.js @@ -7,24 +7,22 @@ define([ 'use strict'; /** - * Enumerates all possible filters used when magnifying WebGL textures, which takes places when zooming - * into imagery. Provides the possible values for the {@link ImageryLayer#magnificationFilter} property. + * Enumerates all possible filters used when magnifying WebGL textures. * * @exports TextureMagnificationFilter * * @see TextureMinificationFilter - * @see ImageryLayer#magnificationFilter */ var TextureMagnificationFilter = { /** - * Nearest neighbor sampling of image pixels to texture. + * Samples the texture by returning the closest pixel. * * @type {Number} * @constant */ NEAREST : WebGLConstants.NEAREST, /** - * Bi-linear interpolation of image pixels to texture. + * Samples the texture through bi-linear interpolation of the four nearest pixels. This produces smoother results than NEAREST filtering. * * @type {Number} * @constant diff --git a/Source/Renderer/TextureMinificationFilter.js b/Source/Renderer/TextureMinificationFilter.js index 0f31ea0ee810..338bf4a218c3 100644 --- a/Source/Renderer/TextureMinificationFilter.js +++ b/Source/Renderer/TextureMinificationFilter.js @@ -7,53 +7,68 @@ define([ 'use strict'; /** - * Enumerates all possible filters used when minifying WebGL textures, which takes places when zooming - * out of imagery. Provides the possible values for the {@link ImageryLayer#minificationFilter} property. + * Enumerates all possible filters used when minifying WebGL textures. * * @exports TextureMinificationFilter * * @see TextureMagnificationFilter - * @see ImageryLayer#minificationFilter */ var TextureMinificationFilter = { /** - * Nearest neighbor sampling of image pixels to texture. + * Samples the texture by returning the closest pixel. * * @type {Number} * @constant */ NEAREST : WebGLConstants.NEAREST, /** - * Bi-linear interpolation of image pixels to texture. + * Samples the texture through bi-linear interpolation of the four nearest pixels. This produces smoother results than NEAREST filtering. * * @type {Number} * @constant */ LINEAR : WebGLConstants.LINEAR, /** - * WebGL NEAREST_MIPMAP_NEAREST interpolation of image pixels to texture. + * Selects the nearest mip level and applies nearest sampling within that level. + *

+ * Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture. + *

* * @type {Number} * @constant */ NEAREST_MIPMAP_NEAREST : WebGLConstants.NEAREST_MIPMAP_NEAREST, /** - * WebGL LINEAR_MIPMAP_NEAREST interpolation of image pixels to texture. + * Selects the nearest mip level and applies linear sampling within that level. + *

+ * Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture. + *

* * @type {Number} * @constant */ LINEAR_MIPMAP_NEAREST : WebGLConstants.LINEAR_MIPMAP_NEAREST, /** - * WebGL NEAREST_MIPMAP_LINEAR interpolation of image pixels to texture. + * Read texture values with nearest sampling from two adjacent mip levels and linearly interpolate the results. + *

+ * This option provides a good balance of visual quality and speed when sampling from a mipmapped texture. + *

+ *

+ * Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture. + *

* * @type {Number} * @constant */ NEAREST_MIPMAP_LINEAR : WebGLConstants.NEAREST_MIPMAP_LINEAR, /** - * WebGL LINEAR_MIPMAP_LINEAR interpolation of image pixels to texture. - * + * Read texture values with linear sampling from two adjacent mip levels and linearly interpolate the results. + *

+ * This option provides a good balance of visual quality and speed when sampling from a mipmapped texture. + *

+ *

+ * Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture. + *

* @type {Number} * @constant */ diff --git a/Source/Scene/ImageryLayer.js b/Source/Scene/ImageryLayer.js index 839da40ee183..b7f75914df41 100644 --- a/Source/Scene/ImageryLayer.js +++ b/Source/Scene/ImageryLayer.js @@ -5,6 +5,7 @@ define([ '../Core/defined', '../Core/defineProperties', '../Core/destroyObject', + '../Core/DeveloperError', '../Core/FeatureDetection', '../Core/GeographicTilingScheme', '../Core/IndexDatatype', @@ -45,6 +46,7 @@ define([ defined, defineProperties, destroyObject, + DeveloperError, FeatureDetection, GeographicTilingScheme, IndexDatatype, @@ -814,6 +816,13 @@ define([ } } + //>>includeStart('debug', pragmas.debug); + if (this.minificationFilter !== TextureMinificationFilter.NEAREST && + this.minificationFilter !== TextureMinificationFilter.LINEAR) { + throw new DeveloperError('ImageryLayer minification filter must be NEAREST or LINEAR'); + } + //>>includeEnd('debug'); + var sampler = new Sampler({ minificationFilter : this.minificationFilter, magnificationFilter : this.magnificationFilter diff --git a/Specs/Scene/ImageryLayerSpec.js b/Specs/Scene/ImageryLayerSpec.js index 22fe1c728999..074e12c8f140 100644 --- a/Specs/Scene/ImageryLayerSpec.js +++ b/Specs/Scene/ImageryLayerSpec.js @@ -398,7 +398,26 @@ defineSuite([ }); expect(layer.minificationFilter).toEqual(TextureMinificationFilter.NEAREST); expect(layer.magnificationFilter).toEqual(TextureMagnificationFilter.NEAREST); - layer.destroy(); + + return pollToPromise(function() { + return provider.ready; + }).then(function() { + var imagery = new Imagery(layer, 0, 0, 0); + imagery.addReference(); + layer._requestImagery(imagery); + RequestScheduler.update(); + + return pollToPromise(function() { + return imagery.state === ImageryState.RECEIVED; + }).then(function() { + layer._createTexture(scene.context, imagery); + var sampler = imagery.texture.sampler; + expect(sampler.minificationFilter).toEqual(TextureMinificationFilter.NEAREST); + expect(sampler.magnificationFilter).toEqual(TextureMinificationFilter.NEAREST); + imagery.releaseReference(); + layer.destroy(); + }); + }); }); it('uses default texture filter properties of ImageryProvider', function() {