#include "renderer_window.h"

#include "core/renderer/renderer.h"
#include "GLFW/glfw3native.h"

renderer_window::~renderer_window() { if (window) glfwDestroyWindow(window); }

bool renderer_window::init(const Eigen::Vector2i& in_size, const std::string& in_title) {
    window = glfwCreateWindow(in_size.x(), in_size.y(), in_title.c_str(), nullptr, nullptr);
    if (!window) return false;
    return create_surface(window);
}

Eigen::Matrix4f renderer_window::get_projection_matrix() const {
    return aorii::get_renderer_raw()->make_projection_matrix(get_window_size());
}

void* renderer_window::get_window_handle() const {
#if WINDOWS
    return glfwGetWin32Window(window);
#elif MACOS
    return glfwGetCocoaWindow(window);
#elif LINUX
#if GLFW_EXPOSE_NATIVE_WAYLAND
        return glfwGetWaylandWindow(window);
#else
        return (void*)glfwGetX11Window(window);
#endif
#else
    return nullptr;
#endif
}
