Skip to content

Commit 445afee

Browse files
committed
Add support for Vulkan-Hpp, GLM, and stb libraries with CMake configurations
- Introduced `FindVulkanHpp.cmake`, `Findglm.cmake`, and `Findstb.cmake` for handling Vulkan-Hpp, GLM, and stb dependencies respectively. - Added support for fetching missing dependencies using `FetchContent` if not found locally. - Updated Android `GameActivity` lifecycle code to improve memory handling and match Vulkan initialization requirements. - Enabled all-data cloud backup and device transfer with `data_extraction_rules.xml`. - Added essential Vulkan feature declarations in `AndroidManifest.xml`.
1 parent 00b1286 commit 445afee

22 files changed

+1367
-16147
lines changed

attachments/34_android.cpp

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
import 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";
7486
const std::string TEXTURE_PATH = "textures/viking_room.png";
7587
constexpr 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
78110
struct 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 {

attachments/35_gltf_ktx.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
import 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
#if defined(__ANDROID__)
@@ -31,26 +35,43 @@ import vulkan_hpp;
3135

3236
#if PLATFORM_ANDROID
3337
#include <android/log.h>
34-
#include <android_native_app_glue.h>
38+
#include <game-activity/native_app_glue/android_native_app_glue.h>
3539
#include <android/asset_manager.h>
3640
#include <android/asset_manager_jni.h>
3741

42+
// Declare and implement app_dummy function from native_app_glue
43+
extern "C" void app_dummy() {
44+
// This is a dummy function that does nothing
45+
// It's used to prevent the linker from stripping out the native_app_glue code
46+
}
47+
48+
// Define AAssetManager type for Android
49+
typedef AAssetManager AssetManagerType;
50+
3851
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "VulkanTutorial", __VA_ARGS__))
3952
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "VulkanTutorial", __VA_ARGS__))
4053
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "VulkanTutorial", __VA_ARGS__))
4154
#define LOG_INFO(msg) LOGI("%s", msg)
4255
#define LOG_ERROR(msg) LOGE("%s", msg)
4356
#else
57+
// Define AAssetManager type for non-Android platforms
58+
typedef void AssetManagerType;
59+
// Desktop-specific includes
4460
#define GLFW_INCLUDE_VULKAN
4561
#include <GLFW/glfw3.h>
4662

63+
// Define logging macros for Desktop
64+
#define LOGI(...) printf(__VA_ARGS__); printf("\n")
65+
#define LOGW(...) printf(__VA_ARGS__); printf("\n")
66+
#define LOGE(...) fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n")
4767
#define LOG_INFO(msg) std::cout << msg << std::endl
4868
#define LOG_ERROR(msg) std::cerr << msg << std::endl
4969
#endif
5070

5171
#define GLM_FORCE_RADIANS
5272
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
5373
#define GLM_ENABLE_EXPERIMENTAL
74+
#define GLM_FORCE_CXX11
5475
#include <glm/glm.hpp>
5576
#include <glm/gtc/matrix_transform.hpp>
5677
#include <glm/gtx/hash.hpp>
@@ -63,6 +84,26 @@ const std::string MODEL_PATH = "models/viking_room.glb";
6384
const std::string TEXTURE_PATH = "textures/viking_room.ktx2";
6485
constexpr int MAX_FRAMES_IN_FLIGHT = 2;
6586

87+
#if PLATFORM_ANDROID
88+
// Define VpProfileProperties structure if not already defined
89+
#ifndef VP_PROFILE_PROPERTIES_DEFINED
90+
#define VP_PROFILE_PROPERTIES_DEFINED
91+
struct VpProfileProperties {
92+
char name[256];
93+
uint32_t specVersion;
94+
};
95+
#endif
96+
97+
// Define Vulkan Profile constants
98+
#ifndef VP_KHR_ROADMAP_2022_NAME
99+
#define VP_KHR_ROADMAP_2022_NAME "VP_KHR_roadmap_2022"
100+
#endif
101+
102+
#ifndef VP_KHR_ROADMAP_2022_SPEC_VERSION
103+
#define VP_KHR_ROADMAP_2022_SPEC_VERSION 1
104+
#endif
105+
#endif
106+
66107
struct AppInfo {
67108
bool profileSupported = false;
68109
VpProfileProperties profile;
@@ -167,7 +208,7 @@ class VulkanApplication {
167208
case APP_CMD_INIT_WINDOW:
168209
if (app->window != nullptr) {
169210
appState->nativeWindow = app->window;
170-
auto* vulkanApp = static_cast<VulkanApplication*>(app->userData);
211+
auto* vulkanApp = static_cast<VulkanApplication*>(appState);
171212
vulkanApp->initVulkan();
172213
appState->initialized = true;
173214
}

0 commit comments

Comments
 (0)