Updated trace callback.

This commit is contained in:
Branimir Karadžić 2015-07-24 18:02:17 -07:00
parent 3cdf4beaa7
commit cb6cee9dd1
5 changed files with 22 additions and 24 deletions

View File

@ -136,9 +136,10 @@ struct BgfxCallback : public bgfx::CallbackI
abort();
}
virtual void trace(const char* _str) BX_OVERRIDE
virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) BX_OVERRIDE
{
dbgPrintf("%s", _str);
dbgPrintf("%s (%d): ", _filePath, _line);
dbgPrintfVargs(_format, _argList);
}
virtual uint32_t cacheReadSize(uint64_t _id) BX_OVERRIDE

View File

@ -8,6 +8,7 @@
#ifndef BGFX_C99_H_HEADER_GUARD
#define BGFX_C99_H_HEADER_GUARD
#include <stdarg.h> // va_list
#include <stdbool.h> // bool
#include <stdint.h> // uint32_t
#include <stdlib.h> // size_t
@ -367,7 +368,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);
void (*trace_vargs)(bgfx_callback_interface_t* _this, const char* _filePath, uint16_t _line, const char* _format, va_list _argList);
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);

View File

@ -6,6 +6,7 @@
#ifndef BGFX_H_HEADER_GUARD
#define BGFX_H_HEADER_GUARD
#include <stdarg.h> // va_list
#include <stdint.h> // uint32_t
#include <stdlib.h> // size_t
@ -275,14 +276,18 @@ namespace bgfx
/// Print debug message.
///
/// @param[in] _str Message.
/// @param[in] _filePath File path where debug message was generated.
/// @param[in] _line Line where debug message was generated.
/// @param[in] _format `printf` style format.
/// @param[in] _argList Variable arguments list initialized with
/// `va_start`.
///
/// @remarks
/// Not thread safe and it can be called from any thread.
///
/// @attention C99 equivalent is `bgfx_callback_vtbl.trace`.
/// @attention C99 equivalent is `bgfx_callback_vtbl.trace_vargs`.
///
virtual void trace(const char* _str) = 0;
virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) = 0;
/// Return size of for cached item. Return 0 if no cached item was
/// found.

View File

@ -40,9 +40,10 @@ namespace bgfx
{
}
virtual void trace(const char* _str) BX_OVERRIDE
virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) BX_OVERRIDE
{
bx::debugOutput(_str);
dbgPrintf("%s (%d): ", _filePath, _line);
dbgPrintfVargs(_format, _argList);
}
virtual void fatal(Fatal::Enum _code, const char* _str) BX_OVERRIDE
@ -254,23 +255,13 @@ namespace bgfx
g_callback->fatal(_code, out);
}
void trace(const char* _format, ...)
void trace(const char* _filePath, uint16_t _line, 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';
g_callback->traceVargs(_filePath, _line, _format, argList);
va_end(argList);
g_callback->trace(out);
}
#include "charset.h"
@ -3106,9 +3097,9 @@ namespace bgfx
m_interface->vtbl->fatal(m_interface, (bgfx_fatal_t)_code, _str);
}
virtual void trace(const char* _str) BX_OVERRIDE
virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) BX_OVERRIDE
{
m_interface->vtbl->trace(m_interface, _str);
m_interface->vtbl->trace_vargs(m_interface, _filePath, _line, _format, _argList);
}
virtual uint32_t cacheReadSize(uint64_t _id) BX_OVERRIDE

View File

@ -57,7 +57,7 @@ namespace bgfx
void fatal(Fatal::Enum _code, const char* _format, ...);
#endif // BX_COMPILER_CLANG_ANALYZER
void trace(const char* _format, ...);
void trace(const char* _filePath, uint16_t _line, const char* _format, ...);
void dbgPrintfVargs(const char* _format, va_list _argList);
void dbgPrintf(const char* _format, ...);
@ -65,7 +65,7 @@ namespace bgfx
#define _BX_TRACE(_format, ...) \
BX_MACRO_BLOCK_BEGIN \
bgfx::trace(BX_FILE_LINE_LITERAL "BGFX " _format "\n", ##__VA_ARGS__); \
bgfx::trace(__FILE__, uint16_t(__LINE__), "BGFX " _format "\n", ##__VA_ARGS__); \
BX_MACRO_BLOCK_END
#define _BX_WARN(_condition, _format, ...) \