参考stackoverflow,可行的方法为 一、使用glCopyImageSubData,这个方法最直观而且简单。不过需要 OpenGL 4.3 二、为目标texture创建FBO。使用shader,采用texture2D把源texture画到目标texture 三、为源texture创建FBO。使用glCopyTexSubImage2D从framebuffer拷贝到目标纹理
-
fboId = srcTex->GetFrameBufferId();
-
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
-
outTexId = dstTex->GetTextureId();
-
glActiveTexture(GL_TEXTURE0);
-
glBindTexture(GL_TEXTURE_2D, outTexId);
-
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
-
0, 0, srcTex->GetWidth(), srcTex->GetHeight());
-
glBindTexture(GL_TEXTURE_2D, 0);
-
glBindFramebuffer(GL_FRAMEBUFFER, 0);
四、glBlitFramebuffer。这个需要OpenGL ES 3.0以上支持
-
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
-
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-
GL_TEXTURE_2D, tex1, 0);
-
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
-
GL_TEXTURE_2D, tex2, 0);
-
glDrawBuffer(GL_COLOR_ATTACHMENT1);
-
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height,
-
GL_COLOR_BUFFER_BIT, GL_NEAREST);
五、glCopyPixels
opengl - Best method to copy texture to texture - Stack Overflowopengl - How to copy texture1 to texture2 efficiently? - Stack Overflow