diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 7b8775573..e6a5f43b0 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -478,12 +478,19 @@ void VkRenderState::ApplyMatrices() void VkRenderState::ApplyVertexBuffers() { - VkBuffer vertexBuffers[] = { static_cast(mVertexBuffer)->mBuffer->buffer }; - VkDeviceSize offsets[] = { 0 }; - mCommandBuffer->bindVertexBuffers(0, 1, vertexBuffers, offsets); + if (mVertexBuffer != mLastVertexBuffer && mVertexBuffer) + { + VkBuffer vertexBuffers[] = { static_cast(mVertexBuffer)->mBuffer->buffer }; + VkDeviceSize offsets[] = { 0 }; + mCommandBuffer->bindVertexBuffers(0, 1, vertexBuffers, offsets); + mLastVertexBuffer = mVertexBuffer; + } - if (mIndexBuffer) + if (mIndexBuffer != mLastIndexBuffer && mIndexBuffer) + { mCommandBuffer->bindIndexBuffer(static_cast(mIndexBuffer)->mBuffer->buffer, 0, VK_INDEX_TYPE_UINT32); + mLastIndexBuffer = mIndexBuffer; + } } void VkRenderState::ApplyMaterial() @@ -502,20 +509,6 @@ void VkRenderState::ApplyMaterial() } } -void VkRenderState::Bind(int bindingpoint, uint32_t offset) -{ - if (bindingpoint == VIEWPOINT_BINDINGPOINT) - { - mViewpointOffset = offset; - } - else if (bindingpoint == LIGHTBUF_BINDINGPOINT) - { - mLightBufferOffset = offset; - } - - mDynamicSetChanged = true; -} - void VkRenderState::ApplyDynamicSet() { if (mViewpointOffset != mLastViewpointOffset || mLightBufferOffset != mLastLightBufferOffset) @@ -532,6 +525,20 @@ void VkRenderState::ApplyDynamicSet() mDynamicSetChanged = false; } +void VkRenderState::Bind(int bindingpoint, uint32_t offset) +{ + if (bindingpoint == VIEWPOINT_BINDINGPOINT) + { + mViewpointOffset = offset; + } + else if (bindingpoint == LIGHTBUF_BINDINGPOINT) + { + mLightBufferOffset = offset; + } + + mDynamicSetChanged = true; +} + void VkRenderState::EndRenderPass() { if (mCommandBuffer) @@ -546,5 +553,7 @@ void VkRenderState::EndRenderPass() mDataIndex = -1; mLastViewpointOffset = 0xffffffff; mLastLightBufferOffset = 0xffffffff; + mLastVertexBuffer = nullptr; + mLastIndexBuffer = nullptr; } } diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/rendering/vulkan/renderer/vk_renderstate.h index 99db9aebe..be3722e64 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/rendering/vulkan/renderer/vk_renderstate.h @@ -82,4 +82,7 @@ private: uint32_t mStreamDataOffset = 0; VSMatrix mIdentityMatrix; + + IVertexBuffer *mLastVertexBuffer = nullptr; + IIndexBuffer *mLastIndexBuffer = nullptr; };