#pragma once // gl_texture_load — carga PNG/JPG/BMP/TGA/HDR desde disco o memoria a una // textura OpenGL lista para usar como sampler2D en shaders. Vendorea stb_image // en cpp/vendor/stb/. Funcion impura: hace I/O y crea recursos GPU. #include "gl_loader.h" namespace fn { struct GlTexture { GLuint id = 0; int w = 0; int h = 0; int channels = 0; bool ok() const { return id != 0; } }; // Carga desde disco. flip_y=true (por defecto) coincide con la convencion // de OpenGL (V hacia arriba). srgb=true sube como GL_SRGB8_ALPHA8 (gamma // correcto sin pow(c, 2.2) en shader). Si el path termina en .hdr se carga // como float (GL_RGBA16F). // // Si falla, devuelve GlTexture con id=0 (ok() == false). Llama a // gl_texture_last_error() para obtener el detalle. GlTexture gl_texture_load(const char* path, bool flip_y = true, bool srgb = false); // Igual que arriba pero leyendo de un buffer en memoria (PNG/JPG/etc bytes). GlTexture gl_texture_load_from_memory(const unsigned char* data, int size, bool flip_y = true, bool srgb = false); // Libera la textura GPU y deja id=0. void gl_texture_destroy(GlTexture& tex); // Mensaje de error del ultimo gl_texture_load* en este thread. "" si no hubo // fallo. Permanece valido hasta el siguiente gl_texture_load* en el thread. const char* gl_texture_last_error(); // Helper: bind a una texture unit y subir uniform sampler2D al programa. // program debe ser un GLuint valido, name el nombre del uniform sampler2D, // unit el slot de textura (0..N). void gl_texture_bind_uniform(GLuint program, const char* name, const GlTexture& tex, int unit); } // namespace fn