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


 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值