00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTGLOBALS_H
00030 #define NVBLASTGLOBALS_H
00031
00032 #include <new>
00033 #include "NvBlastTypes.h"
00034
00035
00036 namespace Nv
00037 {
00038 namespace Blast
00039 {
00040
00041
00045 class AllocatorCallback
00046 {
00047 public:
00051 virtual ~AllocatorCallback()
00052 {
00053 }
00054
00067 virtual void* allocate(size_t size, const char* typeName, const char* filename, int line) = 0;
00068
00074 virtual void deallocate(void* ptr) = 0;
00075 };
00076
00077
00088 struct ErrorCode
00089 {
00090 enum Enum
00091 {
00092 eNO_ERROR = 0,
00093
00095 eDEBUG_INFO = 1,
00096
00098 eDEBUG_WARNING = 2,
00099
00101 eINVALID_PARAMETER = 4,
00102
00104 eINVALID_OPERATION = 8,
00105
00107 eOUT_OF_MEMORY = 16,
00108
00112 eINTERNAL_ERROR = 32,
00113
00115 eABORT = 64,
00116
00118 ePERF_WARNING = 128,
00119
00121 eMASK_ALL = -1
00122 };
00123 };
00124
00125
00131 class ErrorCallback
00132 {
00133 public:
00134 virtual ~ErrorCallback()
00135 {
00136 }
00137
00145 virtual void reportError(ErrorCode::Enum code, const char* message, const char* file, int line) = 0;
00146 };
00147
00148
00149 }
00150 }
00151
00152
00154
00161 NVBLAST_API Nv::Blast::AllocatorCallback* NvBlastGlobalGetAllocatorCallback();
00162
00166 NVBLAST_API void NvBlastGlobalSetAllocatorCallback(Nv::Blast::AllocatorCallback* allocatorCallback);
00167
00174 NVBLAST_API Nv::Blast::ErrorCallback* NvBlastGlobalGetErrorCallback();
00175
00179 NVBLAST_API void NvBlastGlobalSetErrorCallback(Nv::Blast::ErrorCallback* errorCallback);
00180
00181
00183
00184 namespace Nv
00185 {
00186 namespace Blast
00187 {
00188
00189
00195 NV_INLINE void logLL(int type, const char* msg, const char* file, int line)
00196 {
00197 ErrorCode::Enum errorCode = ErrorCode::eNO_ERROR;
00198 switch (type)
00199 {
00200 case NvBlastMessage::Error: errorCode = ErrorCode::eINVALID_OPERATION; break;
00201 case NvBlastMessage::Warning: errorCode = ErrorCode::eDEBUG_WARNING; break;
00202 case NvBlastMessage::Info: errorCode = ErrorCode::eDEBUG_INFO; break;
00203 case NvBlastMessage::Debug: errorCode = ErrorCode::eNO_ERROR; break;
00204 }
00205
00206 NvBlastGlobalGetErrorCallback()->reportError(errorCode, msg, file, line);
00207 }
00208
00209
00210 }
00211 }
00212
00213
00214
00216
00220 #define NVBLAST_ALLOC(_size) NvBlastGlobalGetAllocatorCallback()->allocate(_size, nullptr, __FILE__, __LINE__)
00221 #define NVBLAST_ALLOC_NAMED(_size, _name) NvBlastGlobalGetAllocatorCallback()->allocate(_size, _name, __FILE__, __LINE__)
00222 #define NVBLAST_FREE(_mem) NvBlastGlobalGetAllocatorCallback()->deallocate(_mem)
00223
00228 #define NVBLAST_NEW(T) new (NvBlastGlobalGetAllocatorCallback()->allocate(sizeof(T), #T, __FILE__, __LINE__)) T
00229
00234 #define NVBLAST_DELETE(obj, T) \
00235 (obj)->~T(); \
00236 NvBlastGlobalGetAllocatorCallback()->deallocate(obj)
00237
00238
00239
00241
00245 #define NVBLAST_LOG(_code, _msg) NvBlastGlobalGetErrorCallback()->reportError(_code, _msg, __FILE__, __LINE__)
00246 #define NVBLAST_LOG_ERROR(_msg) NVBLAST_LOG(Nv::Blast::ErrorCode::eINVALID_OPERATION, _msg)
00247 #define NVBLAST_LOG_WARNING(_msg) NVBLAST_LOG(Nv::Blast::ErrorCode::eDEBUG_WARNING, _msg)
00248 #define NVBLAST_LOG_INFO(_msg) NVBLAST_LOG(Nv::Blast::ErrorCode::eDEBUG_INFO, _msg)
00249 #define NVBLAST_LOG_DEBUG(_msg) NVBLAST_LOG(Nv::Blast::ErrorCode::eNO_ERROR, _msg)
00250
00255 #define NVBLAST_CHECK(_code, _expr, _msg, _onFail) \
00256 { \
00257 if(!(_expr)) \
00258 { \
00259 NVBLAST_LOG(_code, _msg); \
00260 { _onFail; }; \
00261 } \
00262 }
00263
00264 #define NVBLAST_CHECK_ERROR(_expr, _msg, _onFail) NVBLAST_CHECK(Nv::Blast::ErrorCode::eINVALID_OPERATION, _expr, _msg, _onFail)
00265 #define NVBLAST_CHECK_WARNING(_expr, _msg, _onFail) NVBLAST_CHECK(Nv::Blast::ErrorCode::eDEBUG_WARNING, _expr, _msg, _onFail)
00266 #define NVBLAST_CHECK_INFO(_expr, _msg, _onFail) NVBLAST_CHECK(Nv::Blast::ErrorCode::eDEBUG_INFO, _expr, _msg, _onFail)
00267 #define NVBLAST_CHECK_DEBUG(_expr, _msg, _onFail) NVBLAST_CHECK(Nv::Blast::ErrorCode::eNO_ERROR, _expr, _msg, _onFail)
00268
00269
00271
00272
00273
00274 #define NVBLAST_FOURCC(_a, _b, _c, _d) ( (uint32_t)(_a) | (uint32_t)(_b)<<8 | (uint32_t)(_c)<<16 | (uint32_t)(_d)<<24 )
00275
00276
00277 #endif // ifndef NVBLASTGLOBALS_H