OpenGL中如何将某个texture拷贝到另外一个texture

https://www.jianshu.com/p/9e5e7e62e466

 

参考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,还不知道怎么用

https://stackoverflow.com/questions/23981016/best-method-to-copy-texture-to-texture
https://stackoverflow.com/questions/16100308/how-to-copy-texture1-to-texture2-efficiently


 

你可能感兴趣的:(video)