I created a CGRegisterScreenRefreshCallback(refreshCallback, NULL) and in the refreshCallback method get the list of rectangles which have changed.
I am getting the rectangle data from frameBuffer using OpenGL glReadPixels.
Is there a better way of screen capture either with/without opengl and also using OpenGL can I skip reading pixel by pixel ?
I have looked at glGetTexImage and glCopyTexSubImage2D. Any simple code block which can explain how to use these functions to get the changed rectangle data would be very helpful?
The best way to read back pixels is to bind a pixel buffer object (GL_PIXEL_PACK_BUFFER), initialize it with glBufferData and a null data pointer (GL_STREAM_READ, important!) to reserve memory, then call glReadPixels. Then, during the next frame, i.e after swapping buffers, either (preferrably) glMapBuffer or (alternatively) glGetBufferSubData.
This technique makes sure that glReadPixels will not block and the transfer will happen asynchronously at the highest possible transfer speed, with no more extra copies than necessary.