-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Set texture sampler properties of ImageryLayer #5890
Set texture sampler properties of ImageryLayer #5890
Conversation
Welcome to the Cesium community @forman! Can you please send in a Contributor License Agreement (CLA) so that we can review and merge this pull request? I am a bot who helps you make Cesium awesome! Thanks again. |
CLA has been sent just now. |
Thanks for the contribution, @forman! We received your CLA! |
Can you please make Also mention these as new in CHANGES.md please. |
@lilleyse can you review this? |
Sure, I should be able to get to this tomorrow. |
Done.
Done naively, because I couldn't find proper description of WebGL In addition, I'd like some feedback:
|
CHANGES.md
Outdated
of image tiles, namely `minificationFilter` and `magnificationFilter` with possible values `LINEAR` | ||
(the default) and `NEAREST` defined in `TextureMinificationFilter` and `TextureMagnificationFilter`. | ||
[#5846](https://github.com/AnalyticalGraphicsInc/cesium/issues/5846) | ||
Hence, the enums `TextureMagnificationFilter` and `TextureMinificationFilter` have been made public. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we don't use line breaks in CHANGES.md
, one long line is fine.
Hence, the enums `TextureMagnificationFilter` and `TextureMinificationFilter` have been made public.
can be its own bullet.
* Validates the given <code>textureMinificationFilter</code> with respect to the possible enum values. | ||
* | ||
* @param textureMagnificationFilter | ||
* @returns {boolean} <code>true</code> if <code>textureMagnificationFilter</code> is valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically make the type uppercase Boolean
.
* | ||
* @param textureMagnificationFilter | ||
* @returns {boolean} <code>true</code> if <code>textureMagnificationFilter</code> is valid. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate
can be marked as @private
.
* | ||
* @param textureMinificationFilter | ||
* @returns {boolean} <code>true</code> if <code>textureMinificationFilter</code> is valid. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments for this section as above.
* @type {TextureMinificationFilter} | ||
* @default TextureMinificationFilter.LINEAR | ||
*/ | ||
ImageryLayer.DEFAULT_MINIFICATION_FILTER = TextureMinificationFilter.LINEAR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the rest of the code, DEFAULT_MINIFICATION_FILTER
should be above ImageryLayer.DEFAULT_MAGNIFICATION_FILTER
Specs/Scene/ImageryLayerSpec.js
Outdated
url : 'Data/Images/Red16x16.png' | ||
}); | ||
|
||
var layer = new ImageryLayer(provider, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just be new ImageryLayer(provider);
Source/Scene/ImageryLayer.js
Outdated
* or by the imagery provider. | ||
* @type {ImagerySplitDirection} | ||
* @default ImagerySplitDirection.NONE | ||
*/ | ||
ImageryLayer.DEFAULT_SPLIT = ImagerySplitDirection.NONE; | ||
|
||
/** | ||
* This value is used as the default texture magnification filter for the imagery layer if one is not provided | ||
* during construction or by the imagery provider. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you decide to leave texture filtering out of the imagery provider, tweak this and below's doc.
* @type {TextureMagnificationFilter} | ||
* @default {@link ImageryLayer.DEFAULT_MAGNIFICATION_FILTER} | ||
*/ | ||
this.magnificationFilter = defaultValue(options.magnificationFilter, defaultValue(imageryProvider.defaultMagnificationFilter, ImageryLayer.DEFAULT_MAGNIFICATION_FILTER)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be noted somewhere that these values can be set immediately after adding the imagery layer but once a texture is loaded it won't be possible to change its filter.
* 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. | ||
* | ||
* @alias TextureMagnificationFilter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use @exports TextureMagnificationFilter
instead, so it appears as its own section in the documentation. Same for TextureMinificationFilter
.
*/ | ||
var TextureMagnificationFilter = { | ||
/** | ||
* Nearest neighbor sampling of image pixels to texture. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For each of these also add
* @type {Number}
* @constant
Do you have some sample code for this? I'm having some problems with seeing nearest filtering, even though I see it gets to the sampler correctly. Maybe I'm doing something incorrectly:
|
Those descriptions are fine.
I'm okay with the names as they are.
The validation is handled when the sampler is created for the texture, so I don't think anything extra needs to be added. |
@lilleyse thanks for the review, Fixem them now. Have an idea. why the example wont work... |
…imageryLayer<x>Samplers so that we can holds samplers with different configurations
@lilleyse the example doesn't work for at least two reasons:
If my theory holds, your example should work with non-mipmap textures. (And after you fix a tiny typo: I fear, I need some more (Web)GL insights to make this work for all kind of imagery layers. I'd be really glad if someone could help here, first to get this PR done and secondly because we urgently need this feature in our app. Thanks EDIT: I believe, this line has no effect. |
@lilleyse If I comment out creation of mipmaps in Here the SandCastle code:
|
This is ready now for another review.
|
Source/Scene/ImageryLayer.js
Outdated
var maximumAnisotropy = Math.min(maximumSupportedAnisotropy, defaultValue(imageryLayer._maximumAnisotropy, maximumSupportedAnisotropy)); | ||
var mipmapSamplerKey = getSamplerKey(minificationFilter, magnificationFilter, maximumAnisotropy); | ||
var mipmapSamplers = context.cache.imageryLayerMipmapSamplers; | ||
var mipmapSampler = mipmapSamplers && mipmapSamplers[mipmapSamplerKey]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually try to be more explicit about checking if something is undefined. The section could be written slightly differently to be a bit more conformant with the rest of the code:
var mipmapSamplers = context.cache.imageryLayerMipmapSamplers;
if (!defined(mipmapSamplers)) {
mipmapSamplers = {};
context.cache.imageryLayerMipmapSamplers = mipmapSamplers;
}
var mipmapSampler = mipmapSamplers[mipmapSamplerKey];
if (!defined(mipmapSampler)) {
mipmapSampler = new Sampler({
wrapS : TextureWrap.CLAMP_TO_EDGE,
wrapT : TextureWrap.CLAMP_TO_EDGE,
minificationFilter : minificationFilter,
magnificationFilter : magnificationFilter,
maximumAnisotropy : maximumAnisotropy
});
mipmapSamplers[mipmapSamplerKey] = mipmapSampler;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change this, thanks!
Source/Scene/ImageryLayer.js
Outdated
var usesLinearTextureFilter = minificationFilter === TextureMinificationFilter.LINEAR && magnificationFilter === TextureMagnificationFilter.LINEAR; | ||
// Use mipmaps if this texture uses linear filters and has power-of-two dimensions. | ||
if (usesLinearTextureFilter && !PixelFormat.isCompressedFormat(texture.pixelFormat) && CesiumMath.isPowerOfTwo(texture.width) && CesiumMath.isPowerOfTwo(texture.height)) { | ||
if (minificationFilter === TextureMinificationFilter.NEAREST) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for NEAREST
here is no longer needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops
The code doesn't seem too much of a concern to me. I ran the Chrome profiler in case and didn't notice any change. |
All else looks good, this should be ready soon. |
Done. May add an explicit spec later verifying |
I tweaked some wording in the recent commit.
This would be good to add. I think just editing the existing test to check |
# Conflicts: # CHANGES.md
Ready now. |
The failing test is unrelated to this PR, so this should be good to go. Thanks @forman! |
* @exports TextureMagnificationFilter | ||
* | ||
* @see TextureMinificationFilter | ||
* @see ImageryLayer#magnificationFilter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lilleyse this @see
- and the one in TextureMinificationFilter.js
- is not needed and not customary. Can you please remove in master?
@@ -367,6 +380,41 @@ defineSuite([ | |||
expect(layer.isDestroyed()).toEqual(true); | |||
}); | |||
|
|||
it('allows setting texture filter properties', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lilleyse are these tests sufficient? How is coverage? Should these also do a smokescreen render?
* Possible values are {@link TextureMagnificationFilter.LINEAR} (the default) | ||
* and {@link TextureMagnificationFilter.NEAREST}. | ||
* | ||
* To take effect, this property must be set immediately after adding the imagery layer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an important comment since I do not believe we ever create mipmaps for imagery tiles since the mipmapping is basically implicit in the tileset. Is this ever validated? A DeveloperError
should be thrown if one of these two values is not set.
*/ | ||
var TextureMagnificationFilter = { | ||
/** | ||
* Nearest neighbor sampling of image pixels to texture. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file and below, try to avoid providing reference doc that is just a repeat of the enum. @lilleyse could you add a tad more description and trade offs, e.g., visual quality vs speed?
This is ready and addresses #5846, Nearest-neighbor image resampling for ImageryLayer.
It adds two new properties to
ImageryLayer
:minificationFilter
with possible valuesTextureMinificationFilter.LINEAR
and.NEAREST
magnificationFilter
with possible valuesTextureMagnificationFilter.LINEAR
and.NEAREST