微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用pbo生成mipmap太慢?

如何解决用pbo生成mipmap太慢?

我正在开发类似视频的应用程序。
为了加快贴图上传的速度,我用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 举报,一经查实,本站将立刻删除。