Added ANSI escape codes for debug text. Added info about backbuffer and debug text width/height.
This commit is contained in:
parent
88ba04a4c9
commit
0e933091ed
@ -65,6 +65,16 @@ class ExampleHelloWorld : public entry::AppI
|
||||
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/00-helloworld");
|
||||
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Initialization and debug text.");
|
||||
|
||||
bgfx::dbgTextPrintf(0, 4, 0x0f, "Color can be changed with ANSI \e[9;me\e[10;ms\e[11;mc\e[12;ma\e[13;mp\e[14;me\e[0m code too.");
|
||||
|
||||
const bgfx::Stats* stats = bgfx::getStats();
|
||||
bgfx::dbgTextPrintf(0, 6, 0x0f, "Backbuffer %dW x %dH in pixels, debug text %dW x %dH in characters."
|
||||
, stats->width
|
||||
, stats->height
|
||||
, stats->textWidth
|
||||
, stats->textHeight
|
||||
);
|
||||
|
||||
// Advance to next frame. Rendering thread will be kicked to
|
||||
// process submitted rendering primitives.
|
||||
bgfx::frame();
|
||||
|
@ -720,6 +720,11 @@ namespace bgfx
|
||||
int64_t waitRender; //!< Time spent waiting for render backend thread to finish issuing
|
||||
//! draw commands to underlying graphics API.
|
||||
int64_t waitSubmit; //!< Time spent waiting for submit thread to advance to next frame.
|
||||
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t textWidth;
|
||||
uint16_t textHeight;
|
||||
};
|
||||
|
||||
/// Vertex declaration.
|
||||
|
@ -6,7 +6,7 @@
|
||||
#ifndef BGFX_DEFINES_H_HEADER_GUARD
|
||||
#define BGFX_DEFINES_H_HEADER_GUARD
|
||||
|
||||
#define BGFX_API_VERSION UINT32_C(32)
|
||||
#define BGFX_API_VERSION UINT32_C(33)
|
||||
|
||||
///
|
||||
#define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write.
|
||||
|
@ -329,6 +329,12 @@ typedef struct bgfx_stats
|
||||
|
||||
int64_t waitRender;
|
||||
int64_t waitSubmit;
|
||||
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t textWidth;
|
||||
uint16_t textHeight;
|
||||
|
||||
} bgfx_stats_t;
|
||||
|
||||
/**/
|
||||
|
72
src/bgfx.cpp
72
src/bgfx.cpp
@ -529,6 +529,78 @@ namespace bgfx
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t parseAttrTo(char*& _ptr, char _to, uint8_t _default)
|
||||
{
|
||||
const char* str = strchr(_ptr, _to);
|
||||
if (NULL != str
|
||||
&& 3 > str-_ptr)
|
||||
{
|
||||
char tmp[4];
|
||||
uint32_t len = uint32_t(str-_ptr);
|
||||
|
||||
len = bx::uint32_min(BX_COUNTOF(tmp), len);
|
||||
strncpy(tmp, _ptr, len);
|
||||
tmp[len] = '\0';
|
||||
|
||||
uint8_t attr = uint8_t(atoi(tmp) );
|
||||
_ptr += len+1;
|
||||
return attr;
|
||||
}
|
||||
|
||||
return _default;
|
||||
}
|
||||
|
||||
static uint8_t parseAttr(char*& _ptr, uint8_t _default)
|
||||
{
|
||||
char* ptr = _ptr;
|
||||
if (*ptr++ != '[')
|
||||
{
|
||||
return _default;
|
||||
}
|
||||
|
||||
if (0 == strncmp(ptr, "0m", 2) )
|
||||
{
|
||||
_ptr = ptr + 2;
|
||||
return _default;
|
||||
}
|
||||
|
||||
uint8_t fg = parseAttrTo(ptr, ';', _default & 0xf);
|
||||
uint8_t bg = parseAttrTo(ptr, 'm', _default >> 4);
|
||||
|
||||
uint8_t attr = (bg<<4) | fg;
|
||||
_ptr = ptr;
|
||||
return attr;
|
||||
}
|
||||
|
||||
void TextVideoMem::printfVargs(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList)
|
||||
{
|
||||
if (_x < m_width && _y < m_height)
|
||||
{
|
||||
char* temp = (char*)alloca(m_width);
|
||||
|
||||
uint32_t num = bx::vsnprintf(temp, m_width, _format, _argList);
|
||||
|
||||
uint8_t attr = _attr;
|
||||
uint8_t* mem = &m_mem[(_y*m_width+_x)*2];
|
||||
for (uint32_t ii = 0, xx = _x; ii < num && xx < m_width; ++ii, ++xx)
|
||||
{
|
||||
char ch = temp[ii];
|
||||
if (BX_UNLIKELY(ch == '\e') )
|
||||
{
|
||||
char* ptr = &temp[ii+1];
|
||||
attr = parseAttr(ptr, _attr);
|
||||
ii += uint32_t(ptr - &temp[ii+1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
mem[0] = ch;
|
||||
mem[1] = attr;
|
||||
mem += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const uint32_t numCharsPerBatch = 1024;
|
||||
static const uint32_t numBatchVertices = numCharsPerBatch*4;
|
||||
static const uint32_t numBatchIndices = numCharsPerBatch*6;
|
||||
|
27
src/bgfx_p.h
27
src/bgfx_p.h
@ -433,23 +433,7 @@ namespace bgfx
|
||||
}
|
||||
}
|
||||
|
||||
void printfVargs(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList)
|
||||
{
|
||||
if (_x < m_width && _y < m_height)
|
||||
{
|
||||
char* temp = (char*)alloca(m_width);
|
||||
|
||||
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)
|
||||
{
|
||||
mem[0] = temp[ii];
|
||||
mem[1] = _attr;
|
||||
mem += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
void printfVargs(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList);
|
||||
|
||||
void printf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...)
|
||||
{
|
||||
@ -2288,7 +2272,14 @@ namespace bgfx
|
||||
|
||||
BGFX_API_FUNC(const Stats* getPerfStats() )
|
||||
{
|
||||
return &m_submit->m_perfStats;
|
||||
Stats& stats = m_submit->m_perfStats;
|
||||
const Resolution& resolution = m_submit->m_resolution;
|
||||
stats.width = uint16_t(resolution.m_width);
|
||||
stats.height = uint16_t(resolution.m_height);
|
||||
const TextVideoMem* tvm = m_submit->m_textVideoMem;
|
||||
stats.textWidth = tvm->m_width;
|
||||
stats.textHeight = tvm->m_height;
|
||||
return &stats;
|
||||
}
|
||||
|
||||
BGFX_API_FUNC(IndexBufferHandle createIndexBuffer(const Memory* _mem, uint16_t _flags) )
|
||||
|
Loading…
x
Reference in New Issue
Block a user