开始Vulkan尝试
This commit is contained in:
parent
04c17e53e4
commit
37c0501bed
@ -19,8 +19,12 @@ IF(WIN32)
|
|||||||
include_directories(3rdpty/glfw/include)
|
include_directories(3rdpty/glfw/include)
|
||||||
|
|
||||||
SET(OPENGL_LIB opengl32)
|
SET(OPENGL_LIB opengl32)
|
||||||
|
|
||||||
|
SET(VULKAN_LIB vulkan-1)
|
||||||
ELSE()
|
ELSE()
|
||||||
SET(OPENGL_LIB GL)
|
SET(OPENGL_LIB GL)
|
||||||
|
|
||||||
|
SET(VULKAN_LIB vulkan)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
add_definitions(-DMATH_USE_OPENGL)
|
add_definitions(-DMATH_USE_OPENGL)
|
||||||
|
@ -4,3 +4,5 @@ add_subdirectory(NullWindow)
|
|||||||
add_subdirectory(DirectGLRender)
|
add_subdirectory(DirectGLRender)
|
||||||
add_subdirectory(DirectGLTexture)
|
add_subdirectory(DirectGLTexture)
|
||||||
add_subdirectory(TextureSampler)
|
add_subdirectory(TextureSampler)
|
||||||
|
|
||||||
|
add_subdirectory(Vulkan)
|
||||||
|
4
example/Vulkan/CMakeLists.txt
Normal file
4
example/Vulkan/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
add_executable(VulkanTest main.cpp
|
||||||
|
VKInstance.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(VulkanTest PRIVATE ${ULRE} ${VULKAN_LIB})
|
52
example/Vulkan/VKInstance.cpp
Normal file
52
example/Vulkan/VKInstance.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include"VKInstance.h"
|
||||||
|
#include<hgl/type/DataType.h>
|
||||||
|
|
||||||
|
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
|
30
example/Vulkan/VKInstance.h
Normal file
30
example/Vulkan/VKInstance.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef HGL_GRAPH_VULKAN_INSTANCE_INCLUDE
|
||||||
|
#define HGL_GRAPH_VULKAN_INSTANCE_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/type/BaseString.h>
|
||||||
|
#include<vulkan/vulkan.h>
|
||||||
|
|
||||||
|
#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
|
13
example/Vulkan/main.cpp
Normal file
13
example/Vulkan/main.cpp
Normal file
@ -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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user