memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.15k stars 769 forks source link

Flickering issue in demo #109

Open dougbinks opened 10 years ago

dougbinks commented 10 years ago

I get a flickering issue in the latest code (https://github.com/memononen/nanovg/commit/0dbf53ebadd2206b27370daba6bb7ee0cf65aadd), with the thumbnail widget flickering on both the main render and the scaled down render to texture view.

The screenshot below only shows the issue in the texture view, but this appears to be due to an interaction with FRAPS as normally it shows up on both. The problem appears more frequently when the mouse is hovering over the text.

I get this on windows, unsure if it's on other builds.

nanovg_flicker

memononen commented 10 years ago

I think the culprit is https://github.com/memononen/nanovg/commit/003561e72136b3b0a4fe6122c76017015633c3a4 where I added the stroke stencil trick. On one of my machines the GL3 performance tanked after that. It works well on GL2 :/

I'll see if I can figure out what is causing it.

dougbinks commented 10 years ago

I just tried removing NVG_STENCIL_STROKES from the demo CreateGL3, but this didn't resolve the issue. I'll try reverting the code before that commit.

dougbinks commented 10 years ago

OK - can confirm that reverting the code to the commit before that one resolves the issue.

memononen commented 10 years ago

If I remove the occurrences of strokeThr things get back to normal (sans the slowdown of rendering everything twice). I guess, it's time to see about that debug API.

memononen commented 10 years ago

I'm not able to repro your flickering, but I got much more stable and better performance with a little tweak to the shader. Basically, I moved the discard to the end of the shader (was in the beginning). Can you check if that fixes your problems too?

dougbinks commented 10 years ago

Moving discard didn't solve the problem it seems.

I managed to get a video of the flickering using my phone, link here: https://www.dropbox.com/sc/grlm38vkt0dxkky/AABkmnL6PJgmqd47a8CE5W2Pa

I'll look into this a little later on - since others haven't seen this I'd guess it's driver specific (Intel HD3000 on Windows 8).

memononen commented 10 years ago

It looks similar to the problems I had some time ago with the GL2 version of the buffered backend. I got sort of checker pattern errors with the images and with the scissor. Eventually it got fixed when I permuted the shader long enough :(

dougbinks commented 10 years ago

Good news - latest code fixes the issue somehow.

So it's not the move of the discard alone which fixes things, but some combo. I might go through and try to find what the exact change was for experiences sake, but for now this issue closed.

dougbinks commented 10 years ago

Reopening - further investigation shows that the code change improved performance, but enlarging the screensize enabled me to re-discover the issue.

So far it seems that when the framerate drops below the refresh rate I can observe the issue. Will keep looking...

floooh commented 10 years ago

FYI: I'm also seeing the flickering on OSX 10.10 (Intel HD4000) with the gl3 sample, but don't see it in my engine with nanovg integrated on the same scene or in the WebGL port. May be it's the vsync? In my demos I generally have vsync on, while I think in the original sample it is off for performance measurement?

dougbinks commented 10 years ago

I haven't had the time to investigate this further yet. One issue I've seen on Intel is that discarding constant buffers doesn't always lead to correct results if the buffer is still in use (buffer is discarded, but some draws use the old buffer), so a round-robin switching of constant buffers is sometimes required. I'll try to test that out in a few days time.

floooh commented 10 years ago

Hmm, I must correct myself, the flickering is gone on my machine. I recently upgraded to OSX10.10 Preview7, may be that fixed it. I'll keep an eye on it.