<commit_before>#include <HgVbo.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>

#include <string.h>

HgVboMemory staticVbo;
HgVboMemory staticVboVNU;

static HgVboMemory* _currentVbo;

static uint16_t struct_size(VBO_TYPE type) {
	if (type == VBO_VC) return sizeof(vbo_layout_vc);
	if (type == VBO_VNU) return sizeof(vbo_layout_vnu);
	if (type == VBO_INDEX8) return sizeof(uint8_t);
	if (type == VBO_INDEX16) return sizeof(uint16_t);

	fprintf(stderr, "Unknown vbo type:%d\n", type);
	assert(!"Unknown vbo type");
	return 0;
}

void hgvbo_init(HgVboMemory* vbo_mem, VBO_TYPE type) {
	vbo_mem->type = type;
	vbo_mem->size = struct_size(type);
}

static void* resize(HgVboMemory* vbo_mem, uint32_t count, uint32_t size) {
	void* buf = realloc(vbo_mem->buffer, count * size);
	assert(buf != NULL);
	vbo_mem->buffer = buf;

	return buf;
}

void hgvbo_clear(HgVboMemory* vbo_mem) {
	free(vbo_mem->buffer);
	vbo_mem->buffer = NULL;
	vbo_mem->count = 0;
}

void hgvbo_destroy(HgVboMemory* vbo) {
	glDeleteBuffers(1, vbo->vbo_id);
	glDeleteBuffers(1, vbo->vao_id);
	free(vbo->buffer);
	vbo->buffer = NULL;
	vbo->count = 0;
}

uint32_t hgvbo_add_data_vc(HgVboMemory* vbo_mem, vertex* vertices, color* color, uint16_t count) {
	vbo_layout_vc* buf = resize(vbo_mem, vbo_mem->count + count, sizeof(*buf));
	buf = buf + vbo_mem->count;

	for (uint16_t i = 0; i < count; ++i) {
		buf[i].v = vertices[i];
		buf[i].c = color[i];
	}

	uint32_t offset = vbo_mem->count;
	vbo_mem->count += count;
	vbo_mem->needsUpdate = 1;

	return offset;
}

uint32_t hgvbo_add_data_vnu_raw(HgVboMemory* vbo_mem, vbo_layout_vnu* data, uint16_t count) {
	vbo_layout_vnu* buf = resize(vbo_mem, vbo_mem->count + count, sizeof(*buf));
	buf = buf + vbo_mem->count;

	for (uint16_t i = 0; i < count; ++i) {
		buf[i]= data[i];
	}

	uint32_t offset = vbo_mem->count;
	vbo_mem->count += count;
	vbo_mem->needsUpdate = 1;

	return offset;
}

uint32_t hgvbo_add_data_raw(HgVboMemory* vbo_mem, void* data, uint16_t count) {
	vbo_layout_vnu* buf = resize(vbo_mem, vbo_mem->count + count, vbo_mem->size);
	buf = buf + vbo_mem->count;

	memcpy(buf, data, count*vbo_mem->size);

	uint32_t offset = vbo_mem->count;
	vbo_mem->count += count;
	vbo_mem->needsUpdate = 1;

	return offset;
}

static void hgvbo_sendogl(HgVboMemory* vbo_mem) {
	if (vbo_mem->vbo_id == 0) glGenBuffers(1, &vbo_mem->vbo_id);
	if (vbo_mem->vao_id == 0) glGenVertexArrays(1, &vbo_mem->vao_id);
<commit_msg>fix possible bug in pointer math<commit_after>#include <HgVbo.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>

#include <string.h>

HgVboMemory staticVbo;
HgVboMemory staticVboVNU;

static HgVboMemory* _currentVbo;

static uint16_t struct_size(VBO_TYPE type) {
	if (type == VBO_VC) return sizeof(vbo_layout_vc);
	if (type == VBO_VNU) return sizeof(vbo_layout_vnu);
	if (type == VBO_INDEX8) return sizeof(uint8_t);
	if (type == VBO_INDEX16) return sizeof(uint16_t);

	fprintf(stderr, "Unknown vbo type:%d\n", type);
	assert(!"Unknown vbo type");
	return 0;
}

void hgvbo_init(HgVboMemory* vbo_mem, VBO_TYPE type) {
	vbo_mem->type = type;
	vbo_mem->size = struct_size(type);
}

static void* resize(HgVboMemory* vbo_mem, uint32_t count, uint32_t size) {
	void* buf = realloc(vbo_mem->buffer, count * size);
	assert(buf != NULL);
	vbo_mem->buffer = buf;

	return buf;
}

void hgvbo_clear(HgVboMemory* vbo_mem) {
	free(vbo_mem->buffer);
	vbo_mem->buffer = NULL;
	vbo_mem->count = 0;
}

void hgvbo_destroy(HgVboMemory* vbo) {
	glDeleteBuffers(1, vbo->vbo_id);
	glDeleteBuffers(1, vbo->vao_id);
	free(vbo->buffer);
	vbo->buffer = NULL;
	vbo->count = 0;
}

uint32_t hgvbo_add_data_vc(HgVboMemory* vbo_mem, vertex* vertices, color* color, uint16_t count) {
	vbo_layout_vc* buf = resize(vbo_mem, vbo_mem->count + count, sizeof(*buf));
	buf = buf + vbo_mem->count;

	for (uint16_t i = 0; i < count; ++i) {
		buf[i].v = vertices[i];
		buf[i].c = color[i];
	}

	uint32_t offset = vbo_mem->count;
	vbo_mem->count += count;
	vbo_mem->needsUpdate = 1;

	return offset;
}

uint32_t hgvbo_add_data_vnu_raw(HgVboMemory* vbo_mem, vbo_layout_vnu* data, uint16_t count) {
	vbo_layout_vnu* buf = resize(vbo_mem, vbo_mem->count + count, sizeof(*buf));
	buf = buf + vbo_mem->count;

	for (uint16_t i = 0; i < count; ++i) {
		buf[i]= data[i];
	}

	uint32_t offset = vbo_mem->count;
	vbo_mem->count += count;
	vbo_mem->needsUpdate = 1;

	return offset;
}

uint32_t hgvbo_add_data_raw(HgVboMemory* vbo_mem, void* data, uint16_t count) {
	uint8_t* buf = resize(vbo_mem, vbo_mem->count + count, vbo_mem->size);
	buf = buf + (vbo_mem->count * vbo_mem->size);

	memcpy(buf, data, count*vbo_mem->size);

	uint32_t offset = vbo_mem->count;
	vbo_mem->count += count;
	vbo_mem->needsUpdate = 1;

	return offset;
}

static void hgvbo_sendogl(HgVboMemory* vbo_mem) {
	if (vbo_mem->vbo_id == 0) glGenBuffers(1, &vbo_mem->vbo_id);
	if (vbo_mem->vao_id == 0) glGenVertexArrays(1, &vbo_mem->vao_id);

{'fraction_non_alphanumeric': 0.14997964997965, 'fraction_numerical': 0.01973951973951974, 'mean_word_length': 5.182389937106918, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 80, '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': '5955853', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2170, 'n_words': 432}