⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 texture.cpp

📁 最新osg包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <osg/Texture>#include <osg/Notify>#include <osg/io_utils>#include <osgDB/Registry>#include <osgDB/Input>#include <osgDB/Output>using namespace osg;using namespace osgDB;// forward declare functions to use later.bool Texture_readLocalData(Object& obj, Input& fr);bool Texture_writeLocalData(const Object& obj, Output& fw);bool Texture_matchWrapStr(const char* str,Texture::WrapMode& wrap);const char* Texture_getWrapStr(Texture::WrapMode wrap);bool Texture_matchFilterStr(const char* str,Texture::FilterMode& filter);const char* Texture_getFilterStr(Texture::FilterMode filter);bool Texture_matchInternalFormatModeStr(const char* str,Texture::InternalFormatMode& mode);const char* Texture_getInternalFormatModeStr(Texture::InternalFormatMode mode);bool Texture_matchInternalFormatStr(const char* str,int& value);const char* Texture_getInternalFormatStr(int value);bool Texture_matchSourceTypeStr(const char* str,int& value);const char* Texture_getSourceTypeStr(int value);// register the read and write functions with the osgDB::Registry.RegisterDotOsgWrapperProxy g_TextureProxy(    0,    "TextureBase",    "Object StateAttribute TextureBase",    &Texture_readLocalData,    &Texture_writeLocalData);bool Texture_readLocalData(Object& obj, Input& fr){    bool iteratorAdvanced = false;    Texture& texture = static_cast<Texture&>(obj);    Texture::WrapMode wrap;    if (fr[0].matchWord("wrap_s") && Texture_matchWrapStr(fr[1].getStr(),wrap))    {        texture.setWrap(Texture::WRAP_S,wrap);        fr+=2;        iteratorAdvanced = true;    }    if (fr[0].matchWord("wrap_t") && Texture_matchWrapStr(fr[1].getStr(),wrap))    {        texture.setWrap(Texture::WRAP_T,wrap);        fr+=2;        iteratorAdvanced = true;    }    if (fr[0].matchWord("wrap_r") && Texture_matchWrapStr(fr[1].getStr(),wrap))    {        texture.setWrap(Texture::WRAP_R,wrap);        fr+=2;        iteratorAdvanced = true;    }    Texture::FilterMode filter;    if (fr[0].matchWord("min_filter") && Texture_matchFilterStr(fr[1].getStr(),filter))    {        texture.setFilter(Texture::MIN_FILTER,filter);        fr+=2;        iteratorAdvanced = true;    }    if (fr[0].matchWord("mag_filter") && Texture_matchFilterStr(fr[1].getStr(),filter))    {        texture.setFilter(Texture::MAG_FILTER,filter);        fr+=2;        iteratorAdvanced = true;    }    if (fr.matchSequence("maxAnisotropy %f"))    {        float anis=1.0f;        fr[1].getFloat(anis);        texture.setMaxAnisotropy(anis);        fr +=2 ;        iteratorAdvanced = true;    }    if (fr.matchSequence("borderColor %f %f %f %f"))    {        Vec4 color;        fr[1].getFloat(color[0]);        fr[2].getFloat(color[1]);        fr[3].getFloat(color[2]);        fr[4].getFloat(color[3]);        texture.setBorderColor(color);        fr +=5 ;        iteratorAdvanced = true;    }    if (fr.matchSequence("borderWidth %i"))    {        int width=0;        fr[1].getInt(width);        texture.setBorderWidth(width);        fr +=2 ;        iteratorAdvanced = true;    }    if (fr[0].matchWord("useHardwareMipMapGeneration"))    {        if (fr[1].matchWord("TRUE"))         {            texture.setUseHardwareMipMapGeneration(true);            fr +=2 ;            iteratorAdvanced = true;        }        else if (fr[1].matchWord("FALSE"))         {            texture.setUseHardwareMipMapGeneration(false);            fr +=2 ;            iteratorAdvanced = true;        }    }    if (fr[0].matchWord("unRefImageDataAfterApply"))    {        if (fr[1].matchWord("TRUE"))         {            texture.setUnRefImageDataAfterApply(true);            fr +=2 ;            iteratorAdvanced = true;        }        else if (fr[1].matchWord("FALSE"))         {            texture.setUnRefImageDataAfterApply(false);            fr +=2 ;            iteratorAdvanced = true;        }    }    Texture::InternalFormatMode mode;    if (fr[0].matchWord("internalFormatMode") && Texture_matchInternalFormatModeStr(fr[1].getStr(),mode))    {        texture.setInternalFormatMode(mode);        fr+=2;        iteratorAdvanced = true;    }    if (fr[0].matchWord("internalFormat"))    {        int value;        if (Texture_matchInternalFormatStr(fr[1].getStr(),value) || fr[1].getInt(value))        {            texture.setInternalFormat(value);            fr+=2;            iteratorAdvanced = true;        }    }    if (fr[0].matchWord("sourceFormat"))    {        int value;        if (Texture_matchInternalFormatStr(fr[1].getStr(),value) || fr[1].getInt(value))        {            texture.setSourceFormat(value);            fr+=2;            iteratorAdvanced = true;        }    }    if (fr[0].matchWord("sourceType"))    {        int value;        if (Texture_matchInternalFormatStr(fr[1].getStr(),value) || fr[1].getInt(value))        {            texture.setSourceType(value);            fr+=2;            iteratorAdvanced = true;        }    }    if (fr[0].matchWord("resizeNonPowerOfTwo"))    {        if (fr[1].matchWord("TRUE"))         {            texture.setResizeNonPowerOfTwoHint(true);            fr +=2 ;            iteratorAdvanced = true;        }        else if (fr[1].matchWord("FALSE"))         {            texture.setResizeNonPowerOfTwoHint(false);            fr +=2 ;            iteratorAdvanced = true;        }    }    return iteratorAdvanced;}bool Texture_writeLocalData(const Object& obj, Output& fw){    const Texture& texture = static_cast<const Texture&>(obj);    fw.indent() << "wrap_s " << Texture_getWrapStr(texture.getWrap(Texture::WRAP_S)) << std::endl;    fw.indent() << "wrap_t " << Texture_getWrapStr(texture.getWrap(Texture::WRAP_T)) << std::endl;    fw.indent() << "wrap_r " << Texture_getWrapStr(texture.getWrap(Texture::WRAP_R)) << std::endl;    fw.indent() << "min_filter " << Texture_getFilterStr(texture.getFilter(Texture::MIN_FILTER)) << std::endl;    fw.indent() << "mag_filter " << Texture_getFilterStr(texture.getFilter(Texture::MAG_FILTER)) << std::endl;    fw.indent() << "maxAnisotropy " << texture.getMaxAnisotropy() << std::endl;        fw.indent() << "borderColor " << texture.getBorderColor() << std::endl;    fw.indent() << "borderWidth " << texture.getBorderWidth() << std::endl;    fw.indent() << "useHardwareMipMapGeneration "<< (texture.getUseHardwareMipMapGeneration()?"TRUE":"FALSE") << std::endl;    fw.indent() << "unRefImageDataAfterApply "<< (texture.getUnRefImageDataAfterApply()?"TRUE":"FALSE") << std::endl;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -