#include <pch.hpp>

#include <core.hpp>
#include <opengl/opengl_context.hpp>
#include <logging.hpp>

#include <glad/glad.h>
#include <GLFW/glfw3.h>

namespace OpenEngine {
    OpenGLContext::OpenGLContext(GLFWwindow* window_handle)
        : window_handle(window_handle)
    {
        OE_CORE_ASSERT(window_handle, "Handle is null!");
    }

    void OpenGLContext::Init()
    {
        OE_PROFILE_FUNCTION();

        glfwMakeContextCurrent(window_handle);
        int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
        OE_CORE_ASSERT(status, "Failed to initialize Glad!");

        OE_CORE_DEBUG("Opengl info:");
        OE_CORE_DEBUG("\tVendor: {}", (char*)glGetString(GL_VENDOR));
        OE_CORE_DEBUG("\tRenderer: {}", (char*)glGetString(GL_RENDERER));
        OE_CORE_DEBUG("\tVersion: {}", (char*)glGetString(GL_VERSION));
    }

    void OpenGLContext::SwapBuffers()
    {
        glfwSwapBuffers(window_handle);
    }
}
