From 2026c41a231ea08812ce55a41314f35dd9090049 Mon Sep 17 00:00:00 2001 From: Xiang Silian Date: Thu, 18 Sep 2025 11:39:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=BE=E5=BC=83=E7=94=BB3d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/texture_loading/texture_loading.cpp | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/samples/api/texture_loading/texture_loading.cpp b/samples/api/texture_loading/texture_loading.cpp index f28d78a..2ba2f91 100644 --- a/samples/api/texture_loading/texture_loading.cpp +++ b/samples/api/texture_loading/texture_loading.cpp @@ -23,7 +23,7 @@ TextureLoading::TextureLoading() { - zoom = -2.5f; + zoom = -1.f; rotation = { 0.0f, 15.0f, 0.0f }; title = "Texture loading"; this_instance = this; @@ -99,7 +99,7 @@ std::vector generateSimpleTestImage(int width, int height, int* outRowS if (x < width / 3) { // 红色区域 - imageData[pixelOffset] = 255; // R + imageData[pixelOffset] = 2; // R imageData[pixelOffset + 1] = 0; // G imageData[pixelOffset + 2] = 0; // B } @@ -107,7 +107,7 @@ std::vector generateSimpleTestImage(int width, int height, int* outRowS { // 绿色区域 imageData[pixelOffset] = 0; // R - imageData[pixelOffset + 1] = 255; // G + imageData[pixelOffset + 1] = 2; // G imageData[pixelOffset + 2] = 0; // B } else @@ -115,7 +115,7 @@ std::vector generateSimpleTestImage(int width, int height, int* outRowS // 蓝色区域 imageData[pixelOffset] = 0; // R imageData[pixelOffset + 1] = 0; // G - imageData[pixelOffset + 2] = 255; // B + imageData[pixelOffset + 2] = 2; // B } imageData[pixelOffset + 3] = 255; // A (完全不透明) @@ -511,9 +511,9 @@ 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_ui(draw_cmd_buffers[i]); + //draw_ui(draw_cmd_buffers[i]); vkCmdEndRenderPass(draw_cmd_buffers[i]); @@ -546,12 +546,18 @@ void TextureLoading::draw() void TextureLoading::generate_quad() { // Setup vertices for a single uv-mapped quad made from two triangles + //std::vector vertices = + //{ + // {{1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f, 1.0f}}, + // {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}}, + // {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}, + // {{1.0f, -1.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}} }; std::vector vertices = { - {{1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f, 1.0f}}, - {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}}, - {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}, - {{1.0f, -1.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}} }; + {{0.3f, 0.3f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f, 1.0f}}, + {{-0.3f, 0.3f, 0.0f}, {0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}}, + {{-0.3f, -0.3f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}, + {{0.3f, -0.3f, 0.0f}, {1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}} }; // Setup indices std::vector indices = { 0, 1, 2, 2, 3, 0 }; @@ -943,8 +949,20 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) prepare_point_pipeline(); setup_point_descriptor_set(); + float z = 0.1; + //build_command_buffers(); + float simPoint[] = { + 1.0, 1.0, z, + -1.0, 1.0, z, + -1.0, -1.0, z, + 1.0, -1.0, z, + 0.8, 0.8, z, + -0.8, 0.8, z, + -0.8, -0.8, z, + 0.8, -0.8, z, + }; - build_command_buffers(); + update_point_vertex_buffer(simPoint, 8); prepared = true; //start(); @@ -1450,9 +1468,9 @@ void TextureLoading::prepare_point_pipeline() // 深度和模板测试 (通常对点云启用深度测试) VkPipelineDepthStencilStateCreateInfo depth_stencil_state{ VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO }; - depth_stencil_state.depthTestEnable = VK_TRUE; - depth_stencil_state.depthWriteEnable = VK_TRUE; - depth_stencil_state.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; // 或 VK_COMPARE_OP_LESS + depth_stencil_state.depthTestEnable = VK_FALSE; + depth_stencil_state.depthWriteEnable = VK_FALSE; + depth_stencil_state.depthCompareOp = VK_COMPARE_OP_ALWAYS; // 或 VK_COMPARE_OP_LESS depth_stencil_state.depthBoundsTestEnable = VK_FALSE; depth_stencil_state.stencilTestEnable = VK_FALSE;