I'm trying to use QT's QGLBuffer with glCompressedTexImage2D() and glCompressedTexSubImage2D() but with no success.
This is a working segment of code using QGLBuffer and glTexImage2D():
auto pbo = new QGLBuffer(QGLBuffer::PixelUnpackBuffer);
pbo->create();
pbo->bind();
pbo->allocate(image->pixelsData(), image->pixelDataSize());
// pixelsData() returns std::vector.data() of uncompressed data,
// pixelDataSize() returns size of the vector
GLuint imageTex;
glGenTextures(1, &imageTex);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, imageTex);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,
0,
GL_RGBA,
image->width(), image->height(),
0,
GL_RGBA, GL_UNSIGNED_BYTE,
0);
pbo->release();
and this is another segment of code using compressed image data that works as well:
GLuint imageTex;
glGenTextures(1, &imageTex);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, imageTex);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glCompressedTexImage2D(GL_TEXTURE_RECTANGLE_ARB,
0,
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
image->width(), image->height(),
0,
image->pixelDataSize(),
image->pixelsData());
// pixelDataSize() in this case returns std::vector.data() of image compressed to DXT1
// and pixelDataSize() returns the compressed size
// saw in another post that you can't pass in NULL and 0 for compressed texture
However, if I use a PBO with glCompressedTexImage2D() like this:
auto pbo = new QGLBuffer(QGLBuffer::PixelUnpackBuffer);
pbo->create();
pbo->bind();
pbo->allocate(image->pixelsData(), image->pixelDataSize());
GLuint imageTex;
glGenTextures(1, &imageTex);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, imageTex);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glCompressedTexImage2D(GL_TEXTURE_RECTANGLE_ARB,
0,
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
image->width(), image->height(),
0,
image->pixelDataSize(),
image->pixelsData());
pbo->release();
I got a invalid operation error. QGLBuffer's docs says that its for "writing pixel data to the GL server (for example, with glTexImage2D()).", but it doesn't mention anything about other unpacking commands such as glCompressedTexImage2D().
I'd searched the web for more docs on both QGLBuffer and glCompressedTexImage2D() but can't find anything on using them at the same time.
I'm working under linux using QT4.8.
Anyone has experience doing this with success?
The call to glCompressedTexImage2D
looks wrong. When a Pixel Unpack Buffer Object is bound, the last argument is an offset (in bytes) into that PUBO. Which means it should very likely be 0, since you uploaded your texture data from byte 0, in the previous allocate
call.