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" #include "Application.h"
#ifndef _WIN32
#ifdef _WIN32
#else #else
#include <game-activity/native_app_glue/android_native_app_glue.h> #include <game-activity/native_app_glue/android_native_app_glue.h>
#include <game-activity/GameActivity.h> #include <game-activity/GameActivity.h>
#include <vulkan/vulkan_android.h>
#include "../app/src/main/cpp/AndroidOut.h" #include "../app/src/main/cpp/AndroidOut.h"
#endif #endif
@@ -78,9 +80,9 @@ void Application::run()
cleanup(); cleanup();
} }
#ifndef _WIN32 #ifdef _WIN32
#else #else
extern android_app* g_android_app extern android_app* g_android_app;
#endif #endif
void Application::createSurface() { void Application::createSurface() {
@@ -89,10 +91,6 @@ void Application::createSurface() {
throw std::runtime_error("failed to create window surface!"); throw std::runtime_error("failed to create window surface!");
} }
#else #else
if (instance == VK_NULL_HANDLE || !g_android_app)
{
return VK_NULL_HANDLE;
}
VkSurfaceKHR surface{}; VkSurfaceKHR surface{};
@@ -388,11 +386,32 @@ void Application::createLogicalDevice() {
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue); 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() { void Application::createSwapChain() {
// 选择交换链格式、颜色空间和分辨率 // 选择交换链格式、颜色空间和分辨率
VkSurfaceFormatKHR surfaceFormat = { VK_FORMAT_B8G8R8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR }; VkSurfaceFormatKHR surfaceFormat = { VK_FORMAT_B8G8R8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR };
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR; VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
VkExtent2D extent = { kWidth, kHeight }; VkExtent2D extent = { 0, 0 };
// 创建交换链 // 创建交换链
VkSwapchainCreateInfoKHR createInfo{}; VkSwapchainCreateInfoKHR createInfo{};
@@ -401,7 +420,7 @@ void Application::createSwapChain() {
createInfo.minImageCount = 2; // 双缓冲 createInfo.minImageCount = 2; // 双缓冲
createInfo.imageFormat = surfaceFormat.format; createInfo.imageFormat = surfaceFormat.format;
createInfo.imageColorSpace = surfaceFormat.colorSpace; 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.imageArrayLayers = 1;
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+13
View File
@@ -16,6 +16,18 @@
#include <vector> #include <vector>
#include <optional> #include <optional>
#include <set> #include <set>
#include <assert.h>
#include <vulkan/vulkan_structs.hpp>
#define VK_CHECK(x) \
do \
{ \
VkResult err = x; \
if (err) \
{ \
assert(false); \
} \
} while (0)
struct QueueFamilyIndices { struct QueueFamilyIndices {
std::optional<uint32_t> graphicsFamily; std::optional<uint32_t> graphicsFamily;
@@ -26,6 +38,7 @@ struct QueueFamilyIndices {
} }
}; };
class Application class Application
{ {
private: private: