Mipmaps+PBO: strange issues
I'm using PBOs to load textures faster in my application. If I use an opengl 3 or better video card I can then easily build the mipmaps with a call to glGenerateMipmap and it works fine. But on my older opengl 2.1 card (radeon x800), that function is not available so i must use one of two legacy methods:
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w,h, 0,GL_RGBA,GL_UNSIGNED_BYTE, src);
or
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA8, w,h, GL_RGBA,GL_UNSIGNED_BYTE, src);
The first method doesn't work fine even whitout the PBO, it introduces strange artifacts. The second one, whitout the PBO builds the correct mipmaps, and with the PBO generates a segfault. Anyone can help??
For completeness I attach the code I use for the PBO:
uint pixelBuffer;
glGenBuffers(1, &pixelBuffer);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelBuffer);
glBufferData(GL_PIXEL_UNPACK_BUFFER, size*4, NULL, GL_STATIC_READ);
char *pixels = (char*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
... transfer data
glUnma开发者_C百科pBuffer(GL_PIXEL_UNPACK_BUFFER);
... and then I use the buffer to create the texture
PS If I don't try to generate mipmaps, the pbo loading works on all my video cards.
This is simple, gluBuild2DMipmaps() expects pointer in client memory (because it is just a glu function, not a part of the driver) so it will not work with PBO. As for using the
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
try calling it after glTexImage2D(). Some drivers implement this extension differently and actually require this line to be called everytime when the mipmaps should be generated (there's nothing done "automatic aly"). Your strange artifacts are actually random data in higher mipmap levels because the mipmaps weren't generated at all.
As for using PBO for speed, it is perfectly legit method. There might be a new way possible with the "pinned memory", but I haven't looked into it yet.
精彩评论