开发者

Screen Capture with Open GL using glReadPixels

开发者 https://www.devze.com 2023-02-14 09:00 出处:网络
I created a CGRegisterScreenRefreshCallback(refreshCallback, NULL) and in the refreshCallback method get the list of rectangles which have changed.

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 u开发者_运维问答se 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.


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 ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号