@@ -36,18 +36,26 @@ import vulkan_hpp;
3636 #include < android/asset_manager.h>
3737 #include < android/asset_manager_jni.h>
3838
39+ // Define AAssetManager type for Android
40+ typedef AAssetManager AssetManagerType;
41+
3942 // Define logging macros for Android
4043 #define LOGI (...) ((void )__android_log_print(ANDROID_LOG_INFO, " VulkanTutorial" , __VA_ARGS__))
4144 #define LOGW (...) ((void )__android_log_print(ANDROID_LOG_WARN, " VulkanTutorial" , __VA_ARGS__))
4245 #define LOGE (...) ((void )__android_log_print(ANDROID_LOG_ERROR, " VulkanTutorial" , __VA_ARGS__))
4346 #define LOG_INFO (msg ) LOGI(" %s" , msg)
4447 #define LOG_ERROR (msg ) LOGE(" %s" , msg)
4548#else
49+ // Define AAssetManager type for non-Android platforms
50+ typedef void AssetManagerType;
4651 // Desktop-specific includes
4752 #define GLFW_INCLUDE_VULKAN
4853 #include < GLFW/glfw3.h>
4954
5055 // Define logging macros for Desktop
56+ #define LOGI (...) printf(__VA_ARGS__); printf(" \n " )
57+ #define LOGW (...) printf(__VA_ARGS__); printf(" \n " )
58+ #define LOGE (...) fprintf(stderr, __VA_ARGS__); fprintf(stderr, " \n " )
5159 #define LOG_INFO (msg ) std::cout << msg << std::endl
5260 #define LOG_ERROR (msg ) std::cerr << msg << std::endl
5361#endif
@@ -107,7 +115,7 @@ struct UniformBufferObject {
107115};
108116
109117// Cross-platform file reading function
110- std::vector<char > readFile (const std::string& filename, std::optional<AAssetManager *> assetManager = std::nullopt ) {
118+ std::vector<char > readFile (const std::string& filename, std::optional<AssetManagerType *> assetManager = std::nullopt ) {
111119#if PLATFORM_ANDROID
112120 // On Android, use asset manager if provided
113121 if (assetManager.has_value () && *assetManager != nullptr ) {
@@ -224,47 +232,13 @@ class HelloTriangleApplication {
224232 void cleanup () {
225233 if (initialized) {
226234 // Wait for device to finish operations
227- if (device) {
235+ if (* device) {
228236 device.waitIdle ();
229237 }
230238
231239 // Cleanup resources
232240 cleanupSwapChain ();
233241
234- // Cleanup other resources
235- for (size_t i = 0 ; i < MAX_FRAMES_IN_FLIGHT; i++) {
236- uniformBuffers[i] = nullptr ;
237- uniformBuffersMemory[i] = nullptr ;
238- }
239-
240- descriptorPool = nullptr ;
241- descriptorSetLayout = nullptr ;
242-
243- textureImageView = nullptr ;
244- textureImage = nullptr ;
245- textureImageMemory = nullptr ;
246- textureSampler = nullptr ;
247-
248- indexBuffer = nullptr ;
249- indexBufferMemory = nullptr ;
250- vertexBuffer = nullptr ;
251- vertexBufferMemory = nullptr ;
252-
253- for (size_t i = 0 ; i < MAX_FRAMES_IN_FLIGHT; i++) {
254- imageAvailableSemaphores[i] = nullptr ;
255- renderFinishedSemaphores[i] = nullptr ;
256- inFlightFences[i] = nullptr ;
257- }
258-
259- commandPool = nullptr ;
260- graphicsPipeline = nullptr ;
261- pipelineLayout = nullptr ;
262- renderPass = nullptr ;
263-
264- device = nullptr ;
265- surface = nullptr ;
266- instance = nullptr ;
267-
268242 initialized = false ;
269243 }
270244 }
@@ -273,7 +247,7 @@ class HelloTriangleApplication {
273247#if PLATFORM_ANDROID
274248 // Android-specific members
275249 android_app* androidApp = nullptr ;
276- AAssetManager * assetManager = nullptr ;
250+ AssetManagerType * assetManager = nullptr ;
277251#else
278252 // Desktop-specific members
279253 GLFWwindow* window = nullptr ;
@@ -466,7 +440,7 @@ class HelloTriangleApplication {
466440
467441 // Print device information
468442 vk::PhysicalDeviceProperties deviceProperties = physicalDevice.getProperties ();
469- LOGI (" Selected GPU: %s" , deviceProperties.deviceName );
443+ LOGI (" Selected GPU: %s" , deviceProperties.deviceName . data () );
470444 } else {
471445 throw std::runtime_error (" Failed to find a suitable GPU" );
472446 }
@@ -711,9 +685,9 @@ class HelloTriangleApplication {
711685
712686 // Load shader files using cross-platform function
713687#if PLATFORM_ANDROID
714- std::optional<AAssetManager *> optionalAssetManager = assetManager;
688+ std::optional<AssetManagerType *> optionalAssetManager = assetManager;
715689#else
716- std::optional<AAssetManager *> optionalAssetManager = std::nullopt ;
690+ std::optional<void *> optionalAssetManager = std::nullopt ;
717691#endif
718692 std::vector<char > vertShaderCode = readFile (" shaders/vert.spv" , optionalAssetManager);
719693 std::vector<char > fragShaderCode = readFile (" shaders/frag.spv" , optionalAssetManager);
@@ -882,7 +856,7 @@ class HelloTriangleApplication {
882856
883857#if PLATFORM_ANDROID
884858 // Load image from Android assets
885- std::optional<AAssetManager *> optionalAssetManager = assetManager;
859+ std::optional<AssetManagerType *> optionalAssetManager = assetManager;
886860 std::vector<char > imageData = readFile (TEXTURE_PATH, optionalAssetManager);
887861 pixels = stbi_load_from_memory (
888862 reinterpret_cast <const stbi_uc*>(imageData.data ()),
@@ -990,7 +964,7 @@ class HelloTriangleApplication {
990964
991965#if PLATFORM_ANDROID
992966 // Load OBJ file from Android assets
993- std::optional<AAssetManager *> optionalAssetManager = assetManager;
967+ std::optional<AssetManagerType *> optionalAssetManager = assetManager;
994968 std::vector<char > objData = readFile (MODEL_PATH, optionalAssetManager);
995969 std::string objString (objData.begin (), objData.end ());
996970 std::istringstream objStream (objString);
@@ -1076,8 +1050,13 @@ class HelloTriangleApplication {
10761050 void createUniformBuffers () {
10771051 vk::DeviceSize bufferSize = sizeof (UniformBufferObject);
10781052
1079- uniformBuffers.resize (MAX_FRAMES_IN_FLIGHT);
1080- uniformBuffersMemory.resize (MAX_FRAMES_IN_FLIGHT);
1053+ uniformBuffers.clear ();
1054+ uniformBuffersMemory.clear ();
1055+
1056+ for (size_t i = 0 ; i < MAX_FRAMES_IN_FLIGHT; i++) {
1057+ uniformBuffers.push_back (nullptr );
1058+ uniformBuffersMemory.push_back (nullptr );
1059+ }
10811060
10821061 for (size_t i = 0 ; i < MAX_FRAMES_IN_FLIGHT; i++) {
10831062 createBuffer (bufferSize, vk::BufferUsageFlagBits::eUniformBuffer, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent, uniformBuffers[i], uniformBuffersMemory[i]);
@@ -1211,7 +1190,8 @@ class HelloTriangleApplication {
12111190 }
12121191 };
12131192
1214- vk::ClearValue clearColor = {{{0 .0f , 0 .0f , 0 .0f , 1 .0f }}};
1193+ vk::ClearValue clearColor;
1194+ clearColor.color .float32 = std::array<float , 4 >{0 .0f , 0 .0f , 0 .0f , 1 .0f };
12151195 renderPassInfo.clearValueCount = 1 ;
12161196 renderPassInfo.pClearValues = &clearColor;
12171197
@@ -1256,6 +1236,9 @@ class HelloTriangleApplication {
12561236 return ;
12571237 }
12581238
1239+ // Update uniform buffer with current transformation
1240+ updateUniformBuffer (currentFrame);
1241+
12591242 device.resetFences ({*inFlightFences[currentFrame]});
12601243
12611244 commandBuffers[currentFrame].reset ();
0 commit comments