From d6818e881619b8b57f198745a0dabbd836759f31 Mon Sep 17 00:00:00 2001 From: xiangsilian Date: Sun, 28 Sep 2025 22:20:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/texture_loading/texture_loading.cpp | 20 ++++++++---- samples/api/texture_loading/texture_loading.h | 31 ++++++------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/samples/api/texture_loading/texture_loading.cpp b/samples/api/texture_loading/texture_loading.cpp index 5a90d33..15c0b58 100644 --- a/samples/api/texture_loading/texture_loading.cpp +++ b/samples/api/texture_loading/texture_loading.cpp @@ -572,7 +572,7 @@ void TextureLoading::build_command_buffers() - draw_point_cloud(draw_cmd_buffers[i]); + //draw_point_cloud(draw_cmd_buffers[i]); //draw_point_cloud_line(draw_cmd_buffers[i]); @@ -582,7 +582,11 @@ void TextureLoading::build_command_buffers() 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); + + if (getCurrentTimeMillis() - last_update_time < 1000) + { + vkCmdDrawIndexed(draw_cmd_buffers[i], index_count, 1, 0, 0, 0); + } //draw_ui(draw_cmd_buffers[i]); @@ -692,7 +696,7 @@ bool TextureLoading::LoadOBJ(const std::string& filename, float u, v; iss >> u >> v; temp_texcoords.push_back(u); - temp_texcoords.push_back(v); + temp_texcoords.push_back(1-v); } else if (type == "vn") { // 法线 float nx, ny, nz; @@ -1659,6 +1663,8 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) return false; } + last_update_time = getCurrentTimeMillis(); + myFloatValue = 1.5f; // --- 加载前景纹理 (示例) --- @@ -1692,9 +1698,9 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options) dataSize = lineImage.size(); processWithVulkan(lineImage.data(), width, height, rowStride, dataSize, texture_point_line); #ifdef _WIN32 - const char* filename_test = "assets/test_trans.png"; + const char* filename_test = "assets/DemoHeadBaseColor.png"; #else - const char* filename_test = "/sdcard/Android/data/com.khronos.vulkan_samples/files/assets/test_trans.png"; + const char* filename_test = "/sdcard/Android/data/com.khronos.vulkan_samples/files/assets/DemoHeadBaseColor.png"; #endif // _WIN32 @@ -1844,7 +1850,7 @@ void ReceiveFacePoint(float* pos, int pointCount, int width, int height) // } //} //debug_str += "]"; - + TextureLoading* self = TextureLoading::Get(); if (self != nullptr) { @@ -1923,6 +1929,8 @@ void TextureLoading::extendPoint(float* pos, int start_id, int end_id, float rat void TextureLoading::update_face_vertex_buffer(float* pos, int pointCount) { + last_update_time = getCurrentTimeMillis(); + extendPoint(pos, 68, 54); extendPoint(pos, 104, 103); extendPoint(pos, 69, 67); diff --git a/samples/api/texture_loading/texture_loading.h b/samples/api/texture_loading/texture_loading.h index 9e0bef6..27f499c 100644 --- a/samples/api/texture_loading/texture_loading.h +++ b/samples/api/texture_loading/texture_loading.h @@ -1,24 +1,4 @@ -/* Copyright (c) 2019-2024, Sascha Willems - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 the "License"; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - /* - * Texture loading (and display) example (including mip maps) - */ - + #pragma once #include @@ -26,6 +6,8 @@ #include "api_vulkan_sample.h" #include #include +#include +#include // Vertex layout for this example struct TextureLoadingVertexStructure @@ -220,6 +202,13 @@ private: std::thread workerThread; bool running = false; + long long getCurrentTimeMillis() { + auto now = std::chrono::system_clock::now(); + auto duration = now.time_since_epoch(); + return std::chrono::duration_cast(duration).count(); + } + + long long last_update_time; public: //void run(); //void start();