PDA

View Full Version : glCopyTexImage2D for mipmaps



AzureRain
01-06-2009, 12:29 AM
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

dletozeun
01-06-2009, 05:27 AM
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.

AzureRain
01-06-2009, 05:53 AM
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.

_NK47
01-06-2009, 07:39 AM
maybe you forgot to activate mipmap filtering. GL_LINEAR_MIPMAP_LINEAR / GL_NEAREST_MIPMAP_NEAREST

AzureRain
01-15-2009, 08:07 AM
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...

_NK47
01-15-2009, 08:16 AM
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.

AzureRain
01-25-2009, 12:16 AM
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 (http://picasaweb.google.com/lh/photo/nuD7I92yNKjHC28lbOUrWg?authkey=eZu_zWz2vt4&feat=directlink)

Level 1 (http://picasaweb.google.com/lh/photo/sNpyIxU3sSorf8ij4V2POA?authkey=eZu_zWz2vt4&feat=directlink)

Level 0 texture (http://picasaweb.google.com/lh/photo/LSeBdSXFvh0fsXJkgi2kIA?authkey=eZu_zWz2vt4&feat=directlink)

Level 1 texture (http://picasaweb.google.com/lh/photo/FuxLPrO6f-PMDEbl1zwbng?authkey=eZu_zWz2vt4&feat=directlink)