diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CustomMemory.cpp | 6 | ||||
| -rw-r--r-- | src/Entrypoints.cpp | 46 | ||||
| -rw-r--r-- | src/InternalLogger.cpp | 52 | ||||
| -rw-r--r-- | src/InternalLogger.h | 108 | ||||
| -rw-r--r-- | src/LoggerImpl.h | 0 | ||||
| -rw-r--r-- | src/Simulation.cpp | 13 |
6 files changed, 200 insertions, 25 deletions
diff --git a/src/CustomMemory.cpp b/src/CustomMemory.cpp index d511da1..c8102ae 100644 --- a/src/CustomMemory.cpp +++ b/src/CustomMemory.cpp @@ -4,6 +4,7 @@ #if defined(TARGET_PLATFORM_LINUX) #include <malloc.h> #endif +#include "InternalLogger.h" #if (defined(TARGET_PLATFORM_MACOSX) || defined(TARGET_PLATFORM_ANDROID)) #define _THROW0() @@ -67,8 +68,9 @@ GFSDK_WAVEWORKS_FREE NVSDK_free = free; void* internalMalloc( size_t size ) { void* p = NVSDK_malloc( size ); - if( !p ) - diagnostic_message( TEXT("WaveWorks: MEMORY ALLOCATION ERROR. Check memory allocation callback pointer\n") ); + if (!p) + NV_ERROR(TEXT("WaveWorks: MEMORY ALLOCATION ERROR. Check memory allocation callback pointer\n")); +// diagnostic_message( TEXT("WaveWorks: MEMORY ALLOCATION ERROR. Check memory allocation callback pointer\n") ); return p; } diff --git a/src/Entrypoints.cpp b/src/Entrypoints.cpp index cfd1d10..953decf 100644 --- a/src/Entrypoints.cpp +++ b/src/Entrypoints.cpp @@ -47,6 +47,8 @@ #if WAVEWORKS_ENABLE_GNM #include "orbis\GNM_Util.h" #endif +#include "InternalLogger.h" +#include "Logger.h" // Misc helper macros which can be used to bracket entrypoints to: // - catch any and all exceptions, to keep them out of the app @@ -67,13 +69,13 @@ #define ENTRYPOINT_BEGIN_API(x) BEGIN_TRY_BLOCK { \ if(g_InitialisedAPI != nv_water_d3d_api_##x) { \ - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called but the library was not initialised for ") TSTR(#x) TEXT("\n")); \ + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called but the library was not initialised for ") TSTR(#x)); \ return gfsdk_waveworks_result_FAIL; \ } #define CUSTOM_ENTRYPOINT_BEGIN(r) BEGIN_TRY_BLOCK { \ if(g_InitialisedAPI == nv_water_d3d_api_undefined) { \ - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called but the library was not initialised\n")); \ + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called but the library was not initialised\n")); \ return r; \ } #define ENTRYPOINT_BEGIN CUSTOM_ENTRYPOINT_BEGIN(gfsdk_waveworks_result_FAIL) @@ -258,7 +260,7 @@ namespace #if !defined(TARGET_PLATFORM_PS4) if( !mallocHooks.pMalloc || !mallocHooks.pFree || !mallocHooks.pAlignedMalloc || !mallocHooks.pAlignedFree) { - diagnostic_message(TEXT("SetMemoryManagementCallbacks received invalid pointer to memory allocation routines") ); + NV_ERROR(TEXT("SetMemoryManagementCallbacks received invalid pointer to memory allocation routines")); return gfsdk_waveworks_result_FAIL; } @@ -269,7 +271,7 @@ namespace #else if( !mallocHooks.pOnionAlloc || !mallocHooks.pOnionFree || !mallocHooks.pGarlicAlloc || !mallocHooks.pGarlicFree) { - diagnostic_message(TEXT("SetMemoryManagementCallbacks received invalid pointer to memory allocation routines") ); + NV_ERROR(TEXT("SetMemoryManagementCallbacks received invalid pointer to memory allocation routines")); return gfsdk_waveworks_result_FAIL; } @@ -300,7 +302,7 @@ namespace if(g_CanUseCUDA) break; // We detected CUDA, keep going - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: %s failed because the hardware does not support the detail_level specified in the simulation settings\n"), szEntrypointFnName); + NV_ERROR(TEXT("ERROR: %s failed because the hardware does not support the detail_level specified in the simulation settings\n"), szEntrypointFnName); return gfsdk_waveworks_result_FAIL; #else @@ -438,6 +440,13 @@ const char* GFSDK_WAVEWORKS_CALL_CONV GFSDK_WaveWorks_GetBuildString() #endif } +gfsdk_waveworks_result GFSDK_WAVEWORKS_CALL_CONV GFSDK_WaveWorks_SetUserLogger(nv::ILogger* userLogger) +{ + g_UserLogger = userLogger; + + return gfsdk_waveworks_result_OK; +} + gfsdk_bool GFSDK_WAVEWORKS_CALL_CONV GFSDK_WaveWorks_GLAttribIsShaderInput(gfsdk_cstr attribName, const GFSDK_WaveWorks_ShaderInput_Desc& inputDesc) { ENTRYPOINT_BEGIN_NO_INIT_CHECK @@ -617,13 +626,16 @@ gfsdk_waveworks_result GFSDK_WAVEWORKS_CALL_CONV GFSDK_WaveWorks_InitD3D11(ID3D1 ENTRYPOINT_BEGIN_NO_INIT_CHECK #if WAVEWORKS_ENABLE_D3D11 + + NV_LOG(TEXT("Initing D3D11")); + if(g_InitialisedAPI != nv_water_d3d_api_undefined) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with the library already in an initialised state\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with the library already in an initialised state\n")); return gfsdk_waveworks_result_FAIL; } if(!equal(apiGUID,GFSDK_WAVEWORKS_API_GUID)) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid API GUID\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid API GUID")); return gfsdk_waveworks_result_FAIL; } @@ -682,22 +694,22 @@ gfsdk_waveworks_result GFSDK_WAVEWORKS_CALL_CONV GFSDK_WaveWorks_InitGnm(const G #if WAVEWORKS_ENABLE_GNM if(g_InitialisedAPI != nv_water_d3d_api_undefined) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with the library already in an initialised state\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with the library already in an initialised state")); return gfsdk_waveworks_result_FAIL; } if(!equal(apiGUID,GFSDK_WAVEWORKS_API_GUID)) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid API GUID\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid API GUID")); return gfsdk_waveworks_result_FAIL; } if(!pRequiredMallocHooks) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid pRequiredMallocHooks\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid pRequiredMallocHooks")); return gfsdk_waveworks_result_FAIL; } if(!pRequiredGnmxWrap) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid pRequiredGnmxWrap\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid pRequiredGnmxWrap")); return gfsdk_waveworks_result_FAIL; } @@ -724,12 +736,12 @@ gfsdk_waveworks_result GFSDK_WAVEWORKS_CALL_CONV GFSDK_WaveWorks_InitGL2(const G #if WAVEWORKS_ENABLE_GL if(g_InitialisedAPI != nv_water_d3d_api_undefined) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with the library already in an initialised state\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with the library already in an initialised state")); return gfsdk_waveworks_result_FAIL; } if(!equal(apiGUID,GFSDK_WAVEWORKS_API_GUID)) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid API GUID\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid API GUID")); return gfsdk_waveworks_result_FAIL; } @@ -869,12 +881,12 @@ gfsdk_waveworks_result GFSDK_WAVEWORKS_CALL_CONV GFSDK_WaveWorks_InitNoGraphics( ENTRYPOINT_BEGIN_NO_INIT_CHECK if(g_InitialisedAPI != nv_water_d3d_api_undefined) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with the library already in an initialised state\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with the library already in an initialised state")); return gfsdk_waveworks_result_FAIL; } if(!equal(apiGUID,GFSDK_WAVEWORKS_API_GUID)) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid API GUID\n")); + NV_ERROR(TEXT("ERROR: ") __DEF_FUNCTION__ TEXT(" was called with an invalid API GUID")); return gfsdk_waveworks_result_FAIL; } @@ -1738,7 +1750,7 @@ namespace { void msg_and_break(const char_type* errMsg) { - WaveWorks_Internal::diagnostic_message(errMsg); + NV_ERROR(errMsg); DebugBreak(); } } @@ -1772,7 +1784,7 @@ void check_gl_errors(const char_type* file, gfsdk_S32 line) GLenum error; while (( error = NVSDK_GLFunctions.glGetError() ) != 0) { - WaveWorks_Internal::diagnostic_message(TEXT("\r\n%s(%i): OpenGL error : %i\n"), file, line, error); + NV_ERROR(TEXT("\r\n%s(%i): OpenGL error : %i\n"), file, line, error); } } #endif // WAVEWORKS_ENABLE_GL diff --git a/src/InternalLogger.cpp b/src/InternalLogger.cpp new file mode 100644 index 0000000..e8e8898 --- /dev/null +++ b/src/InternalLogger.cpp @@ -0,0 +1,52 @@ +#include "InternalLogger.h" +#include <iostream> +#include <sstream> +#include <windows.h> + +std::unique_ptr<InternalLogger> g_Logger; +nv::ILogger* g_UserLogger = nullptr; + +InternalLogger::InternalLogger() +{ + +} + +InternalLogger::InternalLogger(nv::LogSeverity loggingLevel): + LoggingLevel(loggingLevel) +{ + +} + +nv::LogSeverity InternalLogger::getLoggingLevel() +{ + return LoggingLevel; +} + +void InternalLogger::setLoggingLevel(nv::LogSeverity newLevel) +{ + LoggingLevel = newLevel; +} + +void InternalLogger::log(const char* text, nv::LogSeverity severity, const char* filename, int linenumber) +{ + if (getLoggingLevel() > severity) + return; + + std::ostringstream out; + + out << filename << "(" << linenumber << "): " << "[" << nv::LogSeverityStrings[(int)severity] << "] " << text << std::endl; + + OutputDebugStringA(out.str().c_str()); +} + +void InternalLogger::log(const wchar_t* text, nv::LogSeverity severity, const wchar_t* filename, int linenumber) +{ + if (getLoggingLevel() > severity) + return; + + std::wstringstream out; + + out << filename << "(" << linenumber << "): " << "[" << nv::LogSeverityStrings[(int)severity] << "] " << text << std::endl; + + OutputDebugStringW(out.str().c_str()); +} diff --git a/src/InternalLogger.h b/src/InternalLogger.h new file mode 100644 index 0000000..d10f263 --- /dev/null +++ b/src/InternalLogger.h @@ -0,0 +1,108 @@ +#pragma once + +#include "Logger.h" +#include <cstdarg> +#include <cstdio> +#include <wtypes.h> +#include <stdio.h> +#include <wchar.h> +#include <memory> + +class InternalLogger : public nv::ILogger +{ +public: + InternalLogger(); + InternalLogger(nv::LogSeverity loggingLevel); + virtual ~InternalLogger() = default; + + virtual void log(const char* text, nv::LogSeverity severity, const char* filename, int linenumber) override; + virtual void log(const wchar_t* text, nv::LogSeverity severity, const wchar_t* filename, int linenumber) override; + + nv::LogSeverity getLoggingLevel(); + void setLoggingLevel(nv::LogSeverity newLevel); + + static InternalLogger* GetInstance() + { + static InternalLogger Instance; + return &Instance; + } + +private: + nv::LogSeverity LoggingLevel; + +}; + +extern nv::ILogger* g_UserLogger; + +namespace WaveworksInternal +{ + inline void log(nv::LogSeverity severity, const wchar_t* filename, int linenumber, const wchar_t* format, ...) + { + wchar_t buffer[1024]; + + va_list args; + va_start(args, format); +#if NV_GCC_FAMILY +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + _vsnwprintf_s(buffer, sizeof(buffer), format, args); +#if NV_GCC_FAMILY +#pragma GCC diagnostic pop +#endif + va_end(args); + + + // Only output to one logger at a time. May not be the desired behaviour. + if (g_UserLogger) + { + g_UserLogger->log(buffer, severity, filename, linenumber); + } + else + { + InternalLogger::GetInstance()->log(buffer, severity, filename, linenumber); + } + + } + + inline void log(nv::LogSeverity severity, const char* filename, int linenumber, const char* format, ...) + { + char buffer[1024]; + + va_list args; + va_start(args, format); +#if NV_GCC_FAMILY +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + vsnprintf_s(buffer, sizeof(buffer), format, args); +#if NV_GCC_FAMILY +#pragma GCC diagnostic pop +#endif + va_end(args); + + // Only output to one logger at a time. May not be the desired behaviour. + if (g_UserLogger) + { + g_UserLogger->log(buffer, severity, filename, linenumber); + } + else + { + InternalLogger::GetInstance()->log(buffer, severity, filename, linenumber); + } + } +} + + + +#ifndef NV_LOG +/// <param name="__VA_ARGS__">format, ...</param> +#define NV_LOG(...) WaveworksInternal::log(nv::LogSeverity::kInfo, __DEF_FILE__, __LINE__, __VA_ARGS__) +/// <param name="__VA_ARGS__">format, ...</param> +#define NV_WARN(...) WaveworksInternal::log(nv::LogSeverity::kWarning, __DEF_FILE__, __LINE__, __VA_ARGS__) +/// <param name="__VA_ARGS__">format, ...</param> +#define NV_ERROR(...) WaveworksInternal::log(nv::LogSeverity::kError, __DEF_FILE__, __LINE__, __VA_ARGS__) +/// <param name="__VA_ARGS__">format, ...</param> +#define NV_FATAL(...) WaveworksInternal::log(nv::LogSeverity::kFatal, __DEF_FILE__, __LINE__, __VA_ARGS__) + +#endif
\ No newline at end of file diff --git a/src/LoggerImpl.h b/src/LoggerImpl.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/LoggerImpl.h diff --git a/src/Simulation.cpp b/src/Simulation.cpp index cc54db0..039d191 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -50,6 +50,7 @@ #include "orbis\GNM_Util.h" using namespace sce; #endif +#include "InternalLogger.h" namespace { #if WAVEWORKS_ENABLE_GRAPHICS @@ -2078,7 +2079,7 @@ HRESULT GFSDK_WaveWorks_Simulation::setRenderState( Graphics_Context* pGC, { if(NULL == pGlPool) { - WaveWorks_Internal::diagnostic_message(TEXT("ERROR: a valid gl pool is required when setting simulation state for gl rendering\n")); + NV_ERROR(TEXT("ERROR: a valid gl pool is required when setting simulation state for gl rendering\n")); return E_FAIL; } @@ -3601,10 +3602,10 @@ GLuint GFSDK_WaveWorks_Simulation::compileGLShader(const char* GL_ONLY(text), GL GLsizei logSize; NVSDK_GLFunctions.glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logSize); CHECK_GL_ERRORS; char* pLog = new char[logSize]; - diagnostic_message(TEXT("\nGL shader [%i] compilation error"),type); - diagnostic_message(TEXT("\n...\n") ASCII_STR_FMT TEXT("\n...\n"),text); + NV_ERROR(TEXT("\nGL shader [%i] compilation error"),type); +// NV_LOG("\n...\n") ASCII_STR_FMT TEXT("\n...\n"),text); NVSDK_GLFunctions.glGetShaderInfoLog(shader, logSize, NULL, pLog); CHECK_GL_ERRORS; - diagnostic_message(TEXT("\ninfolog: ") ASCII_STR_FMT, pLog); + NV_ERROR(TEXT("\ninfolog: %s"), pLog); NVSDK_GLFunctions.glDeleteShader(shader); CHECK_GL_ERRORS; return 0; } @@ -3682,9 +3683,9 @@ GLuint GFSDK_WaveWorks_Simulation::loadGLProgram(const char* GL_ONLY(vstext), co GLsizei logSize; NVSDK_GLFunctions.glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logSize); CHECK_GL_ERRORS; char* pLog = new char[logSize]; - diagnostic_message(TEXT("gl program link error\n")); + NV_ERROR(TEXT("gl program link error\n")); NVSDK_GLFunctions.glGetProgramInfoLog(program, logSize, NULL, pLog); CHECK_GL_ERRORS; - diagnostic_message(TEXT("\ninfolog: ") ASCII_STR_FMT TEXT("\n"),pLog); + NV_ERROR(TEXT("\ninfolog: %s"), pLog); return 0; } return program; |