| 1 | #include "osg/Texture2D" |
|---|
| 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 Texture2D_readLocalData(Object& obj, Input& fr); |
|---|
| 14 | bool Texture2D_writeLocalData(const Object& obj, Output& fw); |
|---|
| 15 | |
|---|
| 16 | bool Texture2D_matchWrapStr(const char* str,Texture2D::WrapMode& wrap); |
|---|
| 17 | const char* Texture2D_getWrapStr(Texture2D::WrapMode wrap); |
|---|
| 18 | bool Texture2D_matchFilterStr(const char* str,Texture2D::FilterMode& filter); |
|---|
| 19 | const char* Texture2D_getFilterStr(Texture2D::FilterMode filter); |
|---|
| 20 | bool Texture2D_matchInternalFormatModeStr(const char* str,Texture2D::InternalFormatMode& mode); |
|---|
| 21 | const char* Texture2D_getInternalFormatModeStr(Texture2D::InternalFormatMode mode); |
|---|
| 22 | bool Texture2D_matchInternalFormatStr(const char* str,int& value); |
|---|
| 23 | const char* Texture2D_getInternalFormatStr(int value); |
|---|
| 24 | |
|---|
| 25 | REGISTER_DOTOSGWRAPPER(OldTexture) |
|---|
| 26 | ( |
|---|
| 27 | new osg::Texture2D, |
|---|
| 28 | "Texture", |
|---|
| 29 | "Object StateAttribute Texture2D TextureBase", |
|---|
| 30 | 0, |
|---|
| 31 | 0 |
|---|
| 32 | ); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | REGISTER_DOTOSGWRAPPER(Texture2D) |
|---|
| 36 | ( |
|---|
| 37 | new osg::Texture2D, |
|---|
| 38 | "Texture2D", |
|---|
| 39 | "Object StateAttribute Texture2D TextureBase", |
|---|
| 40 | &Texture2D_readLocalData, |
|---|
| 41 | &Texture2D_writeLocalData |
|---|
| 42 | ); |
|---|
| 43 | |
|---|
| 44 | bool Texture2D_readLocalData(Object& obj, Input& fr) |
|---|
| 45 | { |
|---|
| 46 | bool iteratorAdvanced = false; |
|---|
| 47 | |
|---|
| 48 | Texture2D& texture = static_cast<Texture2D&>(obj); |
|---|
| 49 | |
|---|
| 50 | if (fr[0].matchWord("file") && fr[1].isString()) |
|---|
| 51 | { |
|---|
| 52 | std::string filename = fr[1].getStr(); |
|---|
| 53 | Image* image = fr.readImage(filename.c_str()); |
|---|
| 54 | if (image) |
|---|
| 55 | { |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | texture.setImage(image); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | fr += 2; |
|---|
| 64 | iteratorAdvanced = true; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | if (fr[0].matchWord("ImageSequence") || fr[0].matchWord("Image")) |
|---|
| 68 | { |
|---|
| 69 | osg::Image* image = fr.readImage(); |
|---|
| 70 | if (image) texture.setImage(image); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | return iteratorAdvanced; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | bool Texture2D_writeLocalData(const Object& obj, Output& fw) |
|---|
| 77 | { |
|---|
| 78 | const Texture2D& texture = static_cast<const Texture2D&>(obj); |
|---|
| 79 | |
|---|
| 80 | if (texture.getImage()) |
|---|
| 81 | { |
|---|
| 82 | const osg::ImageSequence* is = dynamic_cast<const osg::ImageSequence*>(texture.getImage()); |
|---|
| 83 | if (is) |
|---|
| 84 | { |
|---|
| 85 | fw.writeObject(*is); |
|---|
| 86 | } |
|---|
| 87 | else |
|---|
| 88 | { |
|---|
| 89 | std::string fileName = texture.getImage()->getFileName(); |
|---|
| 90 | if (fw.getOutputTextureFiles()) |
|---|
| 91 | { |
|---|
| 92 | if (fileName.empty()) |
|---|
| 93 | { |
|---|
| 94 | fileName = fw.getTextureFileNameForOutput(); |
|---|
| 95 | } |
|---|
| 96 | osgDB::writeImageFile(*texture.getImage(), fileName); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | if (!fileName.empty()) |
|---|
| 100 | { |
|---|
| 101 | fw.indent() << "file "<<fw.wrapString(fw.getFileNameForOutput(fileName))<< std::endl; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | return true; |
|---|
| 107 | } |
|---|