Android 编译通过,但肯定运行不了

This commit is contained in:
xsl
2025-10-16 16:40:41 +08:00
parent fc5d6e5cd8
commit 64a22ca513
4 changed files with 43 additions and 7 deletions
+17 -3
View File
@@ -10,7 +10,7 @@ void Application::createInstance()
VkApplicationInfo appInfo{};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Hello Triangle";
appInfo.pApplicationName = "Sample";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
@@ -20,6 +20,7 @@ void Application::createInstance()
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
#ifdef _WIN32
// 获取 GLFW 所需的扩展
uint32_t glfwExtensionCount = 0;
const char** glfwExtensions;
@@ -33,6 +34,7 @@ void Application::createInstance()
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
createInfo.ppEnabledExtensionNames = extensions.data();
#endif
if (enableValidationLayers) {
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
@@ -49,12 +51,16 @@ void Application::createInstance()
void Application::initWindow()
{
#ifdef _WIN32
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
window = glfwCreateWindow(kWidth, kHeight, "Vulkan", nullptr, nullptr);
#else
#endif
}
void Application::run()
@@ -66,9 +72,11 @@ void Application::run()
}
void Application::createSurface() {
#ifdef _WIN32
if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {
throw std::runtime_error("failed to create window surface!");
}
#endif
}
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
@@ -202,11 +210,15 @@ void Application::createCommandBuffer() {
void Application::mainLoop()
{
#ifdef _WIN32
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
drawFrame(); // 在这里调用
}
#else
#endif
vkDeviceWaitIdle(device); // 等待设备空闲
}
@@ -417,8 +429,8 @@ void Application::createPipelineLayout() {
void Application::createGraphicsPipeline() {
// 顶点着色器和片段着色器
auto vertShaderCode = readFile("D:/Graphics/vulkan_demo/shaders/simple_shader.vert.spv");
auto fragShaderCode = readFile("D:/Graphics/vulkan_demo/shaders/simple_shader.frag.spv");
auto vertShaderCode = readFile("shaders/simple_shader.vert.spv");
auto fragShaderCode = readFile("shaders/simple_shader.frag.spv");
// 创建着色器模块
VkShaderModule vertShaderModule = createShaderModule(vertShaderCode);
@@ -727,9 +739,11 @@ void Application::cleanup() {
// 销毁 Vulkan 实例
vkDestroyInstance(instance, nullptr);
#ifdef _WIN32
// 销毁 GLFW 窗口
glfwDestroyWindow(window);
// 终止 GLFW
glfwTerminate();
#endif
}