问题描述
我正在开发类似视频的应用程序。
为了加快贴图上传的速度,我用pbo增加了。
为了处理走样神器,我使用mipmap来帮助这个。
好吧,让我给你看看主要代码
// Step 1: Build the texture.
// Generate texture.
gluint tex;
glGenTextures(1,&tex)
// Generate pbo.
gluint pbo;
glGenBuffers(1,&pbo);
glBufferData(GL_PIXEL_UNPACK_BUFFER,width_* height_ * channel_,GL_DYNAMIC_DRAW);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER,0);
// Set tex parameters.
glBindTexture(GL_TEXTURE_2D,tex_id);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_LINEAR);
// Allocate memory for texture
glTexImage2D(GL_TEXTURE_2D,GL_RGB,width_,height_,GL_UNSIGNED_BYTE,0);
// Generate the mipmap
glGenerateMipMap(GL_TEXTURE_2D);
// Step2: For each frame,upload texture and generate mipmap.
while(true){
// Map pbo to client memory.
glBindBuffer(GL_PIXEL_UNPACK_BUFFER,pbo);
glBufferData(GL_PIXEL_UNPACK_BUFFER,GL_DYNAMIC_DRAW);
mapped_buffer_ = (glubyte*) glMapBufferRange(GL_PIXEL_UNPACK_BUFFER,width_ * height_ * channel_,GL_MAP_WRITE_BIT);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER,0);
// copy image data.
memcpy(mapped_buffer,pointer,height_ * width * channel_);
// Setting last parameter to 0 indicate that we use async mode to upload texture from pbo to texture.
glTexSubImage2D(GL_TEXTURE_2D,0);
// Generate mip map is sync function,so it will block until texture uploading is done.
glGenerateMipMap(GL_TEXTURE_2D);
}
结果是帧率大幅下降。
我认为原因是生成mipmap会破坏使用pbo异步上传纹理的优势。
据我所知,没有任何方法可以在纹理上传完成时自动生成 mipmap。
有没有提前?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)