完成在Android上渲染三角形
This commit is contained in:
+6
-32
@@ -181,47 +181,22 @@ void Application::createLogicalDevice() {
|
||||
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);
|
||||
}
|
||||
|
||||
inline VkExtent2D choose_extent(
|
||||
VkExtent2D request_extent,
|
||||
const VkExtent2D &min_image_extent,
|
||||
const VkExtent2D &max_image_extent,
|
||||
const VkExtent2D ¤t_extent)
|
||||
{
|
||||
if (current_extent.width == 0xFFFFFFFF)
|
||||
{
|
||||
return request_extent;
|
||||
}
|
||||
|
||||
if (request_extent.width < 1 || request_extent.height < 1)
|
||||
{
|
||||
logOut << "(Swapchain) Image extent ("<< request_extent.width << ", " << request_extent.height << ") not supported. Selecting ("<< current_extent.width << ", " << current_extent.height << ")." << std::endl;
|
||||
return current_extent;
|
||||
}
|
||||
|
||||
request_extent.width = std::max(request_extent.width, min_image_extent.width);
|
||||
request_extent.width = std::min(request_extent.width, max_image_extent.width);
|
||||
|
||||
request_extent.height = std::max(request_extent.height, min_image_extent.height);
|
||||
request_extent.height = std::min(request_extent.height, max_image_extent.height);
|
||||
|
||||
return request_extent;
|
||||
}
|
||||
|
||||
void Application::createSwapChain() {
|
||||
// 选择交换链格式、颜色空间和分辨率
|
||||
VkSurfaceFormatKHR surfaceFormat = { VK_FORMAT_B8G8R8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR };
|
||||
VkSurfaceFormatKHR surfaceFormat = { VK_FORMAT_R8G8B8A8_SRGB, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR };
|
||||
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||
VkExtent2D extent = { 1, 1 };
|
||||
|
||||
VkSurfaceCapabilitiesKHR surface_capabilities{};
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(this->physicalDevice, this->surface, &surface_capabilities);
|
||||
|
||||
extent = choose_extent(extent, surface_capabilities.minImageExtent, surface_capabilities.maxImageExtent, surface_capabilities.currentExtent);
|
||||
VkExtent2D extent = surface_capabilities.currentExtent;
|
||||
|
||||
uint32_t imageCount = 2;
|
||||
// 创建交换链
|
||||
VkSwapchainCreateInfoKHR createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
createInfo.surface = surface;
|
||||
createInfo.minImageCount = 2; // 双缓冲
|
||||
createInfo.minImageCount = imageCount; // 双缓冲
|
||||
createInfo.imageFormat = surfaceFormat.format;
|
||||
createInfo.imageColorSpace = surfaceFormat.colorSpace;
|
||||
createInfo.imageExtent = extent;
|
||||
@@ -252,8 +227,7 @@ void Application::createSwapChain() {
|
||||
throw std::runtime_error("failed to create swap chain!");
|
||||
}
|
||||
|
||||
// 获取交换链图像
|
||||
uint32_t imageCount;
|
||||
|
||||
vkGetSwapchainImagesKHR(device, swapChain, &imageCount, nullptr);
|
||||
swapChainImages.resize(imageCount);
|
||||
vkGetSwapchainImagesKHR(device, swapChain, &imageCount, swapChainImages.data());
|
||||
|
||||
Reference in New Issue
Block a user