- fix model rendering glitch

This commit is contained in:
Magnus Norddahl 2019-04-09 18:19:14 +02:00
parent d413581ee2
commit 85b754b9ca
2 changed files with 9 additions and 4 deletions

View file

@ -476,12 +476,16 @@ void VkRenderState::ApplyMatrices()
void VkRenderState::ApplyVertexBuffers()
{
if (mVertexBuffer != mLastVertexBuffer && mVertexBuffer)
if ((mVertexBuffer != mLastVertexBuffer || mVertexOffsets[0] != mLastVertexOffsets[0] || mVertexOffsets[1] != mLastVertexOffsets[1]) && mVertexBuffer)
{
VkBuffer vertexBuffers[] = { static_cast<VKVertexBuffer*>(mVertexBuffer)->mBuffer->buffer };
VkDeviceSize offsets[] = { 0 };
mCommandBuffer->bindVertexBuffers(0, 1, vertexBuffers, offsets);
auto vkbuf = static_cast<VKVertexBuffer*>(mVertexBuffer);
const auto &format = GetVulkanFrameBuffer()->GetRenderPassManager()->VertexFormats[vkbuf->VertexFormat];
VkBuffer vertexBuffers[2] = { vkbuf->mBuffer->buffer, vkbuf->mBuffer->buffer };
VkDeviceSize offsets[] = { mVertexOffsets[0] * format.Stride, mVertexOffsets[1] * format.Stride };
mCommandBuffer->bindVertexBuffers(0, 2, vertexBuffers, offsets);
mLastVertexBuffer = mVertexBuffer;
mLastVertexOffsets[0] = mVertexOffsets[0];
mLastVertexOffsets[1] = mVertexOffsets[1];
}
if (mIndexBuffer != mLastIndexBuffer && mIndexBuffer)

View file

@ -105,6 +105,7 @@ protected:
VSMatrix mIdentityMatrix;
int mLastVertexOffsets[2] = { 0, 0 };
IVertexBuffer *mLastVertexBuffer = nullptr;
IIndexBuffer *mLastIndexBuffer = nullptr;