-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Anti-aliased rendering #133
Comments
Can you clarify, to what end would you want to use NanoVG ? If it is to render the triangle lists output by ImGui. You can do already do this since the rendering of those lists is your responsibility. However there would be no point rendering the triangles via NanoVG, they won't look any better. But for the sake of integration with an existing codebase it could be nice to provide stock function that uses NanoVG or bgfx (this function would be 30 lines of code). If what you desire are anti-aliasing shapes such as the rounded rectangles, it would need to be done at a lower level. I intend to implement more consistently anti-aliased primitives in ImGui but the implementation for that would need to stay very performant. Naively adding NanoVG in the middle of ImDrawList would affect performance, and although possible my intuition is that reimplementing anti-aliased primitives based on techniques used by NanoVG would be better. (In fact Mikko the author of NanoVG has done so in an ImGui branch). So again I am curious to know exactly to what end you desire to include NanoVG in the loop. |
The intent is to use imgui rich and clear API to render antialiased vectorized GUI. If there is already a fork using nanovg i will look at it. Thanks a lot. |
Indeed mikko's fork gives already nice results On my side I did not observe a real performance hit (in opengl) Do you intend adding mikko's change in your repository ? |
I won't merge them as is, but something similar and based on this will be integrated eventually. For rounded rectangles we'll use textures to reduce vertex count, which will also enable us to use rounded frames as the default. There is a performance hit. It's not major but it exists and I need to measure it more carefully before taking on further step. It's just that it's not at the top of priority list right now. Mikko sent me an e-mail with infos because he knows about those stuff well but I haven't had time to dig on any of it yet. However I see no harm in using this branch if you want the anti-aliased lines right away (preferably kept up to date, thats a rather old base it is using at the moment). |
I have merged and moved Mikko changes into a new branch until they are sorted out |
IMHO this is pleasant, most noticeable in apps that use graphs and lines a lot (or probably almost any app on a low-DPI display). One downside is that it seems pretty consistently about 5% slower than master imgui. That's not a big deal considering how fast imgui is anyway :) but it's a bit surprising that it's even measurable given how fast my* GPU is. (* or any modern) |
We need to turn all the rendering into using indexed vertices, it'll save on both front. |
I have changed the rendering to output indexed primitives. Reduced vertices by about 35%. https://github.com/ocornut/imgui/tree/2015-04-indexed-rendering So I'll only merge that into trunk along with bigger changes such as the AA rendering or new design, and we'll take the opportunity to change the signature of the render function and provide more information/tools to the user so that code can be smaller. ImGui could flatten the vertices/indices into a contiguous buffer for you. Considering just doing that to make it easier for the user. The reason I'm not doing it is that some user may want to change the vertex format and then it becomes 2 cpu passes over the vertices instead of one.. so that becomes a bit of a waste. |
Done some further optimisations. Measuring in Debug and testing with some fairly loaded screens, the AA branch with AA enabled is now slightly faster than Master at rendering. Opening all the windows from the demo, within the AA branch:
Note that those costs don't grow with clipped objects (outside of screen, outside of scrolled view), a list with thousands of items won't be affected. It only grows up to how much can fit on the screen. Again those worse cases numbers are better than the current Master, so nothing to worry about. |
I have committed the render API breaking changes that should now be more future proof. If you are feeling like testing the anti-aliased branch now, please do it and give me feedback! I would like to know if the breakage makes sense, what's your experience with updating, etc. thanks! |
While I'm breaking this I may just rename all the fields in ImDrawList to use PascalCase to be consistent with the other types. It always bothered me that they used a lower_case_with_underscore because ImDrawList is a proper class with functions and it makes. |
A few questions:
|
I see a couple of runtime style flags (AntiAliasedLines and AntiAliasedShapes) that I assume do what their name suggests. |
Ah nice :) |
It's pretty much done, I may decide to do the UpperCase renaming of all fields in ImDrawData, ImDrawList but other than that not much, need some testing on people apps mainly.
|
Sound good! 👍 |
…mDrawData to match the rest of our coding convention (#133)
OK i went and done the renaming I wanted to do. This is mildly annoying to the user but it's the final touch to the breaking changes of that branch. Most programmers should be able to fix everything in 5 minutes. HOPEFULLY. I can still revert that change if a riot start.
With that I'm pretty much ok to merge that in master after 2-3 people have tested it (I'll integrate it in a big codebase I have access to first). Maybe provide a monospaced AA font as well ? I may need to re-add the thickness feature of AddLine(), or direct it to non-anti-aliased path for now. It's not hard to add in the AA path but quite a fair amount of extra code. Edit Done |
I just tested it on my end and it was a very easy and trivial change! I am getting some warnings on my Linux machine, though:
|
I also tested this today - necessary changes were extremely straightforward and quick (except maybe for a function I use to draw linear gradient quads which uses internal ImDrawList stuff, but that's very clearly marked as internal, so that doesn't really count), everything looks great, didn't notice any issues at all and there seems to be zero performance impact even in debug builds - great work! |
Nice. Today I have merged in SDL and Allegro 5 sample to it was reassuring to see it all work. Allegro 5 doesn't support 16-bit indices or 32-bit colors but then it's a rather old and clunky library. Easy to convert the data. Perhaps I should re-add the PrimVtx and PrimIdx functions for that sort of custom use? |
These could indeed be useful to avoid breaking changes in the future, maybe together with overloads (or something like "PrimVtxs" and "PrimIdxs") for arrays of ImDrawVerts and ImDrawIdxs; not sure how critical that is though (it's quite simple to update even when the internals change) |
I have re-added PrimVtx() plus lower-level helpers now. Don't want to surchage this so I won't add array versions but yeah it should be trivial. |
Now merged in and we have a more flexible font API: oversampling, horizontal sub-pixel positioning, ability to merge glyphs from multiple fonts into one font and various extra options. I'll let it sit in master for a few days I assume there will be reactions/issues since it's quite a breaking change. |
In the next days I will branch my app applying this update on flexible fonts api and AA / Indexed rendering changes, reporting here any problems. |
FYI: Sean Barrett pushed stb_truetype.h v1.06 today, with significantly improved rasterization with AA. Might be pertinent here. |
Updated! |
Will release this as 1.43 tomorrow morning and finally close this topic! |
Updating my apps with latest master works with one exception. Stb_truetype 1.06 crashes on one assertion when adding font awesome. |
Do you have a repro? or - which setting are you using? I tried various combination and didn't get an assert firing. On updating to indexed rendering - did you run into any issue or confusing thing that you think could have been easier? I need to keep in mind that many users are not as proficient in C/C++ as we may be, some are just learning programming so any confusion that anyone here has is mulitplied by 100 with a junior programmer and I'd like to smooth them out. |
Closing this! |
Re-opening this just so I can close it AGAIN. |
Double close just to be safe! :) |
It would really be nice if imgui would use nanovg as a backend for drawing widgets.
As it seems now the backend already receive a list of triangle to render. I suppose then the integration with nanovg would need to be done at an upper layer.
What do you think ?
I already use nanovg for an user interface but I use pure C for the imgui and it is less rich than your library but it definitively give nice result.
The text was updated successfully, but these errors were encountered: