From 28fcdb621699db9d2b7c70305e56b2e102a22504 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 30 Jul 2024 00:11:04 +0800 Subject: [PATCH] preparing LerpLine example. --- CMCore | 2 +- CMUtil | 2 +- example/2dVector/CMakeLists.txt | 4 +- example/2dVector/LerpLine.cpp | 121 +++++++++++++++++++++ inc/hgl/graph/mtl/Material2DCreateConfig.h | 9 ++ 5 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 example/2dVector/LerpLine.cpp diff --git a/CMCore b/CMCore index 1a61053e..9fdefa18 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 1a61053e33ba573fb80a3775200e3db83dafd6bd +Subproject commit 9fdefa18fa2d7ce86ac48668110ed75c65d226ef diff --git a/CMUtil b/CMUtil index 259f0ef4..1e121c1b 160000 --- a/CMUtil +++ b/CMUtil @@ -1 +1 @@ -Subproject commit 259f0ef40c46c7cb6fadc4f9402e100c352df9d9 +Subproject commit 1e121c1b3ebfbc46ce310335e2fb3b4c8ecdf8e0 diff --git a/example/2dVector/CMakeLists.txt b/example/2dVector/CMakeLists.txt index be9ff514..582627bd 100644 --- a/example/2dVector/CMakeLists.txt +++ b/example/2dVector/CMakeLists.txt @@ -10,4 +10,6 @@ endmacro() CreateProject(00.line line.cpp) -CreateProject(01.roundbox roundbox.cpp) +CreateProject(01.LerpLine LerpLine.cpp) + +CreateProject(02.roundbox roundbox.cpp) diff --git a/example/2dVector/LerpLine.cpp b/example/2dVector/LerpLine.cpp new file mode 100644 index 00000000..600794b7 --- /dev/null +++ b/example/2dVector/LerpLine.cpp @@ -0,0 +1,121 @@ +// 主要用于测试几种2D插值算法 + +#include"VulkanAppFramework.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace hgl; +using namespace hgl::graph; + +constexpr uint32_t SCREEN_WIDTH=1280; +constexpr uint32_t SCREEN_HEIGHT=720; + +constexpr uint32_t VERTEX_COUNT=3; + +constexpr float position_data[VERTEX_COUNT*2]= +{ + -1.0, 0.0, + 1.0, 0.0, +}; + +constexpr VkFormat PositionFormat=VF_V2F; + +constexpr float color_data[VERTEX_COUNT*4]= +{ 1,0,0,1, + 0,1,0,1, + 0,0,1,1 +}; + +constexpr VkFormat ColorFormat=VF_V4F; + +class TestApp:public VulkanApplicationFramework +{ +private: + + MaterialInstance * material_instance =nullptr; + Renderable * render_obj =nullptr; + + Pipeline * pipeline =nullptr; + +private: + + bool InitAutoMaterial() + { + mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Lines); + + cfg.coordinate_system=CoordinateSystem2D::NDC; + cfg.local_to_world=false; + + AutoDelete mci=mtl::CreateVertexColor2D(&cfg); + + material_instance=db->CreateMaterialInstance(mci); + + return material_instance; + } + + bool InitPipeline() + { + pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Lines); + + return pipeline; + } + + bool InitVBO() + { + PrimitiveCreater rpc(device,material_instance->GetVIL()); + + rpc.Init("Triangle",VERTEX_COUNT); + + if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false); + if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false); + + render_obj=db->CreateRenderable(&rpc,material_instance,pipeline); + return(render_obj); + } + +public: + + bool Init() + { + if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT)) + return(false); + + if(!InitAutoMaterial()) + return(false); + + if(!InitPipeline()) + return(false); + + if(!InitVBO()) + return(false); + + if(!BuildCommandBuffer(render_obj)) + return(false); + + return(true); + } + + void Resize(uint w,uint h)override + { + VulkanApplicationFramework::Resize(w,h); + + BuildCommandBuffer(render_obj); + } +};//class TestApp:public VulkanApplicationFramework + +int main(int,char **) +{ + TestApp app; + + if(!app.Init()) + return(-1); + + while(app.Run()); + + return 0; +} diff --git a/inc/hgl/graph/mtl/Material2DCreateConfig.h b/inc/hgl/graph/mtl/Material2DCreateConfig.h index 40a73b32..443cac67 100644 --- a/inc/hgl/graph/mtl/Material2DCreateConfig.h +++ b/inc/hgl/graph/mtl/Material2DCreateConfig.h @@ -54,6 +54,15 @@ public: MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *); MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *); + + +struct MaterialLerpLineConfig +{ + +}; + +MaterialCreateInfo *CreateLerpLine2D(const Material2DCreateConfig *); + MaterialCreateInfo *CreatePureTexture2D(const Material2DCreateConfig *); MaterialCreateInfo *CreateRectTexture2D(Material2DCreateConfig *); MaterialCreateInfo *CreateRectTexture2DArray(Material2DCreateConfig *);