您当前的位置: 首页 > 

鱼儿-1226

暂无认证

  • 0浏览

    0关注

    1100博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

OpenGL拷贝纹理的两种方式

鱼儿-1226 发布时间:2020-08-28 10:21:46 ,浏览量:0

一种是直观的使用glGetTexImage,然后获取数据到内存再贴上去,这种方法很慢

另一种是使用FBO,将纹理附加到FBO,然后用glCopyTexSubImage2D,不涉及跟内存交换数据,速度飞快。

方法一:获取纹理再拷贝

 
  1. unsigned char * data = new unsigned char[normal_texture.width*normal_texture.Hight*4];

  2. glBindTexture(GL_TEXTURE_2D,src_id);

  3. glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_BYTE,data);

  4. glBindTexture(GL_TEXTURE_2D,dest_id);

  5. glTexSubImage2D(GL_TEXTURE_2D,0,0,0,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);

  6. glBindTexture(GL_TEXTURE_2D,0);

第二种方法:FBO拷贝

 
  1. GLuint fbo;

  2. glGenFramebuffers(1,&fbo);

  3. /// bind the FBO

  4. glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);

  5. /// attach the source texture to the fbo

  6. glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,

  7. GL_TEXTURE_2D, src_id, 0);

  8. /// bind the destination texture

  9. glBindTexture(GL_TEXTURE_2D, dest_id);

  10. /// copy from framebuffer (here, the FBO!) to the bound texture

  11. glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width,height);

  12. /// unbind the FBO

  13. glBindFramebuffer(GL_FRAMEBUFFER, 0);

  14. glBindTexture(GL_TEXTURE_2D,0);

 

关注
打赏
1604459285
查看更多评论
立即登录/注册

微信扫码登录

0.0428s