<commit_before>#include "core/debug_print.h"
#include "core/ensure.h"
#include "platform/gl.h"
#include "texture.h"

#include <lodepng/lodepng.h>

void init_texture(Texture *tex)
{
	debug_print("Texture init: %s", tex->res.name);

	glGenTextures(1, &tex->gl_id);
	glBindTexture(GL_TEXTURE_2D, tex->gl_id);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); /// @todo Mipmaps

	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1000);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1000);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -0.6);

	glTexImage2D(	GL_TEXTURE_2D,
					0,
					GL_RGBA8,
					tex->reso[0],
					tex->reso[1],
					0,
					GL_RGBA,
					GL_UNSIGNED_BYTE,
					(void*)tex->texels);
}

void deinit_texture(Texture *tex)
{
	debug_print("Texture deinit: %s", tex->res.name);
	glDeleteTextures(1, &tex->gl_id);
}

int json_texture_to_blob(BlobBuf blob, BlobOffset *offset, JsonTok j)
{
	int return_value= 0;

	U8 *image= NULL;
	U32 width, height;
	int err=
		lodepng_decode32_file(&image, &width, &height, "../../resources/gamedata/barrel_color.png");
	if (err) {
		critical_print("PNG load error: %s", lodepng_error_text(err));
		goto error;
	}<commit_msg>Texture file attrib<commit_after>#include "core/debug_print.h"
#include "core/ensure.h"
#include "platform/gl.h"
#include "texture.h"

#include <lodepng/lodepng.h>

void init_texture(Texture *tex)
{
	debug_print("Texture init: %s", tex->res.name);

	glGenTextures(1, &tex->gl_id);
	glBindTexture(GL_TEXTURE_2D, tex->gl_id);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); /// @todo Mipmaps

	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1000);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1000);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -0.6);

	glTexImage2D(	GL_TEXTURE_2D,
					0,
					GL_RGBA8,
					tex->reso[0],
					tex->reso[1],
					0,
					GL_RGBA,
					GL_UNSIGNED_BYTE,
					(void*)tex->texels);
}

void deinit_texture(Texture *tex)
{
	debug_print("Texture deinit: %s", tex->res.name);
	glDeleteTextures(1, &tex->gl_id);
}

int json_texture_to_blob(BlobBuf blob, BlobOffset *offset, JsonTok j)
{
	int return_value= 0;
	U8 *image= NULL;

	JsonTok j_file= json_value_by_key(j, "file");
	if (json_is_null(j_file)) {
		critical_print("Attrib 'file' missing for Texture: %s",
				json_str(json_value_by_key(j, "name")));
		goto error;
	}

	U32 width, height;
	int err=
		lodepng_decode32_file(&image, &width, &height, json_str(j_file));
	if (err) {
		critical_print("PNG load error: %s", lodepng_error_text(err));
		goto error;
	}
{'fraction_non_alphanumeric': 0.1313246162592382, 'fraction_numerical': 0.022171688459351906, 'mean_word_length': 6.270661157024794, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6019705', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1482, 'n_words': 230}