PDA

View Full Version : glCompressedTexImage2D and NULL data



golem
03-30-2006, 05:54 AM
Is it allowed to pass NULL as data to {Compressed}TexImage() to "reserve space" without downloading anything ?

It seems to crash on both Nvidia and ATI

The motivation for doing this is to download a large precompressed texture in small pieces by first creating an empty texture with glCompressedTexImage2D(..., NULL) and then subloading small blocks of texture data with glCompressedTexSubImage2D(..., data)

Thanks

andras
03-30-2006, 07:35 AM
I'm not sure why this crashes, but surely you could use glTexImage2D(..., NULL) for reserving the texture (with a compressed internalformat). And then using subsequent glCompressedTexSubImage calls to upload the small pieces.

tamlin
03-30-2006, 03:05 PM
I experienced something similar (http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=014112#000000) some time ago.

Worth noting might be that the code in that thread does not crash on an Intel implementation I tested it on (though it should be noted I didn't really check the resulting texture to see if it indeed was compressed).

Humus
03-30-2006, 08:53 PM
Originally posted by golem:
Is it allowed to pass NULL as data to {Compressed}TexImage() to "reserve space" without downloading anything ?The spec doesn't say NULL is allowed, so that would mean it's not. But as andras said, you can use glTexImage2D().

golem
03-31-2006, 07:13 AM
Andras,

Your suggestion is working !
Thank you very much

I suppose this is the normal way to use the API. I think this should have been explained better in the documentation. I am pretty sure i am not the only one to be confused.

canuckle
03-11-2007, 09:22 PM
Sorry to revive the thread, but I'm having a similar problem that when I call glTexImage2D(... NULL) for compressed textures, and then glCompressedTexSubImage2D(..., data), it always displays a white texture.

I'm running on nVidia ForceWare ver. 81.63 (Quadro FX 1400).

Does anyone else have similar problems?

knackered
03-12-2007, 03:38 AM
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

canuckle
03-13-2007, 12:14 PM
Thanks, knackered. Apparently, the MIN filter does matter (is mip map the default?), but my problem was that I was calling glTexImage2D() with the wrong parameters.

I was calling glTexImage2D() with GL_COMPRESSED_RGB_S3TC_DXT1_EXT instead of GL_RGB for the "format" parameter.

Here's my testing code for anyone that might bump into similar problems:


glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texHandle);

unsigned char red_pixels[4][4][4];
for (int i=0; i < 4; ++i) {
for (int j=0; j < 4; ++j) {
red_pixels[i][j][0] = 0xff;
red_pixels[i][j][1] = 0x00;
red_pixels[i][j][2] = 0x00;
red_pixels[i][j][3] = 0xff;
}
}

unsigned char red_dxt1[4 * 4 / 2] =
{ 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00 };

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
static int chooser = 2;
switch (chooser) {
case 0:
// Load uncompressed image in one shot.
// Should work.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, (void *)red_pixels);
break;
case 1:
// Load compressed image in one shot.
// Should work.
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 8, (void *)red_dxt1);
break;
case 2:
// Make space for uncompressed image, then load through subtexture region.
// Should work.
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8, (void *)red_dxt1);
break;
case 3:
// Just load subtexture region.
// Should NOT work.
glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8, (void *)red_dxt1);
break;
}


glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(-1, -1);
glVertex3f(-1, -1, 0.5);
glTexCoord2f(1, -1);
glVertex3f(1, -1, 0.5);
glTexCoord2f(-1, 1);
glVertex3f(-1, 1, 0.5);
glTexCoord2f(1, 1);
glVertex3f(1, 1, 0.5);
glEnd();

Humus
03-13-2007, 09:18 PM
Originally posted by canuckle:
is mip map the default?Yes. Specifically, it's GL_NEAREST_MIPMAP_LINEAR.