How to copy data from one texture to another?

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.

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.

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.

But why do you want to duplicate resource?

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.

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.:slight_smile:

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.

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.

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).

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).