Swapchain recreation
- Swapchain的圖片跟image buffer有關(guān)聯(lián)。
- RenderPass的渲染目標須指定frame buffer。
- 由於surface大小改變,牽扯到image的需重新創(chuàng)立。
Dynamic viewport
//------------------- // Dynamic //------------------- // While most of the pipeline state needs to be baked into the pipeline state, a limited amount of // the state can actually be changed without recreating the pipeline at draw time. Examples are the // size of the viewport, line width and blend constants. // This will cause the configuration of these values to be ignored and you will be able (and required) // to specify the data at drawing time. std::vector<VkDynamicState> dynamicStates = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; VkPipelineDynamicStateCreateInfo dynamicState{}; dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; dynamicState.dynamicStateCount = static_cast<uint32_t>(dynamicStates.size()); dynamicState.pDynamicStates = dynamicStates.data(); VkPipelineViewportStateCreateInfo viewportState{}; viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; viewportState.viewportCount = 1; viewportState.scissorCount = 1; |
Window resize觸發(fā)
namespace ltn { class DisplayWindow { private: static void framebufferResizeCallback(GLFWwindow* window, int width, int height); }; } |
void ltn::DisplayWindow::init_window() { // Init window glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); this->window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "test window", nullptr, nullptr); glfwSetWindowUserPointer(window,this); glfwSetFramebufferSizeCallback(window, framebufferResizeCallback); } void ltn::DisplayWindow::framebufferResizeCallback(GLFWwindow* window, int width, int height) { auto ltnWindow = reinterpret_cast<DisplayWindow*>(glfwGetWindowUserPointer(window)); ltnWindow->SCR_WIDTH = width; ltnWindow->SCR_HEIGHT = height; ltnWindow->frameBufferedResized = true; } |
while (main_window.is_window_alive()) { glfwPollEvents(); // Detect resize : if (main_window.frameBufferedResized) { main_window.frameBufferedResized = false; vkDeviceWaitIdle(coreInstance.get_device()); swapchain->cleanup(); forward_renderer_pass->cleanup(); swapchain = std::make_unique<ltn::SwapChain>(coreInstance, main_window.SCR_WIDTH, main_window.SCR_HEIGHT); forward_renderer_pass = std::make_unique<ltn::Renderer>(coreInstance, *swapchain); /* pipeline = std::make_unique<ltn::GraphicsPipeline>(coreInstance, *swapchain); pipeline->create_pipleine( forward_renderer_pass->get_renderPass(), nullptr //gameobject.get_all_descriptorLayouts() ); */ } } |