optmized TextRender.
This commit is contained in:
parent
be2b3b7bcf
commit
0f963fb74b
@ -77,7 +77,9 @@ public:
|
||||
if(!InitUBO())
|
||||
return(false);
|
||||
|
||||
text_render=CreateTextRender(device,device_render_pass,ubo_camera_info);
|
||||
FontSource *fs=CreateFontSource(OS_TEXT("微软雅黑"),12);
|
||||
|
||||
text_render=CreateTextRender(device,fs,device_render_pass,ubo_camera_info);
|
||||
if(!text_render)
|
||||
return(false);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_TEXT_RENDER_INCLUDE
|
||||
#ifndef HGL_GRAPH_TEXT_RENDER_INCLUDE
|
||||
#define HGL_GRAPH_TEXT_RENDER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
@ -9,7 +9,6 @@ namespace hgl
|
||||
namespace graph
|
||||
{
|
||||
class FontSource;
|
||||
class FontSourceMulti;
|
||||
class TileFont;
|
||||
class TextLayout;
|
||||
class TextRenderable;
|
||||
@ -26,9 +25,7 @@ namespace hgl
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
FontSource * eng_fs =nullptr;
|
||||
FontSource * chs_fs =nullptr;
|
||||
FontSourceMulti * font_source =nullptr;
|
||||
FontSource * font_source =nullptr;
|
||||
|
||||
TileFont * tile_font =nullptr;
|
||||
TextLayout * tl_engine =nullptr;
|
||||
@ -38,14 +35,8 @@ namespace hgl
|
||||
|
||||
private:
|
||||
|
||||
friend TextRender *CreateTextRender(GPUDevice *,RenderPass *,GPUBuffer *);
|
||||
TextRender(GPUDevice *dev);
|
||||
|
||||
public:
|
||||
|
||||
~TextRender();
|
||||
|
||||
private:
|
||||
friend TextRender *CreateTextRender(GPUDevice *,FontSource *,RenderPass *,GPUBuffer *);
|
||||
TextRender(GPUDevice *dev,FontSource *);
|
||||
|
||||
bool InitTileFont();
|
||||
bool InitTextLayoutEngine();
|
||||
@ -54,13 +45,35 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
~TextRender();
|
||||
|
||||
bool Init(RenderPass *rp,GPUBuffer *ubo_camera_info);
|
||||
|
||||
public:
|
||||
|
||||
TextRenderable *CreateRenderable();
|
||||
RenderableInstance *CreateRenderableInstance(TextRenderable *text_render_obj,const UTF16String &str);
|
||||
};//class TextRender
|
||||
|
||||
TextRender *CreateTextRender(GPUDevice *,RenderPass *,GPUBuffer *);
|
||||
/**
|
||||
* 创建一个CJK字体源
|
||||
* @param cf CJK字体名称
|
||||
* @param lf 其它字体名称
|
||||
* @param size 字体象素高度
|
||||
*/
|
||||
FontSource *CreateCJKFontSource(const os_char *cf,const os_char *lf,const uint32_t size);
|
||||
|
||||
/**
|
||||
* 创建一个字体源
|
||||
* @param name 字体名称
|
||||
* @param size 字体象素高度
|
||||
*/
|
||||
FontSource *CreateFontSource(const os_char *name,const uint32_t size);
|
||||
|
||||
/**
|
||||
* 创建一个文本渲染器.
|
||||
*/
|
||||
TextRender *CreateTextRender(GPUDevice *,FontSource *,RenderPass *,GPUBuffer *);
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_TEXT_RENDER_INCLUDE
|
||||
|
@ -11,11 +11,12 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
TextRender::TextRender(GPUDevice *dev)
|
||||
TextRender::TextRender(GPUDevice *dev,FontSource *fs)
|
||||
{
|
||||
device=dev;
|
||||
db=new RenderResource(device);
|
||||
tl_engine=new TextLayout();
|
||||
font_source=fs;
|
||||
}
|
||||
|
||||
TextRender::~TextRender()
|
||||
@ -27,15 +28,6 @@ namespace hgl
|
||||
|
||||
bool TextRender::InitTileFont()
|
||||
{
|
||||
Font eng_fnt(OS_TEXT("Source Code Pro"),0,CHAR_BITMAP_SIZE);
|
||||
Font chs_fnt(OS_TEXT("微软雅黑"),0,CHAR_BITMAP_SIZE);
|
||||
|
||||
eng_fs=AcquireFontSource(eng_fnt);
|
||||
chs_fs=AcquireFontSource(chs_fnt);
|
||||
|
||||
font_source=new FontSourceMulti(eng_fs);
|
||||
font_source->AddCJK(chs_fs);
|
||||
|
||||
tile_font=device->CreateTileFont(font_source);
|
||||
return(true);
|
||||
}
|
||||
@ -152,12 +144,34 @@ namespace hgl
|
||||
return db->CreateRenderableInstance(text_render_obj,material_instance,pipeline);
|
||||
}
|
||||
|
||||
TextRender *CreateTextRender(GPUDevice *dev,RenderPass *rp,GPUBuffer *ubo_camera_info)
|
||||
FontSource *CreateCJKFontSource(const os_char *cf,const os_char *lf,const uint32_t size)
|
||||
{
|
||||
Font eng_fnt(lf,0,size);
|
||||
Font chs_fnt(cf,0,size);
|
||||
|
||||
FontSource *eng_fs=AcquireFontSource(eng_fnt);
|
||||
FontSource *chs_fs=AcquireFontSource(chs_fnt);
|
||||
|
||||
FontSourceMulti *font_source=new FontSourceMulti(eng_fs);
|
||||
|
||||
font_source->AddCJK(chs_fs);
|
||||
|
||||
return font_source;
|
||||
}
|
||||
|
||||
FontSource *CreateFontSource(const os_char *name,const uint32_t size)
|
||||
{
|
||||
Font fnt(name,0,size);
|
||||
|
||||
return AcquireFontSource(fnt);
|
||||
}
|
||||
|
||||
TextRender *CreateTextRender(GPUDevice *dev,FontSource *fs,RenderPass *rp,GPUBuffer *ubo_camera_info)
|
||||
{
|
||||
if(!dev||!rp||!ubo_camera_info)
|
||||
return(nullptr);
|
||||
|
||||
TextRender *text_render=new TextRender(dev);
|
||||
TextRender *text_render=new TextRender(dev,fs);
|
||||
|
||||
if(!text_render->Init(rp,ubo_camera_info))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user