| 267 | } // namespace |
| 268 | |
| 269 | GlfwWindow::GlfwWindow(Platform *platform, const Window::Properties &properties) : |
| 270 | Window(properties) |
| 271 | { |
| 272 | #if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 273 | glfwInitHint(GLFW_X11_XCB_VULKAN_SURFACE, false); |
| 274 | #endif |
| 275 | |
| 276 | if (!glfwInit()) |
| 277 | { |
| 278 | throw std::runtime_error("GLFW couldn't be initialized."); |
| 279 | } |
| 280 | |
| 281 | glfwSetErrorCallback(error_callback); |
| 282 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); |
| 283 | |
| 284 | switch (properties.mode) |
| 285 | { |
| 286 | case Window::Mode::Fullscreen: |
| 287 | { |
| 288 | auto *monitor = glfwGetPrimaryMonitor(); |
| 289 | const auto *mode = glfwGetVideoMode(monitor); |
| 290 | handle = glfwCreateWindow(mode->width, mode->height, properties.title.c_str(), monitor, NULL); |
| 291 | break; |
| 292 | } |
| 293 | |
| 294 | case Window::Mode::FullscreenBorderless: |
| 295 | { |
| 296 | auto *monitor = glfwGetPrimaryMonitor(); |
| 297 | const auto *mode = glfwGetVideoMode(monitor); |
| 298 | glfwWindowHint(GLFW_RED_BITS, mode->redBits); |
| 299 | glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); |
| 300 | glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); |
| 301 | glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); |
| 302 | handle = glfwCreateWindow(mode->width, mode->height, properties.title.c_str(), monitor, NULL); |
| 303 | break; |
| 304 | } |
| 305 | |
| 306 | case Window::Mode::FullscreenStretch: |
| 307 | { |
| 308 | throw std::runtime_error("Cannot support stretch mode on this platform."); |
| 309 | break; |
| 310 | } |
| 311 | |
| 312 | default: |
| 313 | handle = glfwCreateWindow(properties.extent.width, properties.extent.height, properties.title.c_str(), NULL, NULL); |
| 314 | break; |
| 315 | } |
| 316 | |
| 317 | resize(Extent{properties.extent.width, properties.extent.height}); |
| 318 | |
| 319 | if (!handle) |
| 320 | { |
| 321 | throw std::runtime_error("Couldn't create glfw window."); |
| 322 | } |
| 323 | |
| 324 | glfwSetWindowUserPointer(handle, platform); |
| 325 | |
| 326 | glfwSetWindowCloseCallback(handle, window_close_callback); |
nothing calls this directly
no outgoing calls
no test coverage detected