diff --git a/samples/api/texture_loading/texture_loading.cpp b/samples/api/texture_loading/texture_loading.cpp index 19cac48..070a855 100644 --- a/samples/api/texture_loading/texture_loading.cpp +++ b/samples/api/texture_loading/texture_loading.cpp @@ -592,6 +592,7 @@ void TextureLoading::draw() std::unique_lock lock_mvp(mtx_mvp); ApiVulkanSample::prepare_frame(); + // --- 新增:在命令缓冲区中绘制点云 --- // 在 build_command_buffers 中已经构建了命令缓冲区,但点数据是动态的。 // 因此,我们在这里重新记录命令缓冲区。 @@ -869,16 +870,16 @@ void TextureLoading::setup_descriptor_set_layout_point_line() // Binding 0 : Vertex shader uniform buffer vkb::initializers::descriptor_set_layout_binding( VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - VK_SHADER_STAGE_VERTEX_BIT, + VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0), - // Binding 0 : Vertex shader uniform buffer + // Binding 1 : Vertex shader uniform buffer vkb::initializers::descriptor_set_layout_binding( VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT, 1), - // Binding 1 : Fragment shader image sampler + // Binding 2 : Fragment shader image sampler vkb::initializers::descriptor_set_layout_binding( VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, @@ -994,6 +995,11 @@ void TextureLoading::prepare_uniform_buffers_DashParameters() void TextureLoading::update_uniform_buffers_DashParameters(float dashSize, float gapSize, float dashOffset, float uAASize, int useWorldSpace) { + if (!prepared) + { + return; + } + std::unique_lock lock(mtx_mvp); _DashParameters.dashSize = dashSize; _DashParameters.gapSize = gapSize; _DashParameters.dashOffset = dashOffset; @@ -1019,7 +1025,6 @@ void TextureLoading::update_uniform_buffers_point(float fov, float x, float y, f { return; } - std::unique_lock lock(mtx_mvp); ubo_vs_point.projection = glm::perspective(glm::radians(fov), static_cast(width) / static_cast(height), 0.001f, 256.0f); @@ -1472,8 +1477,6 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) - //update_point_vertex_buffer(testPoint, sizeof(testPoint) / (3 * 4)); - //update_point_vertex_buffer_line(testPoint_line, sizeof(testPoint_line) / (3 * 4), 1, 0, 0); #ifdef _WIN32 std::ifstream file("face.json"); std::string content((std::istreambuf_iterator(file)),std::istreambuf_iterator()); @@ -1573,7 +1576,7 @@ void TextureLoadProcessWithVulkan(uint8_t* data, int width, int height, int rowS TextureLoading::Get()->processWithVulkan(data, width, height, rowStride, dataSize, cam_tex); } -void update_face_round_line_point(float* pos); + void ReceiveFacePoint(float* pos, int pointCount, int width, int height) { //for (int i = 0; i < pointCount; i++) { @@ -1584,8 +1587,7 @@ void ReceiveFacePoint(float* pos, int pointCount, int width, int height) TextureLoading* self = TextureLoading::Get(); if(self != nullptr) { - //TextureLoading::Get()->update_point_vertex_buffer(pos, pointCount); - //update_face_round_line_point(pos); + TextureLoading::Get()->update_point_vertex_buffer(pos, pointCount); self->demo1(pos); } @@ -2038,49 +2040,6 @@ void TextureLoading::demo1(float* pos) update_point_vertex_buffer_line_save(vertices); } -void update_face_round_line_point(float* pos) -{ - point_index = 0; - float points[100 * 3]; - add_point(pos, points, 152); - add_point(pos, points, 176); - add_point(pos, points, 150); - add_point(pos, points, 172); - add_point(pos, points, 58); - add_point(pos, points, 132); - add_point(pos, points, 234); - add_point(pos, points, 162); - add_point(pos, points, 21); - add_point(pos, points, 54); - add_point(pos, points, 103); - add_point(pos, points, 67); - add_point(pos, points, 109); - add_point(pos, points, 338); - add_point(pos, points, 297); - add_point(pos, points, 332); - add_point(pos, points, 284); - add_point(pos, points, 251); - add_point(pos, points, 389); - add_point(pos, points, 454); - add_point(pos, points, 323); - add_point(pos, points, 361); - add_point(pos, points, 435); - add_point(pos, points, 288); - add_point(pos, points, 397); - add_point(pos, points, 365); - add_point(pos, points, 379); - add_point(pos, points, 378); - add_point(pos, points, 400); - add_point(pos, points, 377); - add_point(pos, points, 152); - TextureLoading* self = TextureLoading::Get(); - if (self != nullptr) - { - std::vector vertices; - self->update_point_vertex_buffer_line(points, point_index, 0.9f, 0.9f, 0.9f, vertices); - self->update_point_vertex_buffer_line_save(vertices); - } -} void TextureLoading::update_point_vertex_buffer_line(float* pos, int count, float r, float g, float b, std::vector& vertices) {