#ifndef _cgfxShaderCommon_h_ #define _cgfxShaderCommon_h_ #ifdef _WIN32 # pragma warning(disable: 4786) #endif // This header file simply defines some things that I // want to use throughout the plug-in // // If assertion is false, throw an InternalError exception. // Note: A Maya MStatus object can be used as the assertion... true means success. #define M_CHECK(assertion) if (assertion) ; else throw ((cgfxShaderCommon::InternalError*)__LINE__) #ifdef DEBUG #define CGFX_DEBUG 1 #endif namespace cgfxShaderCommon { #ifdef _WIN32 class InternalError; // Never defined. Used like this: // throw (InternalError*)__LINE__; #else struct InternalError { char* message; }; // throw (InternalError*)__LINE__; #endif } #define RETURNSTAT(s, msg) \ if (!s) \ { \ s.perror(msg); \ return s; \ } #define lengthof(array) (sizeof(array) / sizeof(array[0])) #if !defined(TEXTURES_BY_NAME) && !defined(TEXTURES_BY_NODE) # define TEXTURES_BY_NODE 1 #endif #if defined(CGFX_DEBUG) && defined(_WIN32) # ifndef _CRTDBG_MAP_ALLOC # define _CRTDBG_MAP_ALLOC # endif #endif /* CGFX_DEBUG && _WIN32 */ #include #if defined(_WIN32) // We must include before or we get // errors about overloading calloc. // # include #endif /* _WIN32 */ #if defined(CGFX_DEBUG2) # define OutputDebugString(s) fprintf(stderr, "%s", s) # define OutputDebugStrings(s1, s2) fprintf(stderr, "%s%s\n", s1, s2); #else # if defined (_WIN32) // In optimized mode, send the string to the debugger # define OutputDebugStrings(s1, s2) \ (OutputDebugString(s1), OutputDebugString(s2), OutputDebugString("\n")) # else # define OutputDebugString(s) ((void) 0) # define OutputDebugStrings(s1, s2) ((void) 0) # endif #endif /* CGFX_DEBUG */ // Return true if item is found in Maya array. template < typename Tarray, typename Titem > bool arrayContains( const Tarray& array, const Titem& item ) { int i; for ( i = array.length(); i > 0; --i ) if ( array[ i - 1 ] == item ) break; return i > 0; } // Append item to Maya array if not already present. // Returns index of the new or existing array element. template < typename Tarray, typename Titem > int findOrAppend( Tarray& array, const Titem& item ) { int i; int n = array.length(); for ( i = 0; i < n; ++i ) if ( array[ i ] == item ) break; if ( i == n ) array.append( item ); return i; } #endif /* _cgfxShaderCommon_h */