//
// Created by Tristan on 1/4/2026.
//

#ifndef TEXTURE_H
#define TEXTURE_H

#include <glad/glad.h>
#include <stdint.h>
#include <stdlib.h>

#ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT  0x83F0
#endif
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
#endif
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
#endif
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
#endif

// BLP2 Header def
typedef struct {
    char   magic[4];            // "BLP2"
    uint32_t version;           // always 1
    uint8_t compression;        // 1=Raw/Paletted, 2=DXT
    uint8_t alphaBits;          // 0, 1, 8
    uint8_t pixelFormat;        // 0=DXT1, 1=DXT3, 7=DXT5
    uint8_t mipFlags;
    uint32_t width;
    uint32_t height;
    uint32_t mipOffset[16];
    uint32_t mipSize[16];
} BLPHeader;

// Loads a BLP file from memory directly to the GPU
GLuint texture_load_from_blp_memory(const uint8_t* file_data, size_t file_size);

#endif //TEXTURE_H
