save code
This commit is contained in:
+28
-9
@@ -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;
|
||||
|
||||
|
||||
@@ -16,6 +16,18 @@
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#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 {
|
||||
std::optional<uint32_t> graphicsFamily;
|
||||
@@ -26,6 +38,7 @@ struct QueueFamilyIndices {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Application
|
||||
{
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user