How to unlock OpenGL call blocking

I am learning GPGPU programming using OpenGL + GLSL. One of the problems is that if you have a shader that takes a lot of time, it cannot be undone.

After setting everything up, I issue a final call to glReadPixels , which blocks until all the pixels are displayed in the framebuffer. Depending on the shader, this can take a long time, even seconds. Is there a way to cancel a call (from another thread) or even request progress? What happens if you set up an infinite loop in a shader?

0
source share
2 answers

instead of glReadPixels you can use PixelBufferObjects that do not block. glReadPixels will wait (in your main thread) for the results, but the PBO will continue ... somewhere later in the code you can check if the data is available in the PBO.

http://www.songho.ca/opengl/gl_pbo.html

http://www.opengl.org/wiki/Pixel_Buffer_Object

if you need more complex calculations, you can use OpenCL, which will give you more flexibility.

+3
source

What happens if you set up an infinite loop in a shader?

I think you will get a video driver crash.

0
source

All Articles