add gui examples.
This commit is contained in:
parent
40d91b5992
commit
0ecd947f8a
@ -1 +1 @@
|
|||||||
Subproject commit 4d15db4b5c42a0fb8fc9d78703ab1e98e90d142d
|
Subproject commit 62a1367e8b346bdcf107e8d586fb5b1f28cd0f04
|
@ -37,9 +37,9 @@ private:
|
|||||||
|
|
||||||
MaterialInstance * material_instance =nullptr;
|
MaterialInstance * material_instance =nullptr;
|
||||||
RenderableInstance *render_instance =nullptr;
|
RenderableInstance *render_instance =nullptr;
|
||||||
GPUBuffer * ubo_world_matrix =nullptr;
|
GPUBuffer * ubo_world_matrix =nullptr;
|
||||||
GPUBuffer * ubo_color_material =nullptr;
|
GPUBuffer * ubo_color_material =nullptr;
|
||||||
GPUBuffer * ubo_line_config =nullptr;
|
GPUBuffer * ubo_line_config =nullptr;
|
||||||
|
|
||||||
Pipeline * pipeline =nullptr;
|
Pipeline * pipeline =nullptr;
|
||||||
|
|
||||||
@ -53,7 +53,8 @@ private:
|
|||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Alpha2D,Prim::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),Prim::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||||
|
//pipeline=CreatePipeline(material_instance,InlinePipeline::Alpha2D,Prim::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||||
|
|
||||||
if(!pipeline)
|
if(!pipeline)
|
||||||
return(false);
|
return(false);
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
add_subdirectory(Vulkan)
|
add_subdirectory(Vulkan)
|
||||||
add_subdirectory(2dVector)
|
add_subdirectory(2dVector)
|
||||||
|
add_subdirectory(GUI)
|
@ -1,5 +1,5 @@
|
|||||||
macro(CreateProject name)
|
macro(CreateProject name)
|
||||||
add_executable(${name} ${ARGN} VulkanAppFramework.h)
|
add_executable(${name} ${ARGN} GUIAppFramework.h)
|
||||||
target_link_libraries(${name} ${ULRE})
|
target_link_libraries(${name} ${ULRE})
|
||||||
|
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
|
0
example/GUI/GUIAppFramework.h
Normal file
0
example/GUI/GUIAppFramework.h
Normal file
0
example/GUI/align_test.cpp
Normal file
0
example/GUI/align_test.cpp
Normal file
@ -337,7 +337,7 @@ public:
|
|||||||
|
|
||||||
VkCommandBuffer cb=*cmd_buf[index];
|
VkCommandBuffer cb=*cmd_buf[index];
|
||||||
|
|
||||||
sc_render_target->Submit(cb,gbuffer_rt->GetCompleteSemaphore());
|
sc_render_target->Submit(cb,gbuffer_rt->GetRenderCompleteSemaphore());
|
||||||
sc_render_target->PresentBackbuffer();
|
sc_render_target->PresentBackbuffer();
|
||||||
sc_render_target->WaitQueue();
|
sc_render_target->WaitQueue();
|
||||||
sc_render_target->WaitFence();
|
sc_render_target->WaitFence();
|
||||||
|
@ -14,12 +14,14 @@ namespace hgl
|
|||||||
*/
|
*/
|
||||||
class Form:public Widget
|
class Form:public Widget
|
||||||
{
|
{
|
||||||
protected: //每个窗体独立一个FBO存在,所以每个窗体会有自己的RenderTarget与pipeline
|
protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Form(ThemeEngine *te=nullptr):Widget(nullptr,te){}
|
Form(ThemeEngine *te=nullptr):Widget(nullptr,te){}
|
||||||
virtual ~Form()=default;
|
virtual ~Form()=default;
|
||||||
|
|
||||||
|
|
||||||
};//class Form
|
};//class Form
|
||||||
}//namespace gui
|
}//namespace gui
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -13,6 +13,8 @@ namespace hgl
|
|||||||
class GPUDevice;
|
class GPUDevice;
|
||||||
}//namespace vulkan
|
}//namespace vulkan
|
||||||
|
|
||||||
|
constexpr VkFormat DefaultRenderTargetFormat=UFMT_ABGR8; ///<缺省窗体绘图表面格式
|
||||||
|
|
||||||
class ThemeEngine
|
class ThemeEngine
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@ -21,6 +23,12 @@ namespace hgl
|
|||||||
|
|
||||||
MapObject<Form *,ThemeForm> form_list;
|
MapObject<Form *,ThemeForm> form_list;
|
||||||
|
|
||||||
|
RenderTarget *CreateRenderTarget(const uint32_t,const uint32_t,const VkFormat);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual bool ThemeRender(Form *)=0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ThemeEngine(GPUDevice *dev){device=dev;}
|
ThemeEngine(GPUDevice *dev){device=dev;}
|
||||||
@ -28,11 +36,11 @@ namespace hgl
|
|||||||
|
|
||||||
virtual bool Init()=0;
|
virtual bool Init()=0;
|
||||||
virtual void Clear()=0;
|
virtual void Clear()=0;
|
||||||
|
|
||||||
virtual bool Registry(Form *)=0;
|
virtual bool Registry(Form *,const VkFormat format=DefaultRenderTargetFormat);
|
||||||
virtual void Unregistry(Form *)=0;
|
virtual void Unregistry(Form *);
|
||||||
virtual void Render(Form *)=0;
|
virtual bool Resize(Form *,const uint32_t,const uint32_t,const VkFormat format=DefaultRenderTargetFormat);
|
||||||
virtual bool Resize(Form *,const uint32_t,const uint32_t);
|
virtual void Render(Form *);
|
||||||
};//class ThemeEngine
|
};//class ThemeEngine
|
||||||
|
|
||||||
// ThemeEngine *CreateThemeEngine();
|
// ThemeEngine *CreateThemeEngine();
|
||||||
|
@ -8,18 +8,26 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace gui
|
namespace gui
|
||||||
{
|
{
|
||||||
|
using namespace hgl::graph;
|
||||||
|
|
||||||
class ThemeForm
|
class ThemeForm
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Form *form;
|
Form *form;
|
||||||
hgl::graph::RenderTarget *render_target;
|
RenderTarget *render_target;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ThemeForm(Form *);
|
ThemeForm(Form *,RenderTarget *);
|
||||||
|
virtual ~ThemeForm();
|
||||||
|
|
||||||
|
RenderTarget * GetRenderTarget(){return render_target;}
|
||||||
|
bool SetRenderTarget(RenderTarget *);
|
||||||
|
|
||||||
|
void Resize(uint w,uint h);
|
||||||
|
|
||||||
|
|
||||||
void SetRenderTarget(hgl::graph::RenderTarget *);
|
|
||||||
};//class ThemeForm
|
};//class ThemeForm
|
||||||
}//namespace gui
|
}//namespace gui
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -52,12 +52,14 @@ namespace hgl
|
|||||||
void SetPosition (const RectScope2i &);
|
void SetPosition (const RectScope2i &);
|
||||||
void SetSize (const Vector2f &);
|
void SetSize (const Vector2f &);
|
||||||
|
|
||||||
|
public: //事件
|
||||||
|
|
||||||
|
virtual void OnResize(uint,uint);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Widget(Widget *parent=nullptr,ThemeEngine *te=nullptr);
|
Widget(Widget *parent=nullptr,ThemeEngine *te=nullptr);
|
||||||
virtual ~Widget()=default;
|
virtual ~Widget()=default;
|
||||||
|
|
||||||
virtual void Draw(){}
|
|
||||||
};//class Widget
|
};//class Widget
|
||||||
}//namespace gui
|
}//namespace gui
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
|
|
||||||
#include<hgl/gui/ThemeForm.h>
|
#include<hgl/gui/ThemeForm.h>
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VK.h>
|
||||||
using namespace hgl::graph;
|
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
namespace gui
|
namespace gui
|
||||||
{
|
{
|
||||||
|
using namespace hgl::graph;
|
||||||
|
|
||||||
class Form;
|
class Form;
|
||||||
|
|
||||||
namespace default_theme
|
namespace default_theme
|
||||||
@ -18,10 +19,10 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DTForm(Form *f):ThemeForm(f){}
|
using ThemeForm::ThemeForm;
|
||||||
~DTForm()=default;
|
~DTForm()=default;
|
||||||
};//class DTForm
|
};//class DTForm
|
||||||
}//namespace default_theme
|
}//namespace default_theme
|
||||||
}//namespace gui
|
}//namespace gui
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_GUI_DEFAULT_THEME_FORM_INCLUDE
|
#endif//HGL_GUI_DEFAULT_THEME_FORM_INCLUDE
|
||||||
|
@ -34,11 +34,8 @@ namespace hgl
|
|||||||
|
|
||||||
bool Init() override;
|
bool Init() override;
|
||||||
void Clear() override;
|
void Clear() override;
|
||||||
|
|
||||||
bool Registry(Form *) override;
|
bool ThemeRender(Form *) override;
|
||||||
void Unregistry(Form *) override;
|
|
||||||
void Render(Form *) override;
|
|
||||||
bool Resize(Form *,const uint32_t,const uint32_t) override;
|
|
||||||
};//class DefaultThemeEngine:public ThemeEngine
|
};//class DefaultThemeEngine:public ThemeEngine
|
||||||
}//namespace default_theme
|
}//namespace default_theme
|
||||||
}//namespace gui
|
}//namespace gui
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include<hgl/gui/ThemeEngine.h>
|
#include<hgl/gui/ThemeEngine.h>
|
||||||
#include<hgl/gui/ThemeForm.h>
|
#include<hgl/gui/ThemeForm.h>
|
||||||
|
#include<hgl/graph/VKRenderTarget.h>
|
||||||
|
#include<hgl/graph/VKDevice.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@ -24,8 +26,48 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
return GetDefaultThemeEngine();
|
return GetDefaultThemeEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ThemeEngine::Resize(Form *f,const uint32_t w,const uint32_t h)
|
RenderTarget *ThemeEngine::CreateRenderTarget(const uint32_t w,const uint32_t h,const VkFormat format)
|
||||||
|
{
|
||||||
|
const uint width=power_to_2(w);
|
||||||
|
const uint height=power_to_2(h);
|
||||||
|
|
||||||
|
return device->CreateColorRenderTarget(width,height,format);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ThemeEngine::Registry(Form *f,const VkFormat format)
|
||||||
|
{
|
||||||
|
if(!f)return(false);
|
||||||
|
|
||||||
|
if(form_list.KeyExist(f))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
Vector2f size=f->GetSize();
|
||||||
|
|
||||||
|
RenderTarget *rt=CreateRenderTarget(size.x,size.y,format);
|
||||||
|
|
||||||
|
if(!rt)return(false);
|
||||||
|
|
||||||
|
ThemeForm *tf=new ThemeForm(f,rt);
|
||||||
|
|
||||||
|
form_list.Add(f,tf);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThemeEngine::Unregistry(Form *f)
|
||||||
|
{
|
||||||
|
if(!f)return;
|
||||||
|
|
||||||
|
ThemeForm *tf;
|
||||||
|
|
||||||
|
if(!form_list.Get(f,tf))
|
||||||
|
return;
|
||||||
|
|
||||||
|
delete tf;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ThemeEngine::Resize(Form *f,const uint32_t w,const uint32_t h,const VkFormat format)
|
||||||
{
|
{
|
||||||
if(!f)return(false);
|
if(!f)return(false);
|
||||||
|
|
||||||
@ -39,6 +81,34 @@ namespace hgl
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RenderTarget *old_rt=tf->GetRenderTarget();
|
||||||
|
|
||||||
|
if(!old_rt)
|
||||||
|
{
|
||||||
|
const VkExtent2D old_size=old_rt->GetExtent();
|
||||||
|
|
||||||
|
if(old_size.width>=w
|
||||||
|
&&old_size.height>=h)
|
||||||
|
{
|
||||||
|
tf->Resize(w,h);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
graph::RenderTarget *rt=CreateRenderTarget(w,h,format);
|
||||||
|
|
||||||
|
if(!rt)return(false);
|
||||||
|
|
||||||
|
tf->SetRenderTarget(rt);
|
||||||
|
tf->Resize(w,h);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThemeEngine::Render(Form *f)
|
||||||
|
{
|
||||||
|
if(!f)return;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}//namespace gui
|
}//namespace gui
|
||||||
}//namespace hgl
|
}//namespace hgl
|
@ -4,9 +4,30 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace gui
|
namespace gui
|
||||||
{
|
{
|
||||||
namespace
|
ThemeForm::ThemeForm(Form *f,RenderTarget *rt)
|
||||||
{
|
{
|
||||||
constexpr VkFormat FORM_RT_PIXEL_FORMAT=UFMT_RGBA8;
|
form=f;
|
||||||
}//namespace
|
render_target=rt;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThemeForm::~ThemeForm()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ThemeForm::SetRenderTarget(RenderTarget *rt)
|
||||||
|
{
|
||||||
|
SAFE_CLEAR(render_target);
|
||||||
|
|
||||||
|
if(!rt)
|
||||||
|
return(true);
|
||||||
|
|
||||||
|
render_target=rt;
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThemeForm::Resize(uint w,uint h)
|
||||||
|
{
|
||||||
|
form->OnResize(w,h);
|
||||||
|
}
|
||||||
}//namespace gui
|
}//namespace gui
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -20,5 +20,9 @@ namespace hgl
|
|||||||
align_bits=0; //不对齐
|
align_bits=0; //不对齐
|
||||||
position.Clear();
|
position.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::OnResize(const uint,const uint)
|
||||||
|
{
|
||||||
|
}
|
||||||
}//namespace gui
|
}//namespace gui
|
||||||
}//namespace hgl
|
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user