Hello,
I have been trying to update a compressed texture of PVRTC_2BPPV2 format using PBO using OpenGL_ES 3. But every time it fails with the code GL_INVALID_OPERATION.
I am using following code to do the task:
[pre]{//buffer: (GLubyte*)holds the raw pixel data
//width: width of the texture
//height: heigth of the texture
//NUM_OF_BITS_PER_PIXEL = 2 since PVRTC_2BPPV2 is used
//so the actual data size is: (widthheight2)/8 bytes
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures ( 1, &texId );
glBindTexture ( GL_TEXTURE_2D, texId );
glCompressedTexImage2D(GL_TEXTURE_2D,0,GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG,width,height,0,(widthheight2)/8,0);
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glBindTexture ( GL_TEXTURE_2D, 0 );
//creating PBO
glGenBuffers(1,&pboID);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboID );
glBufferData(GL_PIXEL_UNPACK_BUFFER, (width * height * 2)/8, 0, GL_STREAM_DRAW);
GLubyte* colorptr = (GLubyte*)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, (width * height * 2)/8, GL_MAP_WRITE_BIT);
if(colorptr)
{
breturen = glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
if(!breturen)
{
//something wrong happened
}
}
glBindTexture( GL_TEXTURE_2D, texId );
glCompressedTexSubImage2D(GL_TEXTURE_2D,0,0,0,width,height,GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG,(widthheight2)/8,0);
memcpy(colorptr, buffer, (sizeof(GLubyte) * width * height *2)/8);
free ( buffer );
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0 );
glBindTexture( GL_TEXTURE_2D, 0 );}[/pre]
I have tried similarly using non-compressed textures with PBO which succeeds.
Again I have tried updating PVRTC_2BPPV2 texture using glCompressedTexSubImage2D without PBO and it succeeds too.
But the combination of Compressed texture along with PBO fails every time.
Is it not supported to update a portion/whole compressed texture using PBO or is the problem related to the emulator?
Looking forward to your replies.
Thanks.