memononen / nanovg

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

Restore previous shader program on nvgEndFrame #622

Open clinthidinger opened 2 years ago

clinthidinger commented 2 years ago

This change restores the previous shader program instead of setting it to 0 on nvgEndFrame()/renderFlush().

This will also help when using nanovg with other graphics libraries that manage a default shader like Cinder.

mulle-nat commented 2 years ago

On one hand this seems like an improvement, but on the other hand isn't there a lot of other state clobbered by nvg ? Only partial restoration of the previous state may lead to other subtle or not so subtle bugs. Just my thoughts on this...

clinthidinger commented 2 years ago

You're right about other states being clobbered. I should have looked through the README more closely in the part where it describes the states that get touched.

However, I think it may be worth considering preserving the program state since it seems common for other graphics libraries to try to simulate a default shader. The change to this state was actually causing an OpenGL error (GL_INVALID_OPERATION) from drawing with a null program handle when I called draw on a 3D object in Cinder after a call to nvgEndFrame(). It was also difficult to track down what the problem was until I used glEnable( GL_DEBUG_OUTPUT ).