/******************************************************************************
*	File		-	shader.h
*	Author		-	Joey Pollack
*	Date		-	2022/08/04 (y/m/d)
*	Mod Date	-	2022/08/04 (y/m/d)
*	Description	-	opengl shader system
******************************************************************************/

#ifndef LUNARIUM_SHADER_H_
#define LUNARIUM_SHADER_H_

#include <core/common_defs.h>
#include <utils/op_res.h>
#include <vector>

namespace lunarium
{
    enum class UniformType
    {
        F1,
        F2,
        F3,
        F4,
        FMAT3,
        FMAT4,

        I1,
        I2,
        I3,
        I4,

        UNKNOWN,
    };

    struct Uniform
    {
        std::string Name;
        UniformType Type;
        i32 Location;
    };

    class Shader
    {
    public:
        Shader(const char* vert_source, const char* geo_source, const char* frag_source);
        ~Shader();
        bool IsValid() const;

        void Use() const;

        OpRes GetAllUniforms(std::vector<Uniform>& uniforms);
        void GetUniformLocation(Uniform& uniform);
        OpRes SetUniform(Uniform& uniform, void* values, int num_uniforms = 1);

    private:
        u32 mGLID;

    private: // HELPERS

        /// Compile the given shader source
        /// Returns the glid of the compiled source
        /// source_type is the GLenum value
        u32 CompileSource(const char* source, u32 source_type);
        UniformType GLToUniformType(u32 type);
    };
}

#endif  // LUNARIUM_SHADER_H_