參考stackoverflow亭罪,可行的方法為
一渴肉、使用glCopyImageSubData玄妈,這個方法最直觀而且簡單包晰。不過需要 OpenGL 4.3
二底瓣、為目標texture創(chuàng)建FBO厅贪。使用shader羞福,采用texture2D把源texture畫到目標texture
三幻碱、為源texture創(chuàng)建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以上支持
glGenFramebuffers(1, &fbo); // 源texture和目標texture共用一個FBO即可
...
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);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
五沼撕、glCopyPixels豫缨,還不知道怎么用
https://stackoverflow.com/questions/23981016/best-method-to-copy-texture-to-texture
https://stackoverflow.com/questions/16100308/how-to-copy-texture1-to-texture2-efficiently