#include <pch.hpp>

#include "open_engine/renderer/renderer.hpp"
#include "open_engine/renderer/render_command.hpp"
#include "open_engine/renderer/renderer2d.hpp"

#include <glad/glad.h>

namespace OpenEngine {
    void Renderer::Init()
    {
        OE_PROFILE_FUNCTION();

        RenderCommand::Init();
    }
    void Renderer::ShutDown()
    {
        OE_PROFILE_FUNCTION();

        Renderer2D::Shutdown();
    }

    void Renderer::OnWindowResize(uint32_t width, uint32_t height)
    {
        OE_PROFILE_FUNCTION();

        RenderCommand::SetViewport(0, 0, width, height);
    }

    void Renderer::BeginScene(const OrthographicCamera& camera)
    {
        OE_PROFILE_FUNCTION();

        scene_data->view_projection_matrix = camera.GetViewProjectionMatrix();
    }
    void Renderer::EndScene()
    {
    }

    void Renderer::Submit(const std::shared_ptr<Shader> shader,
            const std::shared_ptr<VertexArray>& vertex_array,
            const glm::mat4& transform)
    {
        OE_PROFILE_FUNCTION();

        shader->Bind();
        shader->SetMat4("u_ViewProjection", scene_data->view_projection_matrix);
        shader->SetMat4("u_Transform", transform);

        vertex_array->Bind();
        RenderCommand::DrawIndexed(vertex_array);
    }
}
