무지성으로 불칸 초기화 코드 작성 중에 Surface 생성에서 막힘.
D3D처럼 무지성 디폴트 파라매터로 땜빵이 안 되는 듯.
책 봐야겠다.
#include <wx/wx.h>
#include <vulkan/vulkan.h>
#if defined(__WXGTK__)
#include <gdk/gdk.h>
#include <gdk/gdkwayland.h>
#include <gdk/gdkdisplay.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <xcb/xcb.h>
#include <vulkan/vulkan_xlib.h>
#elif defined(__WXMSW__)
#endif
class VulkanApp: public wxApp
{
public:
bool OnInit() override;
int OnExit() override;
private:
wxFrame* frame_;
VkInstance vkInstance_ = nullptr;
VkDevice vkDevice_ = nullptr;
VkSurfaceKHR vkSurface_ = nullptr;
};
wxIMPLEMENT_APP(VulkanApp);
bool VulkanApp::OnInit()
{
frame_ = new wxFrame{nullptr, wxID_ANY, wxT("Hello, World!")};
frame_->Show();
GdkDisplay *display = gdk_display_get_default ();
VkResult ret;
VkPhysicalDevice vkPhysicalDevice{};
VkInstanceCreateInfo instanceDesc{};
VkPhysicalDeviceProperties vkDeviceProps{};
instanceDesc.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
vkCreateInstance(&instanceDesc, nullptr, &vkInstance_);
uint32_t physicalDeviceCount{1};
vkEnumeratePhysicalDevices(vkInstance_, &physicalDeviceCount, &vkPhysicalDevice);
vkGetPhysicalDeviceProperties(vkPhysicalDevice, &vkDeviceProps);
auto textCtrl{new wxTextCtrl{frame_, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE}};
textCtrl->Show();
wxString text;
text << wxT("Device Name: ") << vkDeviceProps.deviceName << '\n';
text << wxT("API Version: ")
<< VK_API_VERSION_MAJOR(vkDeviceProps.apiVersion) << "."
<< VK_API_VERSION_MINOR(vkDeviceProps.apiVersion) << "."
<< VK_API_VERSION_PATCH(vkDeviceProps.apiVersion) << '\n';
VkDeviceCreateInfo deviceDesc{};
deviceDesc.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
vkCreateDevice(vkPhysicalDevice, &deviceDesc, nullptr, &vkDevice_);
if(vkDevice_ == nullptr)
text << "Failed to create device";
else
text << "Success to create device";
text << '\n';
if(GDK_IS_X11_DISPLAY (display)) {
VkXlibSurfaceCreateInfoKHR surfaceDesc{};
surfaceDesc.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
surfaceDesc.window = gdk_x11_window_get_xid(frame_->GTKGetDrawingWindow());
surfaceDesc.dpy = gdk_x11_display_get_xdisplay(display);
ret = vkCreateXlibSurfaceKHR(vkInstance_, &surfaceDesc, nullptr, &vkSurface_);
const char* erroCode = nullptr;
switch(ret)
{
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
erroCode = "VK_ERROR_OUT_OF_DEVICE_MEMORY";
break;
case VK_ERROR_OUT_OF_HOST_MEMORY:
erroCode = "VK_ERROR_OUT_OF_HOST_MEMORY";
break;
default:
erroCode = "Unknown";
break;
}
if(vkSurface_ == nullptr)
text << "Failed to create surface. ret code: "<< erroCode;
else
text << "Success to create surface";
} else if(GDK_IS_WAYLAND_DISPLAY(display)) {
}
textCtrl->ChangeValue(text);
return true;
}
int VulkanApp::OnExit()
{
if(vkDevice_ != nullptr)
vkDestroyDevice(vkDevice_, nullptr);
if(vkSurface_ != nullptr)
vkDestroySurfaceKHR(vkInstance_, vkSurface_, nullptr);
if(vkInstance_ != nullptr)
vkDestroyInstance(vkInstance_, nullptr);
return wxApp::OnExit();
}
댓글 0