Code: Select all
// We store data in Last In First Out structure.
class SMipMap
{
public:
~SMipMap()
{
for(u32 i = 0; i < Level.size(); ++i)
Level[i]->drop();
Level.clear();
}
bool addLevel(IImage* vImage)
{
if(vImage && Level.size() && Level[Level.size() - 1]->getDimension() != dimension2d<u32>(1,1))
{
dimension2d<u32> HalfSize = Level[Level.size() - 1]->getDimension() / 2;
if(vImage->getColorFormat() == Level[0]->getColorFormat() && vImage->getDimension() == HalfSize)
{
vImage->grab();
Level.push_back(vImage);
}
}
return false;
}
IImage* getLevel(u32 vID) const
{
IImage* tImage = 0;
if(vID < Level.size())
tImage = Level[vID];
return tImage;
}
bool replaceLevel(IImage* vImage, u32 vID)
{
if(vImage && vID < Level.size())
if(vImage->getColorFormat() == Level[0]->getColorFormat() && vImage->getDimension() == Level[vID]->getDimension())
{
Level[vID]->drop();
vImage->grab();
Level[vID] = vImage;
return true;
}
return false;
}
bool removeLevel()
{
if(Level.size())
{
Level[Level.size() - 1]->drop();
Level.erase(Level.size() - 1);
return true;
}
return false;
}
u32 getLevelCount()
{
return Level.size();
}
protected:
array<IImage*> Level;
};
Currently I'm adding texture array (i'll release it soon) support for my OpenGL 3 driver and I'm in implementation mipmap phase (I want use this metod) so I posted here my solution for this.
What do You think about it?