typedefs.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MESH_TYPEDEFS_H
00025 #define MESH_TYPEDEFS_H
00026
00027 #define EQUALIZER 1
00028
00029 #ifdef EQUALIZER
00030 # include <eq/eq.h>
00031 # define MESHASSERT EQASSERT
00032 # define MESHERROR EQERROR
00033 # define MESHWARN EQWARN
00034 # define MESHINFO EQINFO
00035 #else
00036 # ifdef _WIN32
00037 # include <Winsock2.h>
00038 # include <Windows.h>
00039 # endif
00040 # ifdef __APPLE__
00041 # include <OpenGL/gl.h>
00042 # else
00043 # include <GL/gl.h>
00044 # endif
00045 # include <cassert>
00046 # define MESHASSERT assert
00047 # define MESHERROR std::cerr
00048 # define MESHWARN std::cout
00049 # define MESHINFO std::cout
00050 #endif
00051
00052 #include <vmmlib/vmmlib.hpp>
00053
00054 #include <exception>
00055 #include <iostream>
00056 #include <string>
00057
00058 namespace mesh
00059 {
00060
00061
00062
00063 typedef vmml::vector< 3, GLfloat > Vertex;
00064 typedef vmml::vector< 4, GLubyte > Color;
00065 typedef vmml::vector< 3, GLfloat > Normal;
00066 typedef size_t Index;
00067 typedef GLushort ShortIndex;
00068
00069
00070
00071 struct MeshException : public std::exception
00072 {
00073 explicit MeshException( const std::string& msg ) : _message( msg ) {}
00074 virtual ~MeshException() throw() {}
00075 virtual const char* what() const throw() { return _message.c_str(); }
00076 private:
00077 std::string _message;
00078 };
00079
00080
00081 struct NullOStream : std::ostream
00082 {
00083 struct NullStreamBuf : std::streambuf
00084 {
00085 int overflow( int c ) { return traits_type::not_eof( c ); }
00086 } _nullBuf;
00087
00088 NullOStream() : std::ios( &_nullBuf ), std::ostream( &_nullBuf ) {}
00089 };
00090
00091
00092 template< class T, size_t d >
00093 struct ArrayWrapper
00094 {
00095 T& operator[]( const size_t i )
00096 {
00097 MESHASSERT( i < d );
00098 return data[i];
00099 }
00100
00101 const T& operator[]( const size_t i ) const
00102 {
00103 MESHASSERT( i < d );
00104 return data[i];
00105 }
00106
00107 private:
00108 T data[d];
00109 };
00110
00111
00112
00113 typedef vmml::vector< 3, Index > Triangle;
00114 typedef ArrayWrapper< Vertex, 2 > BoundingBox;
00115 typedef vmml::vector< 4, float > BoundingSphere;
00116 typedef ArrayWrapper< float, 2 > Range;
00117
00118
00119
00120
00121
00122 const Index LEAF_SIZE( 21845 );
00123
00124
00125 const unsigned short FILE_VERSION ( 0x0115 );
00126
00127
00128
00129 enum Axis
00130 {
00131 AXIS_X,
00132 AXIS_Y,
00133 AXIS_Z
00134 };
00135 inline std::ostream& operator << ( std::ostream& os, const Axis axis )
00136 {
00137 os << ( axis == AXIS_X ? "x axis" : axis == AXIS_Y ? "y axis" :
00138 axis == AXIS_Z ? "z axis" : "ERROR" );
00139 return os;
00140 }
00141
00142
00143 enum BufferObject
00144 {
00145 VERTEX_OBJECT,
00146 NORMAL_OBJECT,
00147 COLOR_OBJECT,
00148 INDEX_OBJECT
00149 };
00150
00151
00152 enum RenderMode
00153 {
00154 RENDER_MODE_IMMEDIATE = 0,
00155 RENDER_MODE_DISPLAY_LIST,
00156 RENDER_MODE_BUFFER_OBJECT,
00157 RENDER_MODE_ALL
00158 };
00159 inline std::ostream& operator << ( std::ostream& os, const RenderMode mode )
00160 {
00161 os << ( mode == RENDER_MODE_IMMEDIATE ? "immediate mode" :
00162 mode == RENDER_MODE_DISPLAY_LIST ? "display list mode" :
00163 mode == RENDER_MODE_BUFFER_OBJECT ? "VBO mode" : "ERROR" );
00164 return os;
00165 }
00166
00167
00168 enum NodeType
00169 {
00170 ROOT_TYPE = 0x07,
00171 NODE_TYPE = 0xde,
00172 LEAF_TYPE = 0xef
00173 };
00174
00175
00176
00177 inline
00178 void memRead( char* destination, char** source, size_t length )
00179 {
00180 memcpy( destination, *source, length );
00181 *source += length;
00182 }
00183
00184
00185
00186 static mesh::NullOStream cnul;
00187 }
00188
00189
00190 #endif // MESH_TYPEDEFS_H