Equalizer  1.2.1
eqPly/vertexBufferData.h
00001 
00002 /* Copyright (c) 2007, Tobias Wolf <twolf@access.unizh.ch>
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *
00007  * - Redistributions of source code must retain the above copyright notice, this
00008  *   list of conditions and the following disclaimer.
00009  * - Redistributions in binary form must reproduce the above copyright notice,
00010  *   this list of conditions and the following disclaimer in the documentation
00011  *   and/or other materials provided with the distribution.
00012  * - Neither the name of Eyescale Software GmbH nor the names of its
00013  *   contributors may be used to endorse or promote products derived from this
00014  *   software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 
00030 #ifndef MESH_VERTEXBUFFERDATA_H
00031 #define MESH_VERTEXBUFFERDATA_H
00032 
00033 
00034 #include "typedefs.h"
00035 #include <vector>
00036 #include <fstream>
00037 
00038 
00039 namespace mesh 
00040 {    
00042     class VertexBufferData
00043     {
00044     public:
00045         void clear()
00046         {
00047             vertices.clear();
00048             colors.clear();
00049             normals.clear();
00050             indices.clear();
00051         }
00052         
00053         /*  Write the vectors' sizes and contents to the given stream.  */
00054         void toStream( std::ostream& os )
00055         {
00056             writeVector( os, vertices );
00057             writeVector( os, colors );
00058             writeVector( os, normals );
00059             writeVector( os, indices );
00060         }
00061         
00062         /*  Read the vectors' sizes and contents from the given MMF address.  */
00063         void fromMemory( char** addr )
00064         {
00065             clear();
00066             readVector( addr, vertices );
00067             readVector( addr, colors );
00068             readVector( addr, normals );
00069             readVector( addr, indices );
00070         }
00071         
00072         std::vector< Vertex >       vertices;
00073         std::vector< Color >        colors;
00074         std::vector< Normal >       normals;
00075         std::vector< ShortIndex >   indices;
00076         
00077     private:
00078         /*  Helper function to write a vector to output stream.  */
00079         template< class T >
00080         void writeVector( std::ostream& os, std::vector< T >& v )
00081         {
00082             size_t length = v.size();
00083             os.write( reinterpret_cast< char* >( &length ), 
00084                       sizeof( size_t ) );
00085             if( length > 0 )
00086                 os.write( reinterpret_cast< char* >( &v[0] ), 
00087                           length * sizeof( T ) );
00088         }
00089         
00090         /*  Helper function to read a vector from the MMF address.  */
00091         template< class T >
00092         void readVector( char** addr, std::vector< T >& v )
00093         {
00094             size_t length;
00095             memRead( reinterpret_cast< char* >( &length ), addr, 
00096                      sizeof( size_t ) );
00097             if( length > 0 )
00098             {
00099                 v.resize( length );
00100                 memRead( reinterpret_cast< char* >( &v[0] ), addr, 
00101                          length * sizeof( T ) );
00102             }
00103         }
00104     };
00105     
00106     
00107 }
00108 
00109 
00110 #endif // MESH_VERTEXBUFFERDATA_H
Generated on Fri Jun 8 2012 15:44:32 for Equalizer 1.2.1 by  doxygen 1.8.0