summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/Logger.h25
-rw-r--r--common/LoggerImpl.cpp46
-rw-r--r--common/LoggerImpl.h67
-rw-r--r--compiler/cmake/NvWaveWorks.cmake5
-rw-r--r--compiler/cmake/sample_d3d11.cmake6
-rw-r--r--compiler/cmake/test_d3d11.cmake6
-rw-r--r--include/GFSDK_WaveWorks.h8
-rw-r--r--media/sample/SunsetFair.ddsbin89478640 -> 22369756 bytes
-rw-r--r--media/sample/SunsetFair24bit.ddsbin16777349 -> 0 bytes
-rw-r--r--media/sample/foam.ddsbin5592528 -> 0 bytes
-rw-r--r--media/sample/foam24bit.ddsbin1048703 -> 1398228 bytes
-rw-r--r--sample/d3d11/distance_field.cpp7
-rw-r--r--sample/d3d11/distance_field.h2
-rw-r--r--sample/d3d11/ocean_surface.cpp16
-rw-r--r--sample/d3d11/ocean_surface.h2
-rw-r--r--sample/d3d11/sample_d3d11.cpp18
-rw-r--r--sample/d3d11/terrain.cpp2
-rw-r--r--src/CustomMemory.cpp6
-rw-r--r--src/Entrypoints.cpp46
-rw-r--r--src/InternalLogger.cpp52
-rw-r--r--src/InternalLogger.h108
-rw-r--r--src/LoggerImpl.h0
-rw-r--r--src/Simulation.cpp13
-rw-r--r--test/d3d11/ocean_cufft_app.cpp16
-rw-r--r--test/d3d11/ocean_surface.cpp8
25 files changed, 396 insertions, 63 deletions
diff --git a/common/Logger.h b/common/Logger.h
new file mode 100644
index 0000000..324b71e
--- /dev/null
+++ b/common/Logger.h
@@ -0,0 +1,25 @@
+#pragma once
+
+namespace nv
+{
+ enum struct LogSeverity
+ {
+ kInfo = 0, // Message contains information about normal and expected behavior
+ kWarning = 1, // Message contains information about a potentially problematic situation
+ kError = 2, // Message contains information about a problem
+ kFatal = 3 // Message contains information about a fatal problem; program should be aborted
+ };
+
+ static const char * LogSeverityStrings[] = { "INFO", "WARNING", "ERROR", "FATAL" };
+
+
+ // Note: Implementation of this interface must be thread-safe
+ class ILogger
+ {
+ public:
+ // �filename� is NULL and �linenumber� is 0 in release builds of GameWorks
+ virtual void log(const char* text, LogSeverity severity, const char* filename, int linenumber) = 0;
+ virtual void log(const wchar_t* text, LogSeverity severity, const wchar_t* filename, int linenumber) = 0;
+ };
+}
+
diff --git a/common/LoggerImpl.cpp b/common/LoggerImpl.cpp
new file mode 100644
index 0000000..9a2921d
--- /dev/null
+++ b/common/LoggerImpl.cpp
@@ -0,0 +1,46 @@
+#include "LoggerImpl.h"
+#include <iostream>
+#include <sstream>
+#include <windows.h>
+
+LoggerWWSamples* g_Logger = nullptr;
+
+LoggerWWSamples::LoggerWWSamples():
+LoggingLevel(nv::LogSeverity::kInfo)
+{
+
+}
+
+LoggerWWSamples::LoggerWWSamples(nv::LogSeverity loggingLevel) :
+ LoggingLevel(loggingLevel)
+{
+
+}
+
+nv::LogSeverity LoggerWWSamples::getLoggingLevel()
+{
+ return LoggingLevel;
+}
+
+void LoggerWWSamples::setLoggingLevel(nv::LogSeverity newLevel)
+{
+ LoggingLevel = newLevel;
+}
+
+void LoggerWWSamples::log(const char* text, nv::LogSeverity severity, const char* filename, int linenumber)
+{
+ std::ostringstream out;
+
+ out << filename << "(" << linenumber << "): " << "[" << nv::LogSeverityStrings[(int) severity] << "] " << text << std::endl;
+
+ OutputDebugStringA(out.str().c_str());
+}
+
+void LoggerWWSamples::log(const wchar_t* text, nv::LogSeverity severity, const wchar_t* filename, int linenumber)
+{
+ std::wstringstream out;
+
+ out << filename << "(" << linenumber << "): " << "[" << nv::LogSeverityStrings[(int)severity] << "] " << text << std::endl;
+
+ OutputDebugStringW(out.str().c_str());
+}
diff --git a/common/LoggerImpl.h b/common/LoggerImpl.h
new file mode 100644
index 0000000..a07cead
--- /dev/null
+++ b/common/LoggerImpl.h
@@ -0,0 +1,67 @@
+#pragma once
+#include "Logger.h"
+#include <cstdarg>
+#include <cstdio>
+
+class LoggerWWSamples : public nv::ILogger
+{
+public:
+ LoggerWWSamples();
+ LoggerWWSamples(nv::LogSeverity loggingLevel);
+ virtual ~LoggerWWSamples() = 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);
+
+private:
+ nv::LogSeverity LoggingLevel;
+};
+
+extern LoggerWWSamples* g_Logger;
+
+namespace wwsamples
+{
+ inline void log(nv::LogSeverity severity, const char* filename, int linenumber, const char* format, ...)
+ {
+ if (g_Logger == nullptr)
+ {
+ g_Logger = new LoggerWWSamples();
+ }
+
+ if (g_Logger->getLoggingLevel() > severity)
+ return;
+
+ 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);
+
+ g_Logger->log(buffer, severity, filename, linenumber);
+ }
+}
+
+
+
+#ifndef NV_LOG
+/// <param name="__VA_ARGS__">format, ...</param>
+#define NV_LOG(...) wwsamples::log(nv::LogSeverity::kInfo, __FILE__, __LINE__, __VA_ARGS__)
+/// <param name="__VA_ARGS__">format, ...</param>
+#define NV_WARN(...) wwsamples::log(nv::LogSeverity::kWarning, __FILE__, __LINE__, __VA_ARGS__)
+/// <param name="__VA_ARGS__">format, ...</param>
+#define NV_ERROR(...) wwsamples::log(nv::LogSeverity::kError, __FILE__, __LINE__, __VA_ARGS__)
+/// <param name="__VA_ARGS__">format, ...</param>
+#define NV_FATAL(...) wwsamples::log(nv::LogSeverity::kFatal, __FILE__, __LINE__, __VA_ARGS__)
+
+#endif \ No newline at end of file
diff --git a/compiler/cmake/NvWaveWorks.cmake b/compiler/cmake/NvWaveWorks.cmake
index 87b62d8..9ac0d91 100644
--- a/compiler/cmake/NvWaveWorks.cmake
+++ b/compiler/cmake/NvWaveWorks.cmake
@@ -9,6 +9,7 @@ SET(WW_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
SET(SHADER_SRC_DIR ${WW_SOURCE_DIR}/shader)
SET(DISTRO_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
SET(GEN_SRC_DIR ${WW_SOURCE_DIR}/generated)
+SET(COMMON_SOURCE_DIR ${PROJECT_SOURCE_DIR}/common)
IF(TARGET_BUILD_PLATFORM STREQUAL "Windows")
@@ -112,6 +113,9 @@ SET(H_FILES
${WW_SOURCE_DIR}/Simulation_impl.h
${WW_SOURCE_DIR}/Simulation_Util.h
${WW_SOURCE_DIR}/Spectrum_Util.h
+
+ ${WW_SOURCE_DIR}/InternalLogger.h
+ ${WW_SOURCE_DIR}/InternalLogger.cpp
)
SET(DISTRO_INCLUDE_FILES
@@ -252,6 +256,7 @@ TARGET_INCLUDE_DIRECTORIES(WaveWorks
PRIVATE ${WW_PLATFORM_INCLUDES}
PRIVATE ${CUDA_INCLUDE_DIRS}
PRIVATE ${GEN_SRC_DIR}
+ PRIVATE ${COMMON_SOURCE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/include
PRIVATE ${SHADER_SRC_DIR}
diff --git a/compiler/cmake/sample_d3d11.cmake b/compiler/cmake/sample_d3d11.cmake
index 28f9895..2d8ddc7 100644
--- a/compiler/cmake/sample_d3d11.cmake
+++ b/compiler/cmake/sample_d3d11.cmake
@@ -9,6 +9,7 @@ FIND_PACKAGE(FX11 REQUIRED)
FIND_PACKAGE(DirectXTK REQUIRED)
SET(SAMP_SOURCE_DIR ${PROJECT_SOURCE_DIR}/sample/d3d11)
+SET(COMMON_SOURCE_DIR ${PROJECT_SOURCE_DIR}/common)
SET(SHARED_CS_DIR ${PROJECT_SOURCE_DIR}/test/client-server)
SET(TL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
@@ -83,7 +84,10 @@ SET(APP_FILES
${SAMP_SOURCE_DIR}/terrain.cpp
${SAMP_SOURCE_DIR}/terrain.h
- ${SAMP_SOURCE_DIR}/util.cpp
+ ${COMMON_SOURCE_DIR}/Logger.h
+ ${COMMON_SOURCE_DIR}/LoggerImpl.h
+ ${COMMON_SOURCE_DIR}/LoggerImpl.cpp
+
)
SET(FX_FILES
diff --git a/compiler/cmake/test_d3d11.cmake b/compiler/cmake/test_d3d11.cmake
index a1679e8..68e5e5e 100644
--- a/compiler/cmake/test_d3d11.cmake
+++ b/compiler/cmake/test_d3d11.cmake
@@ -11,6 +11,7 @@ FIND_PACKAGE(DirectXTK REQUIRED)
MESSAGE("FX11 ${FX11_SDK_PATH}")
SET(TEST_SOURCE_DIR ${PROJECT_SOURCE_DIR}/test/d3d11)
+SET(COMMON_SOURCE_DIR ${PROJECT_SOURCE_DIR}/common)
SET(SHARED_CS_DIR ${PROJECT_SOURCE_DIR}/test/client-server)
SET(TL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
@@ -76,8 +77,11 @@ ENDIF()
SET(APP_FILES
${TEST_SOURCE_DIR}/ocean_cufft_app.cpp
${TEST_SOURCE_DIR}/ocean_surface.cpp
- ${TEST_SOURCE_DIR}/util.cpp
${TEST_SOURCE_DIR}/ocean_surface.h
+
+ ${COMMON_SOURCE_DIR}/Logger.h
+ ${COMMON_SOURCE_DIR}/LoggerImpl.h
+ ${COMMON_SOURCE_DIR}/LoggerImpl.cpp
)
SET(SHARED_CS_FILES
diff --git a/include/GFSDK_WaveWorks.h b/include/GFSDK_WaveWorks.h
index 935c2e6..be2e5fc 100644
--- a/include/GFSDK_WaveWorks.h
+++ b/include/GFSDK_WaveWorks.h
@@ -85,12 +85,20 @@ struct GFSDK_WaveWorks_Malloc_Hooks
#endif
+namespace nv
+{
+ class ILogger;
+}
+
/*===========================================================================
Globals/init
===========================================================================*/
GFSDK_WAVEWORKS_DECL(gfsdk_cstr) GFSDK_WaveWorks_GetBuildString();
+GFSDK_WAVEWORKS_DECL(gfsdk_waveworks_result) GFSDK_WaveWorks_SetUserLogger(nv::ILogger* userLogger);
+
+
// Use these calls to globally initialize/release on D3D device create/destroy.
GFSDK_WAVEWORKS_DECL(gfsdk_waveworks_result) GFSDK_WaveWorks_InitNoGraphics(const GFSDK_WaveWorks_Malloc_Hooks* pOptionalMallocHooks, const GFSDK_WaveWorks_API_GUID& apiGUID);
GFSDK_WAVEWORKS_DECL(gfsdk_waveworks_result) GFSDK_WaveWorks_ReleaseNoGraphics();
diff --git a/media/sample/SunsetFair.dds b/media/sample/SunsetFair.dds
index 54c7f01..be64d15 100644
--- a/media/sample/SunsetFair.dds
+++ b/media/sample/SunsetFair.dds
Binary files differ
diff --git a/media/sample/SunsetFair24bit.dds b/media/sample/SunsetFair24bit.dds
deleted file mode 100644
index 49083a4..0000000
--- a/media/sample/SunsetFair24bit.dds
+++ /dev/null
Binary files differ
diff --git a/media/sample/foam.dds b/media/sample/foam.dds
deleted file mode 100644
index d2481a3..0000000
--- a/media/sample/foam.dds
+++ /dev/null
Binary files differ
diff --git a/media/sample/foam24bit.dds b/media/sample/foam24bit.dds
index 3a8a232..42cd5f2 100644
--- a/media/sample/foam24bit.dds
+++ b/media/sample/foam24bit.dds
Binary files differ
diff --git a/sample/d3d11/distance_field.cpp b/sample/d3d11/distance_field.cpp
index 61e335b..b660fde 100644
--- a/sample/d3d11/distance_field.cpp
+++ b/sample/d3d11/distance_field.cpp
@@ -286,7 +286,12 @@ float DistanceField::FindNearestPixel( float* pTextureData, const int cx, const
return originPositive ? -minDistance/kMaxDistance : minDistance/kMaxDistance;
}
-void DistanceField::GetWorldToTopDownTextureMatrix( XMMATRIX worldToTopDownMatrix )
+void DistanceField::GetWorldToTopDownTextureMatrix( XMMATRIX &worldToTopDownMatrix )
{
+// XMMATRIX wtvMat, vtpMat;
+//
+// XMLoadFloat4x4(&m_worldToViewMatrix);
+// XMLoadFloat4x4(&m_viewToProjectionMatrix);
+
worldToTopDownMatrix = XMLoadFloat4x4(&m_worldToViewMatrix) * XMLoadFloat4x4(&m_viewToProjectionMatrix);
} \ No newline at end of file
diff --git a/sample/d3d11/distance_field.h b/sample/d3d11/distance_field.h
index 5b2e3a2..a8cbe9b 100644
--- a/sample/d3d11/distance_field.h
+++ b/sample/d3d11/distance_field.h
@@ -43,8 +43,8 @@ struct DistanceField
// --------------------------------- Accessors -----------------------------------
ID3D11ShaderResourceView* GetDataTextureSRV() const { return m_pTopDownDataSRV; }
- void GetWorldToTopDownTextureMatrix( XMMATRIX worldToTopDownMatrix );
+ void GetWorldToTopDownTextureMatrix(XMMATRIX &worldToTopDownMatrix);
// --------------------------------- Rendering routines -----------------------------------
void GenerateDataTexture(ID3D11DeviceContext* pDC );
diff --git a/sample/d3d11/ocean_surface.cpp b/sample/d3d11/ocean_surface.cpp
index 4bd0dc6..3bf11c8 100644
--- a/sample/d3d11/ocean_surface.cpp
+++ b/sample/d3d11/ocean_surface.cpp
@@ -31,10 +31,11 @@
#include "ocean_surface.h"
#include "GFSDK_WaveWorks_D3D_Util.h"
+#include "../common/Logger.h"
+#include "../common/LoggerImpl.h"
#pragma warning(disable:4127)
-
OceanSurface::OceanSurface()
{
m_pOceanFX = NULL;
@@ -72,8 +73,10 @@ OceanSurface::~OceanSurface()
HRESULT OceanSurface::initQuadTree(const GFSDK_WaveWorks_Quadtree_Params& params)
{
+ NV_LOG("Initing the QuadTree");
+
if(NULL == m_hOceanQuadTree)
-{
+ {
return GFSDK_WaveWorks_Quadtree_CreateD3D11(params, m_pd3dDevice, &m_hOceanQuadTree);
}
else
@@ -148,13 +151,10 @@ HRESULT OceanSurface::init()
if(NULL == m_pOceanFX)
{
- ID3DBlob* pEffectBuffer = NULL;
-
TCHAR path[MAX_PATH];
V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("ocean_surface_d3d11.fxo")));
- V_RETURN(D3DX11CreateEffectFromFile(path, 0, m_pd3dDevice, &m_pOceanFX));// pEffectBuffer->GetBufferPointer(), pEffectBuffer->GetBufferSize(), 0, pd3dDevice, &g_pEffect));
- SAFE_RELEASE(pEffectBuffer);
+ V_RETURN(D3DX11CreateEffectFromFile(path, 0, m_pd3dDevice, &m_pOceanFX));
// Hook up the shader mappings
@@ -197,7 +197,7 @@ HRESULT OceanSurface::init()
pShadedShoreReflectionHS->Release();
pShadedShoreReflectionDS->Release();
- m_pRenderSurfaceWireframeWithShorelinePass = m_pRenderSurfaceTechnique->GetPassByName("Pass_Wireframe_WithShoreline");
+ //m_pRenderSurfaceWireframeWithShorelinePass = m_pRenderSurfaceTechnique->GetPassByName("Pass_Wireframe_WithShoreline");
}
if(NULL == m_pQuadLayout)
@@ -309,7 +309,7 @@ void OceanSurface::renderShaded( ID3D11DeviceContext* pDC,
m_pOceanFX->GetVariableByName("g_BaseGerstnerWavelength")->AsScalar()->SetFloat( wavelength );
m_pOceanFX->GetVariableByName("g_BaseGerstnerSpeed")->AsScalar()->SetFloat( speed );
m_pOceanFX->GetVariableByName("g_BaseGerstnerParallelness")->AsScalar()->SetFloat( parallelness );
- m_pOceanFX->GetVariableByName("g_WindDirection")->AsVector()->SetFloatVector( &windDir.x );
+ m_pOceanFX->GetVariableByName("g_WindDirection")->AsVector()->SetFloatVector( (FLOAT*) &windDir );
m_pOceanFX->GetVariableByName("g_DataTexture")->AsShaderResource()->SetResource( pDistanceFieldModule->GetDataTextureSRV() );
m_pOceanFX->GetVariableByName("g_Time")->AsScalar()->SetFloat( totalTime );
diff --git a/sample/d3d11/ocean_surface.h b/sample/d3d11/ocean_surface.h
index 5910970..d3b8f00 100644
--- a/sample/d3d11/ocean_surface.h
+++ b/sample/d3d11/ocean_surface.h
@@ -50,7 +50,7 @@ public:
ID3DX11Effect* m_pOceanFX;
ID3DX11EffectTechnique* m_pRenderSurfaceTechnique;
ID3DX11EffectPass* m_pRenderSurfaceShadedWithShorelinePass;
- ID3DX11EffectPass* m_pRenderSurfaceWireframeWithShorelinePass;
+// ID3DX11EffectPass* m_pRenderSurfaceWireframeWithShorelinePass;
ID3D11InputLayout* m_pQuadLayout;
ID3D11InputLayout* m_pRayContactLayout;
diff --git a/sample/d3d11/sample_d3d11.cpp b/sample/d3d11/sample_d3d11.cpp
index 20c2a1c..929ba11 100644
--- a/sample/d3d11/sample_d3d11.cpp
+++ b/sample/d3d11/sample_d3d11.cpp
@@ -46,6 +46,8 @@
#include <locale>
#include <codecvt>
#include <xlocbuf>
+#include "../common/Logger.h"
+#include "../common/LoggerImpl.h"
//#define DEBUG_VS // Uncomment this line to debug vertex shaders
//#define DEBUG_PS // Uncomment this line to debug pixel shaders
@@ -53,8 +55,6 @@
// Disable warning "conditional expression is constant"
#pragma warning(disable:4127)
-extern HRESULT LoadFile(LPCTSTR FileName, ID3DBlob** ppBuffer);
-
//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
@@ -209,6 +209,12 @@ INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR cmdline, int )
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
+ NV_LOG("Testing!");
+
+ GFSDK_WaveWorks_SetUserLogger(static_cast<nv::ILogger*>(g_Logger));
+
+ NV_LOG("User logger set!");
+
//TODO: Take from cmdline
auto mediaPath = "..\\..\\media\\sample";
@@ -494,10 +500,8 @@ HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFA
SAFE_RELEASE(pD3D11Resource);
// Terrain and sky fx
- ID3DBlob* pEffectBuffer = NULL;
V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("sample_d3d11.fxo")));
- V_RETURN(D3DX11CreateEffectFromFile(path, 0, pd3dDevice, &g_pEffect));// pEffectBuffer->GetBufferPointer(), pEffectBuffer->GetBufferSize(), 0, pd3dDevice, &g_pEffect));
- SAFE_RELEASE(pEffectBuffer);
+ V_RETURN(D3DX11CreateEffectFromFile(path, 0, pd3dDevice, &g_pEffect));
// Initialize shoreline interaction.
g_pDistanceField = new DistanceField( &g_Terrain );
@@ -708,7 +712,7 @@ void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext*
oceanFX->GetVariableByName("g_ZNear")->AsScalar()->SetFloat(scene_z_near);
oceanFX->GetVariableByName("g_ZFar")->AsScalar()->SetFloat(scene_z_far);
- XMFLOAT3 light_pos = XMFLOAT3(140000.0f,65000.0f,40000.0f);
+ XMFLOAT4 light_pos = XMFLOAT4(140000.0f,65000.0f,40000.0f,0);
g_pEffect->GetVariableByName("g_LightPosition")->AsVector()->SetFloatVector((FLOAT*)&light_pos);
g_pEffect->GetVariableByName("g_ScreenSizeInv")->AsVector()->SetFloatVector((FLOAT*)&ScreenSizeInv);
oceanFX->GetVariableByName("g_ScreenSizeInv")->AsVector()->SetFloatVector((FLOAT*)&ScreenSizeInv);
@@ -722,7 +726,7 @@ void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext*
- RenderLogo(pDC);
+ //RenderLogo(pDC);
if(g_bShowUI) {
diff --git a/sample/d3d11/terrain.cpp b/sample/d3d11/terrain.cpp
index d52059b..32356db 100644
--- a/sample/d3d11/terrain.cpp
+++ b/sample/d3d11/terrain.cpp
@@ -955,7 +955,7 @@ HRESULT CTerrain::LoadTextures()
V_RETURN(DirectX::CreateDDSTextureFromFile(pDevice, static_cast<const wchar_t *>(path), &pD3D11Resource, &foam_intensity_textureSRV));
SAFE_RELEASE(pD3D11Resource);
- V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("foam.dds")));
+ V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("foam24bit.dds")));
V_RETURN(DirectX::CreateDDSTextureFromFile(pDevice, static_cast<const wchar_t *>(path), &pD3D11Resource, &foam_diffuse_textureSRV));
SAFE_RELEASE(pD3D11Resource);
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;
diff --git a/test/d3d11/ocean_cufft_app.cpp b/test/d3d11/ocean_cufft_app.cpp
index a09261f..4b2a578 100644
--- a/test/d3d11/ocean_cufft_app.cpp
+++ b/test/d3d11/ocean_cufft_app.cpp
@@ -56,8 +56,6 @@
// Disable warning "conditional expression is constant"
#pragma warning(disable:4127)
-extern HRESULT LoadFile(LPCTSTR FileName, ID3DBlob** ppBuffer);
-
//--------------------------------------------------------------------------------------
// Global variables
@@ -572,11 +570,9 @@ HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFA
// Skybox
{
TCHAR path[MAX_PATH];
+
V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("skybox_d3d11.fxo")));
- ID3DBlob* pEffectBuffer = NULL;
- V_RETURN(LoadFile(path, &pEffectBuffer));
- V_RETURN(D3DX11CreateEffectFromMemory(pEffectBuffer->GetBufferPointer(), pEffectBuffer->GetBufferSize(), 0, pd3dDevice, &g_pSkyboxFX));
- pEffectBuffer->Release();
+ V_RETURN(D3DX11CreateEffectFromFile(path, 0, pd3dDevice, &g_pSkyboxFX));
}
g_pSkyBoxTechnique = g_pSkyboxFX->GetTechniqueByName("SkyboxTech");
@@ -622,11 +618,9 @@ HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFA
// Readback marker
{
TCHAR path[MAX_PATH];
- V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("ocean_marker_d3d11.fxo")))
- ID3DBlob* pEffectBuffer = NULL;
- V_RETURN(LoadFile(path, &pEffectBuffer));
- V_RETURN(D3DX11CreateEffectFromMemory(pEffectBuffer->GetBufferPointer(), pEffectBuffer->GetBufferSize(), 0, pd3dDevice, &g_pMarkerFX));
- pEffectBuffer->Release();
+
+ V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("ocean_marker_d3d11.fxo")));
+ V_RETURN(D3DX11CreateEffectFromFile(path, 0, pd3dDevice, &g_pMarkerFX));
}
g_pMarkerTechnique = g_pMarkerFX->GetTechniqueByName("RenderMarkerTech");
diff --git a/test/d3d11/ocean_surface.cpp b/test/d3d11/ocean_surface.cpp
index 2495886..e488e5b 100644
--- a/test/d3d11/ocean_surface.cpp
+++ b/test/d3d11/ocean_surface.cpp
@@ -35,8 +35,6 @@
#pragma warning(disable:4127)
-extern HRESULT LoadFile(LPCTSTR FileName, ID3DBlob** ppBuffer);
-
OceanSurface::OceanSurface()
{
m_pBicolorMap = NULL;
@@ -174,11 +172,9 @@ HRESULT OceanSurface::init(const OceanSurfaceParameters& params)
if(NULL == m_pOceanFX)
{
TCHAR path[MAX_PATH];
+
V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("ocean_surface_d3d11.fxo")));
- ID3DBlob* pEffectBuffer = NULL;
- V_RETURN(LoadFile(path, &pEffectBuffer));
- V_RETURN(D3DX11CreateEffectFromMemory(pEffectBuffer->GetBufferPointer(), pEffectBuffer->GetBufferSize(), 0, m_pd3dDevice, &m_pOceanFX));
- pEffectBuffer->Release();
+ V_RETURN(D3DX11CreateEffectFromFile(path, 0, m_pd3dDevice, &m_pOceanFX));
// Hook up the shader mappings
m_pRenderSurfaceTechnique = m_pOceanFX->GetTechniqueByName("RenderOceanSurfTech");