//#####################################################################
// Copyright 2021, Craig Schroeder.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################

#include <Core/Log/DEBUG_UTILITIES.h>
#include <Core/Log/LOG.h>
#include "QT_SHADER_FLAGS.h"
#include "QT_VERTEX_SHADER.h"
#include <string>
namespace PhysBAM{

std::string Generate_Vertex_Shader(bool use_pos,
    const ARRAY<std::pair<const char*,const char*>>& attr_list,
    const char* new_types)
{
    std::string x="#version 420\n";
    if(new_types) x+=new_types;
    if(use_pos)
        x+=
            "in vec4 vs_pos;\n"
            "out vec4 gs_pos;\n"
            "out vec4 gs_world_pos;\n";

    for(auto a:attr_list)
        x+=LOG::sprintf("in %P vs_%P;\nout %P gs_%P;\n",a.first,a.second,a.first,a.second);

    x+=
        "uniform mat4 obj_to_world;\n"
        "uniform mat4 world_to_gl;\n"
        "\n"
        "void main()\n"
        "{\n";
    if(use_pos)
        x+=
            "    gs_pos = vs_pos;\n"
            "    vec4 A = obj_to_world * vs_pos;\n"
            "    gs_world_pos = A;\n"
            "    gl_Position = world_to_gl * A;\n";
    for(auto a:attr_list)
        x+=LOG::sprintf("    gs_%P = vs_%P;\n",a.second,a.second);
    x+="}\n";
    return x;
}
}
