Mipmaps

another question - I setup my texture like this ( I load it from a RAW file into a PNMImage and the make a texture with it).


PT(Texture) make_tex(BYTE *pBuf, int texSize, bool bWrap, int nChan) 
{
	PNMImage* pImage = new PNMImage(texSize, texSize, nChan);

	for (int y = 0; y < texSize; ++y)
	{
		for (int x = 0; x < texSize; ++x)
		{
			int index = (y * (texSize * nChan)) + (x * nChan);
			if(nChan == 1)
			{
				pImage->set_xel_val(x, y, pBuf[index]);
			}
			if(nChan > 1)
			{
				pImage->set_red_val(x, y, pBuf[index + 0]);
				pImage->set_green_val(x, y, pBuf[index + 1]);
				pImage->set_blue_val(x, y, pBuf[index + 2]);
				if(nChan == 4)
				{
					pImage->set_alpha_val(x, y, pBuf[index + 3]);
				}
			}
		}
	}

	PT(Texture) newTex = new Texture();
	newTex->load(*pImage);
	newTex->set_magfilter(Texture::FT_linear);
	newTex->set_minfilter(Texture::FT_linear_mipmap_linear);
	newTex->set_wrap_u(bWrap ? Texture::WM_repeat : Texture::WM_clamp);
	newTex->set_wrap_v(bWrap ? Texture::WM_repeat : Texture::WM_clamp);
	newTex->set_wrap_w(bWrap ? Texture::WM_repeat : Texture::WM_clamp);

	delete pImage;
	pImage = NULL;

	return newTex;
}

but it reports only 1 mipmap has been generated.

the corrisponding OpenGL code generates several mipmap levels itself like this

          glGenTextures(1, &WaterReflDMID[l]); 
          glBindTexture(GL_TEXTURE_2D, WaterReflDMID[l]);
          //       if (GL.SGIS_generate_mipmap) glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);   

// do some calculations here for pBuf2...
//....
//....
              // Load 2x downscaled - save memory 4x times
              if (k > 0) 
			  {
                glTexImage2D(GL_TEXTURE_2D, k-1, GL_RGBA_FLOAT32_ATI, SZ, SZ, 0, GL_RGBA, GL_FLOAT, pBuf2);

              }

the last part here is the key -

glTexImage2D(GL_TEXTURE_2D, k-1, GL_RGBA_FLOAT32_ATI, SZ, SZ, 0, GL_RGBA, GL_FLOAT, pBuf2);

I suspect this is the reason why I get those weird artefacts (squares) on my water.

Can I force Panda somehow to allow me do the same thing ?

This part is (as far as I can tell) the only thing that is different from my code and the OpenGL code I am trying to port into Panda.

There’s a config setting for this. If you set “driver-generate-mipmaps 0” in your Config.prc file, it means that Panda will pre-compute the mipmap levels on the CPU, as you are doing in your sample OpenGL code. If you set “driver-generate-mipmaps 1”, it means that Panda will ask your OpenGL driver to do it instead, which is usually faster, but leaves yourself open to possible driver bugs.

In Panda3D 1.7.2, the default is “driver-generate-mipmaps 0”. In Panda3D 1.8.0, the default is “driver-generate-mipmaps 1”.

David

I have also just tried to call
generate_ram_mipmap_images() when I create the texture and Panda now reports this

I guess that has the same effect as adding it to the config.prc ?

either way - the artefact squares remain. :-/

[EDIT] Just tried setting the config file and still it reports 1 mipmap level.

In my test cases, when I either set driver-generate-mipmaps 0, or when I explicitly call tex.generateRamMipmapImages(), I see:

:display:gsg:glgsg(debug): loading uncompressed texture smiley
:display:gsg:glgsg(debug): loading new texture object, 512 x 256 x 1, mipmaps 10, uses_mipmaps = 1

David