我已经按照https://vulkan-tutorial.com上的教程进行了操作...我在不使用GLFW扩展的情况下创建了它.到目前为止,我正在进行"Swap chain Recreation",所有设置和渲染都正确.
但是,我似乎无法调整大小正常工作!
我已经迷上了XCB_RESIZE_REQUEST并且正在设置我的信息结构w/h,如下所示:
if (resize->width > 0) { info.width = resize->width; }
if (resize->height > 0) { info.height = resize->height; }
info.framebufferResized = true;
Run Code Online (Sandbox Code Playgroud)
导致(在下次drawFrame()调用中)recreateSwapchain()调用的原因:
if (res == VK_ERROR_OUT_OF_DATE_KHR || res == VK_SUBOPTIMAL_KHR || info.framebufferResized) {
info.framebufferResized = false;
recreateSwapchain();
} else if (res != VK_SUCCESS) {
throw runtime_error("failed to present swap chain image!");
}
recreateSwapchain() {
vkDeviceWaitIdle(info.device);
cleanupSwapchain();
querySwapchainSupport(info.physicalDevice);
createSwapchain();
createImageViews();
createRenderPass();
createGraphicsPipeline();
createFramebuffers();
createCommandBuffers();
}
Run Code Online (Sandbox Code Playgroud)
我做了一些调试,发现swapchainSupport.capabilities.minImageExtent.width(和高度)没有从初始值改变!..就是这个调用
querySwapchainSupport(VkPhysicalDevice physicalDevice) {
VkResult res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
physicalDevice, info.surface, &info.swapchainSupport.capabilities);
assert(res == VK_SUCCESS);
Run Code Online (Sandbox Code Playgroud)
不info.swapchainSupport.capabilities使用新窗口大小更新.
任何帮助或评论将不胜感激.
示例截图:
我不确定是否XCB_RESIZE_REQUEST是正确的等待事件.在我的示例中,我XCB_CONFIGURE_NOTIFY用来检查窗口大小调整事件,并在该事件之后查询表面功能,为我提供了新窗口大小作为预期的表面功能扩展区:
case XCB_CONFIGURE_NOTIFY:
{
const xcb_configure_notify_event_t *cfgEvent = (const xcb_configure_notify_event_t *)event;
if (((cfgEvent->width != width) || (cfgEvent->height != height)))
{
destWidth = cfgEvent->width;
destHeight = cfgEvent->height;
if ((destWidth > 0) && (destHeight > 0))
{
// Swap chain recreation ins done in this function
windowResize();
}
}
}
Run Code Online (Sandbox Code Playgroud)
您还需要在XCB窗口创建时添加附带的标志:
uint32_t value_list[32];
value_list[1] = ... | XCB_EVENT_MASK_STRUCTURE_NOTIFY...
xcb_create_window(connection,
...
value_list);
Run Code Online (Sandbox Code Playgroud)
这已经过测试,适用于许多不同的Linux实现和平台.
如果您需要一些帮助来启动和运行XCB,您可能需要查看我的Vulkan样本.有趣的部分在示例基类和 交换链头中.