OpenGL拷贝纹理的两种方式

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

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

方法一:获取纹理再拷贝

unsigned char * data = new unsigned char[normal_texture.width*normal_texture.Hight*4];
glBindTexture(GL_TEXTURE_2D,src_id);
glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
glBindTexture(GL_TEXTURE_2D,dest_id);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);
glBindTexture(GL_TEXTURE_2D,0);

第二种方法:FBO拷贝

GLuint fbo;
glGenFramebuffers(1,&fbo);
/// bind the FBO
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
/// attach the source texture to the fbo
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
		GL_TEXTURE_2D, src_id, 0);
/// bind the destination texture
glBindTexture(GL_TEXTURE_2D, dest_id);
/// copy from framebuffer (here, the FBO!) to the bound texture
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width,height);
/// unbind the FBO
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D,0);




转载于:https://my.oschina.net/superpdm/blog/376387

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值