android 表面,扩展,实例都创建成功
This commit is contained in:
+10
-10
@@ -44,7 +44,7 @@ void Application::createSurface() {
|
||||
}
|
||||
#else
|
||||
|
||||
VkSurfaceKHR surface{};
|
||||
//VkSurfaceKHR surface{};
|
||||
|
||||
VkAndroidSurfaceCreateInfoKHR info{VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
|
||||
|
||||
@@ -73,6 +73,7 @@ void Application::initVulkan()
|
||||
createCommandPool(); // 创建命令池
|
||||
createCommandBuffer(); // 创建命令缓冲区
|
||||
createSyncObjects(); // 创建同步对象
|
||||
inited = true;
|
||||
}
|
||||
|
||||
void Application::createImageViews() {
|
||||
@@ -259,6 +260,7 @@ void Application::createSwapChain() {
|
||||
|
||||
swapChainImageFormat = surfaceFormat.format;
|
||||
swapChainExtent = extent;
|
||||
MAX_FRAMES_IN_FLIGHT = imageCount;
|
||||
}
|
||||
|
||||
void Application::createPipelineLayout() {
|
||||
@@ -447,12 +449,11 @@ void Application::createCommandBuffer()
|
||||
|
||||
void Application::createSyncObjects()
|
||||
{
|
||||
int swapChainImageCount = swapChainImages.size();
|
||||
|
||||
imageAvailableSemaphores.resize(swapChainImageCount);
|
||||
renderFinishedSemaphores.resize(swapChainImageCount);
|
||||
imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
|
||||
renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
|
||||
inFlightFences.resize(MAX_FRAMES_IN_FLIGHT);
|
||||
imagesInFlight.resize(swapChainImageCount, VK_NULL_HANDLE);
|
||||
imagesInFlight.resize(MAX_FRAMES_IN_FLIGHT, VK_NULL_HANDLE);
|
||||
|
||||
VkSemaphoreCreateInfo semaphoreInfo{};
|
||||
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||
@@ -462,7 +463,7 @@ void Application::createSyncObjects()
|
||||
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
|
||||
|
||||
// 为每个交换链图像创建信号量
|
||||
for (size_t i = 0; i < swapChainImageCount; i++) {
|
||||
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
||||
if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAvailableSemaphores[i]) != VK_SUCCESS ||
|
||||
vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderFinishedSemaphores[i]) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create synchronization objects!");
|
||||
@@ -516,15 +517,14 @@ void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t im
|
||||
}
|
||||
}
|
||||
|
||||
void Application::drawFrame() {
|
||||
void Application::drawFrame()
|
||||
{
|
||||
// 1. 等待前一帧完成
|
||||
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
|
||||
|
||||
// 2. 获取交换链图像 - 使用当前帧的信号量
|
||||
uint32_t imageIndex;
|
||||
VkResult result = vkAcquireNextImageKHR(device, swapChain, UINT64_MAX,
|
||||
imageAvailableSemaphores[currentFrame],
|
||||
VK_NULL_HANDLE, &imageIndex);
|
||||
VkResult result = vkAcquireNextImageKHR(device, swapChain, UINT64_MAX,imageAvailableSemaphores[currentFrame],VK_NULL_HANDLE, &imageIndex);
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to acquire swap chain image!");
|
||||
|
||||
Reference in New Issue
Block a user