From 37c0501bed1f09b75a91f007ef4c91d8aee3f029 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 9 Apr 2019 00:22:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8BVulkan=E5=B0=9D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 +++ example/CMakeLists.txt | 2 ++ example/Vulkan/CMakeLists.txt | 4 +++ example/Vulkan/VKInstance.cpp | 52 +++++++++++++++++++++++++++++++++++ example/Vulkan/VKInstance.h | 30 ++++++++++++++++++++ example/Vulkan/main.cpp | 13 +++++++++ 6 files changed, 105 insertions(+) create mode 100644 example/Vulkan/CMakeLists.txt create mode 100644 example/Vulkan/VKInstance.cpp create mode 100644 example/Vulkan/VKInstance.h create mode 100644 example/Vulkan/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 34680546..385d815f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,12 @@ IF(WIN32) include_directories(3rdpty/glfw/include) SET(OPENGL_LIB opengl32) + + SET(VULKAN_LIB vulkan-1) ELSE() SET(OPENGL_LIB GL) + + SET(VULKAN_LIB vulkan) ENDIF() add_definitions(-DMATH_USE_OPENGL) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 2f271163..5353b027 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -4,3 +4,5 @@ add_subdirectory(NullWindow) add_subdirectory(DirectGLRender) add_subdirectory(DirectGLTexture) add_subdirectory(TextureSampler) + +add_subdirectory(Vulkan) diff --git a/example/Vulkan/CMakeLists.txt b/example/Vulkan/CMakeLists.txt new file mode 100644 index 00000000..bee6fa13 --- /dev/null +++ b/example/Vulkan/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(VulkanTest main.cpp + VKInstance.cpp) + +target_link_libraries(VulkanTest PRIVATE ${ULRE} ${VULKAN_LIB}) diff --git a/example/Vulkan/VKInstance.cpp b/example/Vulkan/VKInstance.cpp new file mode 100644 index 00000000..a569a326 --- /dev/null +++ b/example/Vulkan/VKInstance.cpp @@ -0,0 +1,52 @@ +#include"VKInstance.h" +#include + +VK_NAMESPACE_BEGIN + +Instance::Instance(const UTF8String &an) +{ + app_name=an; + + app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + app_info.pNext = nullptr; + app_info.pApplicationName = app_name.c_str(); + app_info.applicationVersion = 1; + app_info.pEngineName = "CMGameEngine/ULRE"; + app_info.engineVersion = 1; + app_info.apiVersion = VK_API_VERSION_1_0; + + 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.enabledLayerCount = 0; + inst_info.ppEnabledLayerNames = nullptr; + + inst=nullptr; +} + +Instance::~Instance() +{ + if(inst) + vkDestroyInstance(inst,nullptr); +} + +bool Instance::Init() +{ + if(inst) + return(false); + + VkResult res=vkCreateInstance(&inst_info,nullptr,&inst); + + if(res) + { + inst=nullptr; + return(false); + } + + return(true); +} + +VK_NAMESPACE_END diff --git a/example/Vulkan/VKInstance.h b/example/Vulkan/VKInstance.h new file mode 100644 index 00000000..0a7258b8 --- /dev/null +++ b/example/Vulkan/VKInstance.h @@ -0,0 +1,30 @@ +#ifndef HGL_GRAPH_VULKAN_INSTANCE_INCLUDE +#define HGL_GRAPH_VULKAN_INSTANCE_INCLUDE + +#include +#include + +#define VK_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace vulkan{ +#define VK_NAMESPACE_END }}} + +VK_NAMESPACE_BEGIN + class Instance + { + VkApplicationInfo app_info; + VkInstanceCreateInfo inst_info; + + VkInstance inst; + + private: + + UTF8String app_name; + + public: + + Instance(const UTF8String &an); + virtual ~Instance(); + + virtual bool Init(); + };//class Instance +VK_NAMESPACE_END +#endif//HGL_GRAPH_VULKAN_INSTANCE_INCLUDE diff --git a/example/Vulkan/main.cpp b/example/Vulkan/main.cpp new file mode 100644 index 00000000..672967fd --- /dev/null +++ b/example/Vulkan/main.cpp @@ -0,0 +1,13 @@ +#include"VKInstance.h" + +int main(int,char **) +{ + using namespace hgl; + using namespace hgl::graph; + + vulkan::Instance inst("Test"); + + inst.Init(); + + return 0; +}