<commit_before>// Copyright (C) 2015 <NAME>
// This file is part of the Ouzel engine.

#include "MeshBufferOGL.h"
#include "Engine.h"
#include "RendererOGL.h"
#include "Utils.h"

namespace ouzel
{
    MeshBufferOGL::MeshBufferOGL()
    {
        
    }
    
    MeshBufferOGL::~MeshBufferOGL()
    {
        if (_vertexArrayId) glDeleteVertexArrays(1, &_vertexArrayId);
        if (_vertexBufferId) glDeleteBuffers(1, &_vertexBufferId);
        if (_indexBufferId) glDeleteBuffers(1, &_indexBufferId);
    }
    
    bool MeshBufferOGL::initFromData(const void* indices, uint32_t indexSize, uint32_t indexCount, bool dynamicIndexBuffer, const void* vertices, uint32_t vertexSize, uint32_t vertexCount, bool dynamicVertexBuffer, uint32_t vertexAttributes)
    {
        if (!MeshBuffer::initFromData(indices, indexSize, indexCount, dynamicIndexBuffer, vertices, vertexSize, vertexCount, dynamicVertexBuffer, vertexAttributes))
        {
            return false;
        }
        
        glGenBuffers(1, &_indexBufferId);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize * indexCount, indices,
                     _dynamicIndexBuffer ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
        
        if (static_cast<RendererOGL*>(Renderer::getInstance())->checkOpenGLErrors())
        {
            return false;
        }
        
        switch (_indexSize)
        {
            case 1: _indexFormat = GL_UNSIGNED_BYTE; break;
            case 2: _indexFormat = GL_UNSIGNED_SHORT; break;
            case 4: _indexFormat = GL_UNSIGNED_INT; break;
            default: log("Invalid index size"); return false;
        }
        
        _indexCount = indexCount;
        
        glGenVertexArrays(1, &_vertexArrayId);
        glBindVertexArray(_vertexArrayId);
        
        glGenBuffers(1, &_vertexBufferId);
        glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferId);
        glBufferData(GL_ARRAY_BUFFER, vertexSize * vertexCount, vertices,
                     _dynamicVertexBuffer ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
        
        if (static_cast<RendererOGL*>(Renderer::getInstance())->checkOpenGLErrors())
        {
            return false;
        }
        
        GLuint index = 0;
        GLuint position = 0;
        
        if (vertexAttributes & VERTEX_POSITION)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 3, GL_FLOAT, GL_FALSE, vertexSize, reinterpret_cast<const GLvoid*>(position));
            position += 3 * sizeof(float);
            index++;
        }
        
        if (vertexAttributes & VERTEX_COLOR)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 4, GL_UNSIGNED_BYTE, GL_TRUE, vertexSize, reinterpret_cast<const GLvoid*>(position));
            position += 4 * sizeof(uint8_t);
            index++;
        }
        
        if (vertexAttributes & VERTEX_NORMAL)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 3, GL_FLOAT, GL_FALSE, vertexSize, reinterpret_cast<const GLvoid*>(position));
            position += 3 * sizeof(float);
            index++;
        }
        
        if (vertexAttributes & VERTEX_TEXCOORD0)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 2, GL_FLOAT, GL_FALSE, vertexSize, reinterpret_cast<const GLvoid*>(position));
            position += 2 * sizeof(float);
            index++;
        }
        
        if (vertexAttributes & VERTEX_TEXCOORD1)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 2, GL_FLOAT, GL_FALSE, vertexSize, reinterpret_cast<const GLvoid*>(position));
            position += 2 * sizeof(float);
            index++;
        }
        
        if (position != _vertexSize)
        {
            log("Invalid vertex size");
            return false;
        }
        
        if (static_cast<RendererOGL*>(Renderer::getInstance())->checkOpenGLErrors())
        {
            return false;<commit_msg>Rename position to offset<commit_after>// Copyright (C) 2015 <NAME>
// This file is part of the Ouzel engine.

#include "MeshBufferOGL.h"
#include "Engine.h"
#include "RendererOGL.h"
#include "Utils.h"

namespace ouzel
{
    MeshBufferOGL::MeshBufferOGL()
    {
        
    }
    
    MeshBufferOGL::~MeshBufferOGL()
    {
        if (_vertexArrayId) glDeleteVertexArrays(1, &_vertexArrayId);
        if (_vertexBufferId) glDeleteBuffers(1, &_vertexBufferId);
        if (_indexBufferId) glDeleteBuffers(1, &_indexBufferId);
    }
    
    bool MeshBufferOGL::initFromData(const void* indices, uint32_t indexSize, uint32_t indexCount, bool dynamicIndexBuffer, const void* vertices, uint32_t vertexSize, uint32_t vertexCount, bool dynamicVertexBuffer, uint32_t vertexAttributes)
    {
        if (!MeshBuffer::initFromData(indices, indexSize, indexCount, dynamicIndexBuffer, vertices, vertexSize, vertexCount, dynamicVertexBuffer, vertexAttributes))
        {
            return false;
        }
        
        glGenBuffers(1, &_indexBufferId);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize * indexCount, indices,
                     _dynamicIndexBuffer ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
        
        if (static_cast<RendererOGL*>(Renderer::getInstance())->checkOpenGLErrors())
        {
            return false;
        }
        
        switch (_indexSize)
        {
            case 1: _indexFormat = GL_UNSIGNED_BYTE; break;
            case 2: _indexFormat = GL_UNSIGNED_SHORT; break;
            case 4: _indexFormat = GL_UNSIGNED_INT; break;
            default: log("Invalid index size"); return false;
        }
        
        _indexCount = indexCount;
        
        glGenVertexArrays(1, &_vertexArrayId);
        glBindVertexArray(_vertexArrayId);
        
        glGenBuffers(1, &_vertexBufferId);
        glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferId);
        glBufferData(GL_ARRAY_BUFFER, vertexSize * vertexCount, vertices,
                     _dynamicVertexBuffer ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
        
        if (static_cast<RendererOGL*>(Renderer::getInstance())->checkOpenGLErrors())
        {
            return false;
        }
        
        GLuint index = 0;
        GLuint offset = 0;
        
        if (vertexAttributes & VERTEX_POSITION)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 3, GL_FLOAT, GL_FALSE, vertexSize, reinterpret_cast<const GLvoid*>(offset));
            offset += 3 * sizeof(float);
            index++;
        }
        
        if (vertexAttributes & VERTEX_COLOR)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 4, GL_UNSIGNED_BYTE, GL_TRUE, vertexSize, reinterpret_cast<const GLvoid*>(offset));
            offset += 4 * sizeof(uint8_t);
            index++;
        }
        
        if (vertexAttributes & VERTEX_NORMAL)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 3, GL_FLOAT, GL_FALSE, vertexSize, reinterpret_cast<const GLvoid*>(offset));
            offset += 3 * sizeof(float);
            index++;
        }
        
        if (vertexAttributes & VERTEX_TEXCOORD0)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 2, GL_FLOAT, GL_FALSE, vertexSize, reinterpret_cast<const GLvoid*>(offset));
            offset += 2 * sizeof(float);
            index++;
        }
        
        if (vertexAttributes & VERTEX_TEXCOORD1)
        {
            glEnableVertexAttribArray(index);
            glVertexAttribPointer(index, 2, GL_FLOAT, GL_FALSE, vertexSize, reinterpret_cast<const GLvoid*>(offset));
            offset += 2 * sizeof(float);
            index++;
        }
        
        if (offset != _vertexSize)
        {
            log("Invalid vertex size");
            return false;
        }
        
        if (static_cast<RendererOGL*>(Renderer::getInstance())->checkOpenGLErrors())
        {
            return false;
{'fraction_non_alphanumeric': 0.09372711740297779, 'fraction_numerical': 0.009275079326336344, 'mean_word_length': 2.2832532051282053, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, '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': '82293', 'n_tokens_mistral': 2365, 'n_tokens_neox': 2321, 'n_words': 444}