Different MipMap Technic!

Hi all!

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

thx

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)

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)

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

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)

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

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.

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)

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?

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.

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.

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! :wink:

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;}
	}
...SNIP

is that correct?

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 && ( w>=1 &#0124;&#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 );
		}

glu does works for 3D textures. It does not work for float texture formats, though.

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!