Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

Support scalable vector icons & patterns #222

Closed
samanpwbb opened this issue Nov 20, 2014 · 13 comments
Closed

Support scalable vector icons & patterns #222

samanpwbb opened this issue Nov 20, 2014 · 13 comments

Comments

@samanpwbb
Copy link
Contributor

There's only mention of .png in the spec when talking about sprites. Can we support vector sprite formats like SVG? I would never want to use a bitmap as my sprite source what with the current state of device screen resolution.

@jfirebaugh
Copy link
Contributor

SVG would be fine in mapbox-gl-js, where we can load it in an Image object and then render to a canvas to generate a raster at a given pixel ratio. Native platform support would likely be more iffy.

Current preference is for SDF images, which can be scaled and recolored, but of course don't support multiple colors.

See also #220.

@ljbade
Copy link

ljbade commented Nov 20, 2014

@jfirebaugh yeah would need a way to parse svg in native, but perhaps if we make a protobuf based vector format for simple sprites at least, then write a preprocessing tool to generate the protobuf files from svg for developers to use?

perhaps we just convert all svg into simple, points, lines and polygon with fixed vertices (ie no beizier curves etc)

@ljbade
Copy link

ljbade commented Nov 20, 2014

@jfirebaugh what is SDF? google is not giving me any relevant hits

@jfirebaugh
Copy link
Contributor

I don't want to get into subsetting SVG or inventing our own vector graphics format. If we're going to support it, we should do so wholeheartedly using a robust rendering library provided by the platform.

SDF is signed distance fields which is what we use for text rendering. It's supported as an icon format as well.

@ljbade
Copy link

ljbade commented Nov 21, 2014

Oh so you mean, load SVG, render to bitmap, then copy to GL texture?

Hmm does Android directly support loading SVG, need to look into it. I know it does have a vector graphics rendering library.

@ljbade
Copy link

ljbade commented Nov 21, 2014

OK Android platform does not support SVG. We either need to use one of the numerous open source Android SVG libraries (and hope they are stable and fast), or roll our own SVG library.

@jfirebaugh
Copy link
Contributor

Good to know @ljbade. That strongly suggests to me that we should not support SVG. I don't think we want to take on a built-in dependency on a SVG rendering library -- that would be very heavy.

@springmeyer
Copy link

I concur with @jfirebaugh's sentiment of doing this right or not at all and that doing it right is a serious effort that would be a distraction right now.

That said, I'll provide a bit more context. In the push to support SVG in Mapnik we found available dependencies at the time very heavy (like librsvg/cairo) so we rolled our own parser using boost::spirit and libxml2 and a custom renderer using AGG. Therefore we support only a subset of SVG, but a very useful subset for icons used in serverside rendering (where you don't need to worry about animations). https://github.com/memononen/nanosvg is an effort worth looking into since it is small and the author @memononen tailored if for use with OpenGL.

@ljbade
Copy link

ljbade commented Nov 21, 2014

@springmeyer I think nanosvg may be the way to go if we do want SVG support, directly rendering in OpenGL will be easier than trying to bake to bitmap on load and having to deal with scaling and rotation problems

@memononen
Copy link

Sorry to eavesdrop :) I thought, I'd share a few words about NanoSVG.

It was originally made to parse SVG files for game levels, it has grown over the years to support all kinds nasty svg things to parse, and more recently I added simple software rasterizer to it to be used to render sprites and icons. The rasterizer is not fully featured or super fast, but should be simple enough to extend when needed. In general it supports all kinds of shapes, solid and gradient fills and outlines (no dashes).

I also have another project called NanoVG (yeah, unfortunate naming), which is html canvas like renderer on top of OpenGL. I've tried to get the SVG rendering to work with it, but the quality is not there (nor speed). NanoVG uses the stencil trick to render complex polygons plus a 1px line for edge antialiasing. That method tends to create small but noticeable artifacts when you have tiny details because of the edge AA overdraw. If you use MSAA, then a OpenGL vector rendering at small size works fine.

There are number of tricks to get subpixel translation and rotation to work ok when using prerendered sprites/icons, scale is always tricky. One such trick is to render the image at 2x, then blur, and then render without mipmaps at half the size.

Multicolor SDF sounds like an interesting idea too (4 SDFs per texture sample! ;)).

@springmeyer
Copy link

@memononen Not eavesdropping at all - exactly why I mentioned you by name :) Thanks for the background and ideas!

@1ec5 1ec5 changed the title resolution independent sprites? Scalable vector images Nov 29, 2016
@1ec5
Copy link
Contributor

1ec5 commented Nov 29, 2016

@samanpwbb clarified in chat that the main use case for the feature described in this issue is to have a style image scale cleanly using icon-size, whereas multiple screen resolutions can already be supported via separate @1x and @2x sprite sheets.

#581 is a related idea about leveraging the tooling around nine-part images that’s present on all the native platforms. Highway shields would benefit from either feature.

@lucaswoj lucaswoj changed the title Scalable vector images Support scalable vector icons & patterns Dec 22, 2016
@lucaswoj
Copy link

lucaswoj commented Feb 1, 2017

Closing this as a "wontfix" for now. We can open a new ticket if there's a newfound pressing need or implementation concept.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants