Equalizer  1.6.1
eqPly/vertexBufferData.h
1 
2 /* Copyright (c) 2007, Tobias Wolf <twolf@access.unizh.ch>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Eyescale Software GmbH nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef MESH_VERTEXBUFFERDATA_H
31 #define MESH_VERTEXBUFFERDATA_H
32 
33 
34 #include "typedefs.h"
35 #include <vector>
36 #include <fstream>
37 
38 
39 namespace mesh
40 {
43  {
44  public:
45  void clear()
46  {
47  vertices.clear();
48  colors.clear();
49  normals.clear();
50  indices.clear();
51  }
52 
53  /* Write the vectors' sizes and contents to the given stream. */
54  void toStream( std::ostream& os )
55  {
56  writeVector( os, vertices );
57  writeVector( os, colors );
58  writeVector( os, normals );
59  writeVector( os, indices );
60  }
61 
62  /* Read the vectors' sizes and contents from the given MMF address. */
63  void fromMemory( char** addr )
64  {
65  clear();
66  readVector( addr, vertices );
67  readVector( addr, colors );
68  readVector( addr, normals );
69  readVector( addr, indices );
70  }
71 
72  std::vector< Vertex > vertices;
73  std::vector< Color > colors;
74  std::vector< Normal > normals;
75  std::vector< ShortIndex > indices;
76 
77  private:
78  /* Helper function to write a vector to output stream. */
79  template< class T >
80  void writeVector( std::ostream& os, std::vector< T >& v )
81  {
82  size_t length = v.size();
83  os.write( reinterpret_cast< char* >( &length ),
84  sizeof( size_t ) );
85  if( length > 0 )
86  os.write( reinterpret_cast< char* >( &v[0] ),
87  length * sizeof( T ) );
88  }
89 
90  /* Helper function to read a vector from the MMF address. */
91  template< class T >
92  void readVector( char** addr, std::vector< T >& v )
93  {
94  size_t length;
95  memRead( reinterpret_cast< char* >( &length ), addr,
96  sizeof( size_t ) );
97  if( length > 0 )
98  {
99  v.resize( length );
100  memRead( reinterpret_cast< char* >( &v[0] ), addr,
101  length * sizeof( T ) );
102  }
103  }
104  };
105 
106 
107 }
108 
109 
110 #endif // MESH_VERTEXBUFFERDATA_H
Holds the final kd-tree data, sorted and reindexed.