From a614b34d4b6cb6a086d053a78e00a85b3949c37a Mon Sep 17 00:00:00 2001 From: HuYingzhuo Date: Fri, 19 Apr 2019 16:32:54 +0800 Subject: [PATCH] =?UTF-8?q?CreateRenderDevice=E6=94=B9=E7=94=A8AutoDelete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/VKDeviceCreater.cpp | 55 ++++++++++-------------------- example/Vulkan/VKInstance.cpp | 2 ++ 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/example/Vulkan/VKDeviceCreater.cpp b/example/Vulkan/VKDeviceCreater.cpp index b8f68091..79aab388 100644 --- a/example/Vulkan/VKDeviceCreater.cpp +++ b/example/Vulkan/VKDeviceCreater.cpp @@ -296,26 +296,6 @@ namespace return desc_pool; } - - struct RenderDeviceCreater - { - DeviceAttribute *attr; - - public: - - RenderDeviceCreater(VkInstance inst,const PhysicalDevice *pd,VkSurfaceKHR sur) - { - attr=new DeviceAttribute(inst,pd,sur); - } - - ~RenderDeviceCreater() - { - if(attr) - delete attr; - } - - DeviceAttribute *operator -> (){return attr;} - };//struct RenderDeviceCreater }//namespace Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device,Window *win) @@ -325,44 +305,45 @@ Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device if(!surface) return(nullptr); - RenderDeviceCreater rdc(inst,physical_device,surface); + DeviceAttribute *attr=new DeviceAttribute(inst,physical_device,surface); - rdc->swapchain_extent=GetSwapchainExtent(rdc->surface_caps,win->GetWidth(),win->GetHeight()); + AutoDelete auto_delete(attr); + + attr->swapchain_extent=GetSwapchainExtent(attr->surface_caps,win->GetWidth(),win->GetHeight()); - if(rdc->graphics_family==ERROR_FAMILY_INDEX) + if(attr->graphics_family==ERROR_FAMILY_INDEX) return(nullptr); - rdc->device=CreateDevice(inst,physical_device->physical_device,rdc->graphics_family); + attr->device=CreateDevice(inst,physical_device->physical_device,attr->graphics_family); - if(!rdc->device) + if(!attr->device) return(nullptr); - GetDeviceQueue(rdc.attr); + GetDeviceQueue(attr); - rdc->cmd_pool=CreateCommandPool(rdc->device,rdc->graphics_family); + attr->cmd_pool=CreateCommandPool(attr->device,attr->graphics_family); - if(!rdc->cmd_pool) + if(!attr->cmd_pool) return(nullptr); - rdc->swap_chain=CreateSwapChain(rdc.attr); + attr->swap_chain=CreateSwapChain(attr); - if(!rdc->swap_chain) + if(!attr->swap_chain) return(nullptr); - if(!CreateSwapchainImageView(rdc.attr)) + if(!CreateSwapchainImageView(attr)) return(nullptr); - if(!CreateDepthBuffer(rdc.attr)) + if(!CreateDepthBuffer(attr)) return(nullptr); - rdc->desc_pool=CreateDescriptorPool(rdc->device,1); + attr->desc_pool=CreateDescriptorPool(attr->device,1); - if(!rdc->desc_pool) + if(!attr->desc_pool) return(nullptr); - Device *dev=new Device(rdc.attr); - rdc.attr=nullptr; + auto_delete.Clear(); - return dev; + return(new Device(attr)); } VK_NAMESPACE_END diff --git a/example/Vulkan/VKInstance.cpp b/example/Vulkan/VKInstance.cpp index 1c58eaae..9d3381d6 100644 --- a/example/Vulkan/VKInstance.cpp +++ b/example/Vulkan/VKInstance.cpp @@ -206,6 +206,8 @@ Instance::Instance(VkInstance i,CharPointerList &el) for(uint32_t i=0;i