MipMap data - more user friendly solution

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

MipMap data - more user friendly solution

Post by Nadro »

I think that we should add some modification in a manual mipmap creation process. In my opinion we should add class:

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;
};
This is more user friendly system than current mipmap system and it need only minor modifications in engine eg. regenerateMipMapLevels and some create texture functions.

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?
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Sounds like a good idea. To be honest, I simply hacked in the miplevel access in order to get the code into the release. Just because I promised to get it into that release. I took the least necessary approach without adding much convenience anywhere. This additional class would even allow for some additional features like partial regeneration of mipmaps etc.
Post Reply