glCopyTexImage2D for mipmaps

Hi,

I want to generate mip levels manually using multiple calls of glCopyTexImage2D, is this possible?

For example,

glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32,
0, 0, 256, 256, 0);

glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT32,
0, 0, 128, 128, 0);

glCopyTexImage2D(GL_TEXTURE_2D, 2, GL_DEPTH_COMPONENT32,
0, 0, 64, 64, 0);

and so on…

Doesn’t work for me so I’d like to ask if there’s something I’m doing wrong.
Thanks

That should work. On what hardware are you working on? Some, need to specify all mipmap levels even if it is not usable in your program.
I have never did that, but you might call glTexImage2D to allocate memory for the last mipmap levels.

I’m using a Nvidia EN8800GT.

When I call tex2Dlod(shadowMap, float4(uPix,vPix, 0, miplevel)) in a Cg shader, I get the same result no matter what value I use for miplevel, i.e. it uses the base level. I don’t know whether the problem is in the generation of the mipmaps or the accessing it in Cg.

maybe you forgot to activate mipmap filtering. GL_LINEAR_MIPMAP_LINEAR / GL_NEAREST_MIPMAP_NEAREST

Thanks, I added in these lines and now I get different results for different mip levels, but still doesn’t seem to work properly.

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);

I get different results when I store a 256 x 256 mipmap as the base level and as level 1.

For example, this works fine:
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32,
0, 0, 256, 256, 0);
tex2Dlod(shadowMap, float4(uPix,vPix, 0, 0)) // correct result

But this doesn’t work:
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32,
0, 0, 512, 512, 0);
glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT32,
0, 0, 256, 256, 0);
tex2Dlod(shadowMap, float4(uPix,vPix, 0, 1)) // different result

Does anyone know what I could be doing wrong from this? Thanks alot…

maybe a screenshot would help. retrieve the texture data from level 0 and 1 and save it as image so to compare between level 0 and 1. but just for information, you copy depth to texture? and why doing it manually?
fyi, GL_TEXTURE_MAG_FILTER cant’ be mipmaped, GL_LINEAR / GL_NEAREST.

I’m trying to create a min-max mipmapped shadow map a.k.a. hierarchical shadow map. Not sure how to do it, but trying to get the mipmaps to work first… I’m doing it manually because I need to manipulate the minimum and maximum values somehow…

The difference is drastic. Please help! Thanks again

Here are the images. The texture is used as a shadow map.

Level 0

Level 1

Level 0 texture

Level 1 texture