Skip to content

only use mipmaps for power-of-two textures - #6444

Merged
ansis merged 5 commits into
masterfrom
fix-6440
Apr 19, 2018
Merged

ansis merged 5 commits into
masterfrom
fix-6440

Conversation

@ansis

@ansis ansis commented Apr 2, 2018

Copy link
Copy Markdown
Contributor

Fixes #6440

The WMS source in that example returns 400x400 tiles. WebGL only supports mipmaps for power-of-two size textures. This fix just disables mipmap generation and filtering for textures that are not power-of-two.

Alternative: we could either upscale the image to a power-of-two texture or add padding and draw only part of the texture but both of these solutions are significantly more complex and might not look better. Mipmapping only helps rasters look a bit better when they are significantly underzoomed (zooming out and the tiles get smaller).

I wrote a render test for this but it doesn't fail without the fix (I guess the node module implementation doesn't error the same way) so I didn't include it here. I don't have any other ideas on how to test this.

Launch Checklist

  • briefly describe the changes in this PR
  • [tried] write tests for all new functionality
  • [n/a] document any changes to public APIs
  • post benchmark scores
  • manually test the debug page

@ansis
ansis requested a review from jfirebaugh April 2, 2018 18:48
Comment thread src/render/texture.js Outdated

const {width, height} = image;
this.size = [width, height];
this.powerOfTwoSize = width === height && (Math.log(width) / Math.LN2) % 1 === 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to use state rather than compute this as needed? As state it could be wrong if the size is changed via update.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW a common neat and fast way to check if a number is a power of two is x & (x - 1) === 0

This lets Texture (instead of RasterTileSource) handle the actual gl
calls and dealing with cases where mipmaps can't be used.
@ansis

ansis commented Apr 12, 2018

Copy link
Copy Markdown
Contributor Author

@jfirebaugh I moved setting powerOfTwoSize from the constructor to the update to fix the bug (
3936aaa). I can switch it to a method if you think that could avoid future bugs.

I also added 8b5ebb0 which moves update-without-reallocation logic into Texture so that we can handle that and mipmap generation within Texture instead of within RasterTileSource. I'm not completely sure if this is better of it's just less direct.

@jfirebaugh jfirebaugh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think a method would be better, just for the sake of avoiding unnecessary state.

Comment thread src/render/texture.js Outdated
powerOfTwoSize: boolean;

constructor(context: Context, image: TextureImage, format: TextureFormat, premultiply: ?boolean) {
constructor(context: Context, image: TextureImage, format: TextureFormat, premultiply: ?boolean, useMipmap: ?boolean) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than add a second optional boolean parameter, let's move premultiply and useMipmap into an options object so they get descriptive names at the call site and there's no need for an undefined placeholder argument.

@ansis

ansis commented Apr 19, 2018

Copy link
Copy Markdown
Contributor Author

244a319 switches the options to and object and 0401bbd moves the power of two calculation to a method

@ansis
ansis merged commit 0a53a14 into master Apr 19, 2018
@ansis
ansis deleted the fix-6440 branch April 19, 2018 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering.

3 participants