Skip to content

Commit

Permalink
expand video memory slot from 16bit to 32bit for unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Oct 2, 2017
1 parent 3f11ae5 commit 118316f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
18 changes: 10 additions & 8 deletions src/bgfx.cpp
Expand Up @@ -543,7 +543,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];
Expand All @@ -555,9 +555,9 @@ namespace bgfx
}
else
{
mem[0] = ch;
mem[1] = attr;
mem += 2;
mem->character = ch;
mem->attribute = attr;
++mem;
++xx;
}
}
Expand Down Expand Up @@ -678,12 +678,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) ) )
Expand Down Expand Up @@ -715,7 +717,7 @@ namespace bgfx
numIndices += 6;
}

line += 2;
line ++;
}

if (numIndices >= numBatchIndices)
Expand Down
41 changes: 27 additions & 14 deletions src/bgfx_p.h
Expand Up @@ -445,25 +445,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;
}
}
}

Expand All @@ -481,16 +482,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::uint32_min(m_width, _width +_x)-_x)*2;
const uint32_t width = bx::uint32_min(m_width, _width +_x)-_x;
const uint32_t height = bx::uint32_min(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 {
uint32_t attribute:8;
uint32_t character:24; // 24bit for dos (code page 437) and unicode (000000–​10FFFF)
};

struct MemSlot* m_mem;
uint32_t m_size;
uint16_t m_width;
uint16_t m_height;
Expand Down

0 comments on commit 118316f

Please sign in to comment.