| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "Exception.h" |
|---|
| 16 | #include "Texture.h" |
|---|
| 17 | #include "Object.h" |
|---|
| 18 | |
|---|
| 19 | using namespace ive; |
|---|
| 20 | |
|---|
| 21 | void Texture::write(DataOutputStream* out){ |
|---|
| 22 | |
|---|
| 23 | out->writeInt(IVETEXTURE); |
|---|
| 24 | |
|---|
| 25 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 26 | if(obj) |
|---|
| 27 | { |
|---|
| 28 | ((ive::Object*)(obj))->write(out); |
|---|
| 29 | } |
|---|
| 30 | else |
|---|
| 31 | out_THROW_EXCEPTION("Texture::write(): Could not cast this osg::Texture to an osg::Object."); |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | out->writeInt(_wrap_s); |
|---|
| 35 | out->writeInt(_wrap_t); |
|---|
| 36 | out->writeInt(_wrap_r); |
|---|
| 37 | |
|---|
| 38 | out->writeInt(_min_filter); |
|---|
| 39 | out->writeInt(_mag_filter); |
|---|
| 40 | out->writeFloat(_maxAnisotropy); |
|---|
| 41 | |
|---|
| 42 | out->writeVec4(_borderColor); |
|---|
| 43 | |
|---|
| 44 | out->writeInt(_internalFormatMode); |
|---|
| 45 | |
|---|
| 46 | if ( out->getVersion() >= VERSION_0008 ) |
|---|
| 47 | { |
|---|
| 48 | out->writeInt(_internalFormat); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | if ( out->getVersion() >= VERSION_0009 ) |
|---|
| 52 | { |
|---|
| 53 | out->writeInt(_borderWidth); |
|---|
| 54 | out->writeBool(_useHardwareMipMapGeneration); |
|---|
| 55 | out->writeBool(_unrefImageDataAfterApply); |
|---|
| 56 | out->writeBool(_clientStorageHint); |
|---|
| 57 | out->writeBool(_resizeNonPowerOfTwoHint); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | if ( out->getVersion() >= VERSION_0014 ) |
|---|
| 61 | { |
|---|
| 62 | out->writeInt(_sourceFormat); |
|---|
| 63 | out->writeInt(_sourceType); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void Texture::read(DataInputStream* in) |
|---|
| 68 | { |
|---|
| 69 | |
|---|
| 70 | int id = in->peekInt(); |
|---|
| 71 | if(id == IVETEXTURE) |
|---|
| 72 | { |
|---|
| 73 | |
|---|
| 74 | id = in->readInt(); |
|---|
| 75 | |
|---|
| 76 | osg::Object* obj = dynamic_cast<osg::Object*>(this); |
|---|
| 77 | if(obj) |
|---|
| 78 | { |
|---|
| 79 | ((ive::Object*)(obj))->read(in); |
|---|
| 80 | } |
|---|
| 81 | else |
|---|
| 82 | in_THROW_EXCEPTION("Texture::read(): Could not cast this osg::Texture to an osg::Object."); |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | _wrap_s = (osg::Texture::WrapMode)in->readInt(); |
|---|
| 86 | _wrap_t = (osg::Texture::WrapMode)in->readInt(); |
|---|
| 87 | _wrap_r = (osg::Texture::WrapMode)in->readInt(); |
|---|
| 88 | |
|---|
| 89 | _min_filter = (osg::Texture::FilterMode)in->readInt(); |
|---|
| 90 | _mag_filter = (osg::Texture::FilterMode)in->readInt(); |
|---|
| 91 | _maxAnisotropy = in->readFloat(); |
|---|
| 92 | |
|---|
| 93 | _borderColor = in->readVec4(); |
|---|
| 94 | |
|---|
| 95 | _internalFormatMode = (osg::Texture::InternalFormatMode)in->readInt(); |
|---|
| 96 | if ( in->getVersion() >= VERSION_0008 ) |
|---|
| 97 | { |
|---|
| 98 | _internalFormat = in->readInt(); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | if ( in->getVersion() >= VERSION_0009 ) |
|---|
| 102 | { |
|---|
| 103 | _borderWidth = in->readInt(); |
|---|
| 104 | _useHardwareMipMapGeneration = in->readBool(); |
|---|
| 105 | _unrefImageDataAfterApply = in->readBool(); |
|---|
| 106 | _clientStorageHint = in->readBool(); |
|---|
| 107 | _resizeNonPowerOfTwoHint = in->readBool(); |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | if ( in->getVersion() >= VERSION_0014 ) |
|---|
| 111 | { |
|---|
| 112 | _sourceFormat = in->readInt(); |
|---|
| 113 | _sourceType = in->readInt(); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | else |
|---|
| 117 | { |
|---|
| 118 | in_THROW_EXCEPTION("Texture::read(): Expected Texture identification."); |
|---|
| 119 | } |
|---|
| 120 | } |
|---|