当前位置:   article > 正文

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

opengl 隔行拷贝

参考stackoverflow,可行的方法为
一、使用glCopyImageSubData,这个方法最直观而且简单。不过需要 OpenGL 4.3
二、为目标texture创建FBO。使用shader,采用texture2D把源texture画到目标texture
三、为源texture创建FBO。使用glCopyTexSubImage2D从framebuffer拷贝到目标纹理

 
  1. fboId = srcTex->GetFrameBufferId();

  2. glBindFramebuffer(GL_FRAMEBUFFER, fboId);

  3. outTexId = dstTex->GetTextureId();

  4. glActiveTexture(GL_TEXTURE0);

  5. glBindTexture(GL_TEXTURE_2D, outTexId);

  6. glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,

  7. 0, 0, srcTex->GetWidth(), srcTex->GetHeight());

  8. glBindTexture(GL_TEXTURE_2D, 0);

  9. glBindFramebuffer(GL_FRAMEBUFFER, 0);

四、glBlitFramebuffer。这个需要OpenGL ES 3.0以上支持

 
  1. glBindFramebuffer(GL_FRAMEBUFFER, fbo);

  2. glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,

  3. GL_TEXTURE_2D, tex1, 0);

  4. glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,

  5. GL_TEXTURE_2D, tex2, 0);

  6. glDrawBuffer(GL_COLOR_ATTACHMENT1);

  7. glBlitFramebuffer(0, 0, width, height, 0, 0, width, height,

  8. GL_COLOR_BUFFER_BIT, GL_NEAREST);

五、glCopyPixels

opengl - Best method to copy texture to texture - Stack Overflow
opengl - How to copy texture1 to texture2 efficiently? - Stack Overflow

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/509886
推荐阅读
相关标签
  

闽ICP备14008679号