java - LWJGL Vulkan:添加第二个顶点缓冲区时未绘制任何内容
问题描述
我用 lwjgl 制作了一个小程序,它使用 Vulkan 显示一个彩色三角形,起初我通过单个顶点缓冲区(颜色 + 位置)将所有需要的数据发送到我的着色器。虽然知道仅使用一个顶点缓冲区是最佳实践,但我仍然想尝试通过 2 个不同的顶点缓冲区发送位置和颜色
为了添加我的第二个顶点缓冲区,我创建它的方式与创建第一个顶点缓冲区的方式相同,然后我添加了一个绑定并将第二个属性归因于它,如下所示:
VkVertexInputBindingDescription.Buffer bindingDescriptor = VkVertexInputAttributeDescription.calloc(2)
.binding(0)
.stride(2 * 4)
.inputRate(VK_VERTEX_INPUT_RATE_VERTEX);
//I added this
bindingDescriptor.binding(1)
.stride(3 * 4)
.inputRate(VK_VERTEX_INPUT_RATE_VERTEX);
VkVertexInputAttributeDescription.Buffer attributeDescription = VkVertexInputAttributeDescription.calloc(2)
.get(0)
.binding(0)
.location(0)
.format(VK_FORMAT_R32G32_SFLOAT)
.offset(0);
attributeDescription.get(1)
//changed the binding from 0 to 1
.binding(1)
.location(1)
.format(VK_FORMAT_R32G32B32_SFLOAT)
.offset(0);
然后在渲染通道的定义中,我将第二个顶点缓冲区添加到提交的缓冲区中,vkCmdBindVertexBuffers
如下所示:
LongBuffer offsets = memAllocLong(2);
offsets.put(0, 0L);
//added this
offsets.put(1, 0L);
LongBuffer pBuffers = memAllocLong(2);
pBuffers.put(0, verticesBuf);
//added this
pBuffers.put(1, colorBuf);
vkCmdBindVertexBuffers(renderCommandBuffers[i], 0, pBuffers, offsets);
问题是,当我添加第二个顶点缓冲区时,不再显示任何内容,唯一剩下的就是我的背景颜色我错过了什么吗?使用多个顶点缓冲区有什么特别的事情要做吗?
解决方案
推荐阅读
- embed - 他们是如何通过 youtube 做到这一点的
- laravel - 当'to'未被覆盖时,Laravel 电子邮件发送不起作用
- python - 通过 rs485 到 Arduino 的 RPi 未接收到所有字符
- android - 如何使用 API 26 或更高版本访问 android 中的帐户名称?
- php - PHP 中的服务器端电子邮件已存在验证
- javascript - 与提示和警报混淆
- logging - logger.getAppender 在哪里(从 log4j 迁移到 slf4j+log4j)
- python - 在 Python 3 中将多个条目解压缩为“字段”的字符串
- coldfusion - Twilio - 在漫长的过程中播放音乐
- ios - 在 Swift 中使用 DispatchQueue 进行同步处理