I am working with compressed textures, which i have loaded successfully using the pixel pointer with glCompressedTexImage2DARB, but unfortunately when I use the PBO texture upload, it comes up wrong .
Now I am working with PBOās. I have tried with this code
snip example code
void CreateTexture(Image* imagedata)
{
switch(imagedata->v_pixelformat)
{
case COMPRESSED_DXT1:
gl_internalformat=GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
gl_format=GL_RGBA;
break;
case COMPRESSED_DXT3:
gl_internalformat=GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
gl_format=GL_RGBA;
break;
case COMPRESSED_DXT5:
gl_internalformat=GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
gl_format=GL_RGBA;
break;
}
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
glGenBuffersARB(1,&pBuf_GL);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pBuf_GL);
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, imagedata->imageSize, NULL, GL_STATIC_DRAW_ARB);
glGenTextures(1,&ID);
glBindTexture(GL_TEXTURE_2D, ID);
iOffset = 0;
int iWidth = imagedata->GetWidth();
int iHeight = imagedata->GetHeight();
unsigned int iNumMipMaps = imagedata->num_mipmaps;
blockSize=(imagedata->v_pixelformat == V_COMPRESSED_DXT1) ? 8 : 16;
if(iNumMipMaps < 2)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
for(Vuint i=0; i<iNumMipMaps; i++)
{
iSize = ((iWidth + 3) / 4) * ((iHeight + 3) / 4) * blockSize;
glCompressedTexImage2DARB(GL_TEXTURE_2D, i, gl_internalformat, iWidth, iHeight, 0, iSize, NULL);
iOffset += iSize;
iWidth /= 2;
iHeight /= 2;
}
unsigned char* tembuffer = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
memcpy(tempbuffer,imagedata->pixels,
glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB);
}
void BindTexture(Image* imagedata)
{
glBindTexture (GL_TEXTURE_2D, ID);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pBuf_GL);
int iOffset=0;
int iWidth = imagedata->GetWidth();
int iHeight = imagedata->GetHeight();
int iSize;
for(Vuint i = 0; i < texture->v_num_mipmaps; i++)
{
iSize = ((iWidth + 3) / 4) * ((iHeight + 3) / 4) * blockSize;
glCompressedTexSubImage2DARB(GL_TEXTURE_2D,i,0,0, iWidth, iHeight,gl_format, iSize,BUFFER_OFFSET(iOffset));
iOffset += iSize;
iHeight /= 2;
iHeight /= 2;
}
}
When I placeā¦
glCompressedTexImage2DARB(GL_TEXTURE_2D, i, gl_internalformat, iWidth, iHeight, 0, iSize, pixels);
The texture comes out right, but if I PBO the texture (by leaving the pixel data pointer NULL) it comes with a bitmap dump.
I was wondering if it is how I have used the glCompressedTexSubImage function which most likely be faulty. Does anybody know where the fault is in this codeā¦
Thank you