diff --git a/samples/api/texture_loading/texture_loading.cpp b/samples/api/texture_loading/texture_loading.cpp index c8ee548..5d12b68 100644 --- a/samples/api/texture_loading/texture_loading.cpp +++ b/samples/api/texture_loading/texture_loading.cpp @@ -670,7 +670,7 @@ void TextureLoading::setup_descriptor_pool() vkb::initializers::descriptor_pool_create_info( static_cast(pool_sizes.size()), pool_sizes.data(), - 4); + 6); VK_CHECK(vkCreateDescriptorPool(get_device().get_handle(), &descriptor_pool_create_info, nullptr, &descriptor_pool)); } @@ -1427,8 +1427,9 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) prepare_pipelines(); prepare_pipeline_bg(); - prepare_pipeline_point(); prepare_pipeline_point_line(); + prepare_pipeline_point(); + float z = -2.0f; float testPoint[] = { @@ -1440,8 +1441,6 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) 0,0.5,z, 1,1,z, }; - int pointCount = sizeof(testPoint) / (3*4); - update_point_vertex_buffer(testPoint, pointCount); float testPoint_line[] = { 0,0,z, @@ -1452,6 +1451,8 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) 0 + 0.1,0.5,z, 1 + 0.1,1,z, }; + + update_point_vertex_buffer(testPoint, sizeof(testPoint) / (3 * 4)); update_point_vertex_buffer_line(testPoint_line, sizeof(testPoint_line) / (3 * 4)); prepared = true; @@ -1947,21 +1948,21 @@ void TextureLoading::update_point_vertex_buffer_line(float* pos, int count) { std::lock_guard lock(mtx_point_line); if (count <= 0) { - count = 0; + point_count_line = 0; return; // 没有点数据,无需更新 } - point_count = count; + point_count_line = count; // 1. 准备顶点数据 - std::vector vertices(point_count); + std::vector vertices(point_count_line); // 假设 pos 数组是 [x0,y0,z0,x1,y1,z1,...] // 为了可视化,这里简单地将坐标映射为颜色 (0-1范围) float min_x = std::numeric_limits::max(), max_x = std::numeric_limits::lowest(); float min_y = std::numeric_limits::max(), max_y = std::numeric_limits::lowest(); float min_z = std::numeric_limits::max(), max_z = std::numeric_limits::lowest(); - for (int i = 0; i < point_count; ++i) { + for (int i = 0; i < point_count_line; ++i) { float x = pos[i * 3 + 0]; float y = pos[i * 3 + 1]; float z = pos[i * 3 + 2]; @@ -1976,7 +1977,7 @@ void TextureLoading::update_point_vertex_buffer_line(float* pos, int count) if (range_y == 0) range_y = 1.0f; if (range_z == 0) range_z = 1.0f; - for (int i = 0; i < point_count; ++i) { + for (int i = 0; i < point_count_line; ++i) { vertices[i].x = pos[i * 3 + 0]; vertices[i].y = pos[i * 3 + 1]; vertices[i].z = pos[i * 3 + 2]; @@ -1987,7 +1988,7 @@ void TextureLoading::update_point_vertex_buffer_line(float* pos, int count) } // 2. 更新或创建顶点缓冲区 - VkDeviceSize buffer_size = sizeof(PointVertex) * point_count; + VkDeviceSize buffer_size = sizeof(PointVertex) * point_count_line; if (!vertex_buffer_point_line || vertex_buffer_point_line->get_size() < buffer_size) { // 如果缓冲区不存在或太小,则重新创建