'The same pipeline or shader is used while drawing multiple Objects in Vulkan

I created a for-loop, that creates descriptorSets(and descriptorLayouts etc.) and pipelines(which are indentical besides the shader) for each Object. I store the pipelines in vectors and descriporSets in nested vectors.

When i want to draw these objects it first binds the vertices and indices with one buffer which is the same buffer for all objects(it just uses an offset) it then iterates through the number of objects i have specified ("MODEL_ARRAY_SIZE") and for each object it gets the corresponding vector index:

VkBuffer vertexBuffers[] = { vertexBuffer };
VkDeviceSize offsets[] = { 0 };
vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets);

vkCmdBindIndexBuffer(commandBuffer, indexBuffer, 0, VK_INDEX_TYPE_UINT32);

for (unsigned int i = 0; i < MODEL_ARRAY_SIZE; i++)
{
    vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout[i], 0, 1, &descriptorSets[i][currentFrame], 0, nullptr);

    vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline[i]);

    vkCmdDrawIndexed(commandBuffer, static_cast<uint32_t>(indices.size()), 1, indicesOffsets[i], verticesOffsets[i], 0);
}

The problem is that the objects i draw use the same shader or pipeline (they have the same texture and so on..), which is wierd because it uses different shaders for each pipeline.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source