Still problems with mipmap

Hi all,

I still have problems generating a mipmap.

Here is what I currently have:

 
energyValuesTex->Activate();
energyValuesTex->Bind();
//?? glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); 
    glTexParameterf(energyValuesTex->GetProps()->target,
                                GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameterf(energyValuesTex->GetProps()->target, 
                                GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(energyValuesTex->GetProps()->target, 
                                GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(energyValuesTex->GetProps()->target, 
                                GL_TEXTURE_WRAP_T, GL_CLAMP);    
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);                                
      
    glEnable(energyValuesTex->GetProps()->target);
        
    GLint dim = (int)(sqrt(vfgUtility::NextPowerOfTwo(particles->GetParticlesCount())));
      glTexImage2D(energyValuesTex->GetProps()->target, 
                 0, 
                 energyValuesTex->GetProps()->format_int, 
                 dim,
                 dim, 
                 0, 
                 energyValuesTex->GetProps()->format_ext, 
                 energyValuesTex->GetProps()->type,
                 BUFFER_OFFSET(0));
    //?? glGenerateMipmapEXT(energyValuesTex->GetProps()->target);
    //?? gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 128, 128, GL_RGB, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
    
        
    // Cleanup    
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
    glDisable(energyValuesTex->GetProps()->target);    
    energyValuesTex->Unbind();
    energyValuesTex->Deactivate();   
        
    // Get back values at certain mipmap level
    energyValuesTex->Activate();
    energyValuesTex->Bind();
        
    GLfloat pixels[3*16384];
    glGetTexImage(energyValuesTex->GetProps()->target, 1, energyValuesTex->GetProps()->format_ext, energyValuesTex->GetProps()->type,pixels);
     
    for(int i=0; i<21; i+=3)  cout << (float)(pixels[i]) << ", " << (float)(pixels[i+1]) << ", " << (float)(pixels[i+2]) << endl;
    
    energyValuesTex->Unbind();
    energyValuesTex->Deactivate();

Currently I fill my texture with all the same values, so I would expect that the first level mipmap averages out to approximately the same value. I just can’t seem to get this to work. Did I forget something?

Regards,

Ropel

You should either use glTexImage2D in a loop or gluBuild2DMipmaps.
Try with gluBuild2DMipmaps.

With glTexImage2D you will have to downscale texture by yourself and make sure you generate proper mipmap sizes.
gluBuild2DMipmaps will do the above for you. If you use it you don’t have to use any kind of generate mipmap stuff.

By the way, you don’t have to enable texture to use TexImage nor GetTexImage, but it’s no problem if you do.

Thank your for your reply. I see the difference now.

Let me check if I’m correct:
1.
glTexImages allows to manually fill a texture at a certain level.

gluBuild2DMipmaps automates this resizing. (It crashes for me, I’m not sure why yet)

glGenerateMipmapEXT can only be used for FBO rendered textures (?)

glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE) I’m not sure about yet.

Is any of these methods hardware rendered?

Thanks again…

gluBuild2DMipmaps will crash if the source image is not power of two in size.
What you should do is use gluScaleImage when manually creating your mipmaps with glTexImage2D.

Currently my texture is 128 square, so that should be no problem.

Actually I only need to calcultate the average of the entire texture, so that is the final mipmap.

I guess the current approach is not hardware rendered. Will this be costly to do using gluScaleImage?!

The generate mipmaps stuff is a driver level auto-generation capaility that might be hardware accelerated it generates based on level zero which could be rendered with the right extensions.

gluBuild2DMipmaps is a software utility that ultimately calls glTexImage for each level. You can also do your own calls to glTexImage.

If that software is crashing it is very probably because you have given image data that is not correctly described by your image parameters and/or is incompatible with the texture format you have bound.

You don’t say what your BUFFER_OFFSET() macro does but that whole build2dmipmaps call is hardcoded and may be incompatile with the internal and external texture format your non hardcoded teximage call.

RGB textures are not always RGB format internal and/or external and in this case size matters A LOT.

I was considering the gluScaleImage to manually do the mipmapping, not to resize to a 2^n texture.

The macro I use can be found is several OpenGL specs in the examples:
#define BUFFER_OFFSET(i) ((char *)NULL + (i))

Nothing fancy there, except that I read from a PB. Since I receive my values back through a transform feedback I need to somehow turn this into a mipmapped texture.

The parameters for my texture:

  vfgTexProps properties;
  properties.unit       = GL_TEXTURE5;
  properties.target     = GL_TEXTURE_2D;
  properties.format_int = GL_RGB;  
  properties.format_ext = GL_RGB;
  properties.type       = GL_UNSIGNED_BYTE; 

I just want to be able to call glTexImage for the smallest (1 texel) mipmap, but I can’t get it generated :S.

Originally posted by ropel:

1.glTexImages allows to manually fill a texture at a certain level.

yes, stick it in google.


2.gluBuild2DMipmaps automates this resizing. (It crashes for me, I’m not sure why yet)

it doesn’t resize the initial image, but it progressively halves the size while calling teximage with a greater and greater value in the mipmap level parameter. It crashes on non-pow2 initial textures. For older hardware, you should use this function, but check the pow2 validity and call gluScaleImage beforehand if not pow2 (it should do this itself, but unfortunately it doesn’t). Software only.


3.glGenerateMipmapEXT can only be used for FBO rendered textures (?)

no, although its a function introduced in the FBO extension, it can be used on any texture. (only if FBO extension is supported though). Hardware accelerated.


4.glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE) I’m not sure about yet.

with this enabled, the mipmap pyramid is automatically re-generated every time a glteximage/gltexsubimage is called on that texture object. Hardware accelerated.

Ah, thank you so much for the clear overview!!

So what I should be using is the glGenerateMipmapEXT in combination with the correct TexParameter!

How can I verify if glGenerateMipmapEXT actually performs the mipmapping? The values I get back from glGetTexImage are just a bunch of garbage.

Originally posted by knackered:

[quote]
2.gluBuild2DMipmaps automates this resizing.

it doesn’t resize the initial image[/QUOTE]It does resize the initial image. Read the manpage.