notlion / Cinder-NanoVG

A C++11 wrapper for NanoVG meant for use with Cinder
51 stars 15 forks source link

Texture Proxy Motivation #9

Closed sansumbrella closed 9 years ago

sansumbrella commented 9 years ago

This is a great wrapper! The shapes look so nice. I'm really looking forward to diving in deeper.

I added a simple ci::Timer to get the number of milliseconds spent per frame in the RenderToTexture sample, and found that the NanoVG performance is generally better than the Texture Proxy performance (on a Mac Pro w/ AMD Firepro card). When running in Release with 512 shapes, I see the following frame times:

Texture Proxies: ~10.0 ms
NanoVG:          ~ 2.8 ms

My guess is that the proxies aren't really worth it unless the underlying shape is very complex.

notlion commented 9 years ago

It's true. On OS X this ended up being a pretty bad example of why you'd want to render to texture. I really should have used the pony SVG or something more complex. On iOS, though the proxies end up being slightly faster; 60fps vs 40 or so.

notlion commented 9 years ago

Also, proxies will get less efficient as you increase the shape count due to the cost of rebinding textures. In that case you'd want a texture atlas or something.. but that's a little too involved for sample code.

notlion commented 9 years ago

BTW, Do you happen to know a C/C++ library that performs dynamic incremental texture atlas allocation? :wink:

sansumbrella commented 9 years ago

Oh boy, that would be really nice to have. It would be pretty easy (though potentially wasteful) if you required square allocations.

Wrote something kind of like that for SelfieSelfie called GridTexture.

sansumbrella commented 9 years ago

But once you're out of space, it just wraps around. The part that I think would be most annoying is atlasing across multiple textures. Since then you would need to order your draws to avoid swapping between all the textures.

notlion commented 9 years ago

The closest thing I've found is fontstash (used in nanovg). It uses the skyline algorithm and can allocate across multiple textures.. It's specifically designed for font glyphs, though. Seems like these algorithms are not too complex, so maybe I'll try one out if I get desperate enough..

notlion commented 9 years ago

Looks like the guy who wrote that paper shared his code. Could be a good starting point. :wink: