<commit_before>#include "vertexLayout.h"

std::unordered_map<GLint, GLuint> VertexLayout::s_enabledAttribs = std::unordered_map<GLint, GLuint>();

VertexLayout::VertexLayout(std::vector<VertexAttrib> _attribs) : m_attribs(_attribs) {

    m_stride = 0; 

    for (auto& attrib : m_attribs) {

        GLint byteSize = attrib.size;

        switch (attrib.type) {
            case GL_FLOAT:
            case GL_INT:
            case GL_UNSIGNED_INT:
                byteSize *= 4; // 4 bytes for floats, ints, and uints
                break;
            case GL_SHORT:
            case GL_UNSIGNED_SHORT:
                byteSize *= 2; // 2 bytes for shorts and ushorts
                break;
        }

        attrib.offset = reinterpret_cast<void*>(m_stride);

        m_stride += byteSize;

    }
}

void VertexLayout::enable(ShaderProgram* _program) {

    GLuint glProgram = _program->getGlProgram();

    // Enable all attributes for this layout
    for (auto& attrib : m_attribs) {

        GLint location = _program->getAttribLocation(attrib.name);

        if (location != -1) {
            glEnableVertexAttribArray(location);
            glVertexAttribPointer(location, attrib.size, attrib.type, attrib.normalized, m_stride, attrib.offset);
            s_enabledAttribs[location] = glProgram; // Track currently enabled attribs by the program to which they are bound
        }

    }

    // Disable previously bound and now-unneeded attributes
    for (auto locationProgramPair : s_enabledAttribs) {
<commit_msg>Use reference for iterating over a list<commit_after>#include "vertexLayout.h"

std::unordered_map<GLint, GLuint> VertexLayout::s_enabledAttribs = std::unordered_map<GLint, GLuint>();

VertexLayout::VertexLayout(std::vector<VertexAttrib> _attribs) : m_attribs(_attribs) {

    m_stride = 0; 

    for (auto& attrib : m_attribs) {

        GLint byteSize = attrib.size;

        switch (attrib.type) {
            case GL_FLOAT:
            case GL_INT:
            case GL_UNSIGNED_INT:
                byteSize *= 4; // 4 bytes for floats, ints, and uints
                break;
            case GL_SHORT:
            case GL_UNSIGNED_SHORT:
                byteSize *= 2; // 2 bytes for shorts and ushorts
                break;
        }

        attrib.offset = reinterpret_cast<void*>(m_stride);

        m_stride += byteSize;

    }
}

void VertexLayout::enable(ShaderProgram* _program) {

    GLuint glProgram = _program->getGlProgram();

    // Enable all attributes for this layout
    for (auto& attrib : m_attribs) {

        GLint location = _program->getAttribLocation(attrib.name);

        if (location != -1) {
            glEnableVertexAttribArray(location);
            glVertexAttribPointer(location, attrib.size, attrib.type, attrib.normalized, m_stride, attrib.offset);
            s_enabledAttribs[location] = glProgram; // Track currently enabled attribs by the program to which they are bound
        }

    }

    // Disable previously bound and now-unneeded attributes
    for (auto& locationProgramPair : s_enabledAttribs) {

{'fraction_non_alphanumeric': 0.09392265193370165, 'fraction_numerical': 0.003899902502437439, 'mean_word_length': 2.477966101694915, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7289117', 'n_tokens_mistral': 953, 'n_tokens_neox': 912, 'n_words': 220}