If I try a
pushContext(imageA) in Lua followed by a
drawBitmap(bitmapB) in CAPI, bitmapB ends up on the screen, not in imageA.
- When drawing directly the screen, Lua/setStencilPattern() will apply to C/drawBitmap().
- When Lua/pushContext(imageA) + C/pushContext(bitmapA), Lua/setStencilPattern() doesn't apply to C/drawBitmap().
- In all cases, C/drawBitmap() honors Lua/setClipRect().
Any idea if this a bug, a mistake on my part, or by design?
Oh that's super confusing. Originally all of the global drawing context was in the Lua module, then as we later filled out the C API all of those graphics functions had that state passed as arguments, since that's how the underlying functions work. We quickly discovered that's a huge pain in the ass and makes for really ugly code so I added a separate state on the C API side. At some point I'd also moved some context state (drawing offset, stencil for some reason, and clip rect) to the framebuffer, which means it's shared between Lua and C.
I've got an issue filed to combine the Lua and C contexts but there's a bit of tricky factoring that needs to be done there. I'd completely missed the fact that some of the state is already shared and how weird that is.
Apologies for the confusion! I'll file a separate issue to document this for now, until we get it sorted out.
Gotcha, thanks for the details. I'm doing a lot of C/Lua splitting and was surprised I hadn't seen this before. I can work around it by manually syncing the states now that I know what's going on.
Updating the docs would be appreciated though. These decorations weren't doing me any favors: