0
votes

I've created a vertex buffer in the "load vulkan" stage of my program. it's ment to be a buffer for all vertices, no matter what model instances may use them. My application should be able to load vertices during run time at any time, using different offsets for the vertex buffer (and of course index buffer).

for testing the vertex buffer has a static size of 8 vertices, and the index buffer has a static size of 12 indices.

I'm tryin' now to load a first model instance (4 vertices, 6 indices), which works. I can see a result on the screen. (it's a square) Then I'm tryin' to load another model instance (again 4 vertices, 6 indices) (another square).

problem: the second model instance wouldn't show up on the screen. I checked the offsets for vertex buffer and index buffer. they seem right. i know that there is no texture image for the second instance yet, however there should be a white square at least, 'cause default mix color in the shaders is white. default clear color for the screen is black. for testing I also changed it to white, assuming, that uv colors could be 0, 0, 0.

so why isn't the second instance visible on the screen? I read some articles and some suggest to "execute the command buffer" after updating the vertex buffer. aside from understanding what that means, it wouldn't make sense really, 'cause both instances are created during run time, and the first one works!

so any help please?

you can find the source code here:

project: main function

game design, loading model instances: gm_update.cpp

engine stuff, vulkan: de_core.cpp

vertex shader: shaders/stage.vert

fragment shader: shaders/stage.frag

you can find all source files in that folder. just change the file name. I wanted to post code samples. but I don't know really where exactly the error is located in de_core.cpp

1
Please don't post your code as a link but a minimal reproducible example in your question that reproduces your problem. - πάντα ῥεῖ
Yea, you are making too many assumptions. One other benefit of having minimal example is that you can easily experiment with new features like that. ;; But I see in your code VkDeviceSize offsets[] = {0}; before vkCmdBindVertexBuffers(), and vkCmdBindIndexBuffer()::offset = 0 too, so that looks you are not using offsets yet at all. - krOoze

1 Answers

0
votes

The link to your source code isn't working for me but I have a suggestion. When binding the buffers make sure you only call vkBindVertexBuffers once per draw call. it replaces the currently bound buffers. If you need to bind multiple buffers do something like this

vkBuffer buffers[2] = {buffer1, buffer2};
vkDeviceSize offsets[2] = {0, 0};//offsets of buffers
vkbindVertexBuffers(commandBuffer, firstInputBindingToUpdate(probably 0), 2, buffers, offsets);