简体   繁体   中英

Screen Capture with Open GL using glReadPixels

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, ie 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.

Capture Thread -> HandlerThread

CaptureThread runs CGRegisterScreenRefreshCallback-> Callback notifies a Handler thread that rectangles have changed -> If needed the handler thread only will ask for rectangle data.

At this stage we would be using glReadPixels to read the rectangle data.

Can this be changed to any faster API which can read the data from just the rectangle which has changed ? This should be very fast as there will be a large number of rectangles which will be changed and would be checking for screen updates many number of times.

Do we need to change the design to make it faster ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM