Skip to content

Commit 532b268

Browse files
committed
VulkanTriangle adapt for Open/HarmonyOS
1 parent 02bf229 commit 532b268

4 files changed

Lines changed: 81 additions & 27 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ set(CMAKE_CXX_STANDARD 11)
1010
set(CMAKE_CXX_STANDARD_REQUIRED True)
1111
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
1212

13+
set(VULKAN_TRIANGLE_SOURCE_FILE ./VulkanTriangle.h ./VulkanTriangle.cpp VkString.cpp)
14+
1315
if(OHOS)
1416
# -D OHOS_VERSION=4 (HarmonyOS 4 use API 10 begain support Vulkan)
1517
# -D OHOS_VERSION=5 (HarmonyOS 5 use API 19)
@@ -21,19 +23,19 @@ if(OHOS)
2123
message("Use OHOS_VERSION = ${OHOS_VERSION}")
2224

2325
if(${OHOS_VERSION} EQUAL 4)
24-
add_library(${PROJECT_NAME} SHARED napi_init_10.cpp)
26+
add_library(${PROJECT_NAME} SHARED napi_init_10.cpp ${VULKAN_TRIANGLE_SOURCE_FILE})
2527
target_compile_definitions(${PROJECT_NAME} PUBLIC OHOS_API_VERSION=10)
2628
target_link_libraries(${PROJECT_NAME}
2729
PUBLIC native_vsync
2830
)
2931
elseif(${OHOS_VERSION} EQUAL 5)
30-
add_library(${PROJECT_NAME} SHARED napi_init_19.cpp)
32+
add_library(${PROJECT_NAME} SHARED napi_init_19.cpp ${VULKAN_TRIANGLE_SOURCE_FILE})
3133
target_compile_definitions(${PROJECT_NAME} PUBLIC OHOS_API_VERSION=19)
3234
target_link_libraries(${PROJECT_NAME}
3335
PUBLIC native_display_soloist
3436
)
3537
else(${OHOS_VERSION} EQUAL 6)
36-
add_library(${PROJECT_NAME} SHARED napi_init_20.cpp)
38+
add_library(${PROJECT_NAME} SHARED napi_init_20.cpp ${VULKAN_TRIANGLE_SOURCE_FILE})
3739
target_compile_definitions(${PROJECT_NAME} PUBLIC OHOS_API_VERSION=20)
3840
endif()
3941
target_compile_definitions(${PROJECT_NAME} PUBLIC OHOS)
@@ -46,7 +48,8 @@ if(OHOS)
4648
)
4749
else()
4850
#add_executable(${PROJECT_NAME} ./main.cpp VkString.cpp)
49-
add_executable(${PROJECT_NAME} ./VulkanTriangle.h ./VulkanTriangle.cpp VkString.cpp)
51+
#add_executable(${PROJECT_NAME} ./VulkanTriangle.h ./VulkanTriangle.cpp VkString.cpp)
52+
add_executable(${PROJECT_NAME} ${VULKAN_TRIANGLE_SOURCE_FILE})
5053
add_subdirectory(./thirdparty)
5154
add_dependencies(${PROJECT_NAME} glfw)
5255

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
> >研究尝试适配 `鸿蒙 6` 。
4040
>
4141
> >更新 `Vulkan` 头文件版本到 `1.4.352` 。
42+
>
43+
> >更新 `VulkanTriangle.h/cpp` 适配 `Open/HarmonyOS` 。
4244
4345
> **2026/5/26**
4446
>

VulkanTriangle.cpp

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
#include <VulkanTriangle.h>
22

3+
#include <stdio.h>
4+
void MyPrint(const char *format, ...)
5+
{
6+
va_list args;
7+
va_start(args, format);
8+
#if defined(USE_HARMONY_OS_PLATFORM)
9+
OH_LOG_Print(LOG_APP, LOG_DEBUG, 0x1, "VulkanTriangle", format, args);
10+
#else
11+
vprintf(format, args);
12+
#endif
13+
va_end(args);
14+
}
15+
316
static const uint32_t MY_VERT_SHADER_BIN[] = {0x07230203, 0x00010000, 0x000d000b, 0x0000004d, 0x00000000, 0x00020011, 0x00000001, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001, 0x0008000f, 0x00000000, 0x00000004, 0x6e69616d, 0x00000000, 0x00000017, 0x00000021, 0x0000003b, 0x00050048, 0x00000009, 0x00000000, 0x00000023, 0x00000000, 0x00030047, 0x00000009, 0x00000002, 0x00040047, 0x00000017, 0x0000000b, 0x0000002a, 0x00040047, 0x00000021, 0x0000001e, 0x00000000, 0x00050048, 0x00000039, 0x00000000, 0x0000000b, 0x00000000, 0x00050048, 0x00000039, 0x00000001, 0x0000000b, 0x00000001, 0x00050048, 0x00000039, 0x00000002, 0x0000000b, 0x00000003, 0x00050048, 0x00000039, 0x00000003, 0x0000000b, 0x00000004, 0x00030047, 0x00000039, 0x00000002, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00030016, 0x00000006, 0x00000020, 0x0003001e, 0x00000009, 0x00000006, 0x00040020, 0x0000000a, 0x00000009, 0x00000009, 0x0004003b, 0x0000000a, 0x0000000b, 0x00000009, 0x00040015, 0x0000000c, 0x00000020, 0x00000001, 0x0004002b, 0x0000000c, 0x0000000d, 0x00000000, 0x00040020, 0x0000000e, 0x00000009, 0x00000006, 0x00040017, 0x00000011, 0x00000006, 0x00000002, 0x0004002b, 0x00000006, 0x00000014, 0x00000000, 0x0005002c, 0x00000011, 0x00000015, 0x00000014, 0x00000014, 0x00040020, 0x00000016, 0x00000001, 0x0000000c, 0x0004003b, 0x00000016, 0x00000017, 0x00000001, 0x00020014, 0x00000019, 0x0004002b, 0x00000006, 0x0000001d, 0xbf000000, 0x0005002c, 0x00000011, 0x0000001e, 0x00000014, 0x0000001d, 0x00040017, 0x0000001f, 0x00000006, 0x00000003, 0x00040020, 0x00000020, 0x00000003, 0x0000001f, 0x0004003b, 0x00000020, 0x00000021, 0x00000003, 0x0004002b, 0x00000006, 0x00000022, 0x3f800000, 0x0006002c, 0x0000001f, 0x00000023, 0x00000022, 0x00000014, 0x00000014, 0x0004002b, 0x0000000c, 0x00000026, 0x00000001, 0x0004002b, 0x00000006, 0x0000002a, 0x3f000000, 0x0005002c, 0x00000011, 0x0000002b, 0x0000002a, 0x0000002a, 0x0006002c, 0x0000001f, 0x0000002c, 0x00000014, 0x00000022, 0x00000014, 0x0004002b, 0x0000000c, 0x0000002f, 0x00000002, 0x0005002c, 0x00000011, 0x00000033, 0x0000001d, 0x0000002a, 0x0006002c, 0x0000001f, 0x00000034, 0x00000014, 0x00000014, 0x00000022, 0x00040017, 0x00000035, 0x00000006, 0x00000004, 0x00040015, 0x00000036, 0x00000020, 0x00000000, 0x0004002b, 0x00000036, 0x00000037, 0x00000001, 0x0004001c, 0x00000038, 0x00000006, 0x00000037, 0x0006001e, 0x00000039, 0x00000035, 0x00000006, 0x00000038, 0x00000038, 0x00040020, 0x0000003a, 0x00000003, 0x00000039, 0x0004003b, 0x0000003a, 0x0000003b, 0x00000003, 0x00040020, 0x00000042, 0x00000003, 0x00000035, 0x00040017, 0x0000004a, 0x00000019, 0x00000002, 0x00050036, 0x00000002, 0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x00050041, 0x0000000e, 0x0000000f, 0x0000000b, 0x0000000d, 0x0004003d, 0x00000006, 0x00000010, 0x0000000f, 0x0004003d, 0x0000000c, 0x00000018, 0x00000017, 0x000500aa, 0x00000019, 0x0000001a, 0x00000018, 0x0000000d, 0x000300f7, 0x0000001c, 0x00000000, 0x000400fa, 0x0000001a, 0x0000001b, 0x00000024, 0x000200f8, 0x0000001b, 0x0003003e, 0x00000021, 0x00000023, 0x000200f9, 0x0000001c, 0x000200f8, 0x00000024, 0x000500aa, 0x00000019, 0x00000027, 0x00000018, 0x00000026, 0x000300f7, 0x00000029, 0x00000000, 0x000400fa, 0x00000027, 0x00000028, 0x0000002d, 0x000200f8, 0x00000028, 0x0003003e, 0x00000021, 0x0000002c, 0x000200f9, 0x00000029, 0x000200f8, 0x0000002d, 0x000500aa, 0x00000019, 0x00000030, 0x00000018, 0x0000002f, 0x000300f7, 0x00000032, 0x00000000, 0x000400fa, 0x00000030, 0x00000031, 0x00000032, 0x000200f8, 0x00000031, 0x0003003e, 0x00000021, 0x00000034, 0x000200f9, 0x00000032, 0x000200f8, 0x00000032, 0x00050050, 0x0000004a, 0x0000004b, 0x00000030, 0x00000030, 0x000600a9, 0x00000011, 0x0000004c, 0x0000004b, 0x00000033, 0x00000015, 0x000200f9, 0x00000029, 0x000200f8, 0x00000029, 0x000700f5, 0x00000011, 0x00000045, 0x0000002b, 0x00000028, 0x0000004c, 0x00000032, 0x000200f9, 0x0000001c, 0x000200f8, 0x0000001c, 0x000700f5, 0x00000011, 0x00000044, 0x0000001e, 0x0000001b, 0x00000045, 0x00000029, 0x0005008e, 0x00000011, 0x0000003e, 0x00000044, 0x00000010, 0x00050051, 0x00000006, 0x0000003f, 0x0000003e, 0x00000000, 0x00050051, 0x00000006, 0x00000040, 0x0000003e, 0x00000001, 0x00070050, 0x00000035, 0x00000041, 0x0000003f, 0x00000040, 0x00000014, 0x00000022, 0x00050041, 0x00000042, 0x00000043, 0x0000003b, 0x0000000d, 0x0003003e, 0x00000043, 0x00000041, 0x000100fd, 0x00010038};
417

518
static const uint32_t MY_FRAG_SHADER_BIN[] = {0x07230203, 0x00010000, 0x0008000b, 0x00000013, 0x00000000, 0x00020011, 0x00000001, 0x0006000b, 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001, 0x0007000f, 0x00000004, 0x00000004, 0x6e69616d, 0x00000000, 0x00000009, 0x0000000c, 0x00030010, 0x00000004, 0x00000007, 0x00030003, 0x00000002, 0x000001c2, 0x00040005, 0x00000004, 0x6e69616d, 0x00000000, 0x00050005, 0x00000009, 0x4374756f, 0x726f6c6f, 0x00000000, 0x00040005, 0x0000000c, 0x6f6c6f63, 0x00000072, 0x00040047, 0x00000009, 0x0000001e, 0x00000000, 0x00040047, 0x0000000c, 0x0000001e, 0x00000000, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00030016, 0x00000006, 0x00000020, 0x00040017, 0x00000007, 0x00000006, 0x00000004, 0x00040020, 0x00000008, 0x00000003, 0x00000007, 0x0004003b, 0x00000008, 0x00000009, 0x00000003, 0x00040017, 0x0000000a, 0x00000006, 0x00000003, 0x00040020, 0x0000000b, 0x00000001, 0x0000000a, 0x0004003b, 0x0000000b, 0x0000000c, 0x00000001, 0x0004002b, 0x00000006, 0x0000000e, 0x3f800000, 0x00050036, 0x00000002, 0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x0004003d, 0x0000000a, 0x0000000d, 0x0000000c, 0x00050051, 0x00000006, 0x0000000f, 0x0000000d, 0x00000000, 0x00050051, 0x00000006, 0x00000010, 0x0000000d, 0x00000001, 0x00050051, 0x00000006, 0x00000011, 0x0000000d, 0x00000002, 0x00070050, 0x00000007, 0x00000012, 0x0000000f, 0x00000010, 0x00000011, 0x0000000e, 0x0003003e, 0x00000009, 0x00000012, 0x000100fd, 0x00010038};
@@ -15,7 +28,7 @@ VulkanTriangle::VulkanTriangle()
1528

1629
driver.vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)GetProcAddress(library, "vkGetInstanceProcAddr");
1730
assert(driver.vkGetInstanceProcAddr && "vkGetInstanceProcAddr");
18-
#elif defined(USE_LINUX_PLATFORM)
31+
#elif defined(USE_LINUX_PLATFORM) || defined(USE_HARMONY_OS_PLATFORM)
1932
void *library = dlopen("libvulkan.so.1", RTLD_NOW | RTLD_LOCAL);
2033
if (!library)
2134
{
@@ -81,7 +94,7 @@ VulkanTriangle::VulkanTriangle()
8194
auto version_minor = VK_VERSION_MINOR(support_vulkan_version);
8295
auto version_patch = VK_VERSION_PATCH(support_vulkan_version);
8396

84-
std::cout << "Support Vulkan: " << version_major << "." << version_minor << "." << version_patch << std::endl;
97+
MyPrint("Support Vulkan: %o.%o.%o\n", version_major, version_minor, version_patch);
8598

8699
{
87100
driver.vkEnumerateInstanceLayerProperties = (PFN_vkEnumerateInstanceLayerProperties)driver.vkGetInstanceProcAddr(VK_NULL_HANDLE, "vkEnumerateInstanceLayerProperties");
@@ -112,7 +125,7 @@ VulkanTriangle::VulkanTriangle()
112125

113126
for (auto &layer_property : layer_properties)
114127
{
115-
std::cout << "[layer]: " << layer_property.layerName << " - (" << layer_property.description << ")" << std::endl;
128+
MyPrint("[layer]: %s - (%s)\n", layer_property.layerName, layer_property.description);
116129

117130
if (std::string(layer_property.layerName) == std::string("VK_LAYER_KHRONOS_validation"))
118131
{
@@ -135,7 +148,7 @@ VulkanTriangle::VulkanTriangle()
135148

136149
for (auto &extension_property : extension_properties)
137150
{
138-
std::cout << "[instance-extension]: " << extension_property.extensionName << std::endl;
151+
MyPrint("[instance-extension]: %s\n", extension_property.extensionName);
139152

140153
if (std::string(extension_property.extensionName) == std::string(VK_KHR_SURFACE_EXTENSION_NAME)) // "VK_KHR_surface"
141154
{
@@ -174,6 +187,11 @@ VulkanTriangle::VulkanTriangle()
174187
enabled_instance_extensions.push_back(extension_property.extensionName);
175188
}
176189
*/
190+
#elif defined(USE_HARMONY_OS_PLATFORM)
191+
else if (std::string(extension_property.extensionName) == std::string("VK_OHOS_surface")) // VK_OHOS_SURFACE_EXTENSION_NAME
192+
{
193+
enabled_instance_extensions.push_back(extension_property.extensionName);
194+
}
177195
#else
178196
throw std::runtime_error("Surface Not compatible with this platform!");
179197
#endif
@@ -208,7 +226,7 @@ VulkanTriangle::VulkanTriangle()
208226
}
209227
else
210228
{
211-
std::cout << "vkCreateInstance success" << std::endl;
229+
MyPrint("vkCreateInstance success\n");
212230
}
213231

214232
driver.vkDestroyInstance = (PFN_vkDestroyInstance)driver.vkGetInstanceProcAddr(this->instance, "vkDestroyInstance");
@@ -280,7 +298,7 @@ VulkanTriangle::VulkanTriangle()
280298
}
281299
else
282300
{
283-
std::cout << "Select Physical Device:" << target_physical_device_name << std::endl;
301+
MyPrint("Select Physical Device: %s\n", target_physical_device_name.c_str());
284302
}
285303

286304
uint32_t queue_family_count = 0;
@@ -325,7 +343,7 @@ VulkanTriangle::VulkanTriangle()
325343

326344
for (auto &extension_property : extension_properties)
327345
{
328-
std::cout << "[device-extension]: " << extension_property.extensionName << std::endl;
346+
MyPrint("[device-extension]: %s\n", extension_property.extensionName);
329347

330348
if (std::string(extension_property.extensionName) == std::string(VK_KHR_SWAPCHAIN_EXTENSION_NAME)) // "VK_KHR_swapchain"
331349
{
@@ -362,7 +380,7 @@ VulkanTriangle::VulkanTriangle()
362380
{
363381
throw std::runtime_error("vkCreateDevice failed!");
364382
}
365-
std::cout << "vkCreateDevice success" << std::endl;
383+
MyPrint("vkCreateDevice success\n");
366384

367385
{
368386
driver.vkCreateImage = (PFN_vkCreateImage)driver.vkGetDeviceProcAddr(this->device, "vkCreateImage");
@@ -568,8 +586,8 @@ VulkanTriangle::VulkanTriangle()
568586
}
569587
}
570588

571-
std::cout << "visible coherent memory index:" << visible_coherent_memory_index << std::endl;
572-
std::cout << "device local memory index:" << device_local_memory_index << std::endl;
589+
MyPrint("visible coherent memory index: %o\n", visible_coherent_memory_index);
590+
MyPrint("device local memory index: %o\n", device_local_memory_index);
573591

574592
if (visible_coherent_memory_index == std::numeric_limits<uint32_t>::max() || device_local_memory_index == std::numeric_limits<uint32_t>::max())
575593
{
@@ -611,10 +629,10 @@ VulkanTriangle::~VulkanTriangle()
611629
driver.vkDestroySurfaceKHR(this->instance, this->surface, nullptr);
612630

613631
driver.vkDestroyDevice(this->device, nullptr);
614-
std::cout << "vkDestroyDevice success" << std::endl;
632+
MyPrint("vkDestroyDevice success\n");
615633

616634
driver.vkDestroyInstance(this->instance, nullptr);
617-
std::cout << "vkDestroyInstance success" << std::endl;
635+
MyPrint("vkDestroyInstance success\n");
618636
}
619637

620638
void VulkanTriangle::CreateSurface(void *window)
@@ -624,7 +642,22 @@ void VulkanTriangle::CreateSurface(void *window)
624642
throw std::runtime_error("Can not get window when surface create!");
625643
}
626644

645+
#if defined(USE_WINDOWS_PLATFORM) || defined(USE_LINUX_PLATFORM)
627646
glfwCreateWindowSurface(this->instance, (GLFWwindow *)window, NULL, &this->surface);
647+
#elif defined(USE_HARMONY_OS_PLATFORM)
648+
driver.vkCreateSurfaceOHOS = (PFN_vkCreateSurfaceOHOS)driver.vkGetInstanceProcAddr(this->instance, "vkCreateSurfaceOHOS");
649+
assert(driver.vkCreateSurfaceOHOS && "vkCreateSurfaceOHOS");
650+
651+
VkSurfaceCreateInfoOHOS vk_surface_create_info_ohos = {};
652+
vk_surface_create_info_ohos.sType = VkStructureType::VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
653+
vk_surface_create_info_ohos.pNext = nullptr;
654+
vk_surface_create_info_ohos.flags = 0;
655+
vk_surface_create_info_ohos.window = (OHNativeWindow *)window;
656+
657+
driver.vkCreateSurfaceOHOS(this->instance, &vk_surface_create_info_ohos, nullptr, &this->surface);
658+
#else
659+
throw std::runtime_error("Not compatible with this platform!");
660+
#endif
628661

629662
driver.vkGetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR)driver.vkGetInstanceProcAddr(this->instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
630663
assert(driver.vkGetPhysicalDeviceSurfaceFormatsKHR && "vkGetPhysicalDeviceSurfaceFormatsKHR");
@@ -688,7 +721,7 @@ void VulkanTriangle::CreateSurface(void *window)
688721
throw std::runtime_error("Can not find a appropriate format for swapchain as color attachment!");
689722
}
690723

691-
std::cout << "swapchain use " << to_string(this->targetSwapchainFormat) << " format" << std::endl;
724+
MyPrint("swapchain use %s format\n", to_string(this->targetSwapchainFormat).c_str());
692725

693726
VkSwapchainCreateInfoKHR vk_swapchain_create_info_khr = {};
694727
vk_swapchain_create_info_khr.sType = VkStructureType::VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
@@ -1051,7 +1084,7 @@ void VulkanTriangle::CreateSurface(void *window)
10511084
VkResult pipeline_create_result = driver.vkCreateGraphicsPipelines(this->device, VK_NULL_HANDLE, 1, &vk_graphics_pipeline_create_info, nullptr, &this->pipeline);
10521085
if (pipeline_create_result != VkResult::VK_SUCCESS)
10531086
{
1054-
std::cout << "pipeline_create_result:" << pipeline_create_result << std::endl;
1087+
MyPrint("pipeline_create_result: %o\n", pipeline_create_result);
10551088
throw std::runtime_error("Can not create rendering pipeline!");
10561089
}
10571090

@@ -1123,7 +1156,8 @@ void VulkanTriangle::Draw(float time)
11231156
VkSurfaceCapabilitiesKHR vk_surface_capabilities_khr = {};
11241157
driver.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(this->targetPhysicalDevice, this->surface, &vk_surface_capabilities_khr);
11251158

1126-
//std::cout << "new (width = " << vk_surface_capabilities_khr.currentExtent.width << ", height = " << vk_surface_capabilities_khr.currentExtent.height << ")" << std::endl;
1159+
MyPrint("new (width = %g, height = %g)\n", vk_surface_capabilities_khr.currentExtent.width, vk_surface_capabilities_khr.currentExtent.height);
1160+
11271161
if (vk_surface_capabilities_khr.currentExtent.width == 0 || vk_surface_capabilities_khr.currentExtent.height == 0)
11281162
{
11291163
// TODO: not drawing
@@ -1356,6 +1390,7 @@ void VulkanTriangle::Draw(float time)
13561390
// Vulkan loop
13571391
}
13581392

1393+
#if defined(USE_WINDOWS_PLATFORM) || defined(USE_LINUX_PLATFORM)
13591394
int main()
13601395
{
13611396
if (!glfwInit())
@@ -1380,4 +1415,5 @@ int main()
13801415
}
13811416

13821417
return 0;
1383-
}
1418+
}
1419+
#endif

VulkanTriangle.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,47 @@
22

33
#if defined(_WIN16) || defined(_WIN32) || defined(_WIN64)
44
#define USE_WINDOWS_PLATFORM
5+
#elif defined(OHOS) // NOTE: must before linux marco for override linux statement
6+
#define USE_HARMONY_OS_PLATFORM
57
#elif defined(__linux) || defined(__linux__)
68
#define USE_LINUX_PLATFORM
79
#elif defined(__APPLE__)
810
#define USE_APPLE_PLATFORM
9-
#elif defined(OHOS)
10-
#define USE_HARMONY_OS
1111
#endif
1212

1313
#if defined(USE_WINDOWS_PLATFORM)
1414
#include <Windows.h>
15-
#elif defined(USE_LINUX_PLATFORM) || defined(USE_APPLE_PLATFORM)
15+
#elif defined(USE_LINUX_PLATFORM) || defined(USE_APPLE_PLATFORM) || defined(USE_HARMONY_OS_PLATFORM)
1616
#include <dlfcn.h>
1717
#include <stdlib.h>
18-
#elif defined(USE_HARMONY_OS)
1918
#endif
2019

2120
#include <vulkan/vulkan.h>
2221

22+
#if defined(USE_WINDOWS_PLATFORM) || defined(USE_LINUX_PLATFORM)
23+
#include <GLFW/glfw3.h>
24+
#endif
25+
26+
#if defined(USE_HARMONY_OS_PLATFORM)
27+
#include <native_window/external_window.h>
28+
#include <hilog/log.h>
29+
#endif
30+
2331
#include <assert.h>
2432
#include <iostream>
2533
#include <stdexcept>
2634
#include <vector>
2735

28-
#include <GLFW/glfw3.h>
29-
3036
#include <glm/ext.hpp>
3137

3238
#include "VkString.h"
3339

3440
#include <chrono>
3541

42+
#if defined(USE_HARMONY_OS_PLATFORM)
43+
#include <vulkan/vulkan_ohos.h>
44+
#endif
45+
3646
struct VkDriver
3747
{
3848
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = nullptr;
@@ -63,6 +73,9 @@ struct VkDriver
6373

6474
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR = nullptr;
6575

76+
#if defined(USE_HARMONY_OS_PLATFORM)
77+
PFN_vkCreateSurfaceOHOS vkCreateSurfaceOHOS = nullptr;
78+
#endif
6679
PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR = nullptr;
6780
PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR = nullptr;
6881
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR = nullptr;
@@ -188,7 +201,7 @@ class VulkanTriangle
188201
~VulkanTriangle();
189202

190203
void CreateSurface(void *window);
191-
//void ResizeSurface();
204+
// void ResizeSurface();
192205

193206
void Draw(float time);
194207
};

0 commit comments

Comments
 (0)