diff --git a/CMSceneGraph b/CMSceneGraph index 4d15db4b..62a1367e 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit 4d15db4b5c42a0fb8fc9d78703ab1e98e90d142d +Subproject commit 62a1367e8b346bdcf107e8d586fb5b1f28cd0f04 diff --git a/example/2dVector/line.cpp b/example/2dVector/line.cpp index 3b5e6178..6ca581de 100644 --- a/example/2dVector/line.cpp +++ b/example/2dVector/line.cpp @@ -37,9 +37,9 @@ private: MaterialInstance * material_instance =nullptr; RenderableInstance *render_instance =nullptr; - GPUBuffer * ubo_world_matrix =nullptr; - GPUBuffer * ubo_color_material =nullptr; - GPUBuffer * ubo_line_config =nullptr; + GPUBuffer * ubo_world_matrix =nullptr; + GPUBuffer * ubo_color_material =nullptr; + GPUBuffer * ubo_line_config =nullptr; Pipeline * pipeline =nullptr; @@ -53,7 +53,8 @@ private: return(false); // 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) return(false); diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index ee5381c8..c1e2bc19 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -2,3 +2,4 @@ add_subdirectory(Vulkan) add_subdirectory(2dVector) +add_subdirectory(GUI) \ No newline at end of file diff --git a/example/GUI/CMakeLists.txt b/example/GUI/CMakeLists.txt index 8359de68..b244edfa 100644 --- a/example/GUI/CMakeLists.txt +++ b/example/GUI/CMakeLists.txt @@ -1,5 +1,5 @@ macro(CreateProject name) - add_executable(${name} ${ARGN} VulkanAppFramework.h) + add_executable(${name} ${ARGN} GUIAppFramework.h) target_link_libraries(${name} ${ULRE}) IF(WIN32) diff --git a/example/GUI/GUIAppFramework.h b/example/GUI/GUIAppFramework.h new file mode 100644 index 00000000..e69de29b diff --git a/example/GUI/align_test.cpp b/example/GUI/align_test.cpp new file mode 100644 index 00000000..e69de29b diff --git a/example/Vulkan/DeferredModel.cpp b/example/Vulkan/DeferredModel.cpp index eda80249..a9ff57de 100644 --- a/example/Vulkan/DeferredModel.cpp +++ b/example/Vulkan/DeferredModel.cpp @@ -337,7 +337,7 @@ public: 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->WaitQueue(); sc_render_target->WaitFence(); diff --git a/inc/hgl/gui/Form.h b/inc/hgl/gui/Form.h index 48461ea6..5e5c6e39 100644 --- a/inc/hgl/gui/Form.h +++ b/inc/hgl/gui/Form.h @@ -14,12 +14,14 @@ namespace hgl */ class Form:public Widget { - protected: //每个窗体独立一个FBO存在,所以每个窗体会有自己的RenderTarget与pipeline + protected: public: Form(ThemeEngine *te=nullptr):Widget(nullptr,te){} virtual ~Form()=default; + + };//class Form }//namespace gui }//namespace hgl diff --git a/inc/hgl/gui/ThemeEngine.h b/inc/hgl/gui/ThemeEngine.h index ecad81a9..f0d35d53 100644 --- a/inc/hgl/gui/ThemeEngine.h +++ b/inc/hgl/gui/ThemeEngine.h @@ -13,6 +13,8 @@ namespace hgl class GPUDevice; }//namespace vulkan + constexpr VkFormat DefaultRenderTargetFormat=UFMT_ABGR8; ///<缺省窗体绘图表面格式 + class ThemeEngine { protected: @@ -21,6 +23,12 @@ namespace hgl MapObject
form_list; + RenderTarget *CreateRenderTarget(const uint32_t,const uint32_t,const VkFormat); + + protected: + + virtual bool ThemeRender(Form *)=0; + public: ThemeEngine(GPUDevice *dev){device=dev;} @@ -28,11 +36,11 @@ namespace hgl virtual bool Init()=0; virtual void Clear()=0; - - virtual bool Registry(Form *)=0; - virtual void Unregistry(Form *)=0; - virtual void Render(Form *)=0; - virtual bool Resize(Form *,const uint32_t,const uint32_t); + + virtual bool Registry(Form *,const VkFormat format=DefaultRenderTargetFormat); + virtual void Unregistry(Form *); + virtual bool Resize(Form *,const uint32_t,const uint32_t,const VkFormat format=DefaultRenderTargetFormat); + virtual void Render(Form *); };//class ThemeEngine // ThemeEngine *CreateThemeEngine(); diff --git a/inc/hgl/gui/ThemeForm.h b/inc/hgl/gui/ThemeForm.h index 4909e3e0..7b2cd6ac 100644 --- a/inc/hgl/gui/ThemeForm.h +++ b/inc/hgl/gui/ThemeForm.h @@ -8,18 +8,26 @@ namespace hgl { namespace gui { + using namespace hgl::graph; + class ThemeForm { protected: Form *form; - hgl::graph::RenderTarget *render_target; + RenderTarget *render_target; 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 }//namespace gui }//namespace hgl diff --git a/inc/hgl/gui/Widget.h b/inc/hgl/gui/Widget.h index 443d6014..bd9a7c38 100644 --- a/inc/hgl/gui/Widget.h +++ b/inc/hgl/gui/Widget.h @@ -52,12 +52,14 @@ namespace hgl void SetPosition (const RectScope2i &); void SetSize (const Vector2f &); + public: //事件 + + virtual void OnResize(uint,uint); + public: Widget(Widget *parent=nullptr,ThemeEngine *te=nullptr); virtual ~Widget()=default; - - virtual void Draw(){} };//class Widget }//namespace gui }//namespace hgl diff --git a/src/GUI/DTForm.h b/src/GUI/DTForm.h index e3a2abb1..65805d8c 100644 --- a/src/GUI/DTForm.h +++ b/src/GUI/DTForm.h @@ -3,12 +3,13 @@ #include #include -using namespace hgl::graph; namespace hgl { namespace gui { + using namespace hgl::graph; + class Form; namespace default_theme @@ -18,10 +19,10 @@ namespace hgl public: - DTForm(Form *f):ThemeForm(f){} + using ThemeForm::ThemeForm; ~DTForm()=default; };//class DTForm }//namespace default_theme }//namespace gui }//namespace hgl -#endif//HGL_GUI_DEFAULT_THEME_FORM_INCLUDE \ No newline at end of file +#endif//HGL_GUI_DEFAULT_THEME_FORM_INCLUDE diff --git a/src/GUI/DefaultThemeEngine.h b/src/GUI/DefaultThemeEngine.h index 0070c8f2..81567599 100644 --- a/src/GUI/DefaultThemeEngine.h +++ b/src/GUI/DefaultThemeEngine.h @@ -34,11 +34,8 @@ namespace hgl bool Init() override; void Clear() override; - - bool Registry(Form *) override; - void Unregistry(Form *) override; - void Render(Form *) override; - bool Resize(Form *,const uint32_t,const uint32_t) override; + + bool ThemeRender(Form *) override; };//class DefaultThemeEngine:public ThemeEngine }//namespace default_theme }//namespace gui diff --git a/src/GUI/ThemeEngine.cpp b/src/GUI/ThemeEngine.cpp index b0a7eb60..d5fb4c45 100644 --- a/src/GUI/ThemeEngine.cpp +++ b/src/GUI/ThemeEngine.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include namespace hgl { @@ -24,8 +26,48 @@ namespace hgl { 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); @@ -39,6 +81,34 @@ namespace hgl 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 hgl \ No newline at end of file diff --git a/src/GUI/ThemeForm.cpp b/src/GUI/ThemeForm.cpp index fc77fc0b..b8da9a08 100644 --- a/src/GUI/ThemeForm.cpp +++ b/src/GUI/ThemeForm.cpp @@ -4,9 +4,30 @@ namespace hgl { namespace gui { - namespace + ThemeForm::ThemeForm(Form *f,RenderTarget *rt) { - constexpr VkFormat FORM_RT_PIXEL_FORMAT=UFMT_RGBA8; - }//namespace + form=f; + 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 hgl \ No newline at end of file +}//namespace hgl diff --git a/src/GUI/Widget.cpp b/src/GUI/Widget.cpp index b8186039..39d8423d 100644 --- a/src/GUI/Widget.cpp +++ b/src/GUI/Widget.cpp @@ -20,5 +20,9 @@ namespace hgl align_bits=0; //不对齐 position.Clear(); } + + void Widget::OnResize(const uint,const uint) + { + } }//namespace gui }//namespace hgl \ No newline at end of file