Equalizer 1.0
|
00001 00002 /* Copyright (c) 2007, Tobias Wolf <twolf@access.unizh.ch> 00003 * 2009, Cedric Stalder <cedric.stalder@gmail.com> 00004 * 2011, Stefan Eilemann <eile@eyescale.ch> 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright notice, this 00010 * list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * - Neither the name of Eyescale Software GmbH nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00028 * POSSIBILITY OF SUCH DAMAGE. 00029 00030 00031 Type definitions for the mesh classes. 00032 */ 00033 00034 00035 #ifndef MESH_TYPEDEFS_H 00036 #define MESH_TYPEDEFS_H 00037 00038 #define EQUALIZER 1 00039 00040 #ifdef EQUALIZER 00041 # include <eq/eq.h> 00042 # define MESHASSERT EQASSERT 00043 # define MESHERROR EQERROR 00044 # define MESHWARN EQWARN 00045 # define MESHINFO EQINFO 00046 #else 00047 # include <vmmlib/vmmlib.hpp> 00048 # ifdef _WIN32 00049 # include <Winsock2.h> 00050 # include <Windows.h> 00051 # endif 00052 # ifdef __APPLE__ 00053 # include <OpenGL/gl.h> 00054 # else 00055 # include <GL/gl.h> 00056 # endif 00057 # include <cassert> 00058 # define MESHASSERT assert 00059 # define MESHERROR std::cerr 00060 # define MESHWARN std::cout 00061 # define MESHINFO std::cout 00062 #endif 00063 00064 00065 #include <exception> 00066 #include <iostream> 00067 #include <string> 00068 00069 namespace mesh 00070 { 00071 // basic type definitions 00072 typedef vmml::vector< 3, GLfloat > Vertex; 00073 typedef vmml::vector< 4, GLubyte > Color; 00074 typedef vmml::vector< 3, GLfloat > Normal; 00075 typedef size_t Index; 00076 typedef GLushort ShortIndex; 00077 00078 00079 // mesh exception 00080 struct MeshException : public std::exception 00081 { 00082 explicit MeshException( const std::string& msg ) : _message( msg ) {} 00083 virtual ~MeshException() throw() {} 00084 virtual const char* what() const throw() { return _message.c_str(); } 00085 private: 00086 std::string _message; 00087 }; 00088 00089 // null output stream that discards everything written to it 00090 struct NullOStream : std::ostream 00091 { 00092 struct NullStreamBuf : std::streambuf 00093 { 00094 int overflow( int c ) { return traits_type::not_eof( c ); } 00095 } _nullBuf; 00096 00097 NullOStream() : std::ios( &_nullBuf ), std::ostream( &_nullBuf ) {} 00098 }; 00099 00100 // wrapper to enable array use where arrays would not be allowed otherwise 00101 template< class T, size_t d > 00102 struct ArrayWrapper 00103 { 00104 T& operator[]( const size_t i ) 00105 { 00106 MESHASSERT( i < d ); 00107 return data[i]; 00108 } 00109 00110 const T& operator[]( const size_t i ) const 00111 { 00112 MESHASSERT( i < d ); 00113 return data[i]; 00114 } 00115 00116 private: 00117 T data[d]; 00118 }; 00119 00120 00121 // compound type definitions 00122 typedef vmml::vector< 3, Index > Triangle; 00123 typedef ArrayWrapper< Vertex, 2 > BoundingBox; 00124 typedef vmml::vector< 4, float > BoundingSphere; 00125 typedef ArrayWrapper< float, 2 > Range; 00126 00127 00128 // maximum triangle count per leaf node (keep in mind that the number of 00129 // different vertices per leaf must stay below ShortIndex range; usually 00130 // #vertices ~ #triangles/2, but max #vertices = #triangles * 3) 00131 const Index LEAF_SIZE( 21845 ); 00132 00133 // binary mesh file version, increment if changing the file format 00134 const unsigned short FILE_VERSION ( 0x0115 ); 00135 00136 00137 // enumeration for the sort axis 00138 enum Axis 00139 { 00140 AXIS_X, 00141 AXIS_Y, 00142 AXIS_Z 00143 }; 00144 inline std::ostream& operator << ( std::ostream& os, const Axis axis ) 00145 { 00146 os << ( axis == AXIS_X ? "x axis" : axis == AXIS_Y ? "y axis" : 00147 axis == AXIS_Z ? "z axis" : "ERROR" ); 00148 return os; 00149 } 00150 00151 // enumeration for the buffer objects 00152 enum BufferObject 00153 { 00154 VERTEX_OBJECT, 00155 NORMAL_OBJECT, 00156 COLOR_OBJECT, 00157 INDEX_OBJECT 00158 }; 00159 00160 // enumeration for the render modes 00161 enum RenderMode 00162 { 00163 RENDER_MODE_IMMEDIATE = 0, 00164 RENDER_MODE_DISPLAY_LIST, 00165 RENDER_MODE_BUFFER_OBJECT, 00166 RENDER_MODE_ALL // must be last 00167 }; 00168 inline std::ostream& operator << ( std::ostream& os, const RenderMode mode ) 00169 { 00170 os << ( mode == RENDER_MODE_IMMEDIATE ? "immediate mode" : 00171 mode == RENDER_MODE_DISPLAY_LIST ? "display list mode" : 00172 mode == RENDER_MODE_BUFFER_OBJECT ? "VBO mode" : "ERROR" ); 00173 return os; 00174 } 00175 00176 // enumeration for kd-tree node types 00177 enum NodeType 00178 { 00179 ROOT_TYPE = 0x07, 00180 NODE_TYPE = 0xde, 00181 LEAF_TYPE = 0xef 00182 }; 00183 00184 00185 // helper function for MMF (memory mapped file) reading 00186 inline 00187 void memRead( char* destination, char** source, size_t length ) 00188 { 00189 memcpy( destination, *source, length ); 00190 *source += length; 00191 } 00192 00193 00194 // internally linked null stream, every translation unit gets a copy 00195 static mesh::NullOStream cnul; 00196 } 00197 00198 00199 #endif // MESH_TYPEDEFS_H