mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
remove m_ from POD struct + clean 3rdparty include
This commit is contained in:
parent
925e0eb371
commit
cf895eb5ba
4 changed files with 223 additions and 223 deletions
|
@ -10,15 +10,15 @@
|
|||
# pragma warning(disable: 4146) // DISABLE warning C4146: unary minus operator applied to unsigned type, result still unsigned
|
||||
# pragma warning(disable: 4700) // DISABLE warning C4700: uninitialized local variable 'temp' used
|
||||
# pragma warning(disable: 4701) // DISABLE warning C4701: potentially uninitialized local variable '' used
|
||||
# include "../../../3rdparty/freetype/freetype.h"
|
||||
# include <freetype/freetype.h>
|
||||
# pragma warning(pop)
|
||||
#else
|
||||
# include "../../../3rdparty/freetype/freetype.h"
|
||||
# include <freetype/freetype.h>
|
||||
#endif // BX_COMPILER_MSVC
|
||||
|
||||
|
||||
#include "../../../3rdparty/edtaa3/edtaa3func.h"
|
||||
#include "../../../3rdparty/edtaa3/edtaa3func.cpp"
|
||||
#include <edtaa3/edtaa3func.h>
|
||||
#include <edtaa3/edtaa3func.cpp>
|
||||
#include <math.h>
|
||||
#include <bx/bx.h>
|
||||
|
||||
|
@ -80,8 +80,8 @@ private:
|
|||
|
||||
struct FTHolder
|
||||
{
|
||||
FT_Library m_library;
|
||||
FT_Face m_face;
|
||||
FT_Library library;
|
||||
FT_Face face;
|
||||
};
|
||||
FontManager::TrueTypeFont::TrueTypeFont(): m_font(NULL)
|
||||
{
|
||||
|
@ -92,8 +92,8 @@ FontManager::TrueTypeFont::~TrueTypeFont()
|
|||
if(m_font!=NULL)
|
||||
{
|
||||
FTHolder* holder = (FTHolder*) m_font;
|
||||
FT_Done_Face( holder->m_face );
|
||||
FT_Done_FreeType( holder->m_library );
|
||||
FT_Done_Face( holder->face );
|
||||
FT_Done_FreeType( holder->library );
|
||||
delete m_font;
|
||||
m_font = NULL;
|
||||
}
|
||||
|
@ -109,19 +109,19 @@ bool FontManager::TrueTypeFont::init(const uint8_t* _buffer, uint32_t _bufferSiz
|
|||
FTHolder* holder = new FTHolder();
|
||||
|
||||
// Initialize Freetype library
|
||||
FT_Error error = FT_Init_FreeType( &holder->m_library );
|
||||
FT_Error error = FT_Init_FreeType( &holder->library );
|
||||
if( error)
|
||||
{
|
||||
delete holder;
|
||||
return false;
|
||||
}
|
||||
|
||||
error = FT_New_Memory_Face( holder->m_library, _buffer, _bufferSize, _fontIndex, &holder->m_face );
|
||||
error = FT_New_Memory_Face( holder->library, _buffer, _bufferSize, _fontIndex, &holder->face );
|
||||
if ( error == FT_Err_Unknown_File_Format )
|
||||
{
|
||||
// the font file could be opened and read, but it appears
|
||||
//that its font format is unsupported
|
||||
FT_Done_FreeType( holder->m_library );
|
||||
FT_Done_FreeType( holder->library );
|
||||
delete holder;
|
||||
return false;
|
||||
}
|
||||
|
@ -129,25 +129,25 @@ bool FontManager::TrueTypeFont::init(const uint8_t* _buffer, uint32_t _bufferSiz
|
|||
{
|
||||
// another error code means that the font file could not
|
||||
// be opened or read, or simply that it is broken...
|
||||
FT_Done_FreeType( holder->m_library );
|
||||
FT_Done_FreeType( holder->library );
|
||||
delete holder;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select unicode charmap
|
||||
error = FT_Select_Charmap( holder->m_face, FT_ENCODING_UNICODE );
|
||||
error = FT_Select_Charmap( holder->face, FT_ENCODING_UNICODE );
|
||||
if( error )
|
||||
{
|
||||
FT_Done_Face( holder->m_face );
|
||||
FT_Done_FreeType( holder->m_library );
|
||||
FT_Done_Face( holder->face );
|
||||
FT_Done_FreeType( holder->library );
|
||||
return false;
|
||||
}
|
||||
//set size in pixels
|
||||
error = FT_Set_Pixel_Sizes( holder->m_face, 0, _pixelHeight );
|
||||
error = FT_Set_Pixel_Sizes( holder->face, 0, _pixelHeight );
|
||||
if( error )
|
||||
{
|
||||
FT_Done_Face( holder->m_face );
|
||||
FT_Done_FreeType( holder->m_library );
|
||||
FT_Done_Face( holder->face );
|
||||
FT_Done_FreeType( holder->library );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -161,19 +161,19 @@ FontInfo FontManager::TrueTypeFont::getFontInfo()
|
|||
FTHolder* holder = (FTHolder*) m_font;
|
||||
|
||||
//todo manage unscalable font
|
||||
BX_CHECK(FT_IS_SCALABLE (holder->m_face), "Font is unscalable");
|
||||
BX_CHECK(FT_IS_SCALABLE (holder->face), "Font is unscalable");
|
||||
|
||||
FT_Size_Metrics metrics = holder->m_face->size->metrics;
|
||||
FT_Size_Metrics metrics = holder->face->size->metrics;
|
||||
|
||||
|
||||
FontInfo outFontInfo;
|
||||
outFontInfo.m_scale = 1.0f;
|
||||
outFontInfo.m_ascender = metrics.ascender /64.0f;
|
||||
outFontInfo.m_descender = metrics.descender /64.0f;
|
||||
outFontInfo.m_lineGap = (metrics.height - metrics.ascender + metrics.descender) /64.0f;
|
||||
outFontInfo.scale = 1.0f;
|
||||
outFontInfo.ascender = metrics.ascender /64.0f;
|
||||
outFontInfo.descender = metrics.descender /64.0f;
|
||||
outFontInfo.lineGap = (metrics.height - metrics.ascender + metrics.descender) /64.0f;
|
||||
|
||||
outFontInfo.m_underline_position = FT_MulFix(holder->m_face->underline_position, metrics.y_scale) /64.0f;
|
||||
outFontInfo.m_underline_thickness= FT_MulFix(holder->m_face->underline_thickness,metrics.y_scale) /64.0f;
|
||||
outFontInfo.underline_position = FT_MulFix(holder->face->underline_position, metrics.y_scale) /64.0f;
|
||||
outFontInfo.underline_thickness= FT_MulFix(holder->face->underline_thickness,metrics.y_scale) /64.0f;
|
||||
return outFontInfo;
|
||||
}
|
||||
|
||||
|
@ -182,10 +182,10 @@ bool FontManager::TrueTypeFont::bakeGlyphAlpha(CodePoint_t _codePoint, GlyphInfo
|
|||
BX_CHECK(m_font != NULL, "TrueTypeFont not initialized" );
|
||||
FTHolder* holder = (FTHolder*) m_font;
|
||||
|
||||
_glyphInfo.m_glyphIndex = FT_Get_Char_Index( holder->m_face, _codePoint );
|
||||
_glyphInfo.glyphIndex = FT_Get_Char_Index( holder->face, _codePoint );
|
||||
|
||||
FT_GlyphSlot slot = holder->m_face->glyph;
|
||||
FT_Error error = FT_Load_Glyph( holder->m_face, _glyphInfo.m_glyphIndex, FT_LOAD_DEFAULT );
|
||||
FT_GlyphSlot slot = holder->face->glyph;
|
||||
FT_Error error = FT_Load_Glyph( holder->face, _glyphInfo.glyphIndex, FT_LOAD_DEFAULT );
|
||||
if(error) { return false; }
|
||||
|
||||
FT_Glyph glyph;
|
||||
|
@ -202,12 +202,12 @@ bool FontManager::TrueTypeFont::bakeGlyphAlpha(CodePoint_t _codePoint, GlyphInfo
|
|||
int32_t w = bitmap->bitmap.width;
|
||||
int32_t h = bitmap->bitmap.rows;
|
||||
|
||||
_glyphInfo.m_offset_x = (float) x;
|
||||
_glyphInfo.m_offset_y = (float) y;
|
||||
_glyphInfo.m_width = (float) w;
|
||||
_glyphInfo.m_height = (float) h;
|
||||
_glyphInfo.m_advance_x = (float)slot->advance.x /64.0f;
|
||||
_glyphInfo.m_advance_y = (float)slot->advance.y /64.0f;
|
||||
_glyphInfo.offset_x = (float) x;
|
||||
_glyphInfo.offset_y = (float) y;
|
||||
_glyphInfo.width = (float) w;
|
||||
_glyphInfo.height = (float) h;
|
||||
_glyphInfo.advance_x = (float)slot->advance.x /64.0f;
|
||||
_glyphInfo.advance_y = (float)slot->advance.y /64.0f;
|
||||
|
||||
int32_t charsize = 1;
|
||||
int32_t depth=1;
|
||||
|
@ -226,10 +226,10 @@ bool FontManager::TrueTypeFont::bakeGlyphSubpixel(CodePoint_t _codePoint, GlyphI
|
|||
BX_CHECK(m_font != NULL, "TrueTypeFont not initialized" );
|
||||
FTHolder* holder = (FTHolder*) m_font;
|
||||
|
||||
_glyphInfo.m_glyphIndex = FT_Get_Char_Index( holder->m_face, _codePoint );
|
||||
_glyphInfo.glyphIndex = FT_Get_Char_Index( holder->face, _codePoint );
|
||||
|
||||
FT_GlyphSlot slot = holder->m_face->glyph;
|
||||
FT_Error error = FT_Load_Glyph( holder->m_face, _glyphInfo.m_glyphIndex, FT_LOAD_DEFAULT );
|
||||
FT_GlyphSlot slot = holder->face->glyph;
|
||||
FT_Error error = FT_Load_Glyph( holder->face, _glyphInfo.glyphIndex, FT_LOAD_DEFAULT );
|
||||
if(error) { return false; }
|
||||
|
||||
FT_Glyph glyph;
|
||||
|
@ -245,12 +245,12 @@ bool FontManager::TrueTypeFont::bakeGlyphSubpixel(CodePoint_t _codePoint, GlyphI
|
|||
int32_t w = bitmap->bitmap.width;
|
||||
int32_t h = bitmap->bitmap.rows;
|
||||
|
||||
_glyphInfo.m_offset_x = (float) x;
|
||||
_glyphInfo.m_offset_y = (float) y;
|
||||
_glyphInfo.m_width = (float) w;
|
||||
_glyphInfo.m_height = (float) h;
|
||||
_glyphInfo.m_advance_x = (float)slot->advance.x /64.0f;
|
||||
_glyphInfo.m_advance_y = (float)slot->advance.y /64.0f;
|
||||
_glyphInfo.offset_x = (float) x;
|
||||
_glyphInfo.offset_y = (float) y;
|
||||
_glyphInfo.width = (float) w;
|
||||
_glyphInfo.height = (float) h;
|
||||
_glyphInfo.advance_x = (float)slot->advance.x /64.0f;
|
||||
_glyphInfo.advance_y = (float)slot->advance.y /64.0f;
|
||||
int32_t charsize = 1;
|
||||
int32_t depth=3;
|
||||
int32_t stride = bitmap->bitmap.pitch;
|
||||
|
@ -346,13 +346,13 @@ bool FontManager::TrueTypeFont::bakeGlyphDistance(CodePoint_t _codePoint, GlyphI
|
|||
BX_CHECK(m_font != NULL, "TrueTypeFont not initialized" );
|
||||
FTHolder* holder = (FTHolder*) m_font;
|
||||
|
||||
_glyphInfo.m_glyphIndex = FT_Get_Char_Index( holder->m_face, _codePoint );
|
||||
_glyphInfo.glyphIndex = FT_Get_Char_Index( holder->face, _codePoint );
|
||||
|
||||
FT_Int32 loadMode = FT_LOAD_DEFAULT|FT_LOAD_NO_HINTING;
|
||||
FT_Render_Mode renderMode = FT_RENDER_MODE_NORMAL;
|
||||
|
||||
FT_GlyphSlot slot = holder->m_face->glyph;
|
||||
FT_Error error = FT_Load_Glyph( holder->m_face, _glyphInfo.m_glyphIndex, loadMode );
|
||||
FT_GlyphSlot slot = holder->face->glyph;
|
||||
FT_Error error = FT_Load_Glyph( holder->face, _glyphInfo.glyphIndex, loadMode );
|
||||
if(error) { return false; }
|
||||
|
||||
FT_Glyph glyph;
|
||||
|
@ -369,12 +369,12 @@ bool FontManager::TrueTypeFont::bakeGlyphDistance(CodePoint_t _codePoint, GlyphI
|
|||
int32_t w = bitmap->bitmap.width;
|
||||
int32_t h = bitmap->bitmap.rows;
|
||||
|
||||
_glyphInfo.m_offset_x = (float) x;
|
||||
_glyphInfo.m_offset_y = (float) y;
|
||||
_glyphInfo.m_width = (float) w;
|
||||
_glyphInfo.m_height = (float) h;
|
||||
_glyphInfo.m_advance_x = (float)slot->advance.x /64.0f;
|
||||
_glyphInfo.m_advance_y = (float)slot->advance.y /64.0f;
|
||||
_glyphInfo.offset_x = (float) x;
|
||||
_glyphInfo.offset_y = (float) y;
|
||||
_glyphInfo.width = (float) w;
|
||||
_glyphInfo.height = (float) h;
|
||||
_glyphInfo.advance_x = (float)slot->advance.x /64.0f;
|
||||
_glyphInfo.advance_y = (float)slot->advance.y /64.0f;
|
||||
|
||||
int32_t charsize = 1;
|
||||
int32_t depth=1;
|
||||
|
@ -412,10 +412,10 @@ bool FontManager::TrueTypeFont::bakeGlyphDistance(CodePoint_t _codePoint, GlyphI
|
|||
make_distance_map(alphaImg, _outBuffer, nw, nh);
|
||||
free(alphaImg);
|
||||
|
||||
_glyphInfo.m_offset_x -= (float) dw;
|
||||
_glyphInfo.m_offset_y -= (float) dh;
|
||||
_glyphInfo.m_width = (float) nw ;
|
||||
_glyphInfo.m_height = (float) nh;
|
||||
_glyphInfo.offset_x -= (float) dw;
|
||||
_glyphInfo.offset_y -= (float) dh;
|
||||
_glyphInfo.width = (float) nw ;
|
||||
_glyphInfo.height = (float) nh;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -429,13 +429,13 @@ typedef stl::unordered_map<CodePoint_t, GlyphInfo> GlyphHash_t;
|
|||
// cache font data
|
||||
struct FontManager::CachedFont
|
||||
{
|
||||
CachedFont(){ m_trueTypeFont = NULL; m_masterFontHandle.idx = -1; }
|
||||
FontInfo m_fontInfo;
|
||||
GlyphHash_t m_cachedGlyphs;
|
||||
FontManager::TrueTypeFont* m_trueTypeFont;
|
||||
CachedFont(){ trueTypeFont = NULL; masterFontHandle.idx = -1; }
|
||||
FontInfo fontInfo;
|
||||
GlyphHash_t cachedGlyphs;
|
||||
FontManager::TrueTypeFont* trueTypeFont;
|
||||
// an handle to a master font in case of sub distance field font
|
||||
FontHandle m_masterFontHandle;
|
||||
int16_t m_padding;
|
||||
FontHandle masterFontHandle;
|
||||
int16_t padding;
|
||||
};
|
||||
|
||||
|
||||
|
@ -470,11 +470,11 @@ void FontManager::init()
|
|||
uint8_t buffer[W*W*4];
|
||||
memset( buffer, 255, W * W * 4);
|
||||
|
||||
m_blackGlyph.m_width = W;
|
||||
m_blackGlyph.m_height = W;
|
||||
m_blackGlyph.width = W;
|
||||
m_blackGlyph.height = W;
|
||||
|
||||
///make sure the black glyph doesn't bleed by using a one pixel inner outline
|
||||
m_blackGlyph.m_regionIndex = m_atlas->addRegion(W, W, buffer, AtlasRegion::TYPE_GRAY, 1 );
|
||||
m_blackGlyph.regionIndex = m_atlas->addRegion(W, W, buffer, AtlasRegion::TYPE_GRAY, 1 );
|
||||
}
|
||||
|
||||
FontManager::~FontManager()
|
||||
|
@ -582,12 +582,12 @@ FontHandle FontManager::createFontByPixelSize(TrueTypeHandle _tt_handle, uint32_
|
|||
uint16_t fontIdx = m_fontHandles.alloc();
|
||||
BX_CHECK(fontIdx != bx::HandleAlloc::invalid, "Invalid handle used");
|
||||
|
||||
m_cachedFonts[fontIdx].m_trueTypeFont = ttf;
|
||||
m_cachedFonts[fontIdx].m_fontInfo = ttf->getFontInfo();
|
||||
m_cachedFonts[fontIdx].m_fontInfo.m_fontType = _fontType;
|
||||
m_cachedFonts[fontIdx].m_fontInfo.m_pixelSize = _pixelSize;
|
||||
m_cachedFonts[fontIdx].m_cachedGlyphs.clear();
|
||||
m_cachedFonts[fontIdx].m_masterFontHandle.idx = -1;
|
||||
m_cachedFonts[fontIdx].trueTypeFont = ttf;
|
||||
m_cachedFonts[fontIdx].fontInfo = ttf->getFontInfo();
|
||||
m_cachedFonts[fontIdx].fontInfo.fontType = _fontType;
|
||||
m_cachedFonts[fontIdx].fontInfo.pixelSize = _pixelSize;
|
||||
m_cachedFonts[fontIdx].cachedGlyphs.clear();
|
||||
m_cachedFonts[fontIdx].masterFontHandle.idx = -1;
|
||||
FontHandle ret = {fontIdx};
|
||||
return ret;
|
||||
}
|
||||
|
@ -596,24 +596,24 @@ FontHandle FontManager::createScaledFontToPixelSize(FontHandle _baseFontHandle,
|
|||
{
|
||||
BX_CHECK(bgfx::invalidHandle != _baseFontHandle.idx, "Invalid handle used");
|
||||
CachedFont& font = m_cachedFonts[_baseFontHandle.idx];
|
||||
FontInfo& fontInfo = font.m_fontInfo;
|
||||
FontInfo& fontInfo = font.fontInfo;
|
||||
|
||||
FontInfo newFontInfo = fontInfo;
|
||||
newFontInfo.m_pixelSize = _pixelSize;
|
||||
newFontInfo.m_scale = (float)_pixelSize / (float) fontInfo.m_pixelSize;
|
||||
newFontInfo.m_ascender = (newFontInfo.m_ascender * newFontInfo.m_scale);
|
||||
newFontInfo.m_descender = (newFontInfo.m_descender * newFontInfo.m_scale);
|
||||
newFontInfo.m_lineGap = (newFontInfo.m_lineGap * newFontInfo.m_scale);
|
||||
newFontInfo.m_underline_thickness = (newFontInfo.m_underline_thickness * newFontInfo.m_scale);
|
||||
newFontInfo.m_underline_position = (newFontInfo.m_underline_position * newFontInfo.m_scale);
|
||||
newFontInfo.pixelSize = _pixelSize;
|
||||
newFontInfo.scale = (float)_pixelSize / (float) fontInfo.pixelSize;
|
||||
newFontInfo.ascender = (newFontInfo.ascender * newFontInfo.scale);
|
||||
newFontInfo.descender = (newFontInfo.descender * newFontInfo.scale);
|
||||
newFontInfo.lineGap = (newFontInfo.lineGap * newFontInfo.scale);
|
||||
newFontInfo.underline_thickness = (newFontInfo.underline_thickness * newFontInfo.scale);
|
||||
newFontInfo.underline_position = (newFontInfo.underline_position * newFontInfo.scale);
|
||||
|
||||
|
||||
uint16_t fontIdx = m_fontHandles.alloc();
|
||||
BX_CHECK(fontIdx != bx::HandleAlloc::invalid, "Invalid handle used");
|
||||
m_cachedFonts[fontIdx].m_cachedGlyphs.clear();
|
||||
m_cachedFonts[fontIdx].m_fontInfo = newFontInfo;
|
||||
m_cachedFonts[fontIdx].m_trueTypeFont = NULL;
|
||||
m_cachedFonts[fontIdx].m_masterFontHandle = _baseFontHandle;
|
||||
m_cachedFonts[fontIdx].cachedGlyphs.clear();
|
||||
m_cachedFonts[fontIdx].fontInfo = newFontInfo;
|
||||
m_cachedFonts[fontIdx].trueTypeFont = NULL;
|
||||
m_cachedFonts[fontIdx].masterFontHandle = _baseFontHandle;
|
||||
FontHandle ret = {fontIdx};
|
||||
return ret;
|
||||
}
|
||||
|
@ -636,12 +636,12 @@ void FontManager::destroyFont(FontHandle _handle)
|
|||
{
|
||||
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
|
||||
if(m_cachedFonts[_handle.idx].m_trueTypeFont != NULL)
|
||||
if(m_cachedFonts[_handle.idx].trueTypeFont != NULL)
|
||||
{
|
||||
delete m_cachedFonts[_handle.idx].m_trueTypeFont;
|
||||
m_cachedFonts[_handle.idx].m_trueTypeFont = NULL;
|
||||
delete m_cachedFonts[_handle.idx].trueTypeFont;
|
||||
m_cachedFonts[_handle.idx].trueTypeFont = NULL;
|
||||
}
|
||||
m_cachedFonts[_handle.idx].m_cachedGlyphs.clear();
|
||||
m_cachedFonts[_handle.idx].cachedGlyphs.clear();
|
||||
m_fontHandles.free(_handle.idx);
|
||||
}
|
||||
|
||||
|
@ -651,7 +651,7 @@ bool FontManager::preloadGlyph(FontHandle _handle, const wchar_t* _string)
|
|||
CachedFont& font = m_cachedFonts[_handle.idx];
|
||||
|
||||
//if truetype present
|
||||
if(font.m_trueTypeFont != NULL)
|
||||
if(font.trueTypeFont != NULL)
|
||||
{
|
||||
//parse string
|
||||
for( uint32_t ii=0, end = wcslen(_string) ; ii < end; ++ii )
|
||||
|
@ -673,33 +673,33 @@ bool FontManager::preloadGlyph(FontHandle _handle, CodePoint_t _codePoint)
|
|||
{
|
||||
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
CachedFont& font = m_cachedFonts[_handle.idx];
|
||||
FontInfo& fontInfo = font.m_fontInfo;
|
||||
FontInfo& fontInfo = font.fontInfo;
|
||||
//check if glyph not already present
|
||||
GlyphHash_t::iterator iter = font.m_cachedGlyphs.find(_codePoint);
|
||||
if(iter != font.m_cachedGlyphs.end())
|
||||
GlyphHash_t::iterator iter = font.cachedGlyphs.find(_codePoint);
|
||||
if(iter != font.cachedGlyphs.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//if truetype present
|
||||
if(font.m_trueTypeFont != NULL)
|
||||
if(font.trueTypeFont != NULL)
|
||||
{
|
||||
GlyphInfo glyphInfo;
|
||||
|
||||
//bake glyph as bitmap to buffer
|
||||
switch(font.m_fontInfo.m_fontType)
|
||||
switch(font.fontInfo.fontType)
|
||||
{
|
||||
case FONT_TYPE_ALPHA:
|
||||
font.m_trueTypeFont->bakeGlyphAlpha(_codePoint, glyphInfo, m_buffer);
|
||||
font.trueTypeFont->bakeGlyphAlpha(_codePoint, glyphInfo, m_buffer);
|
||||
break;
|
||||
//case FONT_TYPE_LCD:
|
||||
//font.m_trueTypeFont->bakeGlyphSubpixel(codePoint, glyphInfo, m_buffer);
|
||||
//break;
|
||||
case FONT_TYPE_DISTANCE:
|
||||
font.m_trueTypeFont->bakeGlyphDistance(_codePoint, glyphInfo, m_buffer);
|
||||
font.trueTypeFont->bakeGlyphDistance(_codePoint, glyphInfo, m_buffer);
|
||||
break;
|
||||
case FONT_TYPE_DISTANCE_SUBPIXEL:
|
||||
font.m_trueTypeFont->bakeGlyphDistance(_codePoint, glyphInfo, m_buffer);
|
||||
font.trueTypeFont->bakeGlyphDistance(_codePoint, glyphInfo, m_buffer);
|
||||
break;
|
||||
default:
|
||||
BX_CHECK(false, "TextureType not supported yet");
|
||||
|
@ -711,35 +711,35 @@ bool FontManager::preloadGlyph(FontHandle _handle, CodePoint_t _codePoint)
|
|||
return false;
|
||||
}
|
||||
|
||||
glyphInfo.m_advance_x = (glyphInfo.m_advance_x * fontInfo.m_scale);
|
||||
glyphInfo.m_advance_y = (glyphInfo.m_advance_y * fontInfo.m_scale);
|
||||
glyphInfo.m_offset_x = (glyphInfo.m_offset_x * fontInfo.m_scale);
|
||||
glyphInfo.m_offset_y = (glyphInfo.m_offset_y * fontInfo.m_scale);
|
||||
glyphInfo.m_height = (glyphInfo.m_height * fontInfo.m_scale);
|
||||
glyphInfo.m_width = (glyphInfo.m_width * fontInfo.m_scale);
|
||||
glyphInfo.advance_x = (glyphInfo.advance_x * fontInfo.scale);
|
||||
glyphInfo.advance_y = (glyphInfo.advance_y * fontInfo.scale);
|
||||
glyphInfo.offset_x = (glyphInfo.offset_x * fontInfo.scale);
|
||||
glyphInfo.offset_y = (glyphInfo.offset_y * fontInfo.scale);
|
||||
glyphInfo.height = (glyphInfo.height * fontInfo.scale);
|
||||
glyphInfo.width = (glyphInfo.width * fontInfo.scale);
|
||||
|
||||
// store cached glyph
|
||||
font.m_cachedGlyphs[_codePoint] = glyphInfo;
|
||||
font.cachedGlyphs[_codePoint] = glyphInfo;
|
||||
return true;
|
||||
}else
|
||||
{
|
||||
//retrieve glyph from parent font if any
|
||||
if(font.m_masterFontHandle.idx != bgfx::invalidHandle)
|
||||
if(font.masterFontHandle.idx != bgfx::invalidHandle)
|
||||
{
|
||||
if(preloadGlyph(font.m_masterFontHandle, _codePoint))
|
||||
if(preloadGlyph(font.masterFontHandle, _codePoint))
|
||||
{
|
||||
GlyphInfo glyphInfo;
|
||||
getGlyphInfo(font.m_masterFontHandle, _codePoint, glyphInfo);
|
||||
getGlyphInfo(font.masterFontHandle, _codePoint, glyphInfo);
|
||||
|
||||
glyphInfo.m_advance_x = (glyphInfo.m_advance_x * fontInfo.m_scale);
|
||||
glyphInfo.m_advance_y = (glyphInfo.m_advance_y * fontInfo.m_scale);
|
||||
glyphInfo.m_offset_x = (glyphInfo.m_offset_x * fontInfo.m_scale);
|
||||
glyphInfo.m_offset_y = (glyphInfo.m_offset_y * fontInfo.m_scale);
|
||||
glyphInfo.m_height = (glyphInfo.m_height * fontInfo.m_scale);
|
||||
glyphInfo.m_width = (glyphInfo.m_width * fontInfo.m_scale);
|
||||
glyphInfo.advance_x = (glyphInfo.advance_x * fontInfo.scale);
|
||||
glyphInfo.advance_y = (glyphInfo.advance_y * fontInfo.scale);
|
||||
glyphInfo.offset_x = (glyphInfo.offset_x * fontInfo.scale);
|
||||
glyphInfo.offset_y = (glyphInfo.offset_y * fontInfo.scale);
|
||||
glyphInfo.height = (glyphInfo.height * fontInfo.scale);
|
||||
glyphInfo.width = (glyphInfo.width * fontInfo.scale);
|
||||
|
||||
// store cached glyph
|
||||
font.m_cachedGlyphs[_codePoint] = glyphInfo;
|
||||
font.cachedGlyphs[_codePoint] = glyphInfo;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -751,17 +751,17 @@ bool FontManager::preloadGlyph(FontHandle _handle, CodePoint_t _codePoint)
|
|||
const FontInfo& FontManager::getFontInfo(FontHandle _handle)
|
||||
{
|
||||
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
return m_cachedFonts[_handle.idx].m_fontInfo;
|
||||
return m_cachedFonts[_handle.idx].fontInfo;
|
||||
}
|
||||
|
||||
bool FontManager::getGlyphInfo(FontHandle _handle, CodePoint_t _codePoint, GlyphInfo& _outInfo)
|
||||
{
|
||||
GlyphHash_t::iterator iter = m_cachedFonts[_handle.idx].m_cachedGlyphs.find(_codePoint);
|
||||
if(iter == m_cachedFonts[_handle.idx].m_cachedGlyphs.end())
|
||||
GlyphHash_t::iterator iter = m_cachedFonts[_handle.idx].cachedGlyphs.find(_codePoint);
|
||||
if(iter == m_cachedFonts[_handle.idx].cachedGlyphs.end())
|
||||
{
|
||||
if(preloadGlyph(_handle, _codePoint))
|
||||
{
|
||||
iter = m_cachedFonts[_handle.idx].m_cachedGlyphs.find(_codePoint);
|
||||
iter = m_cachedFonts[_handle.idx].cachedGlyphs.find(_codePoint);
|
||||
}else
|
||||
{
|
||||
return false;
|
||||
|
@ -776,6 +776,6 @@ bool FontManager::getGlyphInfo(FontHandle _handle, CodePoint_t _codePoint, Glyph
|
|||
|
||||
bool FontManager::addBitmap(GlyphInfo& _glyphInfo, const uint8_t* _data)
|
||||
{
|
||||
_glyphInfo.m_regionIndex = m_atlas->addRegion((uint16_t) ceil(_glyphInfo.m_width),(uint16_t) ceil(_glyphInfo.m_height), _data, AtlasRegion::TYPE_GRAY);
|
||||
_glyphInfo.regionIndex = m_atlas->addRegion((uint16_t) ceil(_glyphInfo.width),(uint16_t) ceil(_glyphInfo.height), _data, AtlasRegion::TYPE_GRAY);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -18,23 +18,23 @@ enum FontType
|
|||
struct FontInfo
|
||||
{
|
||||
//the font height in pixel
|
||||
uint16_t m_pixelSize;
|
||||
uint16_t pixelSize;
|
||||
/// Rendering type used for the font
|
||||
int16_t m_fontType;
|
||||
int16_t fontType;
|
||||
|
||||
/// The pixel extents above the baseline in pixels (typically positive)
|
||||
float m_ascender;
|
||||
float ascender;
|
||||
/// The extents below the baseline in pixels (typically negative)
|
||||
float m_descender;
|
||||
float descender;
|
||||
/// The spacing in pixels between one row's descent and the next row's ascent
|
||||
float m_lineGap;
|
||||
float lineGap;
|
||||
/// The thickness of the under/hover/striketrough line in pixels
|
||||
float m_underline_thickness;
|
||||
float underline_thickness;
|
||||
/// The position of the underline relatively to the baseline
|
||||
float m_underline_position;
|
||||
float underline_position;
|
||||
|
||||
//scale to apply to glyph data
|
||||
float m_scale;
|
||||
float scale;
|
||||
};
|
||||
|
||||
// Glyph metrics:
|
||||
|
@ -75,34 +75,34 @@ typedef int32_t CodePoint_t;
|
|||
struct GlyphInfo
|
||||
{
|
||||
/// Index for faster retrieval
|
||||
int32_t m_glyphIndex;
|
||||
int32_t glyphIndex;
|
||||
|
||||
/// Glyph's width in pixels.
|
||||
float m_width;
|
||||
float width;
|
||||
|
||||
/// Glyph's height in pixels.
|
||||
float m_height;
|
||||
float height;
|
||||
|
||||
/// Glyph's left offset in pixels
|
||||
float m_offset_x;
|
||||
float offset_x;
|
||||
|
||||
/// Glyph's top offset in pixels
|
||||
/// Remember that this is the distance from the baseline to the top-most
|
||||
/// glyph scan line, upwards y coordinates being positive.
|
||||
float m_offset_y;
|
||||
float offset_y;
|
||||
|
||||
/// For horizontal text layouts, this is the unscaled horizontal distance in pixels
|
||||
/// used to increment the pen position when the glyph is drawn as part of a string of text.
|
||||
float m_advance_x;
|
||||
float advance_x;
|
||||
|
||||
/// For vertical text layouts, this is the unscaled vertical distance in pixels
|
||||
/// used to increment the pen position when the glyph is drawn as part of a string of text.
|
||||
float m_advance_y;
|
||||
float advance_y;
|
||||
|
||||
/// region index in the atlas storing textures
|
||||
uint16_t m_regionIndex;
|
||||
uint16_t regionIndex;
|
||||
///32 bits alignment
|
||||
int16_t m_padding;
|
||||
int16_t padding;
|
||||
};
|
||||
|
||||
BGFX_HANDLE(TrueTypeHandle);
|
||||
|
|
|
@ -321,17 +321,17 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons
|
|||
return;
|
||||
}
|
||||
|
||||
if( _font.m_ascender > m_lineAscender || (_font.m_descender < m_lineDescender) )
|
||||
if( _font.ascender > m_lineAscender || (_font.descender < m_lineDescender) )
|
||||
{
|
||||
if( _font.m_descender < m_lineDescender )
|
||||
if( _font.descender < m_lineDescender )
|
||||
{
|
||||
m_lineDescender = _font.m_descender;
|
||||
m_lineGap = _font.m_lineGap;
|
||||
m_lineDescender = _font.descender;
|
||||
m_lineGap = _font.lineGap;
|
||||
}
|
||||
|
||||
float txtDecals = (_font.m_ascender - m_lineAscender);
|
||||
m_lineAscender = _font.m_ascender;
|
||||
m_lineGap = _font.m_lineGap;
|
||||
float txtDecals = (_font.ascender - m_lineAscender);
|
||||
m_lineAscender = _font.ascender;
|
||||
m_lineGap = _font.lineGap;
|
||||
|
||||
m_penY += txtDecals;
|
||||
verticalCenterLastLine((txtDecals), (m_penY - m_lineAscender), (m_penY - m_lineDescender+m_lineGap));
|
||||
|
@ -345,7 +345,7 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons
|
|||
kerning = texture_glyph_get_kerning( glyph, previous );
|
||||
}
|
||||
*/
|
||||
m_penX += kerning * _font.m_scale;
|
||||
m_penX += kerning * _font.scale;
|
||||
|
||||
GlyphInfo& blackGlyph = m_fontManager->getBlackGlyph();
|
||||
|
||||
|
@ -353,10 +353,10 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons
|
|||
{
|
||||
float x0 = ( m_penX - kerning );
|
||||
float y0 = ( m_penY - m_lineAscender);
|
||||
float x1 = ( (float)x0 + (_glyphInfo.m_advance_x));
|
||||
float x1 = ( (float)x0 + (_glyphInfo.advance_x));
|
||||
float y1 = ( m_penY - m_lineDescender + m_lineGap );
|
||||
|
||||
m_fontManager->getAtlas()->packUV(blackGlyph.m_regionIndex, (uint8_t*)m_vertexBuffer,sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex, (uint8_t*)m_vertexBuffer,sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
|
||||
setVertex(m_vertexCount+0, x0, y0, m_backgroundColor,STYLE_BACKGROUND);
|
||||
setVertex(m_vertexCount+1, x0, y1, m_backgroundColor,STYLE_BACKGROUND);
|
||||
|
@ -377,10 +377,10 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons
|
|||
{
|
||||
float x0 = ( m_penX - kerning );
|
||||
float y0 = (m_penY - m_lineDescender/2 );
|
||||
float x1 = ( (float)x0 + (_glyphInfo.m_advance_x));
|
||||
float y1 = y0+_font.m_underline_thickness;
|
||||
float x1 = ( (float)x0 + (_glyphInfo.advance_x));
|
||||
float y1 = y0+_font.underline_thickness;
|
||||
|
||||
m_fontManager->getAtlas()->packUV(blackGlyph.m_regionIndex, (uint8_t*)m_vertexBuffer,sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex, (uint8_t*)m_vertexBuffer,sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
|
||||
setVertex(m_vertexCount+0, x0, y0, m_underlineColor,STYLE_UNDERLINE);
|
||||
setVertex(m_vertexCount+1, x0, y1, m_underlineColor,STYLE_UNDERLINE);
|
||||
|
@ -400,11 +400,11 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons
|
|||
if( m_styleFlags & STYLE_OVERLINE && m_overlineColor & 0xFF000000)
|
||||
{
|
||||
float x0 = ( m_penX - kerning );
|
||||
float y0 = (m_penY - _font.m_ascender );
|
||||
float x1 = ( (float)x0 + (_glyphInfo.m_advance_x));
|
||||
float y1 = y0+_font.m_underline_thickness;
|
||||
float y0 = (m_penY - _font.ascender );
|
||||
float x1 = ( (float)x0 + (_glyphInfo.advance_x));
|
||||
float y1 = y0+_font.underline_thickness;
|
||||
|
||||
m_fontManager->getAtlas()->packUV(blackGlyph.m_regionIndex, (uint8_t*)m_vertexBuffer,sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex, (uint8_t*)m_vertexBuffer,sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
|
||||
setVertex(m_vertexCount+0, x0, y0, m_overlineColor,STYLE_OVERLINE);
|
||||
setVertex(m_vertexCount+1, x0, y1, m_overlineColor,STYLE_OVERLINE);
|
||||
|
@ -425,11 +425,11 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons
|
|||
if( m_styleFlags & STYLE_STRIKE_THROUGH && m_strikeThroughColor & 0xFF000000)
|
||||
{
|
||||
float x0 = ( m_penX - kerning );
|
||||
float y0 = (m_penY - _font.m_ascender/3 );
|
||||
float x1 = ( (float)x0 + (_glyphInfo.m_advance_x) );
|
||||
float y1 = y0+_font.m_underline_thickness;
|
||||
float y0 = (m_penY - _font.ascender/3 );
|
||||
float x1 = ( (float)x0 + (_glyphInfo.advance_x) );
|
||||
float y1 = y0+_font.underline_thickness;
|
||||
|
||||
m_fontManager->getAtlas()->packUV(blackGlyph.m_regionIndex, (uint8_t*)m_vertexBuffer,sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
m_fontManager->getAtlas()->packUV(blackGlyph.regionIndex, (uint8_t*)m_vertexBuffer,sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
|
||||
setVertex(m_vertexCount+0, x0, y0, m_strikeThroughColor,STYLE_STRIKE_THROUGH);
|
||||
setVertex(m_vertexCount+1, x0, y1, m_strikeThroughColor,STYLE_STRIKE_THROUGH);
|
||||
|
@ -448,13 +448,13 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons
|
|||
|
||||
|
||||
//handle glyph
|
||||
float x0_precise = m_penX + (_glyphInfo.m_offset_x);
|
||||
float x0_precise = m_penX + (_glyphInfo.offset_x);
|
||||
float x0 = ( x0_precise);
|
||||
float y0 = ( m_penY + (_glyphInfo.m_offset_y));
|
||||
float x1 = ( x0 + _glyphInfo.m_width );
|
||||
float y1 = ( y0 + _glyphInfo.m_height );
|
||||
float y0 = ( m_penY + (_glyphInfo.offset_y));
|
||||
float x1 = ( x0 + _glyphInfo.width );
|
||||
float y1 = ( y0 + _glyphInfo.height );
|
||||
|
||||
m_fontManager->getAtlas()->packUV(_glyphInfo.m_regionIndex, (uint8_t*)m_vertexBuffer, sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
m_fontManager->getAtlas()->packUV(_glyphInfo.regionIndex, (uint8_t*)m_vertexBuffer, sizeof(TextVertex) *m_vertexCount + offsetof(TextVertex, u), sizeof(TextVertex));
|
||||
|
||||
setVertex(m_vertexCount+0, x0, y0, m_textColor);
|
||||
setVertex(m_vertexCount+1, x0, y1, m_textColor);
|
||||
|
@ -470,7 +470,7 @@ void TextBuffer::appendGlyph(CodePoint_t _codePoint, const FontInfo& _font, cons
|
|||
m_vertexCount += 4;
|
||||
m_indexCount += 6;
|
||||
|
||||
m_penX += _glyphInfo.m_advance_x;
|
||||
m_penX += _glyphInfo.advance_x;
|
||||
if(m_penX > m_rectangle.width) m_rectangle.width = m_penX;
|
||||
if( (m_penY - m_lineDescender) > m_rectangle.height) m_rectangle.height = (m_penY - m_lineDescender);
|
||||
//if(x1 > m_rectangle.width) m_rectangle.width = x1;
|
||||
|
@ -588,11 +588,11 @@ TextBufferHandle TextBufferManager::createTextBuffer(FontType _type, BufferType
|
|||
uint16_t textIdx = m_textBufferHandles.alloc();
|
||||
BufferCache& bc = m_textBuffers[textIdx];
|
||||
|
||||
bc.m_textBuffer = new TextBuffer(m_fontManager);
|
||||
bc.m_fontType = _type;
|
||||
bc.m_bufferType = _bufferType;
|
||||
bc.m_indexBufferHandle = bgfx::invalidHandle;
|
||||
bc.m_vertexBufferHandle = bgfx::invalidHandle;
|
||||
bc.textBuffer = new TextBuffer(m_fontManager);
|
||||
bc.fontType = _type;
|
||||
bc.bufferType = _bufferType;
|
||||
bc.indexBufferHandle = bgfx::invalidHandle;
|
||||
bc.vertexBufferHandle = bgfx::invalidHandle;
|
||||
|
||||
TextBufferHandle ret = {textIdx};
|
||||
return ret;
|
||||
|
@ -604,19 +604,19 @@ void TextBufferManager::destroyTextBuffer(TextBufferHandle _handle)
|
|||
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
m_textBufferHandles.free(_handle.idx);
|
||||
delete bc.m_textBuffer;
|
||||
bc.m_textBuffer = NULL;
|
||||
delete bc.textBuffer;
|
||||
bc.textBuffer = NULL;
|
||||
|
||||
if(bc.m_vertexBufferHandle == bgfx::invalidHandle ) return;
|
||||
if(bc.vertexBufferHandle == bgfx::invalidHandle ) return;
|
||||
|
||||
switch(bc.m_bufferType)
|
||||
switch(bc.bufferType)
|
||||
{
|
||||
case STATIC:
|
||||
{
|
||||
bgfx::IndexBufferHandle ibh;
|
||||
bgfx::VertexBufferHandle vbh;
|
||||
ibh.idx = bc.m_indexBufferHandle;
|
||||
vbh.idx = bc.m_vertexBufferHandle;
|
||||
ibh.idx = bc.indexBufferHandle;
|
||||
vbh.idx = bc.vertexBufferHandle;
|
||||
bgfx::destroyIndexBuffer(ibh);
|
||||
bgfx::destroyVertexBuffer(vbh);
|
||||
}
|
||||
|
@ -625,8 +625,8 @@ void TextBufferManager::destroyTextBuffer(TextBufferHandle _handle)
|
|||
case DYNAMIC:
|
||||
bgfx::DynamicIndexBufferHandle ibh;
|
||||
bgfx::DynamicVertexBufferHandle vbh;
|
||||
ibh.idx = bc.m_indexBufferHandle;
|
||||
vbh.idx = bc.m_vertexBufferHandle;
|
||||
ibh.idx = bc.indexBufferHandle;
|
||||
vbh.idx = bc.vertexBufferHandle;
|
||||
bgfx::destroyDynamicIndexBuffer(ibh);
|
||||
bgfx::destroyDynamicVertexBuffer(vbh);
|
||||
|
||||
|
@ -641,15 +641,15 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
|
|||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
|
||||
uint32_t indexSize = bc.m_textBuffer->getIndexCount() * bc.m_textBuffer->getIndexSize();
|
||||
uint32_t vertexSize = bc.m_textBuffer->getVertexCount() * bc.m_textBuffer->getVertexSize();
|
||||
uint32_t indexSize = bc.textBuffer->getIndexCount() * bc.textBuffer->getIndexSize();
|
||||
uint32_t vertexSize = bc.textBuffer->getVertexCount() * bc.textBuffer->getVertexSize();
|
||||
const bgfx::Memory* mem;
|
||||
|
||||
bgfx::setTexture(0, u_texColor, m_fontManager->getAtlas()->getTextureHandle());
|
||||
float inverse_gamme = 1.0f/2.2f;
|
||||
bgfx::setUniform(u_inverse_gamma, &inverse_gamme);
|
||||
|
||||
switch (bc.m_fontType)
|
||||
switch (bc.fontType)
|
||||
{
|
||||
case FONT_TYPE_ALPHA:
|
||||
bgfx::setProgram(m_basicProgram);
|
||||
|
@ -661,81 +661,81 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
|
|||
break;
|
||||
case FONT_TYPE_DISTANCE_SUBPIXEL:
|
||||
bgfx::setProgram(m_distanceSubpixelProgram);
|
||||
bgfx::setState( BGFX_STATE_RGB_WRITE |BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_FACTOR, BGFX_STATE_BLEND_INV_SRC_COLOR) , bc.m_textBuffer->getTextColor());
|
||||
bgfx::setState( BGFX_STATE_RGB_WRITE |BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_FACTOR, BGFX_STATE_BLEND_INV_SRC_COLOR) , bc.textBuffer->getTextColor());
|
||||
break;
|
||||
}
|
||||
|
||||
switch(bc.m_bufferType)
|
||||
switch(bc.bufferType)
|
||||
{
|
||||
case STATIC:
|
||||
{
|
||||
bgfx::IndexBufferHandle ibh;
|
||||
bgfx::VertexBufferHandle vbh;
|
||||
|
||||
if(bc.m_vertexBufferHandle == bgfx::invalidHandle)
|
||||
if(bc.vertexBufferHandle == bgfx::invalidHandle)
|
||||
{
|
||||
mem = bgfx::alloc(indexSize);
|
||||
memcpy(mem->data, bc.m_textBuffer->getIndexBuffer(), indexSize);
|
||||
memcpy(mem->data, bc.textBuffer->getIndexBuffer(), indexSize);
|
||||
ibh = bgfx::createIndexBuffer(mem);
|
||||
|
||||
mem = bgfx::alloc(vertexSize);
|
||||
memcpy(mem->data, bc.m_textBuffer->getVertexBuffer(), vertexSize);
|
||||
memcpy(mem->data, bc.textBuffer->getVertexBuffer(), vertexSize);
|
||||
vbh = bgfx::createVertexBuffer(mem, m_vertexDecl);
|
||||
|
||||
bc.m_indexBufferHandle = ibh.idx ;
|
||||
bc.m_vertexBufferHandle = vbh.idx;
|
||||
bc.indexBufferHandle = ibh.idx ;
|
||||
bc.vertexBufferHandle = vbh.idx;
|
||||
}else
|
||||
{
|
||||
ibh.idx = bc.m_indexBufferHandle;
|
||||
vbh.idx = bc.m_vertexBufferHandle;
|
||||
ibh.idx = bc.indexBufferHandle;
|
||||
vbh.idx = bc.vertexBufferHandle;
|
||||
}
|
||||
bgfx::setVertexBuffer(vbh, bc.m_textBuffer->getVertexCount());
|
||||
bgfx::setIndexBuffer(ibh, bc.m_textBuffer->getIndexCount());
|
||||
bgfx::setVertexBuffer(vbh, bc.textBuffer->getVertexCount());
|
||||
bgfx::setIndexBuffer(ibh, bc.textBuffer->getIndexCount());
|
||||
}break;
|
||||
case DYNAMIC:
|
||||
{
|
||||
bgfx::DynamicIndexBufferHandle ibh;
|
||||
bgfx::DynamicVertexBufferHandle vbh;
|
||||
|
||||
if(bc.m_vertexBufferHandle == bgfx::invalidHandle)
|
||||
if(bc.vertexBufferHandle == bgfx::invalidHandle)
|
||||
{
|
||||
mem = bgfx::alloc(indexSize);
|
||||
memcpy(mem->data, bc.m_textBuffer->getIndexBuffer(), indexSize);
|
||||
memcpy(mem->data, bc.textBuffer->getIndexBuffer(), indexSize);
|
||||
ibh = bgfx::createDynamicIndexBuffer(mem);
|
||||
|
||||
mem = bgfx::alloc(vertexSize);
|
||||
memcpy(mem->data, bc.m_textBuffer->getVertexBuffer(), vertexSize);
|
||||
memcpy(mem->data, bc.textBuffer->getVertexBuffer(), vertexSize);
|
||||
vbh = bgfx::createDynamicVertexBuffer(mem, m_vertexDecl);
|
||||
|
||||
bc.m_indexBufferHandle = ibh.idx ;
|
||||
bc.m_vertexBufferHandle = vbh.idx;
|
||||
bc.indexBufferHandle = ibh.idx ;
|
||||
bc.vertexBufferHandle = vbh.idx;
|
||||
}else
|
||||
{
|
||||
ibh.idx = bc.m_indexBufferHandle;
|
||||
vbh.idx = bc.m_vertexBufferHandle;
|
||||
ibh.idx = bc.indexBufferHandle;
|
||||
vbh.idx = bc.vertexBufferHandle;
|
||||
|
||||
mem = bgfx::alloc(indexSize);
|
||||
memcpy(mem->data, bc.m_textBuffer->getIndexBuffer(), indexSize);
|
||||
memcpy(mem->data, bc.textBuffer->getIndexBuffer(), indexSize);
|
||||
bgfx::updateDynamicIndexBuffer(ibh, mem);
|
||||
|
||||
mem = bgfx::alloc(vertexSize);
|
||||
memcpy(mem->data, bc.m_textBuffer->getVertexBuffer(), vertexSize);
|
||||
memcpy(mem->data, bc.textBuffer->getVertexBuffer(), vertexSize);
|
||||
bgfx::updateDynamicVertexBuffer(vbh, mem);
|
||||
}
|
||||
bgfx::setVertexBuffer(vbh, bc.m_textBuffer->getVertexCount());
|
||||
bgfx::setIndexBuffer(ibh, bc.m_textBuffer->getIndexCount());
|
||||
bgfx::setVertexBuffer(vbh, bc.textBuffer->getVertexCount());
|
||||
bgfx::setIndexBuffer(ibh, bc.textBuffer->getIndexCount());
|
||||
|
||||
}break;
|
||||
case TRANSIENT:
|
||||
{
|
||||
bgfx::TransientIndexBuffer tib;
|
||||
bgfx::TransientVertexBuffer tvb;
|
||||
bgfx::allocTransientIndexBuffer(&tib, bc.m_textBuffer->getIndexCount());
|
||||
bgfx::allocTransientVertexBuffer(&tvb, bc.m_textBuffer->getVertexCount(), m_vertexDecl);
|
||||
memcpy(tib.data, bc.m_textBuffer->getIndexBuffer(), indexSize);
|
||||
memcpy(tvb.data, bc.m_textBuffer->getVertexBuffer(), vertexSize);
|
||||
bgfx::setVertexBuffer(&tvb, bc.m_textBuffer->getVertexCount());
|
||||
bgfx::setIndexBuffer(&tib, bc.m_textBuffer->getIndexCount());
|
||||
bgfx::allocTransientIndexBuffer(&tib, bc.textBuffer->getIndexCount());
|
||||
bgfx::allocTransientVertexBuffer(&tvb, bc.textBuffer->getVertexCount(), m_vertexDecl);
|
||||
memcpy(tib.data, bc.textBuffer->getIndexBuffer(), indexSize);
|
||||
memcpy(tvb.data, bc.textBuffer->getVertexBuffer(), vertexSize);
|
||||
bgfx::setVertexBuffer(&tvb, bc.textBuffer->getVertexCount());
|
||||
bgfx::setIndexBuffer(&tib, bc.textBuffer->getIndexCount());
|
||||
}break;
|
||||
}
|
||||
|
||||
|
@ -752,75 +752,75 @@ void TextBufferManager::setStyle(TextBufferHandle _handle, uint32_t _flags )
|
|||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->setStyle(_flags);
|
||||
bc.textBuffer->setStyle(_flags);
|
||||
}
|
||||
|
||||
void TextBufferManager::setTextColor(TextBufferHandle _handle, uint32_t _rgba )
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->setTextColor(_rgba);
|
||||
bc.textBuffer->setTextColor(_rgba);
|
||||
}
|
||||
|
||||
void TextBufferManager::setBackgroundColor(TextBufferHandle _handle, uint32_t _rgba )
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->setBackgroundColor(_rgba);
|
||||
bc.textBuffer->setBackgroundColor(_rgba);
|
||||
}
|
||||
|
||||
void TextBufferManager::setOverlineColor(TextBufferHandle _handle, uint32_t _rgba )
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->setOverlineColor(_rgba);
|
||||
bc.textBuffer->setOverlineColor(_rgba);
|
||||
}
|
||||
|
||||
void TextBufferManager::setUnderlineColor(TextBufferHandle _handle, uint32_t _rgba )
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->setUnderlineColor(_rgba);
|
||||
bc.textBuffer->setUnderlineColor(_rgba);
|
||||
}
|
||||
|
||||
void TextBufferManager::setStrikeThroughColor(TextBufferHandle _handle, uint32_t _rgba )
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->setStrikeThroughColor(_rgba);
|
||||
bc.textBuffer->setStrikeThroughColor(_rgba);
|
||||
}
|
||||
|
||||
void TextBufferManager::setPenPosition(TextBufferHandle _handle, float _x, float _y)
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->setPenPosition(_x,_y);
|
||||
bc.textBuffer->setPenPosition(_x,_y);
|
||||
}
|
||||
|
||||
void TextBufferManager::appendText(TextBufferHandle _handle, FontHandle _fontHandle, const char * _string)
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->appendText(_fontHandle, _string);
|
||||
bc.textBuffer->appendText(_fontHandle, _string);
|
||||
}
|
||||
|
||||
void TextBufferManager::appendText(TextBufferHandle _handle, FontHandle _fontHandle, const wchar_t * _string)
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->appendText(_fontHandle, _string);
|
||||
bc.textBuffer->appendText(_fontHandle, _string);
|
||||
}
|
||||
|
||||
void TextBufferManager::clearTextBuffer(TextBufferHandle _handle)
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
bc.m_textBuffer->clearTextBuffer();
|
||||
bc.textBuffer->clearTextBuffer();
|
||||
}
|
||||
|
||||
TextRectangle TextBufferManager::getRectangle(TextBufferHandle _handle) const
|
||||
{
|
||||
BX_CHECK( bgfx::invalidHandle != _handle.idx, "Invalid handle used");
|
||||
BufferCache& bc = m_textBuffers[_handle.idx];
|
||||
return bc.m_textBuffer->getRectangle();
|
||||
return bc.textBuffer->getRectangle();
|
||||
}
|
||||
|
|
|
@ -70,11 +70,11 @@ private:
|
|||
|
||||
struct BufferCache
|
||||
{
|
||||
uint16_t m_indexBufferHandle;
|
||||
uint16_t m_vertexBufferHandle;
|
||||
TextBuffer* m_textBuffer;
|
||||
BufferType m_bufferType;
|
||||
FontType m_fontType;
|
||||
uint16_t indexBufferHandle;
|
||||
uint16_t vertexBufferHandle;
|
||||
TextBuffer* textBuffer;
|
||||
BufferType bufferType;
|
||||
FontType fontType;
|
||||
};
|
||||
|
||||
BufferCache* m_textBuffers;
|
||||
|
|
Loading…
Reference in a new issue