PDA

View Full Version : Different MipMap Technic!



Golgoth
05-06-2006, 10:47 AM
Hi all!

Is this possible to create Mipmaps after glTexImage2D() as been called, instead of using gluBuild2DMipmaps()?

thx

CrazyButcher
05-06-2006, 03:21 PM
yes, glu just wraps the gl calls and does a simple scaling method for the mipmaps

the second parameter of glTexImage "level" means which mipmap you want to upload (0 is fullsize, 1 quarter and so on)

zed
05-06-2006, 04:34 PM
true, if u want gl to automatically create mipmaps use the generate_mipmap thingee (theres also something for FBO as well)
basically what happens when u change the base level 0 texture (the largest sized texture) all the smaller sized mipmaps will get recreated (does come with a performance hit, but is far faster than glubuildmipmaps)

Golgoth
05-06-2006, 09:58 PM
the second parameter of glTexImage "level" that is really interesting... been using the glu function for ages, didnt realy care till i hit on glGenerateMipmapEXT();...

basically what happens when u change the base level 0 texture (the largest sized texture) all the smaller sized mipmaps will get recreated not sure i get what u mean... if level is set to 1... you ll end up with the full size plus one mimap 1/2 size? if level is set to 2... full, 1/2 and 1/4... ?

thx

zed
05-07-2006, 01:28 AM
level is like describes the mipmaps (smaller textures substituted when the texture covers lesser screen area, ie farther away usually)
thus for a 256x128 sized texture if u have mipmapping u have actually 9 textures in total
256x128 level 0
128x64 level 1
64x32 level 2
32x16 level 3
16x8 level 4
8x4 level 5
4x2 level 6
2x1 level 7
1x1 level 8

normally u just create the base texture (level0) and let gl generate the smaller textures, but its also possible to create the smaller mipmaps yourslef (esp useful for textures with alpha)

Golgoth
05-07-2006, 09:36 AM
hummm.... what im confused about is:

when calling glTexImage2D with level 0... are all mimaps automaticly created or do we have to call glTexImage2D for each level?

i m use to do something like:

if (in_texture->IsState(TEX_MIP_MAP))
gluBuild2DMipmaps
else
glTexImage2D with level 0

k_szczech
05-07-2006, 01:17 PM
Yes, you have to call glTexImage2D multiple times - one per each level.
Remember: if you use mipmaps then you mnust define all levels up to the point where texture gets downscaled to 1x1. If one or more levels remain undefined (glTexImage2D wasn't called for that level) OpenGL will act as if texturing was disabled.

CrazyButcher
05-07-2006, 01:20 PM
he was referring to "GL_GENERATE_MIPMAP_SGIS" when that is set, the automatic mip map stuff will create all mipmaps when level 0 is changed.

else you must specify all levels with teximage yourself (this is wrapped by gluBuildMipmaps)

Golgoth
05-07-2006, 03:32 PM
alright!


Yes, you have to call glTexImage2D multiple times - one per each level.that sounds over kill... anyone is doing this?

so i should use instead:
glTexParameterf(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);?

would it cause any problems when called on 1d and 3d textures?

Humus
05-08-2006, 05:55 AM
Originally posted by Golgoth:
that sounds over kill... anyone is doing this?Pretty much everyone I'd guess. These days some use automipmapping, but repeated glTexImage2D() calls is the standard way. What's so overkill about it? In D3D you upload all mipmaps separately too.


Originally posted by Golgoth:
would it cause any problems when called on 1d and 3d textures? Use glTexParameterf(GL_TEXTURE_1D, GL_GENERATE_MIPMAP, GL_TRUE); and glTexParameterf(GL_TEXTURE_3D, GL_GENERATE_MIPMAP, GL_TRUE); for those.

tamlin
05-08-2006, 07:45 AM
Originally posted by k_szczech:
Yes, you have to call glTexImage2D multiple times - one per each level.
Remember: if you use mipmaps then you mnust define all levels up to the point where texture gets downscaled to 1x1.... unless GL_TEXTURE_MAX_LEVEL is specified. Just wanted to point it out.

Golgoth
05-08-2006, 10:18 AM
Use glTexParameterf(GL_TEXTURE_1D, GL_GENERATE_MIPMAP, GL_TRUE); and glTexParameterf(GL_TEXTURE_3D, GL_GENERATE_MIPMAP, GL_TRUE); for those.Omg, im a noob... yes of course!



What's so overkill about it?Plz, refer to my previous comment! ;)

Now... with all the info i got we seams to have 3 possibilities of creating mipmaps... and i usualy go for the simpliest one...

1- Calling glTexImage() for each level...
2- Use gluBuildxDMipmaps()...
3- Enable automatic mimap with glTexParameterf(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

I m still not 100% sure that mipmaps will be created with this sequence:


... SNIP
if (in_texture->IsState(TEX_MIP_MAP))
glTexParameterf(l_dimension, GL_GENERATE_MIPMAP, GL_TRUE);

switch (l_dimension)
{
case (GL_TEXTURE_1D): {glTexImage1D(l_dimension, 0, ...); break;}
case (GL_TEXTURE_2D): {glTexImage2D(l_dimension, 0, ...); break;}
case (GL_TEXTURE_3D): {glTexImage3D(l_dimension, 0, ...); break;}
}
...SNIPis that correct?

zed
05-08-2006, 08:11 PM
try not to use gluBuildxDMipmaps() its like 10x slower than automatic mipmap creation + also IIRC it doesnt wotk for some things eg 3d textures

heres what i have for 2d texture (non compressed)
u can supply it with all mipmaps or just base level0 + let it generate the rest

for ( level = 0; level < num_mipmap_levels &amp;&amp; ( w>=1 &amp;#0124;&amp;#0124; h>=1 ); level++, w >>= 1, h >>= 1 )
{
if ( w < 1 ) w=1;
if ( h < 1 ) h=1;

glTexImage2D( texture_target, level, internal_format, w, h, texture_border, base_format, GL_UNSIGNED_BYTE, (GLvoid *)(pixels+offset_size) );
if ( pixels ) // only offset if theres some data else well run into trouble
offset_size += ( w * h * texture_bd );
}

arekkusu
05-09-2006, 02:09 AM
glu does works for 3D textures. It does not work for float texture formats, though.

Golgoth
05-09-2006, 10:21 AM
thx Zed!

Idealy, i would like not to have a loop for each texture xD! like in my previous post. Can anyone confirm if it is doable that way too?

if not well, ill use the for technic!