Use dynamic viewport for GEVulkan2dRenderer

This commit is contained in:
Benau 2022-03-24 16:37:34 +08:00
parent 23cd67f45c
commit 68eb70e7e6
3 changed files with 31 additions and 9 deletions

View File

@ -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<s32>& area) {}
virtual void setViewPort(const core::rect<s32>& area);
//! gets the area of the current viewport
virtual const core::rect<s32>& getViewPort() const
{
static core::rect<s32> unused;
return unused;
}
virtual const core::rect<s32>& 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<s32> m_clip;
core::rect<s32> m_viewport;
video::ITexture* m_white_texture;
video::ITexture* m_transparent_texture;

View File

@ -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<VkDynamicState, 2> 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(),

View File

@ -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<s32>& area)
{
core::rect<s32> vp = area;
core::rect<s32> rendert(0,0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height);
vp.clipAgainst(rendert);
if (vp.getHeight() > 0 && vp.getWidth() > 0)
m_viewport = vp;
}
}
namespace irr