至少点是画出来了。
This commit is contained in:
@@ -584,7 +584,7 @@ void TextureLoading::build_command_buffers()
|
||||
|
||||
//vkCmdDrawIndexed(draw_cmd_buffers[i], index_count, 1, 0, 0, 0);
|
||||
|
||||
//draw_point_cloud(draw_cmd_buffers[i]);
|
||||
draw_point_cloud(draw_cmd_buffers[i]);
|
||||
draw_point_cloud_line(draw_cmd_buffers[i]);
|
||||
|
||||
//draw_ui(draw_cmd_buffers[i]);
|
||||
@@ -881,11 +881,11 @@ void TextureLoading::setup_descriptor_set_layout_point_line()
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
VK_SHADER_STAGE_VERTEX_BIT,
|
||||
0),
|
||||
// Binding 1 : Fragment shader image sampler
|
||||
vkb::initializers::descriptor_set_layout_binding(
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
1)
|
||||
// Binding 1 : Fragment shader image sampler
|
||||
vkb::initializers::descriptor_set_layout_binding(
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
1)
|
||||
};
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo descriptor_layout =
|
||||
@@ -930,13 +930,13 @@ void TextureLoading::setup_descriptor_set_point_line()
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
0,
|
||||
&buffer_descriptor),
|
||||
// Binding 1 : Fragment shader texture sampler
|
||||
// Fragment shader: layout (binding = 1) uniform sampler2D samplerColor;
|
||||
vkb::initializers::write_descriptor_set(
|
||||
descriptor_set_point,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, // The descriptor set will use a combined image sampler (sampler and image could be split)
|
||||
1, // Shader binding point 1
|
||||
&image_descriptor) // Pointer to the descriptor image for our texture
|
||||
// Binding 1 : Fragment shader texture sampler
|
||||
// Fragment shader: layout (binding = 1) uniform sampler2D samplerColor;
|
||||
vkb::initializers::write_descriptor_set(
|
||||
descriptor_set_point,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, // The descriptor set will use a combined image sampler (sampler and image could be split)
|
||||
1, // Shader binding point 1
|
||||
&image_descriptor) // Pointer to the descriptor image for our texture
|
||||
};
|
||||
|
||||
vkUpdateDescriptorSets(get_device().get_handle(), static_cast<uint32_t>(write_descriptor_sets.size()), write_descriptor_sets.data(), 0, NULL);
|
||||
@@ -1285,14 +1285,16 @@ void TextureLoading::prepare_pipeline_point()
|
||||
void TextureLoading::prepare_pipeline_point_line()
|
||||
{
|
||||
|
||||
// 顶点输入绑定描述 (告诉 Vulkan 顶点数据的格式)
|
||||
VkVertexInputBindingDescription vertex_input_binding_description{};
|
||||
vertex_input_binding_description.binding = 0;
|
||||
vertex_input_binding_description.stride = sizeof(PointVertex);
|
||||
vertex_input_binding_description.binding = 0; // 绑定点
|
||||
vertex_input_binding_description.stride = sizeof(PointVertex); // 每个顶点的字节大小
|
||||
vertex_input_binding_description.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||
|
||||
// 顶点输入属性描述 (告诉 Vulkan 每个属性在顶点结构中的位置)
|
||||
std::array<VkVertexInputAttributeDescription, 2> vertex_input_attributes = {
|
||||
VkVertexInputAttributeDescription{0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(PointVertex, x)},
|
||||
VkVertexInputAttributeDescription{1, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(PointVertex, r)}
|
||||
VkVertexInputAttributeDescription{0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(PointVertex, x)}, // 位置
|
||||
VkVertexInputAttributeDescription{1, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(PointVertex, r)} // 颜色
|
||||
};
|
||||
|
||||
VkPipelineVertexInputStateCreateInfo vertex_input_state{ VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO };
|
||||
@@ -1301,7 +1303,7 @@ void TextureLoading::prepare_pipeline_point_line()
|
||||
vertex_input_state.vertexAttributeDescriptionCount = static_cast<uint32_t>(vertex_input_attributes.size());
|
||||
vertex_input_state.pVertexAttributeDescriptions = vertex_input_attributes.data();
|
||||
|
||||
|
||||
// 输入装配 (绘制点列表)
|
||||
VkPipelineInputAssemblyStateCreateInfo input_assembly_state{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO };
|
||||
input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
|
||||
input_assembly_state.primitiveRestartEnable = VK_FALSE;
|
||||
@@ -1440,7 +1442,16 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
|
||||
int pointCount = sizeof(testPoint) / (3*4);
|
||||
update_point_vertex_buffer(testPoint, pointCount);
|
||||
|
||||
update_point_vertex_buffer_line(testPoint, pointCount);
|
||||
float testPoint_line[] = {
|
||||
0,0,z,
|
||||
-0.05,0.05,z,
|
||||
-0.1,0.1,z,
|
||||
-0.2,0.2,z,
|
||||
-0.3,0.3,z,
|
||||
-0,0.5,z,
|
||||
-1,1,z,
|
||||
};
|
||||
update_point_vertex_buffer_line(testPoint_line, sizeof(testPoint_line) / (3 * 4));
|
||||
|
||||
prepared = true;
|
||||
|
||||
@@ -1935,14 +1946,16 @@ void TextureLoading::update_point_vertex_buffer_line(float* pos, int count)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_point_line);
|
||||
if (count <= 0) {
|
||||
point_count_line = 0;
|
||||
count = 0;
|
||||
return; // 没有点数据,无需更新
|
||||
}
|
||||
|
||||
point_count_line = count;
|
||||
point_count = count;
|
||||
|
||||
// 1. 准备顶点数据
|
||||
std::vector<PointVertex> vertices(point_count);
|
||||
// 假设 pos 数组是 [x0,y0,z0,x1,y1,z1,...]
|
||||
// 为了可视化,这里简单地将坐标映射为颜色 (0-1范围)
|
||||
float min_x = std::numeric_limits<float>::max(), max_x = std::numeric_limits<float>::lowest();
|
||||
float min_y = std::numeric_limits<float>::max(), max_y = std::numeric_limits<float>::lowest();
|
||||
float min_z = std::numeric_limits<float>::max(), max_z = std::numeric_limits<float>::lowest();
|
||||
@@ -1989,7 +2002,7 @@ void TextureLoading::update_point_vertex_buffer_line(float* pos, int count)
|
||||
void* mapped_data = vertex_buffer_point_line->map();
|
||||
if (mapped_data) {
|
||||
memcpy(mapped_data, vertices.data(), buffer_size);
|
||||
vertex_buffer_point->unmap();
|
||||
vertex_buffer_point_line->unmap();
|
||||
}
|
||||
else {
|
||||
LOGE("Failed to map point vertex buffer for update.");
|
||||
|
||||
Reference in New Issue
Block a user