How to compute an image infinitely

This question is for research purpose. We are working on Sobel computation. We are wondering, if and how, to run a loop (infinite loop) on a image to keep computing (sobel, prewitt anything) and when I am hitting a certain keyboard key say “Q”, the computation will stop and show us the result. If I hit resume again, keyboard key “R”, the computation will start again.

We have almost primary level idea in openGL like how to draw a point, shape etc and we would love to get some suggestions or work-around.

Thank you.

An infinite loop inside a shader program is a bad idea. Some implementations (I know of atleast one where I ran into that problem
with OpenCL®) have a watchdog timer that stops shader evaluation after a certain timeout.

You can only apply one or a few iterations of your loop at a time and write the output to a buffer object that is used as input in the
next step.

The continue-stop-restart logic, along with switching the buffer bindings and starting the computation steps, is done on the CPU.