Removed use of external debug functions.

This commit is contained in:
bkaradzic 2013-04-28 12:27:35 -07:00
Родитель bb8531d9a2
Коммит 0e0fcd22de
6 изменённых файлов: 62 добавлений и 41 удалений

Просмотреть файл

@ -12,24 +12,7 @@
#include "dbg.h"
#include <bx/string.h>
#if BX_PLATFORM_ANDROID
# include <android/log.h>
#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* _str);
#endif // BX_PLATFORM_WINDOWS
void dbgOutput(const char* _out)
{
#if BX_PLATFORM_ANDROID
__android_log_write(ANDROID_LOG_DEBUG, "", _out);
#elif BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360
OutputDebugStringA(_out);
#elif BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_OSX
fputs(_out, stderr);
fflush(stderr);
#endif // BX_PLATFORM_
}
#include <bx/debug.h>
void dbgPrintfVargs(const char* _format, va_list _argList)
{
@ -42,7 +25,7 @@ void dbgPrintfVargs(const char* _format, va_list _argList)
len = bx::vsnprintf(out, len, _format, _argList);
}
out[len] = '\0';
dbgOutput(out);
bx::debugOutput(out);
}
void dbgPrintf(const char* _format, ...)

Просмотреть файл

@ -223,7 +223,8 @@ namespace bgfx
{
enum Enum
{
MinimumRequiredSpecs = 1,
DebugCheck,
MinimumRequiredSpecs,
InvalidShader,
UnableToInitialize,
UnableToCreateRenderTarget,
@ -354,7 +355,8 @@ namespace bgfx
{
virtual ~CallbackI() = 0;
/// Called on unrecoverable error. It's not safe to continue, inform
/// If fatal code code is not Fatal::DebugCheck this callback is
/// called on unrecoverable error. It's not safe to continue, inform
/// user and terminate application from this call.
virtual void fatal(Fatal::Enum _code, const char* _str) = 0;

Просмотреть файл

@ -63,9 +63,16 @@ namespace bgfx
virtual void fatal(Fatal::Enum _code, const char* _str) BX_OVERRIDE
{
BX_TRACE("0x%08x: %s", _code, _str);
BX_UNUSED(_code, _str);
abort();
if (Fatal::DebugCheck == _code)
{
bx::debugBreak();
}
else
{
BX_TRACE("0x%08x: %s", _code, _str);
BX_UNUSED(_code, _str);
abort();
}
}
virtual uint32_t cacheReadSize(uint64_t /*_id*/) BX_OVERRIDE
@ -130,7 +137,7 @@ namespace bgfx
va_list argList;
va_start(argList, _format);
vsnprintf(temp, sizeof(temp), _format, argList);
bx::vsnprintf(temp, sizeof(temp), _format, argList);
va_end(argList);
temp[sizeof(temp)-1] = '\0';

Просмотреть файл

@ -7,6 +7,8 @@
#define __BGFX_P_H__
#include "bgfx.h"
#include "config.h"
#include <inttypes.h>
#include <stdarg.h> // va_list
#include <stdio.h>
@ -14,17 +16,16 @@
#include <string.h>
#include <alloca.h>
extern void dbgPrintf(const char* _format, ...);
extern void dbgPrintfData(const void* _data, uint32_t _size, const char* _format, ...);
#ifndef BGFX_CONFIG_DEBUG
# define BGFX_CONFIG_DEBUG 0
#endif // BGFX_CONFIG_DEBUG
namespace bgfx
{
void fatal(Fatal::Enum _code, const char* _format, ...);
void dbgPrintf(const char* _format, ...);
}
#if BGFX_CONFIG_DEBUG
# define BX_TRACE(_format, ...) \
do { \
dbgPrintf(BX_FILE_LINE_LITERAL "BGFX " _format "\n", ##__VA_ARGS__); \
bgfx::dbgPrintf(BX_FILE_LINE_LITERAL "BGFX " _format "\n", ##__VA_ARGS__); \
} while(0)
# define BX_WARN(_condition, _format, ...) \
@ -40,7 +41,7 @@ extern void dbgPrintfData(const void* _data, uint32_t _size, const char* _format
if (!(_condition) ) \
{ \
BX_TRACE("CHECK " _format, ##__VA_ARGS__); \
bx::debugBreak(); \
bgfx::fatal(bgfx::Fatal::DebugCheck, _format, ##__VA_ARGS__); \
} \
} while(0)
#endif // 0
@ -65,6 +66,7 @@ extern void dbgPrintfData(const void* _data, uint32_t _size, const char* _format
#include <bx/ringbuffer.h>
#include <bx/uint32_t.h>
#include <bx/readerwriter.h>
#include <bx/string.h>
#include "dds.h"
@ -109,8 +111,6 @@ namespace stl {
# include <xtl.h>
#endif // BX_PLATFORM_*
#include "config.h"
#include <bx/cpu.h>
#include <bx/thread.h>
#include <bx/timer.h>
@ -196,7 +196,6 @@ namespace bgfx
extern ReallocFn g_realloc;
extern FreeFn g_free;
void fatal(Fatal::Enum _code, const char* _format, ...);
void release(const Memory* _mem);
void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, bool _grayscale = false, bool _yflip = false);
const char* getAttribName(Attrib::Enum _attr);
@ -323,7 +322,7 @@ namespace bgfx
{
char* temp = (char*)alloca(m_width);
uint32_t num = vsnprintf(temp, m_width, _format, _argList);
uint32_t num = bx::vsnprintf(temp, m_width, _format, _argList);
uint8_t* mem = &m_mem[(_y*m_width+_x)*2];
for (uint32_t ii = 0, xx = _x; ii < num && xx < m_width; ++ii, ++xx)
@ -986,7 +985,11 @@ namespace bgfx
if (0 < m_numDropped)
{
BX_TRACE("Too many draw calls: %d, dropped %d (max: %d)", m_num+m_numDropped, m_numDropped, BGFX_CONFIG_MAX_DRAW_CALLS);
BX_TRACE("Too many draw calls: %d, dropped %d (max: %d)"
, m_num+m_numDropped
, m_numDropped
, BGFX_CONFIG_MAX_DRAW_CALLS
);
}
}

Просмотреть файл

@ -6,6 +6,10 @@
#ifndef __CONFIG_H__
#define __CONFIG_H__
#ifndef BGFX_CONFIG_DEBUG
# define BGFX_CONFIG_DEBUG 0
#endif // BGFX_CONFIG_DEBUG
#if !defined(BGFX_CONFIG_RENDERER_DIRECT3D9) \
&& !defined(BGFX_CONFIG_RENDERER_DIRECT3D11) \
&& !defined(BGFX_CONFIG_RENDERER_OPENGL) \

Просмотреть файл

@ -4,14 +4,14 @@
*/
#include <string.h>
#include <bx/debug.h>
#include <bx/hash.h>
#include <bx/uint32_t.h>
#include <bx/countof.h>
#include <bx/string.h>
#include "vertexdecl.h"
extern void dbgPrintf(const char* _format, ...);
extern void dbgPrintfData(const void* _data, uint32_t _size, const char* _format, ...);
namespace bgfx
{
static const uint8_t s_attribTypeSizeDx9[AttribType::Count][4] =
@ -56,6 +56,28 @@ namespace bgfx
&s_attribTypeSizeGl,
};
void dbgPrintfVargs(const char* _format, va_list _argList)
{
char temp[8192];
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';
bx::debugOutput(out);
}
void dbgPrintf(const char* _format, ...)
{
va_list argList;
va_start(argList, _format);
dbgPrintfVargs(_format, argList);
va_end(argList);
}
void VertexDecl::begin(RendererType::Enum _renderer)
{
m_hash = _renderer; // use hash to store renderer type while building VertexDecl.