Equalizer  1.6.1
typedefs.h
1 
2 /* Copyright (c) 2007, Tobias Wolf <twolf@access.unizh.ch>
3  * 2009, Cedric Stalder <cedric.stalder@gmail.com>
4  * 2011-2012, Stefan Eilemann <eile@eyescale.ch>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * - Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * - Neither the name of Eyescale Software GmbH nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29 
30 
31  Type definitions for the mesh classes.
32 */
33 
34 
35 #ifndef MESH_TYPEDEFS_H
36 #define MESH_TYPEDEFS_H
37 
38 #define EQUALIZER 1
39 
40 #ifdef EQUALIZER
41 # include <eq/eq.h>
42 # define MESHASSERT LBASSERT
43 # define MESHERROR LBERROR
44 # define MESHWARN LBWARN
45 # define MESHINFO LBINFO
46 #else
47 # include <vmmlib/vmmlib.hpp>
48 # ifdef _WIN32
49 # include <Winsock2.h>
50 # include <Windows.h>
51 # endif
52 # ifdef __APPLE__
53 # include <OpenGL/gl.h>
54 # else
55 # include <GL/gl.h>
56 # endif
57 # include <cassert>
58 # define MESHASSERT assert
59 # define MESHERROR std::cerr
60 # define MESHWARN std::cout
61 # define MESHINFO std::cout
62 #endif
63 
64 #include <exception>
65 #include <iostream>
66 #include <string>
67 
68 namespace mesh
69 {
70  // basic type definitions
71  typedef vmml::vector< 3, float > Vertex;
72  typedef vmml::vector< 3, uint8_t > Color;
73  typedef vmml::vector< 3, float > Normal;
74  typedef vmml::matrix< 4, 4, float > Matrix4f;
75  typedef vmml::vector< 4, float > Vector4f;
76  typedef size_t Index;
77  typedef GLushort ShortIndex;
78 
79  // mesh exception
80  struct MeshException : public std::exception
81  {
82  explicit MeshException( const std::string& msg ) : _message( msg ) {}
83  virtual ~MeshException() throw() {}
84  virtual const char* what() const throw() { return _message.c_str(); }
85  private:
86  std::string _message;
87  };
88 
89  // null output stream that discards everything written to it
90  struct NullOStream : std::ostream
91  {
92  struct NullStreamBuf : std::streambuf
93  {
94  int overflow( int c ) { return traits_type::not_eof( c ); }
95  } _nullBuf;
96 
97  NullOStream() : std::ios( &_nullBuf ), std::ostream( &_nullBuf ) {}
98  };
99 
100  // wrapper to enable array use where arrays would not be allowed otherwise
101  template< class T, size_t d >
103  {
104  ArrayWrapper() {}
105  ArrayWrapper( const T* from ) { memcpy( data, from, sizeof( data )); }
106  T& operator[]( const size_t i )
107  {
108  MESHASSERT( i < d );
109  return data[i];
110  }
111 
112  const T& operator[]( const size_t i ) const
113  {
114  MESHASSERT( i < d );
115  return data[i];
116  }
117 
118  private:
119  T data[d];
120  };
121 
122 
123  // compound type definitions
124  typedef vmml::vector< 3, Index > Triangle;
126  typedef vmml::vector< 4, float > BoundingSphere;
128 
129  // maximum triangle count per leaf node (keep in mind that the number of
130  // different vertices per leaf must stay below ShortIndex range; usually
131  // #vertices ~ #triangles/2, but max #vertices = #triangles * 3)
132  const Index LEAF_SIZE( 21845 );
133 
134  // binary mesh file version, increment if changing the file format
135  const unsigned short FILE_VERSION ( 0x0118 );
136 
137  // enumeration for the sort axis
138  enum Axis
139  {
140  AXIS_X,
141  AXIS_Y,
142  AXIS_Z
143  };
144  inline std::ostream& operator << ( std::ostream& os, const Axis axis )
145  {
146  os << ( axis == AXIS_X ? "x axis" : axis == AXIS_Y ? "y axis" :
147  axis == AXIS_Z ? "z axis" : "ERROR" );
148  return os;
149  }
150 
151  // enumeration for the buffer objects
152  enum BufferObject
153  {
154  VERTEX_OBJECT,
155  NORMAL_OBJECT,
156  COLOR_OBJECT,
157  INDEX_OBJECT
158  };
159 
160  // enumeration for the render modes
161  enum RenderMode
162  {
163  RENDER_MODE_IMMEDIATE = 0,
164  RENDER_MODE_DISPLAY_LIST,
165  RENDER_MODE_BUFFER_OBJECT,
166  RENDER_MODE_ALL // must be last
167  };
168  inline std::ostream& operator << ( std::ostream& os, const RenderMode mode )
169  {
170  os << ( mode == RENDER_MODE_IMMEDIATE ? "immediate mode" :
171  mode == RENDER_MODE_DISPLAY_LIST ? "display list mode" :
172  mode == RENDER_MODE_BUFFER_OBJECT ? "VBO mode" : "ERROR" );
173  return os;
174  }
175 
176  // enumeration for kd-tree node types
177  enum NodeType
178  {
179  ROOT_TYPE = 0x07,
180  NODE_TYPE = 0xde,
181  LEAF_TYPE = 0xef
182  };
183 
184 
185  // helper function for MMF (memory mapped file) reading
186  inline void memRead( char* destination, char** source, size_t length )
187  {
188  memcpy( destination, *source, length );
189  *source += length;
190  }
191 
192 
193  // internally linked null stream, every translation unit gets a copy
194  static mesh::NullOStream cnul;
195 }
196 
197 #ifdef EQUALIZER
198 namespace lunchbox
199 {
200 template<> inline void byteswap( mesh::RenderMode& value )
201  { byteswap( reinterpret_cast< uint32_t& >( value )); }
202 
203 template<> inline void byteswap( mesh::Range& value )
204 {
205  byteswap( value[ 0 ]);
206  byteswap( value[ 1 ]);
207 }
208 }
209 #endif
210 #endif // MESH_TYPEDEFS_H
vmml::matrix< 4, 4, float > Matrix4f
A 4x4 float matrix.
Definition: vmmlib.h:39
vmml::vector< 4, float > Vector4f
A four-component float vector.
Definition: vmmlib.h:47
NodeType
Node types to identify connecting nodes.
Definition: nodeType.h:28