Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve doc and tests for imagery layer texture filtering #5969

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Source/Renderer/TextureMagnificationFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>NEAREST</code> filtering.
*
* @type {Number}
* @constant
Expand Down
35 changes: 25 additions & 10 deletions Source/Renderer/TextureMinificationFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>NEAREST</code> filtering.
*
* @type {Number}
* @constant
*/
LINEAR : WebGLConstants.LINEAR,
/**
* WebGL <code>NEAREST_MIPMAP_NEAREST</code> interpolation of image pixels to texture.
* Selects the nearest mip level and applies nearest sampling within that level.
* <p>
* Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture.
* </p>
*
* @type {Number}
* @constant
*/
NEAREST_MIPMAP_NEAREST : WebGLConstants.NEAREST_MIPMAP_NEAREST,
/**
* WebGL <code>LINEAR_MIPMAP_NEAREST</code> interpolation of image pixels to texture.
* Selects the nearest mip level and applies linear sampling within that level.
* <p>
* Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture.
* </p>
*
* @type {Number}
* @constant
*/
LINEAR_MIPMAP_NEAREST : WebGLConstants.LINEAR_MIPMAP_NEAREST,
/**
* WebGL <code>NEAREST_MIPMAP_LINEAR</code> interpolation of image pixels to texture.
* Read texture values with nearest sampling from two adjacent mip levels and linearly interpolate the results.
* <p>
* This option provides a good balance of visual quality and speed when sampling from a mipmapped texture.
* </p>
* <p>
* Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture.
* </p>
*
* @type {Number}
* @constant
*/
NEAREST_MIPMAP_LINEAR : WebGLConstants.NEAREST_MIPMAP_LINEAR,
/**
* WebGL <code>LINEAR_MIPMAP_LINEAR</code> interpolation of image pixels to texture.
*
* Read texture values with linear sampling from two adjacent mip levels and linearly interpolate the results.
* <p>
* This option provides a good balance of visual quality and speed when sampling from a mipmapped texture.
* </p>
* <p>
* Requires that the texture has a mipmap. The mip level is chosen by the view angle and screen-space size of the texture.
* </p>
* @type {Number}
* @constant
*/
Expand Down
9 changes: 9 additions & 0 deletions Source/Scene/ImageryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define([
'../Core/defined',
'../Core/defineProperties',
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/FeatureDetection',
'../Core/GeographicTilingScheme',
'../Core/IndexDatatype',
Expand Down Expand Up @@ -45,6 +46,7 @@ define([
defined,
defineProperties,
destroyObject,
DeveloperError,
FeatureDetection,
GeographicTilingScheme,
IndexDatatype,
Expand Down Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion Specs/Scene/ImageryLayerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down