| 1 | #include "osg/TextureRectangle" |
|---|
| 2 | #include "osg/ImageSequence" |
|---|
| 3 | |
|---|
| 4 | #include "osgDB/Registry" |
|---|
| 5 | #include "osgDB/Input" |
|---|
| 6 | #include "osgDB/Output" |
|---|
| 7 | #include "osgDB/WriteFile" |
|---|
| 8 | |
|---|
| 9 | using namespace osg; |
|---|
| 10 | using namespace osgDB; |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | bool TextureRectangle_readLocalData(Object& obj, Input& fr); |
|---|
| 14 | bool TextureRectangle_writeLocalData(const Object& obj, Output& fw); |
|---|
| 15 | |
|---|
| 16 | bool TextureRectangle_matchWrapStr(const char* str,TextureRectangle::WrapMode& wrap); |
|---|
| 17 | const char* TextureRectangle_getWrapStr(TextureRectangle::WrapMode wrap); |
|---|
| 18 | bool TextureRectangle_matchFilterStr(const char* str,TextureRectangle::FilterMode& filter); |
|---|
| 19 | const char* TextureRectangle_getFilterStr(TextureRectangle::FilterMode filter); |
|---|
| 20 | bool TextureRectangle_matchInternalFormatModeStr(const char* str,TextureRectangle::InternalFormatMode& mode); |
|---|
| 21 | const char* TextureRectangle_getInternalFormatModeStr(TextureRectangle::InternalFormatMode mode); |
|---|
| 22 | bool TextureRectangle_matchInternalFormatStr(const char* str,int& value); |
|---|
| 23 | const char* TextureRectangle_getInternalFormatStr(int value); |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | REGISTER_DOTOSGWRAPPER(TextureRectangle) |
|---|
| 27 | ( |
|---|
| 28 | new osg::TextureRectangle, |
|---|
| 29 | "TextureRectangle", |
|---|
| 30 | "Object StateAttribute TextureRectangle TextureBase", |
|---|
| 31 | &TextureRectangle_readLocalData, |
|---|
| 32 | &TextureRectangle_writeLocalData |
|---|
| 33 | ); |
|---|
| 34 | |
|---|
| 35 | bool TextureRectangle_readLocalData(Object& obj, Input& fr) |
|---|
| 36 | { |
|---|
| 37 | bool iteratorAdvanced = false; |
|---|
| 38 | |
|---|
| 39 | TextureRectangle& texture = static_cast<TextureRectangle&>(obj); |
|---|
| 40 | |
|---|
| 41 | if (fr[0].matchWord("file") && fr[1].isString()) |
|---|
| 42 | { |
|---|
| 43 | std::string filename = fr[1].getStr(); |
|---|
| 44 | Image* image = fr.readImage(filename.c_str()); |
|---|
| 45 | if (image) |
|---|
| 46 | { |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | texture.setImage(image); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | fr += 2; |
|---|
| 55 | iteratorAdvanced = true; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image")) |
|---|
| 59 | { |
|---|
| 60 | osg::Image* image = fr.readImage(); |
|---|
| 61 | if (image) texture.setImage(image); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | return iteratorAdvanced; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | bool TextureRectangle_writeLocalData(const Object& obj, Output& fw) |
|---|
| 69 | { |
|---|
| 70 | const TextureRectangle& texture = static_cast<const TextureRectangle&>(obj); |
|---|
| 71 | |
|---|
| 72 | if (texture.getImage()) |
|---|
| 73 | { |
|---|
| 74 | const osg::ImageSequence* is = dynamic_cast<const osg::ImageSequence*>(texture.getImage()); |
|---|
| 75 | if (is) |
|---|
| 76 | { |
|---|
| 77 | fw.writeObject(*is); |
|---|
| 78 | } |
|---|
| 79 | else |
|---|
| 80 | { |
|---|
| 81 | std::string fileName = texture.getImage()->getFileName(); |
|---|
| 82 | if (fw.getOutputTextureFiles()) |
|---|
| 83 | { |
|---|
| 84 | if (fileName.empty()) |
|---|
| 85 | { |
|---|
| 86 | fileName = fw.getTextureFileNameForOutput(); |
|---|
| 87 | } |
|---|
| 88 | osgDB::writeImageFile(*texture.getImage(), fileName); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | if (!fileName.empty()) |
|---|
| 92 | { |
|---|
| 93 | fw.indent() << "file "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl; |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | return true; |
|---|
| 99 | } |
|---|