nanovg icon indicating copy to clipboard operation
nanovg copied to clipboard

Restore previous shader program on nvgEndFrame

Open clinthidinger opened this issue 3 years ago • 2 comments

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.

clinthidinger avatar Jan 05 '22 16:01 clinthidinger

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...

mulle-nat avatar Jan 05 '22 16:01 mulle-nat

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 ).

clinthidinger avatar Jan 06 '22 15:01 clinthidinger