| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "Exception.h" |
|---|
| 16 | #include "Camera.h" |
|---|
| 17 | #include "Transform.h" |
|---|
| 18 | #include "Image.h" |
|---|
| 19 | |
|---|
| 20 | using namespace ive; |
|---|
| 21 | |
|---|
| 22 | void Camera::write(DataOutputStream* out){ |
|---|
| 23 | |
|---|
| 24 | out->writeInt(IVECAMERA); |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | osg::Transform* transform = dynamic_cast<osg::Transform*>(this); |
|---|
| 28 | if(transform){ |
|---|
| 29 | ((ive::Transform*)(transform))->write(out); |
|---|
| 30 | } |
|---|
| 31 | else |
|---|
| 32 | out_THROW_EXCEPTION("Camera::write(): Could not cast this osg::Camera to an osg::Group."); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | out->writeVec4(getClearColor()); |
|---|
| 36 | out->writeUInt(getClearMask()); |
|---|
| 37 | |
|---|
| 38 | out->writeBool(getColorMask()!=0); |
|---|
| 39 | if (getColorMask()!=0) |
|---|
| 40 | { |
|---|
| 41 | out->writeStateAttribute(getColorMask()); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | out->writeBool(getViewport()!=0); |
|---|
| 45 | if (getViewport()!=0) |
|---|
| 46 | { |
|---|
| 47 | out->writeStateAttribute(getViewport()); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | out->writeInt(getTransformOrder()); |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | out->writeMatrixd(getProjectionMatrix()); |
|---|
| 54 | out->writeMatrixd(getViewMatrix()); |
|---|
| 55 | |
|---|
| 56 | out->writeInt(getRenderOrder()); |
|---|
| 57 | out->writeInt(getRenderTargetImplementation()); |
|---|
| 58 | out->writeInt(getRenderTargetFallback()); |
|---|
| 59 | |
|---|
| 60 | out->writeUInt(getDrawBuffer()); |
|---|
| 61 | out->writeUInt(getReadBuffer()); |
|---|
| 62 | |
|---|
| 63 | const BufferAttachmentMap& baf = getBufferAttachmentMap(); |
|---|
| 64 | out->writeUInt(baf.size()); |
|---|
| 65 | for(BufferAttachmentMap::const_iterator itr = baf.begin(); |
|---|
| 66 | itr != baf.end(); |
|---|
| 67 | ++itr) |
|---|
| 68 | { |
|---|
| 69 | BufferComponent buffer = itr->first; |
|---|
| 70 | const Attachment& attachment = itr->second; |
|---|
| 71 | |
|---|
| 72 | out->writeInt( buffer ); |
|---|
| 73 | out->writeUInt( attachment._internalFormat); |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | out->writeBool(attachment._image.valid()); |
|---|
| 77 | if(attachment._image.valid()) |
|---|
| 78 | ((ive::Image*)attachment._image.get())->write(out); |
|---|
| 79 | |
|---|
| 80 | out->writeBool(attachment._texture.valid()); |
|---|
| 81 | if(attachment._texture.valid()) |
|---|
| 82 | out->writeStateAttribute(attachment._texture.get()); |
|---|
| 83 | |
|---|
| 84 | out->writeUInt(attachment._level); |
|---|
| 85 | out->writeUInt(attachment._face); |
|---|
| 86 | out->writeBool(attachment._mipMapGeneration); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void Camera::read(DataInputStream* in) |
|---|
| 92 | { |
|---|
| 93 | |
|---|
| 94 | int id = in->peekInt(); |
|---|
| 95 | if(id == IVECAMERA) |
|---|
| 96 | { |
|---|
| 97 | |
|---|
| 98 | id = in->readInt(); |
|---|
| 99 | |
|---|
| 100 | osg::Transform* transform = dynamic_cast<osg::Transform*>(this); |
|---|
| 101 | if(transform) |
|---|
| 102 | { |
|---|
| 103 | ((ive::Transform*)(transform))->read(in); |
|---|
| 104 | } |
|---|
| 105 | else |
|---|
| 106 | in_THROW_EXCEPTION("Camera::read(): Could not cast this osg::Camera to an osg::Group."); |
|---|
| 107 | |
|---|
| 108 | setClearColor(in->readVec4()); |
|---|
| 109 | setClearMask(in->readUInt()); |
|---|
| 110 | |
|---|
| 111 | if (in->readBool()) |
|---|
| 112 | { |
|---|
| 113 | osg::ref_ptr<osg::StateAttribute> attribute = in->readStateAttribute(); |
|---|
| 114 | osg::ColorMask* cm = dynamic_cast<osg::ColorMask*>(attribute.get()); |
|---|
| 115 | if (cm) setColorMask(cm); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | if (in->readBool()) |
|---|
| 119 | { |
|---|
| 120 | osg::ref_ptr<osg::StateAttribute> attribute = in->readStateAttribute(); |
|---|
| 121 | osg::Viewport* vp = dynamic_cast<osg::Viewport*>(attribute.get()); |
|---|
| 122 | if (vp) setViewport(vp); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | setTransformOrder((TransformOrder)in->readInt()); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | setProjectionMatrix(in->readMatrixd()); |
|---|
| 129 | setViewMatrix(in->readMatrixd()); |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | setRenderOrder((RenderOrder)in->readInt()); |
|---|
| 133 | |
|---|
| 134 | RenderTargetImplementation impl = (RenderTargetImplementation)in->readInt(); |
|---|
| 135 | RenderTargetImplementation fallback = (RenderTargetImplementation)in->readInt(); |
|---|
| 136 | setRenderTargetImplementation(impl, fallback); |
|---|
| 137 | |
|---|
| 138 | setDrawBuffer((GLenum)in->readUInt()); |
|---|
| 139 | setReadBuffer((GLenum)in->readUInt()); |
|---|
| 140 | |
|---|
| 141 | _bufferAttachmentMap.clear(); |
|---|
| 142 | |
|---|
| 143 | unsigned int numAttachments = in->readUInt(); |
|---|
| 144 | for(unsigned int i=0; i<numAttachments; ++i) |
|---|
| 145 | { |
|---|
| 146 | int buffer_component = in->readInt(); |
|---|
| 147 | if (in->getVersion() < VERSION_0036 ) |
|---|
| 148 | { |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | if (buffer_component >= PACKED_DEPTH_STENCIL_BUFFER) |
|---|
| 152 | { |
|---|
| 153 | ++buffer_component; |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | Attachment& attachment = _bufferAttachmentMap[BufferComponent(buffer_component)]; |
|---|
| 158 | attachment._internalFormat = (GLenum)in->readUInt(); |
|---|
| 159 | |
|---|
| 160 | if (in->readBool()) |
|---|
| 161 | { |
|---|
| 162 | |
|---|
| 163 | attachment._image = new osg::Image; |
|---|
| 164 | ((ive::Image*)attachment._image.get())->read(in); |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | if (in->readBool()) |
|---|
| 168 | { |
|---|
| 169 | osg::ref_ptr<osg::StateAttribute> attribute = in->readStateAttribute(); |
|---|
| 170 | osg::Texture* texture = dynamic_cast<osg::Texture*>(attribute.get()); |
|---|
| 171 | if (texture) attachment._texture = texture; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | attachment._level = in->readUInt(); |
|---|
| 175 | attachment._face = in->readUInt(); |
|---|
| 176 | attachment._mipMapGeneration = in->readBool(); |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | else{ |
|---|
| 180 | in_THROW_EXCEPTION("Camera::read(): Expected Camera identification"); |
|---|
| 181 | } |
|---|
| 182 | } |
|---|