save code

This commit is contained in:
xsl
2025-10-16 22:16:34 +08:00
parent fcdbb4b8fd
commit 25fd704a3f
2 changed files with 41 additions and 9 deletions
+28 -9
View File
@@ -1,9 +1,11 @@
#include "Application.h"
#ifndef _WIN32
#ifdef _WIN32
#else
#include <game-activity/native_app_glue/android_native_app_glue.h>
#include <game-activity/GameActivity.h>
#include <vulkan/vulkan_android.h>
#include "../app/src/main/cpp/AndroidOut.h"
#endif
@@ -78,9 +80,9 @@ void Application::run()
cleanup();
}
#ifndef _WIN32
#ifdef _WIN32
#else
extern android_app* g_android_app
extern android_app* g_android_app;
#endif
void Application::createSurface() {
@@ -89,10 +91,6 @@ void Application::createSurface() {
throw std::runtime_error("failed to create window surface!");
}
#else
if (instance == VK_NULL_HANDLE || !g_android_app)
{
return VK_NULL_HANDLE;
}
VkSurfaceKHR surface{};
@@ -388,11 +386,32 @@ void Application::createLogicalDevice() {
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);
}
//vk::Extent2D choose_extent(vk::Extent2D request_extent,
// const vk::Extent2D& min_image_extent,
// const vk::Extent2D& max_image_extent,
// const vk::Extent2D& current_extent)
//{
// if (current_extent.width == 0xFFFFFFFF)
// {
// return request_extent;
// }
//
// if (request_extent.width < 1 || request_extent.height < 1)
// {
// return current_extent;
// }
//
// request_extent.width = clamp(request_extent.width, min_image_extent.width, max_image_extent.width);
// request_extent.height = clamp(request_extent.height, min_image_extent.height, max_image_extent.height);
//
// return request_extent;
//}
void Application::createSwapChain() {
// 选择交换链格式、颜色空间和分辨率
VkSurfaceFormatKHR surfaceFormat = { VK_FORMAT_B8G8R8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR };
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
VkExtent2D extent = { kWidth, kHeight };
VkExtent2D extent = { 0, 0 };
// 创建交换链
VkSwapchainCreateInfoKHR createInfo{};
@@ -401,7 +420,7 @@ void Application::createSwapChain() {
createInfo.minImageCount = 2; // 双缓冲
createInfo.imageFormat = surfaceFormat.format;
createInfo.imageColorSpace = surfaceFormat.colorSpace;
createInfo.imageExtent = extent;
//createInfo.imageExtent = choose_extent(extent, surface_capabilities.minImageExtent, surface_capabilities.maxImageExtent, surface_capabilities.currentExtent);;
createInfo.imageArrayLayers = 1;
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;