1313
1414import vulkan_hpp;
1515#include < vulkan/vk_platform.h>
16+ #if defined(__ANDROID__)
17+ #include < vulkan/vulkan_core.h>
18+ #include < vulkan/vulkan_android.h>
19+ #endif
1620#include < vulkan/vulkan_profiles.hpp>
1721
1822// Platform detection
@@ -22,6 +26,7 @@ import vulkan_hpp;
2226 #define PLATFORM_DESKTOP 1
2327#endif
2428
29+
2530#define STB_IMAGE_IMPLEMENTATION
2631#include < stb_image.h>
2732
@@ -32,10 +37,16 @@ import vulkan_hpp;
3237#if PLATFORM_ANDROID
3338 // Android-specific includes
3439 #include < android/log.h>
35- #include < android_native_app_glue.h>
40+ #include < game-activity/native_app_glue/ android_native_app_glue.h>
3641 #include < android/asset_manager.h>
3742 #include < android/asset_manager_jni.h>
3843
44+ // Declare and implement app_dummy function from native_app_glue
45+ extern " C" void app_dummy () {
46+ // This is a dummy function that does nothing
47+ // It's used to prevent the linker from stripping out the native_app_glue code
48+ }
49+
3950 // Define AAssetManager type for Android
4051 typedef AAssetManager AssetManagerType;
4152
@@ -63,6 +74,7 @@ import vulkan_hpp;
6374#define GLM_FORCE_RADIANS
6475#define GLM_FORCE_DEPTH_ZERO_TO_ONE
6576#define GLM_ENABLE_EXPERIMENTAL
77+ #define GLM_FORCE_CXX11
6678#include < glm/glm.hpp>
6779#include < glm/gtc/matrix_transform.hpp>
6880#include < glm/gtx/hash.hpp>
@@ -74,6 +86,26 @@ const std::string MODEL_PATH = "models/viking_room.obj";
7486const std::string TEXTURE_PATH = " textures/viking_room.png" ;
7587constexpr int MAX_FRAMES_IN_FLIGHT = 2 ;
7688
89+ #if PLATFORM_ANDROID
90+ // Define VpProfileProperties structure if not already defined
91+ #ifndef VP_PROFILE_PROPERTIES_DEFINED
92+ #define VP_PROFILE_PROPERTIES_DEFINED
93+ struct VpProfileProperties {
94+ char name[256 ];
95+ uint32_t specVersion;
96+ };
97+ #endif
98+
99+ // Define Vulkan Profile constants
100+ #ifndef VP_KHR_ROADMAP_2022_NAME
101+ #define VP_KHR_ROADMAP_2022_NAME " VP_KHR_roadmap_2022"
102+ #endif
103+
104+ #ifndef VP_KHR_ROADMAP_2022_SPEC_VERSION
105+ #define VP_KHR_ROADMAP_2022_SPEC_VERSION 1
106+ #endif
107+ #endif
108+
77109// Application info structure to store profile support flags
78110struct AppInfo {
79111 bool profileSupported = false ;
@@ -170,7 +202,8 @@ class HelloTriangleApplication {
170202 HelloTriangleApplication (android_app* app) : androidApp(app) {
171203 androidApp->userData = this ;
172204 androidApp->onAppCmd = handleAppCommand;
173- androidApp->onInputEvent = handleInputEvent;
205+ // Note: onInputEvent is no longer a member of android_app in the current NDK version
206+ // Input events are now handled differently
174207
175208 // Get the asset manager
176209 assetManager = androidApp->activity ->assetManager ;
@@ -190,7 +223,7 @@ class HelloTriangleApplication {
190223 // Wait for app to initialize
191224 int events;
192225 android_poll_source* source;
193- if (ALooper_pollAll (0 , nullptr , &events, (void **)&source) >= 0 ) {
226+ if (ALooper_pollOnce (0 , nullptr , &events, (void **)&source) >= 0 ) {
194227 if (source != nullptr ) {
195228 source->process (androidApp, source);
196229 }
@@ -381,14 +414,16 @@ class HelloTriangleApplication {
381414
382415#if PLATFORM_ANDROID
383416 // Create Android surface
417+ VkAndroidSurfaceCreateInfoKHR createInfo = {
418+ .sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
419+ .pNext = nullptr ,
420+ .flags = 0 ,
421+ .window = androidApp->window
422+ };
423+
384424 VkResult result = vkCreateAndroidSurfaceKHR (
385425 *instance,
386- &(VkAndroidSurfaceCreateInfoKHR{
387- .sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
388- .pNext = nullptr ,
389- .flags = 0 ,
390- .window = androidApp->window
391- }),
426+ &createInfo,
392427 nullptr ,
393428 &_surface
394429 );
@@ -456,14 +491,31 @@ class HelloTriangleApplication {
456491
457492 // Check if the profile is supported
458493 VkBool32 supported = VK_FALSE;
459- VkResult result = vpGetPhysicalDeviceProfileSupport (
494+
495+ #ifdef PLATFORM_ANDROID
496+ // Create a vp::ProfileDesc from our VpProfileProperties
497+ vp::ProfileDesc profileDesc = {
498+ appInfo.profile .name ,
499+ appInfo.profile .specVersion
500+ };
501+
502+ // Use vp::GetProfileSupport instead of vpGetPhysicalDeviceProfileSupport
503+ bool result = vp::GetProfileSupport (
504+ *physicalDevice, // Pass the physical device directly
505+ &profileDesc, // Pass the profile description
506+ &supported // Output parameter for support status
507+ );
508+ #else
509+ VkResult vk_result = vpGetPhysicalDeviceProfileSupport (
460510 *instance,
461511 *physicalDevice,
462512 &appInfo.profile ,
463513 &supported
464- );
514+ );
515+ bool result = vk_result == VK_SUCCESS;
516+ #endif
465517
466- if (result == VK_SUCCESS && supported == VK_TRUE) {
518+ if (result && supported == VK_TRUE) {
467519 appInfo.profileSupported = true ;
468520 LOGI (" Using KHR roadmap 2022 profile" );
469521 } else {
0 commit comments