简体   繁体   English

vulkan:如何使用一个具有不同偏移量的顶点缓冲区?

[英]vulkan: how to use one vertex buffer with different offsets?

I've created a vertex buffer in the "load vulkan" stage of my program. 我已经在程序的“ load vulkan”阶段创建了一个顶点缓冲区。 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. 用于测试的顶点缓冲区的静态大小为8个顶点,而索引缓冲区的静态大小为12个索引。

I'm tryin' now to load a first model instance (4 vertices, 6 indices), which works. 我现在正在尝试加载第一个模型实例(4个顶点,6个索引),它可以工作。 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). (这是一个正方形)然后,我尝试加载另一个模型实例(再次是4个顶点,6个索引)(另一个正方形)。

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. 为了进行测试,我还将其更改为白色,假设uv颜色可以为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 游戏设计,加载模型实例:gm_update.cpp

engine stuff, vulkan: de_core.cpp vulkan引擎内容:de_core.cpp

vertex shader: shaders/stage.vert 顶点着色器:shaders / stage.vert

fragment shader: shaders/stage.frag 片段着色器: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 但我真的不知道错误的确切位置在de_core.cpp中

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. 绑定缓冲区时,请确保每个绘制调用仅调用vkBindVertexBuffers一次。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM