Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

sprite images missing on > 2.0 scale factors - #843

Merged
kkaefer merged 1 commit into
masterfrom
843-fix-sprites
Mar 17, 2015
Merged

kkaefer merged 1 commit into
masterfrom
843-fix-sprites

Conversation

@kkaefer

@kkaefer kkaefer commented Mar 16, 2015

Copy link
Copy Markdown
Member

Carryover from #621. Sprites are falling down on iPhone 6 Plus and not sure why. We are doing things right AFAICT with 1x/2x sprite sheets etc. by just looking for scale > 1 and using @2x in that case. But perhaps something in the point shader is making the wrong assumption in some math.

This can easily be tested in iPhone 6 Plus simulator.

/cc @ljbade in case this is also an issue on Android hidpi.

screen shot 2015-02-10 at 2 00 06 pm

@incanus incanus added bug iOS Mapbox Maps SDK for iOS labels Feb 10, 2015
@incanus incanus modified the milestone: iOS Beta Feb 13, 2015
@mb12 mb12 mentioned this pull request Feb 17, 2015
@incanus

incanus commented Mar 5, 2015

Copy link
Copy Markdown
Contributor Author

So this also affects the Bright style's water fill pattern. Clearly one approach would be to create 3x versions in the sprite sheets but that's not going to scale when we consider Android goes even higher and probably will continue to climb.

Since we're talking first about an iOS beta, we could just do the 3x to hit the milestone for now.

Another approach would be to upsample 2x versions on the fly by recalculating the offset from the sprite sheet JSON.

@jfirebaugh

Copy link
Copy Markdown
Contributor

Another approach would be to upsample 2x versions on the fly by recalculating the offset from the sprite sheet JSON.

This is the correct approach IMHO. It should support styles without 3x assets (or any particular Nx), picking the best one and scaling it appropriately.

@mb12

mb12 commented Mar 6, 2015

Copy link
Copy Markdown

If the image data is correctly copied to GPU and UV mapping correctly done, icons should be rendered using whatever interpolation algorithm(GL_LINEAR/GL_NEAREST) is set up.
Adding @3x,@4x resources or scaling the image in CPU will just hide the real issue under the rug. This should be no different than scaling 256x256 px raster tiles on higher density devices as far as opengl code is concerned (which works correctly without any scaling done in CPU).

@incanus

incanus commented Mar 6, 2015

Copy link
Copy Markdown
Contributor Author

When I last looked at this, the problem was related to the pixel_ratio currently in play being a factor in figuring out where the pixel offset in the sprite sheet was — i.e. multiplying the JSON-derived offset values by it to figure out where in the 2x sheet they were. When 3x is a factor, it overshoots the sheet in most cases and doesn't grab a valid subtexture to upload. So, less a GL issue and more a calculation issue in passing a valid image to GL.

@mb12

mb12 commented Mar 7, 2015

Copy link
Copy Markdown

This could be a bug in SpriteAtlas::copy, which copies raw pixels from Sprite.raster to to SpriteAtlas.data. It just copies raw pixels without taking into account the difference in pixelRatio between the Sprite and the SpriteAtlas.

@mb12

mb12 commented Mar 7, 2015

Copy link
Copy Markdown

SpriteAtlas has a method resize that can be used to make the pixelRatio same as Sprite.pixelRatio. If one does that this bug goes away for iPhone 6 plus (ratio > 2).
This is most likely not the right fix but if confirms that the bug is in SpriteAtlas::copy.

@mb12

mb12 commented Mar 7, 2015

Copy link
Copy Markdown

I added this in Map::prepare to verify that copy code wasn't correctly handling copying between Sprite to SpriteAtlas. .

if(state.getPixelRatio() >= 2) {
    spriteAtlas->resize(2);
}
else {
    spriteAtlas->resize(1);
}

@jfirebaugh

Copy link
Copy Markdown
Contributor

@kkaefer Can you look at this? @mb12's diagnosis looks correct to me.

@ljbade

ljbade commented Mar 11, 2015

Copy link
Copy Markdown
Contributor

I wonder if this is also the cause of #888

@friedbunny

Copy link
Copy Markdown
Contributor

Yup @ljbade, I'm willing to bet that'll be because of the wave sprite used for Bright's water. (What's the display scale for the Nexus 7?) Happy to see this sprite issue tracked down, good one @mb12.

@kkaefer

kkaefer commented Mar 16, 2015

Copy link
Copy Markdown
Member

This turned out to be a combination of a few issues:

  • Sprite objects returned the map's pixelRatio instead of the sprite's. However, we are currently loading either @1x or @2x assets, so there was a mismatch
  • Copying icons from the sprite into the atlas now uses bilinear scaling to scale up to the actual size. Previously, copying from a 2x sprite to a 3x sprite atlas left 1/3 in each dimension blank as it didn't scale up the image.
  • Most importantly: The logical dimension of our SpriteAtlas is 512x512. When creating a texture, a 3x sprite atlas ends up with a physical texture size of 1536x1536. However, this is not a power of two. While almost all modern OpenGL implementations support NPOT textures, OpenGL ES 2 has a restriction on the wrap mode. We had it set to wrap around, but GLES2 only supports clamping to the edge.

@mb12

mb12 commented Mar 16, 2015

Copy link
Copy Markdown

I have an older git repo. Therein SpriteAtlas::bind uses GL_CLAMP_TO_EDGE. The latest repo uses GL_REPEAT.

MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));

@ljbade

ljbade commented Mar 17, 2015

Copy link
Copy Markdown
Contributor

Hmm I will take a look into this. Android can have some very unusual pixel ratios. Your analysis seems to line up with the behaviour I had been seeing.

@ljbade

ljbade commented Mar 17, 2015

Copy link
Copy Markdown
Contributor

Currently I don't get any POI icons at all on my HTC One which is 3.0x.

- OpenGL ES 2 doesn't allow NPOT textures with wrap-around
- The Sprite object reported the map's pixelRatio, even though it loaded @2x assets
- Copying icons from the sprite into the atlas now uses bilinear scaling to scale up to the actual size
kkaefer added a commit that referenced this pull request Mar 17, 2015
sprite images  missing on > 2.0 scale factors
@kkaefer
kkaefer merged commit 36cee94 into master Mar 17, 2015
@kkaefer
kkaefer deleted the 843-fix-sprites branch March 17, 2015 11:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug iOS Mapbox Maps SDK for iOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants