Added trace method to callback interface.

This commit is contained in:
Branimir Karadžić 2015-07-16 17:39:02 -07:00
parent 1cf4f92152
commit b98d3b6978
6 changed files with 62 additions and 11 deletions

View file

@ -136,6 +136,11 @@ struct BgfxCallback : public bgfx::CallbackI
abort(); abort();
} }
virtual void trace(const char* _str) BX_OVERRIDE
{
dbgPrintf("%s", _str);
}
virtual uint32_t cacheReadSize(uint64_t _id) BX_OVERRIDE virtual uint32_t cacheReadSize(uint64_t _id) BX_OVERRIDE
{ {
char filePath[256]; char filePath[256];

View file

@ -356,6 +356,7 @@ typedef struct bgfx_callback_interface
typedef struct bgfx_callback_vtbl typedef struct bgfx_callback_vtbl
{ {
void (*fatal)(bgfx_callback_interface_t* _this, bgfx_fatal_t _code, const char* _str); 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); 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); 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); void (*cache_write)(bgfx_callback_interface_t* _this, uint64_t _id, const void* _data, uint32_t _size);

View file

@ -234,6 +234,12 @@ namespace bgfx
/// ///
virtual void fatal(Fatal::Enum _code, const char* _str) = 0; 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 /// Return size of for cached item. Return 0 if no cached item was
/// found. /// found.
/// ///

View file

@ -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 virtual void fatal(Fatal::Enum _code, const char* _str) BX_OVERRIDE
{ {
if (Fatal::DebugCheck == _code) if (Fatal::DebugCheck == _code)
@ -236,12 +241,36 @@ namespace bgfx
va_list argList; va_list argList;
va_start(argList, _format); 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); 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" #include "charset.h"
@ -2000,7 +2029,6 @@ again:
void init(RendererType::Enum _type, uint16_t _vendorId, uint16_t _deviceId, CallbackI* _callback, bx::ReallocatorI* _allocator) 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_CHECK(NULL == s_ctx, "bgfx is already initialized.");
BX_TRACE("Init...");
memset(&g_caps, 0, sizeof(g_caps) ); memset(&g_caps, 0, sizeof(g_caps) );
g_caps.maxViews = BGFX_CONFIG_MAX_VIEWS; g_caps.maxViews = BGFX_CONFIG_MAX_VIEWS;
@ -2030,6 +2058,8 @@ again:
s_callbackStub = BX_NEW(g_allocator, CallbackStub); s_callbackStub = BX_NEW(g_allocator, CallbackStub);
} }
BX_TRACE("Init...");
s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16); s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16);
s_ctx->init(_type); s_ctx->init(_type);
@ -2063,10 +2093,11 @@ again:
} }
s_threadIndex = 0; s_threadIndex = 0;
g_callback = NULL;
g_allocator = NULL;
BX_TRACE("Shutdown complete."); BX_TRACE("Shutdown complete.");
g_callback = NULL;
g_allocator = NULL;
} }
void reset(uint32_t _width, uint32_t _height, uint32_t _flags) 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); 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 virtual uint32_t cacheReadSize(uint64_t _id) BX_OVERRIDE
{ {
return m_interface->vtbl->cache_read_size(m_interface, _id); return m_interface->vtbl->cache_read_size(m_interface, _id);

View file

@ -57,12 +57,15 @@ namespace bgfx
void fatal(Fatal::Enum _code, const char* _format, ...); void fatal(Fatal::Enum _code, const char* _format, ...);
#endif // BX_COMPILER_CLANG_ANALYZER #endif // BX_COMPILER_CLANG_ANALYZER
void trace(const char* _format, ...);
void dbgPrintfVargs(const char* _format, va_list _argList);
void dbgPrintf(const char* _format, ...); void dbgPrintf(const char* _format, ...);
} }
#define _BX_TRACE(_format, ...) \ #define _BX_TRACE(_format, ...) \
BX_MACRO_BLOCK_BEGIN \ 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 BX_MACRO_BLOCK_END
#define _BX_WARN(_condition, _format, ...) \ #define _BX_WARN(_condition, _format, ...) \

View file

@ -1579,10 +1579,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
if (NULL != m_swapChain) if (NULL != m_swapChain)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
uint32_t syncInterval = !!(m_flags & BGFX_RESET_VSYNC); uint32_t syncInterval = BX_ENABLED(BX_PLATFORM_WINRT)
#if BX_PLATFORM_WINRT ? 1 // sync interval of 0 is not supported on WinRT
syncInterval = 1; // sync interval of 0 is not supported on WinRT : !!(m_flags & BGFX_RESET_VSYNC)
#endif ;
for (uint32_t ii = 1, num = m_numWindows; ii < num && SUCCEEDED(hr); ++ii) for (uint32_t ii = 1, num = m_numWindows; ii < num && SUCCEEDED(hr); ++ii)
{ {