Support UNDO in openGL
Note - the code is still being used by commercial tools so it can not be published here. I'm just puting the ideas of how to do it.
JERRY OPENGL ES UNDO IMPLEMENTATION
OPENGL (for opengl es 1.1) only allows you to draw things into the buffer while it does not support the UNDO function. So there is no perfect native support.
Here - drawing of paint brush needs to be able to get function of undo. While obvioulsy we can come up with such idea:
- record all the drawing step's information.
- ignore last one when undo happens. (not delete - remember redo)
- clear the screen and re-draw everything.
but this is ofcourse heavy operation - when people draws over 20 lines (very likely case), it could take over 5 seconds or more to do so.
So my current solution is - instead of drawing everything everytime, let's copy the buffer for certain number of step's distance:
- draw and record.
- if it has already drawed N step without copy buffer, then save the buffer to texture.
- when user do undo, find the nearest buffer texture, store it back to screen, then draw the left over strokes (which is less than N for sure).
This is a trade of memory space and efficiency, however, due to the fact that texture's size needs to be power of 2, every copy of buffer needs to add 102410244 size. so - image you have like 10 buffer stored - 40M space! ;-( No idea how to improve...
Another note is.. stored image from glpixel to texture is upside down. needs to glroate and gltranslate after putting into view.