diff --git a/lib/graphics_engine/include/ge_vulkan_driver.hpp b/lib/graphics_engine/include/ge_vulkan_driver.hpp index 48f3f3b73..cb5c1e08e 100644 --- a/lib/graphics_engine/include/ge_vulkan_driver.hpp +++ b/lib/graphics_engine/include/ge_vulkan_driver.hpp @@ -66,14 +66,10 @@ namespace GE SColor color=video::SColor(0,0,0,0)) { return true; } //! sets a viewport - virtual void setViewPort(const core::rect& area) {} + virtual void setViewPort(const core::rect& area); //! gets the area of the current viewport - virtual const core::rect& getViewPort() const - { - static core::rect unused; - return unused; - } + virtual const core::rect& getViewPort() const { return m_viewport; } //! updates hardware buffer if needed virtual bool updateHardwareBuffer(SHWBufferLink *HWBuffer) { return false; } @@ -432,6 +428,7 @@ namespace GE uint32_t m_image_index; video::SColor m_clear_color; core::rect m_clip; + core::rect m_viewport; video::ITexture* m_white_texture; video::ITexture* m_transparent_texture; diff --git a/lib/graphics_engine/src/ge_vulkan_2d_renderer.cpp b/lib/graphics_engine/src/ge_vulkan_2d_renderer.cpp index 7c8fe8953..32289676e 100644 --- a/lib/graphics_engine/src/ge_vulkan_2d_renderer.cpp +++ b/lib/graphics_engine/src/ge_vulkan_2d_renderer.cpp @@ -244,11 +244,15 @@ void GEVulkan2dRenderer::createGraphicsPipeline() color_blending.blendConstants[2] = 0.0f; color_blending.blendConstants[3] = 0.0f; - VkDynamicState dynamic_state = VK_DYNAMIC_STATE_SCISSOR; + std::array dynamic_state = + { + VK_DYNAMIC_STATE_SCISSOR, + VK_DYNAMIC_STATE_VIEWPORT + }; VkPipelineDynamicStateCreateInfo dynamic_state_info = {}; dynamic_state_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, - dynamic_state_info.dynamicStateCount = 1, - dynamic_state_info.pDynamicStates = &dynamic_state; + dynamic_state_info.dynamicStateCount = dynamic_state.size(), + dynamic_state_info.pDynamicStates = dynamic_state.data(); VkGraphicsPipelineCreateInfo pipeline_info = {}; pipeline_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; @@ -462,6 +466,15 @@ void GEVulkan2dRenderer::render() vkCmdBindIndexBuffer(g_vk->getCurrentCommandBuffer(), indices_buffer, 0, VK_INDEX_TYPE_UINT16); + VkViewport vp; + vp.x = g_vk->getViewPort().UpperLeftCorner.X; + vp.y = g_vk->getViewPort().UpperLeftCorner.Y; + vp.width = g_vk->getViewPort().getWidth(); + vp.height = g_vk->getViewPort().getHeight(); + vp.minDepth = 0; + vp.maxDepth = 1.0f; + vkCmdSetViewport(g_vk->getCurrentCommandBuffer(), 0, 1, &vp); + if (GEVulkanFeatures::supportsBindTexturesAtOnce()) { vkCmdBindDescriptorSets(g_vk->getCurrentCommandBuffer(), diff --git a/lib/graphics_engine/src/ge_vulkan_driver.cpp b/lib/graphics_engine/src/ge_vulkan_driver.cpp index ce18df572..8d659c072 100644 --- a/lib/graphics_engine/src/ge_vulkan_driver.cpp +++ b/lib/graphics_engine/src/ge_vulkan_driver.cpp @@ -460,6 +460,7 @@ GEVulkanDriver::GEVulkanDriver(const SIrrlichtCreationParameters& params, m_image_index = 0; m_clear_color = video::SColor(0); m_white_texture = NULL; + m_transparent_texture = NULL; createInstance(window); @@ -991,6 +992,7 @@ found_mode: ScreenSize.Width = m_swap_chain_extent.width; ScreenSize.Height = m_swap_chain_extent.height; m_clip = getFullscreenClip(); + setViewPort(core::recti(0, 0, ScreenSize.Width, ScreenSize.Height)); for (unsigned int i = 0; i < m_vk->swap_chain_images.size(); i++) { @@ -1739,6 +1741,16 @@ void GEVulkanDriver::draw2DImageBatch(const video::ITexture* tex, } } // draw2DImageBatch +// ---------------------------------------------------------------------------- +void GEVulkanDriver::setViewPort(const core::rect& area) +{ + core::rect vp = area; + core::rect rendert(0,0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height); + vp.clipAgainst(rendert); + if (vp.getHeight() > 0 && vp.getWidth() > 0) + m_viewport = vp; +} + } namespace irr