Add struct MemSlot for future use, See #1249 (#1342)

This commit is contained in:
云风 2018-02-22 01:37:55 +08:00 committed by Branimir Karadžić
parent 1142735e9e
commit 5e78c10358
2 changed files with 37 additions and 22 deletions

View File

@ -561,7 +561,7 @@ namespace bgfx
num = bx::vsnprintf(temp, num, _format, argListCopy);
uint8_t attr = _attr;
uint8_t* mem = &m_mem[(_y*m_width+_x)*2];
struct MemSlot* mem = &m_mem[_y*m_width+_x];
for (uint32_t ii = 0, xx = _x; ii < num && xx < m_width; ++ii)
{
char ch = temp[ii];
@ -573,9 +573,9 @@ namespace bgfx
}
else
{
mem[0] = ch;
mem[1] = attr;
mem += 2;
mem->character = ch;
mem->attribute = attr;
++mem;
++xx;
}
}
@ -697,12 +697,14 @@ namespace bgfx
for (; yy < _mem.m_height && numIndices < numBatchIndices; ++yy)
{
xx = xx < _mem.m_width ? xx : 0;
const uint8_t* line = &_mem.m_mem[(yy*_mem.m_width+xx)*2];
const struct TextVideoMem::MemSlot* line = &_mem.m_mem[yy*_mem.m_width+xx];
for (; xx < _mem.m_width && numIndices < numBatchIndices; ++xx)
{
uint8_t ch = line[0];
uint8_t attr = line[1];
uint32_t ch = line->character;
uint8_t attr = line->attribute;
if (ch > 0xff)
ch = 0; // todo: render unicode code point , ch > 255)
if (0 != (ch|attr)
&& (' ' != ch || 0 != (attr&0xf0) ) )
@ -734,7 +736,7 @@ namespace bgfx
numIndices += 6;
}
line += 2;
line ++;
}
if (numIndices >= numBatchIndices)

View File

@ -493,25 +493,26 @@ namespace bgfx
m_height = (uint16_t)height;
uint32_t size = m_size;
m_size = m_width * m_height * 2;
m_size = m_width * m_height;
m_mem = (uint8_t*)BX_REALLOC(g_allocator, m_mem, m_size);
m_mem = (struct MemSlot*)BX_REALLOC(g_allocator, m_mem, m_size * sizeof(struct MemSlot));
if (size < m_size)
{
bx::memSet(&m_mem[size], 0, m_size-size);
bx::memSet(&m_mem[size], 0, (m_size-size) * sizeof(struct MemSlot));
}
}
}
void clear(uint8_t _attr = 0)
{
uint8_t* mem = m_mem;
for (uint32_t ii = 0, num = m_size/2; ii < num; ++ii)
{
mem[0] = 0;
mem[1] = _attr;
mem += 2;
struct MemSlot* mem = m_mem;
bx::memSet(mem, 0, m_size * sizeof(struct MemSlot));
if (_attr != 0) {
for (uint32_t ii = 0, num = m_size; ii < num; ++ii)
{
mem[ii].attribute = _attr;
}
}
}
@ -529,16 +530,28 @@ namespace bgfx
{
if (_x < m_width && _y < m_height)
{
uint8_t* dst = &m_mem[(_y*m_width+_x)*2];
struct MemSlot * dst = &m_mem[_y*m_width+_x];
const uint8_t* src = (const uint8_t*)_data;
const uint32_t width = (bx::min<uint32_t>(m_width, _width +_x)-_x)*2;
const uint32_t width = bx::min<uint32_t>(m_width, _width +_x)-_x;
const uint32_t height = bx::min<uint32_t>(m_height, _height+_y)-_y;
const uint32_t dstPitch = m_width*2;
bx::memCopy(dst, src, width, height, _pitch, dstPitch);
const uint32_t dstPitch = m_width;
for (uint32_t ii = 0; ii < height; ++ii) {
for (uint32_t jj = 0; jj < width; ++jj) {
dst[jj].character = src[jj*2];
dst[jj].attribute = src[jj*2+1];
}
src += _pitch;
dst += dstPitch;
}
}
}
uint8_t* m_mem;
struct MemSlot {
uint8_t attribute;
uint8_t character;
};
struct MemSlot* m_mem;
uint32_t m_size;
uint16_t m_width;
uint16_t m_height;