mipmapping

why

code 1:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST);

code 2:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

why code 1 is faster tha code 2?
how can i do the code 2 faster?

P.s: with code 1: 76 fps
with code 2: 36 fps

Are you sure? Nearest filtering is faster than linear filtering.
Have you used from the function gluBuild2DMipmaps() in code 1?
-Ehsan-

Mipmaping used in first case results in memory access that is more friendly to texture caches and to memory bandwith in situations where the texture is heavily minified on the screen.

Originally posted by Ehsan Kamrani:
Nearest filtering is faster than linear filtering.

For ordinary RGBA8 textures the current HW is optimized for the GL_LINEAR case so it may be at the same speed as GL_NEAREST. Some HW reads four samples used by GL_LINEAR even if GL_NEAREST is used and then simply discards three of them.

Originally posted by Ehsan Kamrani:
Are you sure? Nearest filtering is faster than linear filtering.
Have you used from the function gluBuild2DMipmaps() in code 1?
-Ehsan-

yes i used gluBuild2DMipmaps()…

but the code 1 (mip mapping) don’t work on my notebook, so how can i improve the speed of code 2?

With using a smaller image ?

MIP mapping uses smaller image versions during minification so texture memory access is much better behaved, typically there are a lot more texture cache hits and in general the access pattern is approximately contiguous. This is not an unusual result.