Skip to content

File glfw_extended.cpp

File List > display > glfw_extended.cpp

Go to the documentation of this file

#ifndef __ANDROID__

#    if defined(_WIN32) || defined(_WIN64)
#        include 
#    endif
#    define GLFW_INCLUDE_VULKAN
#    include "glfw_extended.hpp"
#    include "illixr/error_util.hpp"

#    include 

using namespace ILLIXR::display;

void glfw_extended::setup_display(const std::shared_ptr<switchboard> sb, VkInstance vk_instance,
                                  VkPhysicalDevice vk_physical_device) {
    (void) sb;
    (void) vk_physical_device;
    this->vk_instance_ = vk_instance;
}

VkSurfaceKHR glfw_extended::create_surface() {
    VkSurfaceKHR surface;
    auto         ret = glfwCreateWindowSurface(vk_instance_, (GLFWwindow*) window_, nullptr, &surface);
    if (ret != VK_SUCCESS) {
        // get the error code
        auto err = glfwGetError(nullptr);
        // print the error
        std::cerr << "glfw error: " << err << std::endl;

        throw std::runtime_error("failed to create window surface!");
    }
    return surface;
}

void glfw_extended::poll_window_events() {
    glfwPollEvents();
}

std::pair<uint32_t, uint32_t> glfw_extended::get_framebuffer_size() {
    int width, height;
    while (width == 0 || height == 0) {
        glfwGetFramebufferSize((GLFWwindow*) window_, &width, &height);
        glfwWaitEvents();
    }
    return {width, height};
}

void glfw_extended::cleanup() {
    // The display backend is always responsible for terminating GLFW.
    glfwDestroyWindow((GLFWwindow*) window_);
    glfwTerminate();
}

std::set<const char*> glfw_extended::get_required_instance_extensions() {
    uint32_t     glfwExtensionCount = 0;
    const char** glfwExtensions;
    glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
    std::set<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
    return extensions;
}

glfw_extended::glfw_extended() {
    if (!glfwInit()) {
        ILLIXR::abort("Failed to initialize glfw");
    }

    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    window_ = glfwCreateWindow(display_params::width_pixels, display_params::height_pixels, "ILLIXR Eyebuffer Window (Vulkan)",
                               nullptr, nullptr);
}

std::set<const char*> glfw_extended::get_required_device_extensions() {
    return {};
}

display_backend::display_backend_type glfw_extended::get_type() {
    return GLFW;
}

#endif