From aafdbdd4eaf5349f241fc25bf94574a27542bf68 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 25 Jan 2025 15:25:29 +0800 Subject: [PATCH] reduced codes of rf_test.cpp --- example/Basic/rf_test.cpp | 53 +++++----------------------------- inc/hgl/graph/VKRenderTarget.h | 26 +++++++++++++++++ inc/hgl/graph/VKSwapchain.h | 3 +- res | 2 +- 4 files changed, 36 insertions(+), 48 deletions(-) diff --git a/example/Basic/rf_test.cpp b/example/Basic/rf_test.cpp index ef9341e0..18cfa50e 100644 --- a/example/Basic/rf_test.cpp +++ b/example/Basic/rf_test.cpp @@ -21,31 +21,10 @@ constexpr float position_data_float[VERTEX_COUNT*2]= 0.5, 0.5 }; -#define USE_HALF_FLOAT_POSITION - -#ifdef USE_HALF_FLOAT_POSITION -constexpr VkFormat PositionFormat=VF_V2HF; - -half_float position_data_hf[VERTEX_COUNT*2]; - -#define position_data position_data_hf -#else constexpr VkFormat PositionFormat=VF_V2F; #define position_data position_data_float -#endif//USE_HALF_FLOAT_POSITION -#define USE_UNORM8_COLOR - -#ifdef USE_UNORM8_COLOR -constexpr uint8 color_data[VERTEX_COUNT*4]= -{ 255,0,0,255, - 0,255,0,255, - 0,0,255,255 -}; - -constexpr VkFormat ColorFormat=VF_V4UN8; -#else constexpr float color_data[VERTEX_COUNT*4]= { 1,0,0,1, 0,1,0,1, @@ -53,16 +32,11 @@ constexpr float color_data[VERTEX_COUNT*4]= }; constexpr VkFormat ColorFormat=VF_V4F; -#endif//USE_UNORM8_COLOR class TestApp:public WorkObject { private: -#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR) - VILConfig vil_config; -#endif - MaterialInstance * material_instance =nullptr; Renderable * render_obj =nullptr; @@ -70,17 +44,6 @@ private: private: - void InitVIL() - { - #ifdef USE_HALF_FLOAT_POSITION - vil_config.Add(VAN::Position,PositionFormat); - #endif//USE_HALF_FLOAT_POSITION - - #ifdef USE_UNORM8_COLOR - vil_config.Add(VAN::Color,ColorFormat); - #endif//USE_HALF_FLOAT_POSITION - } - bool InitAutoMaterial() { mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles); @@ -109,10 +72,6 @@ private: rpc.Init("Triangle",VERTEX_COUNT); -#ifdef USE_HALF_FLOAT_POSITION - Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2); -#endif//USE_HALF_FLOAT_POSITION - if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false); if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false); @@ -127,8 +86,6 @@ public: if(!VulkanApplicationFramework::Init(w,h)) return(false); - InitVIL(); - if(!InitAutoMaterial()) return(false); @@ -150,6 +107,12 @@ public: BuildCommandBuffer(render_obj); } + + void Tick(double)override + {} + + void Render(double) + {} };//class TestApp:public VulkanApplicationFramework int main(int,char **) @@ -159,7 +122,7 @@ int main(int,char **) if(rf.Init(SCREEN_WIDTH,SCREEN_HEIGHT)) return(-1); - WorkManager wm; + WorkManager wm(&rf); - wm.Start(new TestApp()); + wm.Start(new TestApp); } diff --git a/inc/hgl/graph/VKRenderTarget.h b/inc/hgl/graph/VKRenderTarget.h index d03ae7dc..49aef19e 100644 --- a/inc/hgl/graph/VKRenderTarget.h +++ b/inc/hgl/graph/VKRenderTarget.h @@ -8,6 +8,31 @@ #include #include VK_NAMESPACE_BEGIN + +/** +* RenderTarget 存在几种情况: +* +* 1.正常单帧渲染目标,即只有一帧的数据,每次渲染都是当前帧 +* +* 2.多帧渲染目标,即有多帧数据,每次渲染都是指定帧,典型的是Swapchain +* +* 但不管是单帧还是多帧,又有两种情况: +* +* 1.单个颜色缓冲区 +* +* 2.多个颜色缓冲区,典型如PBR GBuffer +* +* 所以RenderTarget的其实是一个多态类,根据不同的情况,有不同的实现 +*/ + +class IRenderTarget +{ +public: + + IRenderTarget(DeviceQueue *,Semaphore *); + +};//class IRenderTarget + /** * 渲染目标 */ @@ -27,6 +52,7 @@ protected: protected: uint32_t color_count; + Texture2D **color_textures; Texture2D *depth_texture; diff --git a/inc/hgl/graph/VKSwapchain.h b/inc/hgl/graph/VKSwapchain.h index da9942fc..38f89149 100644 --- a/inc/hgl/graph/VKSwapchain.h +++ b/inc/hgl/graph/VKSwapchain.h @@ -13,9 +13,8 @@ struct SwapchainImage Texture2D * depth =nullptr; Framebuffer * fbo =nullptr; - - RenderCmdBuffer * cmd_buf =nullptr; + RenderCmdBuffer * cmd_buf =nullptr; public: diff --git a/res b/res index e1a36d78..475d8ad4 160000 --- a/res +++ b/res @@ -1 +1 @@ -Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d +Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd