//
// Created by sebastian on 29.07.26.
//

#ifndef COLORRACE_ATTRIBUTE_H
#define COLORRACE_ATTRIBUTE_H
#pragma once
#include <glad/glad.h>

namespace engine {
    class Attribute {
    public:
        Attribute(unsigned int attributeNumber, unsigned int dataType, int componentCount);
        Attribute(unsigned int attributeNumber, unsigned int dataType, int componentCount, bool normalized);
        virtual ~Attribute() = default;

        void enable(bool enable) const;
        virtual void link(int offset, int stride);
        int getBytesPerVertex() const { return m_bytesPerVertex; }
        unsigned int getAttributeNumber() const { return m_attributeNumber; }

    protected:
        unsigned int m_attributeNumber;
        unsigned int m_dataType;
        int m_componentCount;
        bool m_normalized;
        int m_bytesPerVertex;

    private:
        int calcBytesPerVertex() const;
    };

    class Vec2Attribute : public Attribute {
    public:
        explicit Vec2Attribute(unsigned int attributeNumber) : Attribute(attributeNumber, GL_FLOAT, 2) {}
    };

    class Vec3Attribute : public Attribute {
    public:
        explicit Vec3Attribute(unsigned int attributeNumber) : Attribute(attributeNumber, GL_FLOAT, 3) {}
    };

    class ColorAttribute : public Attribute {
        public:
            explicit ColorAttribute(unsigned int attributeNumber) : Attribute(attributeNumber, GL_UNSIGNED_BYTE, 4, true) {}
    };

    class NormalAttribute : public Attribute {
        public:
            explicit NormalAttribute(unsigned int attributeNumber) : Attribute(attributeNumber, GL_UNSIGNED_INT_2_10_10_10_REV, 3) {}
    };

    class IntAttribute : public Attribute {
        public:
            explicit IntAttribute(unsigned int attributeNumber) : Attribute(attributeNumber, GL_INT, 1) {}

            void link(int offset, int stride) override;
    };

}

#endif //COLORRACE_ATTRIBUTE_H
