简体   繁体   English

关于 Vulkan 和使用 GLFW 来抽象 Surface 创建

[英]About Vulkan and using GLFW to abstract away Surface creation

I'm trying learn Vulkan API by writing a simple test renderer using Vulkan + GLFW in C++我正在尝试通过在 C++ 中使用 Vulkan + GLFW 编写一个简单的测试渲染器来学习 Vulkan API

So far I have到目前为止我有

  1. Made a Vulkan instance制作了一个 Vulkan 实例
  2. Enumerated physical devices枚举物理设备
  3. Found suitable and compatible GPU找到合适且兼容的 GPU
  4. Created a logical device创建逻辑设备
  5. Created a command pool and buffer创建命令池和缓冲区

and right now I am trying to create a window.现在我正在尝试创建一个窗口。 So far I have two pieces of code that look very similar到目前为止,我有两段看起来非常相似的代码

This one这个

 126   // X11 Window creation                                                                                                        
 127   auto display_pointer = XOpenDisplay("Vulkan App");
 128 
 129   auto default_screen = DefaultScreen(display_pointer);
 130 
 131   auto handle =
 132       XCreateSimpleWindow(display_pointer,
 133                           DefaultRootWindow(display_pointer),
 134                           20,
 135                           20,
 136                           600,
 137                           600,
 138                           1,
 139                           BlackPixel(display_pointer, default_screen),
 140                           WhitePixel(display_pointer, default_screen));
 141 
 142   XSetStandardProperties(display_pointer,
 143                          handle,
 144                          "Vulkan App Title",
 145                          "Vulkan App Title 2",
 146                          None,
 147                          nullptr,
 148                          0,
 149                          nullptr);
 150   XSelectInput(display_pointer,
 151                handle,
 152                ExposureMask | KeyPressMask | StructureNotifyMask);
 153 

and

 157   // GLFW Window creation                                                                                                       
 158   GLFWwindow *glfw_window =
 159       glfwCreateWindow(1280, 720, "Vulkan App", NULL, NULL);
 160   assert(glfw_window);
 161 
 162   while (!glfwWindowShouldClose(glfw_window)) {
 163     glfwPollEvents();
 164   }
 165 
 166   glfwDestroyWindow(glfw_window);

And I am trying to define a function create_surface that'd return a VkSurfaceKHR object.我正在尝试定义一个返回VkSurfaceKHR对象的函数create_surface

Going through some of the tutorials online, I see most of them define a VkXlibSurfaceCreateInfoKHR object to pass to vkCreateXlibSurfaceKHR function.通过一些在线教程,我看到他们中的大多数都定义了一个VkXlibSurfaceCreateInfoKHR对象来传递给vkCreateXlibSurfaceKHR函数。

That looks like it is platform dependent and it would only work on X11 stuff.看起来它依赖于平台,并且只能在X11

Which is fine in my case but I want to let GLFW deal with all that so I could make my application a bit more crossplatform.这对我来说很好,但我想让GLFW处理所有这些,这样我就可以让我的应用程序更具跨平台性。

The problem is I don't know how I would pass GLFWwindow* to VkCreate_(GLFW ?)_SurfaceCreateInfoKHR .问题是我不知道如何将GLFWwindow*传递给VkCreate_(GLFW ?)_SurfaceCreateInfoKHR

I also may be confusing Vulkan surface for something else because of this piece of code of vulkan-tutorial.com由于vulkan-tutorial.com的这段代码,我也可能将 Vulkan 表面混淆为其他东西

VkWin32SurfaceCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
createInfo.hwnd = glfwGetWin32Window(window);
createInfo.hinstance = GetModuleHandle(nullptr);

I'm not too familiar with Windows but it looks like it's using platform dependent info structure and GLFW .我对 Windows 不太熟悉,但看起来它正在使用依赖于平台的信息结构和GLFW

You do not pass GLFWwindow to Vulkan at all.您根本没有将GLFWwindow传递给 Vulkan。 GLFW itself has Vulkan specific function glfwCreateWindowSurface , which gives you the VkSurfaceKHR . GLFW 本身具有 Vulkan 特定函数glfwCreateWindowSurface ,它为您提供VkSurfaceKHR

I have GLFW implementation here for reference: https://github.com/krOoze/Hello_Triangle/blob/master/src/WSI/Glfw.h我这里有 GLFW 实现供参考: https : //github.com/krOoze/Hello_Triangle/blob/master/src/WSI/Glfw.h

https://vulkan-tutorial.com seems to use GLFW as well. https://vulkan-tutorial.com似乎也使用 GLFW。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM