增加VKSurface封装
This commit is contained in:
parent
8afd96408e
commit
9171fdd9a9
@ -8,6 +8,7 @@ ENDIF()
|
||||
add_executable(VulkanTest main.cpp
|
||||
${RENDER_WINDOW_SOURCE}
|
||||
VKInstance.cpp
|
||||
VKSurface.cpp
|
||||
VKPhysicalDevice.cpp
|
||||
VKDevice.cpp
|
||||
VKCommandBuffer.cpp)
|
||||
|
@ -72,4 +72,9 @@ bool Instance::Init()
|
||||
return(true);
|
||||
}
|
||||
|
||||
Surface* Instance::CreateSurface()
|
||||
{
|
||||
return win->CreateVulkanSurface(inst);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include<hgl/type/List.h>
|
||||
#include"Window.h"
|
||||
#include"VK.h"
|
||||
#include"VKSurface.h"
|
||||
#include"VKPhysicalDevice.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
@ -33,6 +34,8 @@ VK_NAMESPACE_BEGIN
|
||||
virtual bool Init();
|
||||
|
||||
const ObjectList<PhysicalDevice> & GetDeviceList()const{return physical_devices;}
|
||||
|
||||
virtual Surface *CreateSurface();
|
||||
};//class Instance
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_INSTANCE_INCLUDE
|
||||
|
8
example/Vulkan/VKSurface.cpp
Normal file
8
example/Vulkan/VKSurface.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include"VKSurface.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Surface::~Surface()
|
||||
{
|
||||
vkDestroySurfaceKHR(instance, surface, nullptr);
|
||||
}
|
||||
VK_NAMESPACE_END
|
25
example/Vulkan/VKSurface.h
Normal file
25
example/Vulkan/VKSurface.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_SURFACE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_SURFACE_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class Surface
|
||||
{
|
||||
VkInstance instance;
|
||||
VkSurfaceKHR surface;
|
||||
|
||||
public:
|
||||
|
||||
Surface(VkInstance inst,VkSurfaceKHR surf)
|
||||
{
|
||||
instance = inst;
|
||||
surface = surf;
|
||||
}
|
||||
|
||||
virtual ~Surface();
|
||||
};//class Surface
|
||||
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SURFACE_INCLUDE
|
@ -34,6 +34,7 @@ namespace hgl
|
||||
*/
|
||||
class WinWindow :public Window
|
||||
{
|
||||
HINSTANCE hInstance = nullptr;
|
||||
HWND win_hwnd=nullptr;
|
||||
HDC win_dc = nullptr;
|
||||
|
||||
@ -50,7 +51,7 @@ namespace hgl
|
||||
win_class.lpfnWndProc = WndProc;
|
||||
win_class.cbClsExtra = 0;
|
||||
win_class.cbWndExtra = 0;
|
||||
win_class.hInstance = GetModuleHandle(nullptr);
|
||||
win_class.hInstance = hInstance;
|
||||
win_class.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
|
||||
win_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
win_class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
||||
@ -102,12 +103,12 @@ namespace hgl
|
||||
win_height, // height
|
||||
nullptr, // handle to parent
|
||||
nullptr, // handle to menu
|
||||
GetModuleHandleW(nullptr), // hInstance
|
||||
hInstance, // hInstance
|
||||
nullptr); // no extra parameters
|
||||
|
||||
if (!win_hwnd)
|
||||
{
|
||||
UnregisterClassW(WIN_CLASS_NAME, GetModuleHandleW(nullptr));
|
||||
UnregisterClassW(WIN_CLASS_NAME, hInstance);
|
||||
return(false);
|
||||
}
|
||||
|
||||
@ -134,6 +135,8 @@ namespace hgl
|
||||
width = w;
|
||||
height = h;
|
||||
|
||||
hInstance = GetModuleHandleW(nullptr);
|
||||
|
||||
if (!Registry())
|
||||
return(false);
|
||||
|
||||
@ -149,7 +152,7 @@ namespace hgl
|
||||
{
|
||||
ReleaseDC(win_hwnd, win_dc);
|
||||
DestroyWindow(win_hwnd);
|
||||
UnregisterClassW(WIN_CLASS_NAME, GetModuleHandleW(nullptr));
|
||||
UnregisterClassW(WIN_CLASS_NAME,hInstance);
|
||||
|
||||
win_dc = nullptr;
|
||||
win_hwnd = nullptr;
|
||||
@ -169,6 +172,24 @@ namespace hgl
|
||||
ShowWindow(win_hwnd, SW_HIDE);
|
||||
UpdateWindow(win_hwnd);
|
||||
}
|
||||
|
||||
vulkan::Surface* CreateVulkanSurface(VkInstance vk_inst)const override
|
||||
{
|
||||
VkWin32SurfaceCreateInfoKHR createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||
createInfo.pNext = nullptr;
|
||||
createInfo.hinstance = hInstance;
|
||||
createInfo.hwnd = win_hwnd;
|
||||
|
||||
VkSurfaceKHR surface;
|
||||
|
||||
VkResult res = vkCreateWin32SurfaceKHR(vk_inst, &createInfo, nullptr, &surface);
|
||||
|
||||
if (res != VK_SUCCESS)
|
||||
return(nullptr);
|
||||
|
||||
return(new vulkan::Surface(vk_inst,surface));
|
||||
}
|
||||
};//class WinWindow :public Window
|
||||
|
||||
Window* CreateRenderWindow(const WideString& win_name)
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define HGL_GRAPH_WINDOW_INCLUDE
|
||||
|
||||
#include<hgl/type/BaseString.h>
|
||||
#include"VKSurface.h"
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
@ -36,6 +37,8 @@ namespace hgl
|
||||
|
||||
virtual void Show()=0;
|
||||
virtual void Hide()=0;
|
||||
|
||||
virtual vulkan::Surface *CreateVulkanSurface(VkInstance)const = 0;
|
||||
};//class Window
|
||||
|
||||
Window *CreateRenderWindow(const OSString &win_name);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include"VK.h"
|
||||
#include"VKInstance.h"
|
||||
#include"VKSurface.h"
|
||||
#include"VKDevice.h"
|
||||
#include"VKCommandBuffer.h"
|
||||
#include"Window.h"
|
||||
@ -21,6 +22,8 @@ int main(int,char **)
|
||||
return(-1);
|
||||
}
|
||||
|
||||
vulkan::Surface *surface = inst.CreateSurface();
|
||||
|
||||
const ObjectList<vulkan::PhysicalDevice> &device_list=inst.GetDeviceList();
|
||||
|
||||
vulkan::PhysicalDevice *pd=device_list[0];
|
||||
@ -29,6 +32,7 @@ int main(int,char **)
|
||||
|
||||
vulkan::CommandBuffer *cmd_buf=dev->CreateCommandBuffer();
|
||||
|
||||
delete surface;
|
||||
delete cmd_buf;
|
||||
delete dev;
|
||||
delete win;
|
||||
|
Loading…
x
Reference in New Issue
Block a user