diff --git a/examples/07-callback/callback.cpp b/examples/07-callback/callback.cpp index 20869984..e79421fd 100644 --- a/examples/07-callback/callback.cpp +++ b/examples/07-callback/callback.cpp @@ -136,6 +136,11 @@ struct BgfxCallback : public bgfx::CallbackI abort(); } + virtual void trace(const char* _str) BX_OVERRIDE + { + dbgPrintf("%s", _str); + } + virtual uint32_t cacheReadSize(uint64_t _id) BX_OVERRIDE { char filePath[256]; diff --git a/include/bgfx.c99.h b/include/bgfx.c99.h index 64d35a83..fa5273e9 100644 --- a/include/bgfx.c99.h +++ b/include/bgfx.c99.h @@ -356,6 +356,7 @@ typedef struct bgfx_callback_interface typedef struct bgfx_callback_vtbl { void (*fatal)(bgfx_callback_interface_t* _this, bgfx_fatal_t _code, const char* _str); + void (*trace)(bgfx_callback_interface_t* _this, const char* _str); uint32_t (*cache_read_size)(bgfx_callback_interface_t* _this, uint64_t _id); bool (*cache_read)(bgfx_callback_interface_t* _this, uint64_t _id, void* _data, uint32_t _size); void (*cache_write)(bgfx_callback_interface_t* _this, uint64_t _id, const void* _data, uint32_t _size); diff --git a/include/bgfx.h b/include/bgfx.h index adfea912..7aae68ff 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -234,6 +234,12 @@ namespace bgfx /// virtual void fatal(Fatal::Enum _code, const char* _str) = 0; + /// Print debug message. + /// + /// @param[in] _str Message. + /// + virtual void trace(const char* _str) = 0; + /// Return size of for cached item. Return 0 if no cached item was /// found. /// diff --git a/src/bgfx.cpp b/src/bgfx.cpp index b4dc62c8..31956b40 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -40,6 +40,11 @@ namespace bgfx { } + virtual void trace(const char* _str) BX_OVERRIDE + { + bx::debugOutput(_str); + } + virtual void fatal(Fatal::Enum _code, const char* _str) BX_OVERRIDE { if (Fatal::DebugCheck == _code) @@ -236,12 +241,36 @@ namespace bgfx va_list argList; va_start(argList, _format); - bx::vsnprintf(temp, sizeof(temp), _format, argList); + char* out = temp; + int32_t len = bx::vsnprintf(out, sizeof(temp), _format, argList); + if ( (int32_t)sizeof(temp) < len) + { + out = (char*)alloca(len+1); + len = bx::vsnprintf(out, len, _format, argList); + } + out[len] = '\0'; va_end(argList); - temp[sizeof(temp)-1] = '\0'; + g_callback->fatal(_code, out); + } - g_callback->fatal(_code, temp); + void trace(const char* _format, ...) + { + char temp[8192]; + + va_list argList; + va_start(argList, _format); + char* out = temp; + int32_t len = bx::vsnprintf(out, sizeof(temp), _format, argList); + if ( (int32_t)sizeof(temp) < len) + { + out = (char*)alloca(len+1); + len = bx::vsnprintf(out, len, _format, argList); + } + out[len] = '\0'; + va_end(argList); + + g_callback->trace(out); } #include "charset.h" @@ -2000,7 +2029,6 @@ again: void init(RendererType::Enum _type, uint16_t _vendorId, uint16_t _deviceId, CallbackI* _callback, bx::ReallocatorI* _allocator) { BX_CHECK(NULL == s_ctx, "bgfx is already initialized."); - BX_TRACE("Init..."); memset(&g_caps, 0, sizeof(g_caps) ); g_caps.maxViews = BGFX_CONFIG_MAX_VIEWS; @@ -2030,6 +2058,8 @@ again: s_callbackStub = BX_NEW(g_allocator, CallbackStub); } + BX_TRACE("Init..."); + s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16); s_ctx->init(_type); @@ -2063,10 +2093,11 @@ again: } s_threadIndex = 0; - g_callback = NULL; - g_allocator = NULL; BX_TRACE("Shutdown complete."); + + g_callback = NULL; + g_allocator = NULL; } void reset(uint32_t _width, uint32_t _height, uint32_t _flags) @@ -3073,6 +3104,11 @@ namespace bgfx m_interface->vtbl->fatal(m_interface, (bgfx_fatal_t)_code, _str); } + virtual void trace(const char* _str) BX_OVERRIDE + { + m_interface->vtbl->trace(m_interface, _str); + } + virtual uint32_t cacheReadSize(uint64_t _id) BX_OVERRIDE { return m_interface->vtbl->cache_read_size(m_interface, _id); diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 97621d31..00d719bb 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -57,12 +57,15 @@ namespace bgfx void fatal(Fatal::Enum _code, const char* _format, ...); #endif // BX_COMPILER_CLANG_ANALYZER + void trace(const char* _format, ...); + + void dbgPrintfVargs(const char* _format, va_list _argList); void dbgPrintf(const char* _format, ...); } #define _BX_TRACE(_format, ...) \ BX_MACRO_BLOCK_BEGIN \ - bgfx::dbgPrintf(BX_FILE_LINE_LITERAL "BGFX " _format "\n", ##__VA_ARGS__); \ + bgfx::trace(BX_FILE_LINE_LITERAL "BGFX " _format "\n", ##__VA_ARGS__); \ BX_MACRO_BLOCK_END #define _BX_WARN(_condition, _format, ...) \ diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 6e07827a..e64c85cf 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1579,10 +1579,10 @@ BX_PRAGMA_DIAGNOSTIC_POP(); if (NULL != m_swapChain) { HRESULT hr = S_OK; - uint32_t syncInterval = !!(m_flags & BGFX_RESET_VSYNC); -#if BX_PLATFORM_WINRT - syncInterval = 1; // sync interval of 0 is not supported on WinRT -#endif + uint32_t syncInterval = BX_ENABLED(BX_PLATFORM_WINRT) + ? 1 // sync interval of 0 is not supported on WinRT + : !!(m_flags & BGFX_RESET_VSYNC) + ; for (uint32_t ii = 1, num = m_numWindows; ii < num && SUCCEEDED(hr); ++ii) {