增加Window/XCBWindow定义,以及增加instance/device扩展定义支持
This commit is contained in:
parent
660892af69
commit
88a6fac5aa
@ -1,7 +1,19 @@
|
||||
add_executable(VulkanTest main.cpp
|
||||
IF(UNIX)
|
||||
SET(RENDER_WINDOW_SOURCE XCBWindow.cpp)
|
||||
SET(RENDER_WINDOW_LIBRARY xcb)
|
||||
ENDIF()
|
||||
if(WIN32)
|
||||
SET(RENDER_WINDOW_SOURCE Win32Window.cpp)
|
||||
ENDIF()
|
||||
if(APPLE)
|
||||
ENDIF()
|
||||
|
||||
|
||||
add_executable(VulkanTest main.cpp
|
||||
${RENDER_WINDOW_SOURCE}
|
||||
VKInstance.cpp
|
||||
VKPhysicalDevice.cpp
|
||||
VKDevice.cpp
|
||||
VKCommandBuffer.cpp)
|
||||
|
||||
target_link_libraries(VulkanTest PRIVATE ${ULRE} ${VULKAN_LIB})
|
||||
target_link_libraries(VulkanTest PRIVATE ${ULRE} ${VULKAN_LIB} ${RENDER_WINDOW_LIBRARY})
|
||||
|
@ -3,8 +3,9 @@
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
Instance::Instance(const UTF8String &an)
|
||||
Instance::Instance(const UTF8String &an,Window *w)
|
||||
{
|
||||
win=w;
|
||||
app_name=an;
|
||||
|
||||
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
@ -15,12 +16,15 @@ Instance::Instance(const UTF8String &an)
|
||||
app_info.engineVersion = 1;
|
||||
app_info.apiVersion = VK_API_VERSION_1_0;
|
||||
|
||||
ext_list.Add(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
ext_list.Add(win->GetVulkanSurfaceExtname());
|
||||
|
||||
inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
inst_info.pNext = nullptr;
|
||||
inst_info.flags = 0;
|
||||
inst_info.pApplicationInfo = &app_info;
|
||||
inst_info.enabledExtensionCount = 0;
|
||||
inst_info.ppEnabledExtensionNames = nullptr;
|
||||
inst_info.enabledExtensionCount = ext_list.GetCount();
|
||||
inst_info.ppEnabledExtensionNames = ext_list.GetData();
|
||||
inst_info.enabledLayerCount = 0;
|
||||
inst_info.ppEnabledLayerNames = nullptr;
|
||||
|
||||
|
@ -3,12 +3,17 @@
|
||||
|
||||
#include<hgl/type/BaseString.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include"Window.h"
|
||||
#include"VK.h"
|
||||
#include"VKPhysicalDevice.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Instance
|
||||
{
|
||||
Window *win;
|
||||
|
||||
List<const char *> ext_list;
|
||||
|
||||
VkApplicationInfo app_info;
|
||||
VkInstanceCreateInfo inst_info;
|
||||
|
||||
@ -22,7 +27,7 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
public:
|
||||
|
||||
Instance(const UTF8String &an);
|
||||
Instance(const UTF8String &,Window *);
|
||||
virtual ~Instance();
|
||||
|
||||
virtual bool Init();
|
||||
|
@ -61,12 +61,13 @@ Device *PhysicalDevice::CreateGraphicsDevice() const
|
||||
queue_info.pQueuePriorities = queue_priorities;
|
||||
|
||||
VkDeviceCreateInfo create_info = {};
|
||||
const char *ext_list[1]={VK_KHR_SWAPCHAIN_EXTENSION_NAME};
|
||||
create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||
create_info.pNext = nullptr;
|
||||
create_info.queueCreateInfoCount = 1;
|
||||
create_info.pQueueCreateInfos = &queue_info;
|
||||
create_info.enabledExtensionCount = 0;
|
||||
create_info.ppEnabledExtensionNames = nullptr;
|
||||
create_info.enabledExtensionCount = 1;
|
||||
create_info.ppEnabledExtensionNames = ext_list;
|
||||
create_info.enabledLayerCount = 0;
|
||||
create_info.ppEnabledLayerNames = nullptr;
|
||||
create_info.pEnabledFeatures = nullptr;
|
||||
|
44
example/Vulkan/Window.h
Normal file
44
example/Vulkan/Window.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef HGL_GRAPH_WINDOW_INCLUDE
|
||||
#define HGL_GRAPH_WINDOW_INCLUDE
|
||||
|
||||
#include<hgl/type/BaseString.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class Window
|
||||
{
|
||||
protected:
|
||||
|
||||
uint width,height;
|
||||
|
||||
OSString win_name;
|
||||
|
||||
public:
|
||||
|
||||
uint GetWidth()const{return width;}
|
||||
uint GetHeight()const{return height;}
|
||||
|
||||
public:
|
||||
|
||||
Window(const OSString &wn)
|
||||
{
|
||||
width=height=0;
|
||||
win_name=wn;
|
||||
}
|
||||
virtual ~Window()=default;
|
||||
|
||||
virtual const char *GetVulkanSurfaceExtname()const=0;
|
||||
|
||||
virtual bool CreateWindow(uint,uint)=0;
|
||||
virtual bool CreateFullscreen(uint,uint,uint)=0;
|
||||
virtual void CloseWindow()=0;
|
||||
|
||||
virtual void Show()=0;
|
||||
virtual void Hide()=0;
|
||||
};//class Window
|
||||
|
||||
Window *CreateRenderWindow(const OSString &win_name);
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_WINDOW_INCLUDE
|
59
example/Vulkan/XCBWindow.cpp
Normal file
59
example/Vulkan/XCBWindow.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include"Window.h"
|
||||
#include<xcb/xcb.h>
|
||||
#include<vulkan/vk_sdk_platform.h>
|
||||
#include<vulkan/vulkan.h>
|
||||
#include<vulkan/vulkan_xcb.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class XCBWindow:public Window
|
||||
{
|
||||
xcb_connection_t *connection;
|
||||
xcb_screen_t *screen;
|
||||
xcb_window_t window;
|
||||
xcb_intern_atom_reply_t *atom_wm_delete_window;
|
||||
|
||||
xcb_screen_iterator_t iter;
|
||||
int scr;
|
||||
|
||||
public:
|
||||
|
||||
XCBWindow(const UTF8String &wn):Window(wn)
|
||||
{
|
||||
connection=nullptr;
|
||||
screen=nullptr;
|
||||
atom_wm_delete_window=nullptr;
|
||||
|
||||
scr=-1;
|
||||
}
|
||||
|
||||
~XCBWindow()
|
||||
{
|
||||
}
|
||||
|
||||
const char *GetVulkanSurfaceExtname()const
|
||||
{
|
||||
return VK_KHR_XCB_SURFACE_EXTENSION_NAME;
|
||||
}
|
||||
|
||||
bool CreateWindow(uint w,uint h) override
|
||||
{
|
||||
if(w<=0||h<=0)return(false);
|
||||
|
||||
xcb_connect(nullptr,&scr);
|
||||
}
|
||||
|
||||
bool CreateFullscreen(uint,uint,uint)override{}
|
||||
void CloseWindow()override{}
|
||||
|
||||
void Show()override{}
|
||||
void Hide()override{}
|
||||
};//class XCBWindow:public Window
|
||||
|
||||
Window *CreateRenderWindow(const UTF8String &win_name)
|
||||
{
|
||||
return(new XCBWindow(win_name));
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@ -2,16 +2,22 @@
|
||||
#include"VKInstance.h"
|
||||
#include"VKDevice.h"
|
||||
#include"VKCommandBuffer.h"
|
||||
#include"Window.h"
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
Window *win=CreateRenderWindow(OS_TEXT("VulkanTest"));
|
||||
|
||||
vulkan::Instance inst("Test");
|
||||
vulkan::Instance inst(U8_TEXT("VulkanTest"),win);
|
||||
|
||||
if(!inst.Init())
|
||||
{
|
||||
delete win;
|
||||
return(-1);
|
||||
}
|
||||
|
||||
const ObjectList<vulkan::PhysicalDevice> &device_list=inst.GetDeviceList();
|
||||
|
||||
@ -23,6 +29,7 @@ int main(int,char **)
|
||||
|
||||
delete cmd_buf;
|
||||
delete dev;
|
||||
delete win;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user