finished first edition of the TextRenderable class.
This commit is contained in:
parent
a6f1657cac
commit
90314c4b97
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 4c22ba5a6066bd60badb65b6ce745562664c1705
|
||||
Subproject commit 46574e0f49560525442b9d46575aed58678b965a
|
@ -6,6 +6,7 @@
|
||||
#include<hgl/graph/TileData.h>
|
||||
#include<hgl/graph/font/TileFont.h>
|
||||
#include<hgl/graph/font/TextLayout.h>
|
||||
#include<hgl/graph/font/TextRenderable.h>
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/graph/vulkan/VKTexture.h>
|
||||
@ -31,7 +32,6 @@ private:
|
||||
vulkan::Material * material =nullptr;
|
||||
vulkan::Sampler * sampler =nullptr;
|
||||
vulkan::MaterialInstance * material_instance =nullptr;
|
||||
vulkan::Renderable * render_obj =nullptr;
|
||||
vulkan::Buffer * ubo_world_matrix =nullptr;
|
||||
vulkan::Buffer * ubo_color =nullptr;
|
||||
|
||||
@ -41,16 +41,15 @@ private:
|
||||
|
||||
FontSource * font_source =nullptr;
|
||||
|
||||
TileFont * tile_font;
|
||||
TileFont * tile_font =nullptr;
|
||||
TextLayout tl_engine; ///<文本排版引擎
|
||||
|
||||
RenderableCreater * text_rc =nullptr;
|
||||
TextRenderable * text_render_obj =nullptr;
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(text_rc);
|
||||
SAFE_CLEAR(tile_font);
|
||||
}
|
||||
|
||||
@ -136,10 +135,11 @@ private:
|
||||
tla.char_layout_attr=&cla;
|
||||
tla.line_gap=0.2f;
|
||||
|
||||
text_rc=new RenderableCreater(db,material);
|
||||
text_render_obj=new TextRenderable(device,material);
|
||||
|
||||
db->Add(text_render_obj);
|
||||
|
||||
tl_engine.Set(tile_font->GetFontSource());
|
||||
tl_engine.Set(text_rc);
|
||||
tl_engine.Set(&tla);
|
||||
tl_engine.SetTextDirection(0);
|
||||
tl_engine.Set(TextAlign::Left);
|
||||
@ -152,13 +152,7 @@ private:
|
||||
UTF16String str;
|
||||
LoadStringFromTextFile(str,OS_TEXT("res/text/DaoDeBible.txt"));
|
||||
|
||||
if(tl_engine.SimpleLayout(tile_font,str)>0)
|
||||
{
|
||||
render_obj=text_rc->Finish();
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
return(tl_engine.SimpleLayout(text_render_obj,tile_font,str)>0);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -183,7 +177,7 @@ public:
|
||||
if(!InitTextRenderable())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(pipeline,material_instance,render_obj);
|
||||
BuildCommandBuffer(pipeline,material_instance,text_render_obj);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -197,7 +191,7 @@ public:
|
||||
|
||||
ubo_world_matrix->Write(&cam.matrix);
|
||||
|
||||
BuildCommandBuffer(pipeline,material_instance,render_obj);
|
||||
BuildCommandBuffer(pipeline,material_instance,text_render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
|
@ -8,27 +8,6 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 预定义一些顶点属性名称,可用可不用。但一般默认shader会使用这些名称
|
||||
*/
|
||||
namespace VertexAttribName
|
||||
{
|
||||
#define VAN_DEFINE(name) constexpr char name[]=#name;
|
||||
VAN_DEFINE(Vertex)
|
||||
VAN_DEFINE(Normal)
|
||||
VAN_DEFINE(Color)
|
||||
VAN_DEFINE(Tangent)
|
||||
VAN_DEFINE(Bitangent)
|
||||
VAN_DEFINE(TexCoord)
|
||||
VAN_DEFINE(Metallic)
|
||||
VAN_DEFINE(Specular)
|
||||
VAN_DEFINE(Roughness)
|
||||
VAN_DEFINE(Emission)
|
||||
#undef VAN_DEFINE
|
||||
}//namespace VertexAttribName
|
||||
|
||||
#define VAN VertexAttribName
|
||||
|
||||
struct ShaderStageBind
|
||||
{
|
||||
AnsiString name;
|
||||
|
@ -6,6 +6,27 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 预定义一些顶点属性名称,可用可不用。但一般默认shader会使用这些名称
|
||||
*/
|
||||
namespace VertexAttribName
|
||||
{
|
||||
#define VAN_DEFINE(name) constexpr char name[]=#name;
|
||||
VAN_DEFINE(Vertex)
|
||||
VAN_DEFINE(Normal)
|
||||
VAN_DEFINE(Color)
|
||||
VAN_DEFINE(Tangent)
|
||||
VAN_DEFINE(Bitangent)
|
||||
VAN_DEFINE(TexCoord)
|
||||
VAN_DEFINE(Metallic)
|
||||
VAN_DEFINE(Specular)
|
||||
VAN_DEFINE(Roughness)
|
||||
VAN_DEFINE(Emission)
|
||||
#undef VAN_DEFINE
|
||||
}//namespace VertexAttribName
|
||||
|
||||
#define VAN VertexAttribName
|
||||
|
||||
/**
|
||||
* 顶点属性数据
|
||||
*/
|
||||
|
@ -5,11 +5,13 @@
|
||||
#include<hgl/graph/font/FontSource.h>
|
||||
#include<hgl/graph/RenderableCreater.h>
|
||||
#include<hgl/graph/TileData.h>
|
||||
#include<hgl/type/MemBlock.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class TileFont;
|
||||
class TextRenderable;
|
||||
|
||||
/**
|
||||
* 字符属性,可精确到字也可精确到段落或是全文
|
||||
@ -86,7 +88,6 @@ namespace hgl
|
||||
protected:
|
||||
|
||||
FontSource *font_source;
|
||||
RenderableCreater *rc;
|
||||
TextLayoutAttributes tla;
|
||||
|
||||
protected:
|
||||
@ -121,7 +122,7 @@ namespace hgl
|
||||
int sl_v_r2l();
|
||||
int sl_v_l2r();
|
||||
|
||||
template<typename T> int SimpleLayout(TileFont *,const BaseString<T> &); ///<简易排版
|
||||
template<typename T> int SimpleLayout(TextRenderable *,TileFont *,const BaseString<T> &); ///<简易排版
|
||||
|
||||
// template<typename T> int SimpleLayout(TileFont *,const StringList<BaseString<T>> &); ///<简易排版
|
||||
|
||||
@ -139,25 +140,22 @@ namespace hgl
|
||||
|
||||
protected:
|
||||
|
||||
VB4f *vertex;
|
||||
VB4f *tex_coord;
|
||||
TextRenderable *text_render_obj;
|
||||
MemBlock<float> vertex;
|
||||
MemBlock<float> tex_coord;
|
||||
|
||||
public:
|
||||
|
||||
TextLayout()
|
||||
{
|
||||
rc=nullptr;
|
||||
|
||||
direction.text_direction=0;
|
||||
draw_chars_count=0;
|
||||
|
||||
vertex =nullptr;
|
||||
tex_coord =nullptr;
|
||||
text_render_obj =nullptr;
|
||||
}
|
||||
|
||||
virtual ~TextLayout()=default;
|
||||
|
||||
void Set (RenderableCreater *_rc) {if(_rc)rc=_rc;}
|
||||
void Set (const TextLayoutAttributes *_tla) {if(_tla)memcpy(&tla,_tla,sizeof(TextLayoutAttributes));}
|
||||
void Set (FontSource *fs) {if(fs)font_source=fs;}
|
||||
void SetTextDirection (const uint8 &td) {tla.text_direction=td;}
|
||||
@ -167,8 +165,8 @@ namespace hgl
|
||||
|
||||
virtual bool Init (); ///<初始化排版
|
||||
|
||||
int SimpleLayout (TileFont *,const UTF16String &); ///<简易排版
|
||||
int SimpleLayout (TileFont *,const UTF32String &); ///<简易排版
|
||||
int SimpleLayout (TextRenderable *,TileFont *,const UTF16String &); ///<简易排版
|
||||
int SimpleLayout (TextRenderable *,TileFont *,const UTF32String &); ///<简易排版
|
||||
|
||||
// int SimpleLayout (TileFont *,const UTF16StringList &); ///<简易排版
|
||||
// int SimpleLayout (TileFont *,const UTF32StringList &); ///<简易排版
|
||||
|
@ -12,21 +12,24 @@ namespace hgl
|
||||
class TextRenderable:public vulkan::Renderable
|
||||
{
|
||||
vulkan::Device * device;
|
||||
vulkan::Material * mtl;
|
||||
|
||||
vulkan::Renderable *render_obj;
|
||||
|
||||
uint32 max_count; ///<缓冲区最大容量
|
||||
uint32 cur_count; ///<当前容量
|
||||
uint max_count; ///<缓冲区最大容量
|
||||
|
||||
vulkan::VAB * vab_vertex;
|
||||
vulkan::VAB * vab_tex_coord;
|
||||
|
||||
public:
|
||||
|
||||
TextRenderable(vulkan::Device *,int mc=1024);
|
||||
TextRenderable(vulkan::Device *,vulkan::Material *,uint mc=1024);
|
||||
virtual ~TextRenderable();
|
||||
|
||||
void SetMaxCount(int);
|
||||
public:
|
||||
|
||||
void SetCharCount (const uint);
|
||||
|
||||
bool WriteVertex (const float *fp);
|
||||
bool WriteTexCoord (const float *fp);
|
||||
};//class TextRenderable:public vulkan::Renderable
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
void Unmap () {return buf.memory->Unmap();}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);}
|
||||
bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
|
||||
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
|
||||
};//class Buffer
|
||||
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
void Unmap ();
|
||||
|
||||
bool Write (const void *ptr,VkDeviceSize start, VkDeviceSize size);
|
||||
bool Write (const void *ptr, VkDeviceSize size) {return Write(ptr,0,size);}
|
||||
bool Write (const void *ptr) {return Write(ptr,0,req.size);}
|
||||
|
||||
bool BindBuffer (VkBuffer buffer);
|
||||
|
@ -19,12 +19,14 @@ class Renderable
|
||||
VkBuffer *buf_list=nullptr;
|
||||
VkDeviceSize *buf_offset=nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
uint32_t draw_count;
|
||||
|
||||
IndexBuffer *indices_buffer=nullptr;
|
||||
VkDeviceSize indices_offset=0;
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
AABB BoundingBox;
|
||||
|
||||
@ -62,8 +64,7 @@ public:
|
||||
public:
|
||||
|
||||
void SetDrawCount(const uint32_t dc){draw_count=dc;} ///<设置当前对象绘制需要多少个顶点
|
||||
|
||||
const uint32_t GetDrawCount ()const ///<取得当前对象绘制需要多少个顶点
|
||||
virtual const uint32_t GetDrawCount()const ///<取得当前对象绘制需要多少个顶点
|
||||
{
|
||||
if(indices_buffer)
|
||||
return indices_buffer->GetCount();
|
||||
|
@ -70,10 +70,13 @@ SET(TILE_FONT_SOURCE ${ROOT_INCLUDE_PATH}/hgl/graph/font/TileFont.h
|
||||
SET(FONT_LAYOUT_SOURCE ${ROOT_INCLUDE_PATH}/hgl/graph/font/TextLayout.h
|
||||
font/TextLayout.cpp)
|
||||
|
||||
SET(TEXT_RENDERABLE_SOURCE ${ROOT_INCLUDE_PATH}/hgl/graph/font/TextRenderable.h
|
||||
font/TextRenderable.cpp)
|
||||
|
||||
SOURCE_GROUP("Font" FILES ${FONT_MANAGE_SOURCE})
|
||||
SOURCE_GROUP("Font\\Source" FILES ${FONT_SOURCE})
|
||||
SOURCE_GROUP("Font\\TileFont" FILES ${TILE_FONT_SOURCE})
|
||||
SOURCE_GROUP("Font\\Layout" FILES ${FONT_LAYOUT_SOURCE})
|
||||
SOURCE_GROUP("Font\\Layout" FILES ${FONT_LAYOUT_SOURCE} ${TEXT_RENDERABLE_SOURCE})
|
||||
|
||||
IF(WIN32)
|
||||
SET(FONT_SOURCE_OS font/FontSourceWin.cpp
|
||||
@ -102,4 +105,5 @@ add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
|
||||
${FONT_SOURCE}
|
||||
${FONT_SOURCE_OS}
|
||||
${TILE_FONT_SOURCE}
|
||||
${FONT_LAYOUT_SOURCE})
|
||||
${FONT_LAYOUT_SOURCE}
|
||||
${TEXT_RENDERABLE_SOURCE})
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include<hgl/graph/font/TextLayout.h>
|
||||
#include<hgl/graph/font/TileFont.h>
|
||||
#include<hgl/graph/font/TextRenderable.h>
|
||||
#include<hgl/type/Extent.h>
|
||||
|
||||
namespace hgl
|
||||
@ -8,8 +9,7 @@ namespace hgl
|
||||
{
|
||||
bool TextLayout::Init()
|
||||
{
|
||||
if(!rc
|
||||
||(!tla.font_source&&!font_source)
|
||||
if((!tla.font_source&&!font_source)
|
||||
||!tla.char_layout_attr)
|
||||
return(false);
|
||||
|
||||
@ -173,8 +173,8 @@ namespace hgl
|
||||
int cur_size=0;
|
||||
int left=0,top=0;
|
||||
|
||||
float *tp=vertex->Get();
|
||||
float *tcp=tex_coord->Get();
|
||||
float *tp=vertex;
|
||||
float *tcp=tex_coord;
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
@ -215,9 +215,6 @@ namespace hgl
|
||||
++cda;
|
||||
}
|
||||
|
||||
tex_coord->End();
|
||||
vertex->End();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@ -229,46 +226,57 @@ namespace hgl
|
||||
* 简易文本排版。无任何特殊处理,不支持任何转义符,不支持\r\n
|
||||
*/
|
||||
template<typename T>
|
||||
int TextLayout::SimpleLayout(TileFont *tf,const BaseString<T> &str)
|
||||
int TextLayout::SimpleLayout(TextRenderable *tr,TileFont *tf,const BaseString<T> &str)
|
||||
{
|
||||
if(!tr)
|
||||
return(-1);
|
||||
|
||||
if(!tf||str.IsEmpty())
|
||||
return(-1);
|
||||
|
||||
if(!preprocess<T>(tf,str.c_str(),str.Length()))
|
||||
int max_chars=str.Length();
|
||||
|
||||
if(!preprocess<T>(tf,str.c_str(),max_chars))
|
||||
return(-2);
|
||||
|
||||
if(draw_chars_count<=0) //可绘制字符为0???这是全空格?
|
||||
return(-3);
|
||||
|
||||
if(!rc->Init(draw_chars_count)) //创建
|
||||
return(-4);
|
||||
|
||||
vertex =rc->CreateVADA<VB4f>(VAN::Vertex);
|
||||
tex_coord =rc->CreateVADA<VB4f>(VAN::TexCoord);
|
||||
vertex .SetLength(max_chars*4);
|
||||
tex_coord .SetLength(max_chars*4);
|
||||
|
||||
if(!vertex||!tex_coord)
|
||||
return(-5);
|
||||
|
||||
int result;
|
||||
|
||||
if(direction.vertical)
|
||||
{
|
||||
if(direction.right_to_left)
|
||||
return sl_v_r2l();
|
||||
result=sl_v_r2l();
|
||||
else
|
||||
return sl_v_l2r();
|
||||
result=sl_v_l2r();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(direction.right_to_left)
|
||||
return sl_h_r2l();
|
||||
result=sl_h_r2l();
|
||||
else
|
||||
return sl_h_l2r();
|
||||
result=sl_h_l2r();
|
||||
}
|
||||
|
||||
return 0;
|
||||
if(result>0)
|
||||
{
|
||||
tr->SetCharCount(result);
|
||||
tr->WriteVertex(vertex);
|
||||
tr->WriteTexCoord(tex_coord);
|
||||
}
|
||||
|
||||
int TextLayout::SimpleLayout(TileFont *tf,const UTF16String &str){return this->SimpleLayout<u16char>(tf,str);}
|
||||
int TextLayout::SimpleLayout(TileFont *tf,const UTF32String &str){return this->SimpleLayout<u32char>(tf,str);}
|
||||
return result;
|
||||
}
|
||||
|
||||
int TextLayout::SimpleLayout(TextRenderable *tr,TileFont *tf,const UTF16String &str){return this->SimpleLayout<u16char>(tr,tf,str);}
|
||||
int TextLayout::SimpleLayout(TextRenderable *tr,TileFont *tf,const UTF32String &str){return this->SimpleLayout<u32char>(tr,tf,str);}
|
||||
|
||||
//template<typename T>
|
||||
//int TextLayout::SimpleLayout(TileFont *tf,const StringList<BaseString<T>> &sl)
|
||||
|
@ -1,58 +1,53 @@
|
||||
#include<hgl/graph/font/TextRenderable.h>
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/graph/vulkan/VKMaterial.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
namespace
|
||||
{
|
||||
vulkan::Pipeline *text_pipeline=nullptr;
|
||||
}//namespace
|
||||
|
||||
TextRenderable::TextRenderable(Device *dev,int mc)
|
||||
TextRenderable::TextRenderable(vulkan::Device *dev,vulkan::Material *m,uint mc):vulkan::Renderable(m->GetVertexShaderModule(),mc)
|
||||
{
|
||||
device=dev;
|
||||
mtl=m;
|
||||
|
||||
max_count=0;
|
||||
|
||||
render_obj=nullptr;
|
||||
vab_vertex=nullptr;
|
||||
vab_tex_coord=nullptr;
|
||||
|
||||
max_count=mc;
|
||||
cur_count=mc;
|
||||
|
||||
SetMaxCount(mc);
|
||||
}
|
||||
|
||||
TextRenderable::~TextRenderable()
|
||||
{
|
||||
SAFE_CLEAR(vab_tex_coord);
|
||||
SAFE_CLEAR(vab_vertex);
|
||||
SAFE_CLEAR(render_obj);
|
||||
}
|
||||
|
||||
void TextRenderable::SetMaxCount(int mc)
|
||||
void TextRenderable::SetCharCount(const uint cc)
|
||||
{
|
||||
if(mc<max_count)return;
|
||||
this->draw_count=cc;
|
||||
if(cc<=max_count)return;
|
||||
|
||||
max_count=mc;
|
||||
max_count=power_to_2(cc);
|
||||
|
||||
{
|
||||
if(vab_vertex)
|
||||
{
|
||||
delete vab_vertex;
|
||||
|
||||
vab_vertex =device->CreateVAB(VAF_VEC4,max_count);
|
||||
|
||||
render_obj->Set(VAN::Vertex,vab_vertex);
|
||||
Set(VAN::Vertex,vab_vertex);
|
||||
}
|
||||
|
||||
if(vab_tex_coord)
|
||||
{
|
||||
if(vab_tex_coord)
|
||||
delete vab_tex_coord;
|
||||
|
||||
vab_tex_coord =device->CreateVAB(VAF_VEC4,max_count);
|
||||
Set(VAN::TexCoord,vab_tex_coord);
|
||||
}
|
||||
}
|
||||
|
||||
render_obj->Set(VAN::TexCoord,vab_tex_coord);
|
||||
}
|
||||
}
|
||||
bool TextRenderable::WriteVertex (const float *fp){if(!fp)return(false);if(!vab_vertex )return(false);return vab_vertex ->Write(fp,draw_count*4*sizeof(float));}
|
||||
bool TextRenderable::WriteTexCoord (const float *fp){if(!fp)return(false);if(!vab_tex_coord)return(false);return vab_tex_coord ->Write(fp,draw_count*4*sizeof(float));}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
Loading…
x
Reference in New Issue
Block a user