推送常量完成。

This commit is contained in:
xsl
2025-09-26 15:09:51 +08:00
parent 7d3427e4c0
commit 3c0dda0e28
2 changed files with 29 additions and 20 deletions
+28 -19
View File
@@ -563,31 +563,21 @@ void TextureLoading::build_command_buffers()
vkCmdBindDescriptorSets(draw_cmd_buffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout_bg, 0, 1, &descriptor_set_bg, 0, NULL);
vkCmdBindPipeline(draw_cmd_buffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.background);
// 在命令缓冲区记录时
float myFloatValue = 1.5f; // 你的 float 值
vkCmdPushConstants(
draw_cmd_buffers[i], // 命令缓冲区
pipeline_layout_bg, // 管线布局
VK_SHADER_STAGE_VERTEX_BIT, //
0, // 偏移量(字节)
sizeof(float), // 数据大小(字节)
&myFloatValue // 数据指针
);
vkCmdPushConstants(draw_cmd_buffers[i], pipeline_layout_bg, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float), &myFloatValue);
vkCmdDraw(draw_cmd_buffers[i], 6, 1, 0, 0);
//vkCmdBindDescriptorSets(draw_cmd_buffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptor_set, 0, NULL);
//vkCmdBindPipeline(draw_cmd_buffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid);
vkCmdBindDescriptorSets(draw_cmd_buffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptor_set, 0, NULL);
vkCmdBindPipeline(draw_cmd_buffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.solid);
//VkDeviceSize offsets[1] = { 0 };
//vkCmdBindVertexBuffers(draw_cmd_buffers[i], 0, 1, vertex_buffer->get(), offsets);
//vkCmdBindIndexBuffer(draw_cmd_buffers[i], index_buffer->get_handle(), 0, VK_INDEX_TYPE_UINT32);
//vkCmdDrawIndexed(draw_cmd_buffers[i], index_count, 1, 0, 0, 0);
VkDeviceSize offsets[1] = { 0 };
vkCmdBindVertexBuffers(draw_cmd_buffers[i], 0, 1, vertex_buffer->get(), offsets);
vkCmdBindIndexBuffer(draw_cmd_buffers[i], index_buffer->get_handle(), 0, VK_INDEX_TYPE_UINT32);
vkCmdDrawIndexed(draw_cmd_buffers[i], index_count, 1, 0, 0, 0);
draw_point_cloud(draw_cmd_buffers[i]);
draw_point_cloud_line(draw_cmd_buffers[i]);
//draw_point_cloud_line(draw_cmd_buffers[i]);
//draw_ui(draw_cmd_buffers[i]);
@@ -841,6 +831,14 @@ void TextureLoading::setup_descriptor_set_layout_point()
&descriptor_set_layout_point,
1);
VkPushConstantRange pushConstantRange{};
pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT; // 只在片段着色器中使用
pushConstantRange.offset = 0;
pushConstantRange.size = sizeof(float); // 或者 sizeof(PushConstants)
pipeline_layout_create_info.pushConstantRangeCount = 1;
pipeline_layout_create_info.pPushConstantRanges = &pushConstantRange;
VK_CHECK(vkCreatePipelineLayout(get_device().get_handle(), &pipeline_layout_create_info, nullptr, &pipeline_layout_point));
}
@@ -919,6 +917,14 @@ void TextureLoading::setup_descriptor_set_layout_point_line()
&descriptor_set_layout_point_line,
1);
VkPushConstantRange pushConstantRange{};
pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT; // 只在片段着色器中使用
pushConstantRange.offset = 0;
pushConstantRange.size = sizeof(float); // 或者 sizeof(PushConstants)
pipeline_layout_create_info.pushConstantRangeCount = 1;
pipeline_layout_create_info.pPushConstantRanges = &pushConstantRange;
VK_CHECK(vkCreatePipelineLayout(get_device().get_handle(), &pipeline_layout_create_info, nullptr, &pipeline_layout_point_line));
}
@@ -1440,6 +1446,8 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
return false;
}
myFloatValue = 1.0f;
// --- 加载前景纹理 (示例) ---
int width = 640;
int height = 480;
@@ -1448,7 +1456,7 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
size_t dataSize = testImage.size();
processWithVulkan(testImage.data(), width, height, rowStride, dataSize, texture_point);
#ifndef _WIN32
#ifdef _WIN32
width = 640;
height = 480;
rowStride = width * 4;
@@ -2143,6 +2151,7 @@ void TextureLoading::draw_point_cloud(VkCommandBuffer command_buffer)
VkDeviceSize offsets[] = { 0 };
vkCmdBindVertexBuffers(command_buffer, 0, 1, vertex_buffer_point->get(), offsets);
vkCmdPushConstants(command_buffer, pipeline_layout_bg, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float), &myFloatValue);
vkCmdDraw(command_buffer, point_count, 1, 0, 0); // 绘制 point_count 个顶点
}
@@ -220,7 +220,7 @@ public:
std::mutex mtx_mvp;
//void stop();
//void updateTexture();
float myFloatValue = 1.5f;
void demo1(float* pos);
};