Main Page -
Class Hierarchy -
Class List -
File List -
Class Members -
Related Pages -

Information | Reference | SourceForge Project | Author
Muli3D

Reference: Muli3D: m3dbase.h Source File

m3dbase.h

Go to the documentation of this file.
00001 /* 00002 Muli3D - a software rendering library 00003 Copyright (C) 2004, 2005 Stephan Reiter <streiter@aon.at> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00022 00023 #ifndef __M3DBASE_H__ 00024 #define __M3DBASE_H__ 00025 00026 // Basic header includes ------------------------------------------------------ 00027 00028 #include <stdlib.h> 00029 #ifndef __amigaos4__ 00030 # include <memory.h> 00031 #else 00032 # include <exec/types.h> 00033 #endif 00034 #include <vector> 00035 00036 // Basic macro definitions ---------------------------------------------------- 00037 00040 #define SAFE_DELETE( p ) { if( p ) { delete p; p = 0; } } 00041 00044 #define SAFE_DELETE_ARRAY( p ) { if( p ) { delete[] p; p = 0; } } 00045 00048 #define SAFE_RELEASE( p ) { if( p ) { ( p )->Release(); p = 0; } } 00049 00050 00051 // Basic variable definitions ------------------------------------------------- 00052 00053 #ifndef __amigaos4__ // avoid conflicts with <exec/types.h> 00054 00055 typedef signed char int8; 00056 typedef signed short int16; 00057 typedef signed int int32; 00058 typedef unsigned char uint8; 00059 typedef unsigned short uint16; 00060 typedef unsigned int uint32; 00061 00062 typedef float float32; 00063 typedef double float64; 00064 00065 #endif 00066 00067 typedef unsigned char byte; 00068 00069 // Floating pointer helper-functions ------------------------------------------ 00070 00071 #ifdef WIN32 00072 00073 #include <float.h> 00074 #pragma warning( disable: 4996 ) // Disable warning about _controlfp being deprecated. 00075 inline void fpuTruncate() { _controlfp( _RC_DOWN + _PC_24, _MCW_RC|_MCW_PC ); } 00076 inline void fpuReset() { _controlfp( _CW_DEFAULT, _MCW_RC|_MCW_PC ); } 00077 00078 #endif 00079 00080 #ifdef LINUX_X11 00081 00082 #include <fpu_control.h> 00083 00085 inline void fpuTruncate() 00086 { 00087 fpu_control_t cwChop = _FPU_RC_DOWN | _FPU_IEEE | _FPU_SINGLE; 00088 _FPU_SETCW( cwChop ); 00089 } 00090 00092 inline void fpuReset() 00093 { 00094 fpu_control_t cwDefault = _FPU_DEFAULT; 00095 _FPU_SETCW( cwDefault ); 00096 } 00097 00098 #endif 00099 00100 #ifdef __amigaos4__ 00101 00102 inline void fpuTruncate() 00103 { 00104 // #warning: fpuTruncate() currently not implemented on AmigaOS 4 00105 } 00106 00107 inline void fpuReset() 00108 { 00109 // #warning: fpuReset() currently not implemented on AmigaOS 4 00110 } 00111 00112 #endif 00113 00120 00121 #ifdef __amigaos4__ 00122 typedef union 00123 { 00124 struct 00125 { 00126 unsigned long hi; 00127 unsigned long lo; 00128 } i; 00129 00130 double d; 00131 } hexdouble; 00132 #endif 00133 00134 inline int32 ftol( float32 f ) 00135 { 00136 #ifdef __amigaos4__ 00137 static hexdouble hd; 00138 __asm__ ( "fctiw %0, %1" : "=f" (hd.d) : "f" (f) ); 00139 return hd.i.lo; 00140 #else 00141 static int32 tmp; 00142 00143 #if _MSC_VER > 1000 00144 __asm 00145 { 00146 fld f 00147 fistp tmp 00148 } 00149 #else 00150 asm volatile( "fistpl %0" : "=m" ( tmp ) : "t" ( f ) : "st" ); 00151 #endif 00152 00153 return tmp; 00154 #endif 00155 } 00156 00157 // Functions and return-values ------------------------------------------------ 00158 00160 enum result 00161 { 00162 s_ok = 0, 00163 e_unknown, 00164 e_invalidparameters, 00165 e_outofmemory, 00166 00167 e_invalidformat, 00168 e_invalidstate 00169 }; 00170 00174 #define FUNC_SUCCESSFUL( res ) ( res == s_ok ) 00175 00179 #define FUNC_FAILED( res ) ( res != s_ok ) 00180 00181 // Debugging-tools ------------------------------------------------------------ 00182 00183 #ifdef _DEBUG 00184 00185 #ifndef WIN32 00186 #define OutputDebugString printf 00187 #endif 00188 00191 #define FUNC_FAILING( errdesc ) { OutputDebugString( errdesc ); } 00192 00195 #define FUNC_NOTIFY( infostring ) { OutputDebugString( infostring ); } 00196 00197 #else 00198 #define FUNC_FAILING ( void ) 00199 #define FUNC_NOTIFY ( void ) 00200 #endif // _DEBUG 00201 00202 // Muli3D base-class definition ----------------------------------------------- 00203 00205 class IBase 00206 { 00207 protected: 00208 inline IBase() : m_iRefCount( 1 ) {} 00209 virtual inline ~IBase() {} 00210 00211 public: 00212 inline void AddRef() { ++m_iRefCount; } 00213 inline void Release() { if( --m_iRefCount == 0 ) delete this; } 00214 00215 private: 00216 IBase( const IBase & ) {} 00217 IBase &operator =( const IBase & ) { return *this; } 00218 00219 private: 00220 uint32 m_iRefCount; 00221 }; 00222 00223 #endif // __M3DBASE_H__

Documentation created with doxygen SourceForge.net Logo