PDA

View Full Version : How to copy data from one texture to another?



Gong
10-12-2008, 12:46 AM
I've tried 3 ways to transfer data from one texture to another.
1. read back to CPU then upload. It's dead slow.
2. bind 2 textures to fbos then glBlitFramebufferEXT. It's much faster but doesn't work with compressed texture format.
3. glGetTexImage to a pbo then glTexSubImage to another texture. Surprisingly, it's as slow as read back to CPU.
My question is, is there any ways in OpenGL to do this job directly? Thanks.

A. Masserann
10-12-2008, 07:59 AM
I'd say, render a fullscreen quad that just copy the texture value to gl_FragColor, but there surely is a better way. Moreover, I don't know if it works with your compressed textures.

Korval
10-12-2008, 03:12 PM
My question is, is there any ways in OpenGL to do this job directly? Thanks.

No. The closest you can get is to use PBOs. Copy one texture into the PBO, then upload it into the destination. The ARB isn't big on adding small-but-important features like direct texture-to-texture copies.

yooyo
10-12-2008, 05:32 PM
But why do you want to duplicate resource?

Gong
10-12-2008, 09:59 PM
Fullscreen quad can't solve the problem because some formats are unrenderable.
I duplicate textures because the top level of my engine is based on double buffer. One for CPU write and one for GPU read/write. Data need to transferred between them.

Well I think PBO-ways is the best but I don't know why it's slow.

Korval
10-13-2008, 12:37 AM
Well I think PBO-ways is the best but I don't know why it's slow.

It's slow because the upload has to block on the CPU until the download finishes. And probably because IHVs don't care much about optimizing unusual PBO usage.

Gong
10-13-2008, 09:06 PM
Well I think PBO-ways is the best but I don't know why it's slow.

It's slow because the upload has to block on the CPU until the download finishes. And probably because IHVs don't care much about optimizing unusual PBO usage.

I see. Thanks.:)

Keith Z. Leonard
10-13-2008, 09:12 PM
Framebuffer blit can do it if they are attachable formats. That's what I would do. EDIT: DOH! Never mind, compression. A full screen quad will work, but your result won't be compressed. So I suppose PBO.

Brolingstanz
10-13-2008, 09:59 PM
Dx10 has a copy API, but really the only thing I've seen it used for is streaming data from disk and screen grabs, scenarios where you're strongly encouraged to use a proxy/staging resource to avoid generic CPU access flags on your textures or render targets - pretty near as much what you get with PBOs, by the way, only these sorts of async copies/updates have been factored out into an API of their own for just this sort of thing.

k_szczech
10-14-2008, 02:02 AM
Try rendering source texture to any framebuffer and using glCopyTexSubImage to copy from framebuffer to destination texture.

I have no idea if it will work but it's so simple it's worth a try (unless someone allready knows it won't work).

kreyszig
10-21-2008, 06:49 AM
I can confirm this will work. I use it to change between texture formats.


Try rendering source texture to any framebuffer and using glCopyTexSubImage to copy from framebuffer to destination texture.

I have no idea if it will work but it's so simple it's worth a try (unless someone allready knows it won't work).