I'm developing a video-like application.
In order to accelerate the speed of the texture uploading, I use pbo to increase it.
In order to deal with the aliasing artifact, I use mipmap to help this.
Well, let me show you the major code
// 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_, 0, 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_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Allocate memory for texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width_, height_, 0, GL_RGB, 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, width_* height_ * channel_, 0, GL_DYNAMIC_DRAW);
mapped_buffer_ = (GLubyte*) glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, 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, 0, 0, width_, height_, GL_RGB, GL_UNSIGNED_BYTE, 0);
// Generate mip map is sync function, so it will block until texture uploading is done.
glGenerateMipMap(GL_TEXTURE_2D);
}
The result is that frame rate dropped significantly.
I think the reason is that generating mipmap will break the advantage of async uploading texture using pbo.
As far as I know, there are no method to make mipmap to be generated automatically when texture-uploading is done.
Is there some advance?