Equalizer 1.0
|
00001 00002 /* Copyright (c) 2008-2010, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 2010, Cedric Stalder <cedric.stalder@gmail.com> 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * - Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * - Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * - Neither the name of Eyescale Software GmbH nor the names of its 00014 * contributors may be used to endorse or promote products derived from this 00015 * software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 00029 * 00030 * co::Object to distribute a model. Has a VertexBufferBase node. 00031 */ 00032 00033 #include "vertexBufferDist.h" 00034 00035 #include "vertexBufferLeaf.h" 00036 00037 using namespace std; 00038 00039 namespace eqPly 00040 { 00041 00042 VertexBufferDist::VertexBufferDist() 00043 : _root( 0 ) 00044 , _node( 0 ) 00045 , _isRoot( false ) 00046 , _left( 0 ) 00047 , _right( 0 ) 00048 {} 00049 00050 VertexBufferDist::VertexBufferDist( const mesh::VertexBufferRoot* root ) 00051 : _root( root ) 00052 , _node( root ) 00053 , _isRoot( true ) 00054 , _left( 0 ) 00055 , _right( 0 ) 00056 { 00057 if( root->getLeft( )) 00058 _left = new VertexBufferDist( root, root->getLeft( )); 00059 00060 if( root->getRight( )) 00061 _right = new VertexBufferDist( root, root->getRight( )); 00062 } 00063 00064 VertexBufferDist::VertexBufferDist( const mesh::VertexBufferRoot* root, 00065 const mesh::VertexBufferBase* node ) 00066 : _root( root ) 00067 , _node( node ) 00068 , _isRoot( false ) 00069 , _left( 0 ) 00070 , _right( 0 ) 00071 { 00072 if( !node ) 00073 return; 00074 00075 if( node->getLeft( )) 00076 _left = new VertexBufferDist( root, node->getLeft( )); 00077 00078 if( node->getRight( )) 00079 _right = new VertexBufferDist( root, node->getRight( )); 00080 } 00081 00082 VertexBufferDist::~VertexBufferDist() 00083 { 00084 delete _left; 00085 _left = 0; 00086 delete _right; 00087 _right = 0; 00088 } 00089 00090 void VertexBufferDist::registerTree( co::LocalNodePtr node ) 00091 { 00092 EQASSERT( !isAttached() ); 00093 EQCHECK( node->registerObject( this )); 00094 00095 if( _left ) 00096 _left->registerTree( node ); 00097 00098 if( _right ) 00099 _right->registerTree( node ); 00100 } 00101 00102 void VertexBufferDist::deregisterTree() 00103 { 00104 EQASSERT( isAttached() ); 00105 EQASSERT( isMaster( )); 00106 00107 getLocalNode()->deregisterObject( this ); 00108 00109 if( _left ) 00110 _left->deregisterTree(); 00111 if( _right ) 00112 _right->deregisterTree(); 00113 } 00114 00115 mesh::VertexBufferRoot* VertexBufferDist::mapModel( 00116 co::LocalNodePtr node, 00117 const eq::uint128_t& modelID ) 00118 { 00119 EQASSERT( !_root && !_node ); 00120 00121 if( !node->mapObject( this, modelID )) 00122 { 00123 EQWARN << "Mapping of model failed" << endl; 00124 return 0; 00125 } 00126 00127 return const_cast< mesh::VertexBufferRoot* >( _root ); 00128 } 00129 00130 void VertexBufferDist::unmapTree() 00131 { 00132 EQASSERT( isAttached() ); 00133 EQASSERT( !isMaster( )); 00134 00135 getLocalNode()->unmapObject( this ); 00136 00137 if( _left ) 00138 _left->unmapTree(); 00139 if( _right ) 00140 _right->unmapTree(); 00141 } 00142 00143 void VertexBufferDist::getInstanceData( co::DataOStream& os ) 00144 { 00145 EQASSERT( _node ); 00146 os << _isRoot; 00147 00148 if( _left && _right ) 00149 { 00150 os << _left->getID() << _right->getID(); 00151 00152 if( _isRoot ) 00153 { 00154 EQASSERT( _root ); 00155 const mesh::VertexBufferData& data = _root->_data; 00156 00157 os << data.vertices << data.colors << data.normals << data.indices 00158 << _root->_name; 00159 } 00160 } 00161 else 00162 { 00163 os << co::base::UUID::ZERO << co::base::UUID::ZERO; 00164 00165 EQASSERT( dynamic_cast< const mesh::VertexBufferLeaf* >( _node )); 00166 const mesh::VertexBufferLeaf* leaf = 00167 static_cast< const mesh::VertexBufferLeaf* >( _node ); 00168 00169 os << uint64_t( leaf->_vertexStart ) << uint64_t( leaf->_indexStart ) 00170 << uint64_t( leaf->_indexLength ) << leaf->_vertexLength; 00171 } 00172 00173 os << _node->_boundingSphere << _node->_range; 00174 } 00175 00176 void VertexBufferDist::applyInstanceData( co::DataIStream& is ) 00177 { 00178 EQASSERT( !_node ); 00179 00180 mesh::VertexBufferNode* node = 0; 00181 mesh::VertexBufferBase* base = 0; 00182 00183 co::base::UUID leftID, rightID; 00184 is >> _isRoot >> leftID >> rightID; 00185 00186 if( leftID != co::base::UUID::ZERO && rightID != co::base::UUID::ZERO ) 00187 { 00188 if( _isRoot ) 00189 { 00190 mesh::VertexBufferRoot* root = new mesh::VertexBufferRoot; 00191 mesh::VertexBufferData& data = root->_data; 00192 00193 is >> data.vertices >> data.colors >> data.normals >> data.indices 00194 >> root->_name; 00195 00196 node = root; 00197 _root = root; 00198 } 00199 else 00200 { 00201 EQASSERT( _root ); 00202 node = new mesh::VertexBufferNode; 00203 } 00204 00205 base = node; 00206 _left = new VertexBufferDist( _root, 0 ); 00207 _right = new VertexBufferDist( _root, 0 ); 00208 co::LocalNodePtr localNode = getLocalNode(); 00209 const uint32_t sync1 = localNode->mapObjectNB( _left, leftID ); 00210 const uint32_t sync2 = localNode->mapObjectNB( _right, rightID ); 00211 00212 EQCHECK( localNode->mapObjectSync( sync1 )); 00213 EQCHECK( localNode->mapObjectSync( sync2 )); 00214 00215 node->_left = const_cast< mesh::VertexBufferBase* >( _left->_node ); 00216 node->_right = const_cast< mesh::VertexBufferBase* >( _right->_node ); 00217 } 00218 else 00219 { 00220 EQASSERT( !_isRoot ); 00221 mesh::VertexBufferData& data = 00222 const_cast< mesh::VertexBufferData& >( _root->_data ); 00223 mesh::VertexBufferLeaf* leaf = new mesh::VertexBufferLeaf( data ); 00224 00225 uint64_t i1, i2, i3; 00226 is >> i1 >> i2 >> i3 >> leaf->_vertexLength; 00227 leaf->_vertexStart = size_t( i1 ); 00228 leaf->_indexStart = size_t( i2 ); 00229 leaf->_indexLength = size_t( i3 ); 00230 00231 base = leaf; 00232 } 00233 00234 EQASSERT( base ); 00235 is >> base->_boundingSphere >> base->_range; 00236 00237 _node = base; 00238 } 00239 00240 }