[fixed]auto mipmapping ?

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
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

[fixed]auto mipmapping ?

Post by Klunk »

I was playing around with using mipmapping for a cheap detailmap solution, so I tried using the following

Code: Select all

bool CreateDetailMap(ITexture *sourceText, ITexture *targetText)
{
	if(sourceText->getColorFormat() != targetText->getColorFormat())
		return false;

	if(sourceText->getOriginalSize() != targetText->getOriginalSize())
		return false;

	if(sourceText->getColorFormat() == ECF_A8R8G8B8)
	{
		unsigned int* sdata = (unsigned int*)sourceText->lock(true,0);
		unsigned int* tdata = (unsigned int*)targetText->lock(false,0);
		
		if(*sdata != 0 && *tdata != 0)
		{
			memmove(tdata,sdata,sizeof(unsigned int) * sourceText->getOriginalSize().getArea());
		}
		sourceText->unlock(); 
		targetText->unlock();
	}
	return true;
}
sourceText is loaded without mipmaps created and targetText is created with mipmapping. The function runs fine and the sourceMap is copied into the target map. Unfortunately all the mipmaps are recalculated from the new copied texture. I thought that I would have need to call regenerateMipMapLevels for that to happen. If someone one could enlighten me that would be great.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

if i create mipmaps for the source and use the following

Code: Select all

bool CreateDetailMap(ITexture *sourceText, ITexture *targetText, int index)
{
	if(sourceText->getColorFormat() != targetText->getColorFormat())
		return false;

	if(sourceText->getSize() != targetText->getSize())
		return false;

	if(sourceText->getColorFormat() == ECF_A8R8G8B8)
	{
		dimension2d<u32> size = sourceText->getSize();
        for(int i = 0; i < index; i++) 
			 size /= 2;

		unsigned int* sdata = (unsigned int*)sourceText->lock(true,index);
		unsigned int* tdata = (unsigned int*)targetText->lock(false,index);
		
		if(*sdata != 0 && *tdata != 0)
		{
			memmove(tdata,sdata,sizeof(unsigned int) * size.getArea());
		}
		sourceText->unlock(); 
		targetText->unlock();
	}
	return true;
}
if works correctly for every mipmap level except 0. :?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Hmm, is that with OpenGL? There had been a bug report which sounds very similar. I guess I have to use this code as a test case and see what goes wrong.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

yes that is openGL.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I've fixed this problem in SVN/trunk.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Re: [fixed]auto mipmapping ?

Post by Klunk »

tried using this again, using the svn/trunk still broken on mipmap index 0, and any attempt to copy into the index 0 forces the engine to automatically regenerate all mipmaps.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: [fixed]auto mipmapping ?

Post by hybrid »

That's interesting, because my regression test (locking and unlocking all layers and getting the manually set mipmap colors from each layer) did work so far. I have to check whether I do something different there, but don't really know why it shouldn't work.
Post Reply