Beginners' questions: Understanding OpenMW/OpenCS code

Everything about development and the OpenMW source code.
User avatar
AnyOldName3
Posts: 725
Joined: 26 Nov 2015, 03:25

Re: Beginners' questions: Understanding OpenMW/OpenCS code

Post by AnyOldName3 » 10 Apr 2018, 23:20

If OpenMW is built using OSG >= 3.6 (which was just released) or using our fork, then there should be the ability to load a DDS image uncompressed. Otherwise, we might have to rely on the QtDDS image module which the Qt people have decided to stop building by default and to exclude from their binary releases because of security concerns (although I'm told that those security concerns apply equally to any bit of software that works with DTX/S3TC compressed images somehow).
AnyOldName3, Master of Shadows

unelsson
Posts: 60
Joined: 17 Mar 2018, 14:57

Re: Beginners' questions: Understanding OpenMW/OpenCS code

Post by unelsson » 11 Apr 2018, 10:10

If I understand the code at imagemanager.cpp correctly, it should automatically decompress loaded textures. In the case of "textures/tx_sand_01.dds" the function loads the image from cache, and apparently at some point in the program, (some/all?) textures have already been cached in compressed format.

I can think of solutions like overloading the Resource::ImageManager::getImage function with version that has two arguments: (const std::string &filename, boolean forceLoad) or just creating another function getNewImage or GetImageLoadNew that never loads from cache. Another, probably best, solution would be to implement software decompress also at terraintexturemode.cpp - there's code for that already in imagemanager.cpp, so it should not a big deal to copy paste the algorhitm.

unelsson
Posts: 60
Joined: 17 Mar 2018, 14:57

Re: Beginners' questions: Understanding OpenMW/OpenCS code

Post by unelsson » 11 Apr 2018, 12:18

Well now, that indeed doesn't work with osg 3.4, as setColor just isn't there. I wonder if it's important for new features to work with older versions of osg too?

Code: Select all

    std::string textureName = "textures/tx_sand_01.dds";
    Resource::ImageManager* imageManager = mData.getResourceSystem()->getImageManager();
    osg::ref_ptr<osg::Image> brushTextureOsg = new osg::Image();
    brushTextureOsg = imageManager->getImage(textureName);

    std::cout << "Pixel format before: " << brushTextureOsg->getPixelFormat() << std::endl; //33776 (compressed)

    if (brushTextureOsg->getPixelFormat() == 33776)
    {
        std::cout << "Software decompress" << std::endl;
        osg::ref_ptr<osg::Image> newImage = new osg::Image;
        newImage->setFileName(brushTextureOsg->getFileName());
        newImage->allocateImage(brushTextureOsg->s(), brushTextureOsg->t(), brushTextureOsg->r(), GL_RGB, GL_UNSIGNED_BYTE);
        for (int s=0; s<brushTextureOsg->s(); ++s)
            for (int t=0; t<brushTextureOsg->t(); ++t)
                for (int r=0; r<brushTextureOsg->r(); ++r)
                    newImage->setColor(brushTextureOsg->getColor(s,t,r), s,t,r);
        brushTextureOsg = newImage;
        brushTextureOsg->setInternalTextureFormat(GL_RGB8);
    }

    std::cout << "Pixel format after: " << brushTextureOsg->getPixelFormat() << std::endl; //6407, GL_RGB

    const uchar *qImageBuffer = (const uchar*)brushTextureOsg->data();

    QImage img(qImageBuffer, brushTextureOsg->s(), brushTextureOsg->t(), QImage::Format_RGB888);

    QPixmap pixmapObject(QPixmap::fromImage(img));

User avatar
AnyOldName3
Posts: 725
Joined: 26 Nov 2015, 03:25

Re: Beginners' questions: Understanding OpenMW/OpenCS code

Post by AnyOldName3 » 11 Apr 2018, 16:17

We need to at least continue supporting our fork of 3.4, even if we end up dropping support for upstream 3.4.
AnyOldName3, Master of Shadows

User avatar
Zini
Posts: 5185
Joined: 06 Aug 2011, 15:16

Re: Beginners' questions: Understanding OpenMW/OpenCS code

Post by Zini » 12 Apr 2018, 09:48

Correct. There are apparently a few concerns about stability issues with 3.6. I don't think we can make it mandatory now. The feature of showing the texture on the button is optional. I suggest we put it on hold for now. We can add it in later if the situation has changed/cleaned up.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests