PDA

View Full Version : DDS + mipmapping doesn't work



Ilian Dinev
03-09-2009, 08:51 PM
Geforce 8600GT, driver 181.22 (6.14.11.8122), winxp sp2

Texture is black, while mipmap sizes and data for each level (down to the 4x4 mip) are correct. Distance from textured object doesn't matter, all mip-levels appear black.
If I specify GL_LINEAR instead of GL_LINEAR_MIPMAP_LINEAR, level0 is visible.
I had this issue with previous drivers, so maybe the problem is with my code.
glGetError reports no problems.



glEnable(GL_TEXTURE_2D);
...
glGenTextures( 1, &me->glTexHandle);
glBindTexture(GL_TEXTURE_2D,me->glTexHandle);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


for(each mipmap){
glCompressedTexImage2D(GL_TEXTURE_2D,LOD,f->iformat,wid,hei,0,nSize,data); // LOD=0,1,2...
}


Everything works as expected when I change just the mipmap-uploading code with this:
glTexParameterf( GL_TEXTURE_2D, GL_GENERATE_MIPMAP,GL_TRUE);
glTexImage2D( GL_TEXTURE_2D, LOD, f->iformat, wid, hei, 0, f->format, f->storage,data); // LOD=0
// uploading GL_BGRA uncompressed texture this time, not DXT

i.e my texture-states, shaders etc are setup correctly.

Any tutorial online on mipmapping with DDS? Or I can create a short simple test-app to demonstrate the bug.

LangFox
03-10-2009, 12:58 AM
Try this:


//glTexParameterf( GL_TEXTURE_2D, GL_GENERATE_MIPMAP,GL_TRUE);
glTexImage2D( GL_TEXTURE_2D, LOD, f->iformat, wid, hei, 0, f->format, f->storage,data); // LOD=0
// uploading GL_BGRA uncompressed texture this time, not DXT
glGenerateMipmapEXT(GL_TEXTURE_2D);

Ilian Dinev
03-10-2009, 02:17 AM
You couldn't understand me. The uncompressed automatic mipmapping works perfectly.
Uploading S3TC mip-levels works, but if I set GL_LINEAR_MIPMAP_LINEAR the texture becomes black.

I simply want to use the basic common functionality: upload tiny S3TC-compressed DDS mips to gpu, use automatic trilinear filtering.

Jan
03-10-2009, 03:17 AM
Are you uploading ALL mipmap levels? Sometimes a DDS only contains part of the mipmap chain. As long as you don't tell gl, that you only have n-k mipmaps, it will assume that the texture is not complete.

glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, iMaxMipmapUsed);

Jan.

_NK47
03-10-2009, 09:43 AM
would it work if say upload uncompressed data to compressed format, read back the compressed data for all mipmap levels, store it and upload all levels again in compressed format? AFAIK something similar to what Jan said that not all levels are provided in DDS.

Ilian Dinev
03-10-2009, 11:43 AM
Jan, that TEXTURE_MAX_LEVEL was the thing I was missing! Thanks :)
The mipmap chain did have all levels uploaded: 0=512x512, 1=256,128,64,32,8,6=4x4 (uploaded in that order)

_NK47, that wouldn't have worked well in a modern game, would it :P

_NK47
03-10-2009, 01:08 PM
well, sure not :D just for testing purpose.

dletozeun
03-10-2009, 01:28 PM
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, iMaxMipmapUsed);


I did not know the existance of that. Thanks Jan :) Once I had problems loading each mipmap level on intel hardware. Like Ilian I had a black texture as long as I did not set explicitly all mipmap levels until 1x1 dimension. The funny thing is that nvidia hardware managed to make it work, but that is not a good thing IMO.