PDA

View Full Version : Can the framebuffer of Graphic Card be copy to texture buffer of OpenGL directly?



Daniel Xie
10-02-2005, 11:06 PM
I want to use the whole Screen of windows(and X Window) as a texture of an opengl program. I do it by grabing the screen first and then puting it to texture buffer, however it is quite slow. I wish I can copy these framebuffer in Graphic Card directly. Is this possible?

wereHamster
10-02-2005, 11:20 PM
glCopyTexSubImage() (which is faster than glCopyTexImage() in nVidia hardware) copies data from GL_READ_BUFFER to the active texture.

So make your window the current read buffer, activate your texture and copy the data over...

But... don't try to copy the texture to system memory with glGetTexImage() because that will be horribly slow (at least on my hardware it the copies with less than 5MiB/s)

Daniel Xie
10-07-2005, 02:04 AM
But how to make the current window as the read buffer? I mean the current GUI window or the whole desktop of system.

Relic
10-07-2005, 02:57 AM
You must not (cannot) use OpenGL to grab the screen contents of other processes windows. Period. Your approach is doomed.

For that to work you would have to have a valid pixelformat and an OpenGL context on other processes windows including the desktop window and that is not under your control.
Read the chapter about pixelownership in the OpenGL spec!
Even worse, SetPixelFormat works only once during the lifetime of a window. You would need to reboot to clean up the desktop's pixelformat for a second try if you actually were succesful.
Happy debugging...

Keep using the standard 2D methods to grab the screen and download it to your texture.

def
10-09-2005, 11:39 PM
Well, there used to be a way to grab the Desktop with OpenGL...
If I remember correctly you can grab the "screen" before doing any clear operation in OpenGL. So, open up a window filling the screen and do a glCopyPixels() befor everything else. Don't remember if it has to be the front or the back buffer...

Maybe this works for you!

Tom Nuydens
10-10-2005, 12:09 AM
Originally posted by def:
If I remember correctly you can grab the "screen" before doing any clear operation in OpenGL. So, open up a window filling the screen and do a glCopyPixels() befor everything else.Ick! I wouldn't go there if I were you. Even if this does turn out to work on your particular machine, the result of such a readback operation is undefined according to the OpenGL spec, and hence is unlikely to be the same on all implementations. It will probably vary from one HW vendor to another, and is even subject to change between driver versions.

Daniel Xie
10-12-2005, 02:32 AM
Thank you. In fact I do grab the desktop using GUI system call, such as XCopyImage and then put it to opengl texture. I have a dual head graph card GForce 5200, and I grab the GUI of one head and show it in the second. However it's quite slow -- only about 4~5 fps. The most time consuming part is to transfer the frame buffer of GUI to main memory and then put back it to texture buffer. So I want to know can I copy the buffer in the card directly without move them out to main memory?


Originally posted by Relic:
You must not (cannot) use OpenGL to grab the screen contents of other processes windows. Period. Your approach is doomed.

For that to work you would have to have a valid pixelformat and an OpenGL context on other processes windows including the desktop window and that is not under your control.
Read the chapter about pixelownership in the OpenGL spec!
Even worse, SetPixelFormat works only once during the lifetime of a window. You would need to reboot to clean up the desktop's pixelformat for a second try if you actually were succesful.
Happy debugging...

Keep using the standard 2D methods to grab the screen and download it to your texture.

Hampel
10-12-2005, 04:13 AM
Perhaps a mapped PBO (pixel buffer object) can help you out?

Daniel Xie
10-19-2005, 05:47 AM
Could you do me a favor to give me more detailed advices?


Originally posted by Hampel:
Perhaps a mapped PBO (pixel buffer object) can help you out?