OpenGL texture: mipmap level 0 changes affect all levels

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

OpenGL texture: mipmap level 0 changes affect all levels

Post by greenya »

Hello!

When i writing into texture into mipmap level 0 only, i getting updating of all other levels. This bug repeats only on OpenGL driver.

To repeat bug open source of 02.Quake3Map example; found line "int lastFPS = -1;" and insert next code just after it:

Code: Select all

	video::ITexture* t = mesh->getMesh(0)->getMeshBuffer(0)->getMaterial().getTexture(0);
	video::SColor c = video::SColor(0xFFFF0000);
	int p = t->getPitch();
	video::ECOLOR_FORMAT f = t->getColorFormat();
	int z = video::IImage::getBitsPerPixelFromFormat(f) / 8;
	int m = 0; // can be from 0 to 8 (for texture with size 256x256)
	void* b = t->lock(false, m);
	if (b)
	{
		for (int x = 0; x < (256 >> m); x++)
			for (int y = 0; y < (256 >> m); y++)
				c.getData((unsigned char*)b + y * (p / (1 << m)) + x * z, f);

		t->unlock();
	}
This code will set all pixels of mipmap level m to red color.
Change m to set which mipmap level to use for writing.

The result is better visible when you compile and run the code.
Next image shows the result in comparison between OpenGL (left) and Direct3D9 (right):

Image

P.S.: tested with Irrlicht trunk rev. 3311 on GeForce 9600M GT / WinVista 32bit.
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

I can confirm that I had a very similar problem with my program before. With my GUI system, scaling down the rendered texture (Which caused different mipmap levels to get used) made the GUI disappear in DirectX but not OpenGL since I didn't update the mipmaps.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Hmm, ok. So we have to think about the intended default bahvior and have to add another flag to automatically update the mipmaps or not. Any opinions?
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

Hmmm, I'd say just make the mipmaps not regenerate on unlock() and then note in the documentation of unlock that regenerateMipMapLevels should be called afterwards.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Yes, as DtD said, there is a method ITexture::regenerateMipMapLevels(), so user can call explicit this method after unlock() to get changes in all mipmap levels if he wants (that how it works in Direct3D driver now; and i believe it is correct). Also if we write into mipmap level >0 (non-zero) and then regenerating mipmap levels, we do not see changes -- this is correct too, because non-zero mipmap levels been generated from level 0.
Post Reply