加入了,png图片加载为纹理。 json 读取点坐标用于调试

This commit is contained in:
xsl
2025-09-22 13:54:51 +08:00
parent 51616af8ce
commit 1070b2f098
48 changed files with 34057 additions and 50 deletions
+44 -50
View File
@@ -1,25 +1,13 @@
/* Copyright (c) 2019-2025, 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)
*/
#include "texture_loading.h"
#ifdef _WIN32
#include <nlohmann/json.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include "lodepng.cpp"
#endif
TextureLoading::TextureLoading()
{
@@ -1388,14 +1376,22 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
int rowStride = width*4;
auto testImage = generateSimpleTestImage(width, height, 80);
size_t dataSize = testImage.size();
processWithVulkan(testImage.data(), width, height, rowStride, dataSize, cam_text);
processWithVulkan(testImage.data(), width, height, rowStride, dataSize, texture_point);
width = 256;
height = 256;
rowStride = width * 4;
auto arrowImage = generateSimpleTestImage(width, height, 80);
dataSize = arrowImage.size();
processWithVulkan(arrowImage.data(), width, height, rowStride, dataSize, texture_point);
//width = 256;
//height = 256;
//rowStride = width * 4;
//auto arrowImage = generateSimpleTestImage(width, height, 80);
//dataSize = arrowImage.size();
//processWithVulkan(arrowImage.data(), width, height, rowStride, dataSize, texture_point);
const char* filename = "face.png";
std::vector<unsigned char> image; // 存储RGB数据
unsigned w, h;
// 解码PNG文件
unsigned error = lodepng::decode(image, w, h, filename, LCT_RGBA, 8);
processWithVulkan(image.data(), w, h, w*4, image.size(), cam_text);
width = 256;
height = 256;
@@ -1432,29 +1428,27 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
prepare_pipeline_point();
float z = -2.0f;
float testPoint[] = {
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,
};
float testPoint_line[] = {
0,0,z,
0.05 + 0.1,0.05,z,
0.1 + 0.1,0.1,z,
0.2 + 0.1,0.2,z,
0.3 + 0.1,0.3,z,
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), 1, 0, 0);
//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<char>(file)),std::istreambuf_iterator<char>());
nlohmann::json msg = nlohmann::json::parse(content);
nlohmann::json rawPoint = msg["data"]["raw_point"];
float pos[480 * 3] = { 0 };
int pos_id = 0;
for (size_t i = 0; i < rawPoint.size(); ++i)
{
nlohmann::json p = rawPoint[i];
int index = p["id"];
pos[pos_id++] = p["x"]/480;
pos[pos_id++] = p["y"] / 480;
pos[pos_id++] = p["z"];
}
update_point_vertex_buffer(pos, rawPoint.size());
demo1(pos);
#endif
prepared = true;
@@ -1582,7 +1576,7 @@ void TextureLoading::createTexture(VkDevice device, VkPhysicalDevice physicalDev
VkImageCreateInfo imageInfo = {};
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageInfo.imageType = VK_IMAGE_TYPE_2D;
imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM; // RGBA_8888
imageInfo.format = VK_FORMAT_R8G8B8A8_SRGB; //VK_FORMAT_R8G8B8A8_UNORM;
imageInfo.extent.width = width;
imageInfo.extent.height = height;
imageInfo.extent.depth = 1;
@@ -1619,7 +1613,7 @@ void TextureLoading::createTexture(VkDevice device, VkPhysicalDevice physicalDev
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
viewInfo.image = texture.image;
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
viewInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
viewInfo.format = VK_FORMAT_R8G8B8A8_SRGB; // VK_FORMAT_R8G8B8A8_UNORM;
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
viewInfo.subresourceRange.baseMipLevel = 0;
viewInfo.subresourceRange.levelCount = 1;