void Texture::Load(const u8 *file ) { header = (Texture::Header *) file; if (header->magic != MAGIC) return; // bad header u32 texture_count = header->num_textures; // only support a single texture if (texture_count > 1) { // Never saw it happen texture_count = 1; gprintf("texture count > 1\n"); } // read textures const TPL_Texture *tpl_list = (const TPL_Texture *) (file + header->header_size); for(u32 i = 0; i < texture_count; i++) { // seek to texture header const TPL_Texture_Header *texture = (const TPL_Texture_Header *) (file + tpl_list[i].texture_offset); u8 mipmap = 0; u8 bias_clamp = 0; if(texture->max_lod > 0) mipmap = GX_TRUE; if(texture->lod_bias > 0.0f) bias_clamp = GX_ENABLE; // texture data u8 *texture_data = (u8 *) (file + texture->offset); // seek to/read palette header if (tpl_list[i].palette_offset != 0) { palette = (TPL_Palette_Header *) (file + tpl_list[i].palette_offset); // load the texture GX_InitTexObjCI(&texobj, texture_data, texture->width, texture->height, texture->format, texture->wrap_s, texture->wrap_t, mipmap, 0); } else { // load the texture GX_InitTexObj(&texobj, texture_data, texture->width, texture->height, texture->format, texture->wrap_s, texture->wrap_t, mipmap); } // filter mode if(mipmap) { GX_InitTexObjLOD(&texobj, texture->min, texture->mag, texture->min_lod, texture->max_lod, texture->lod_bias, bias_clamp, bias_clamp, texture->edge_lod); } } loaded = true; }
Image::Image(void* texture, u16 wd, u16 ht, u8 fmt, u8 wrap_s, u8 wrap_t, u8 mipmap, void* lut, u8 lut_fmt, u8 lut_name, u16 lut_size) : img_ptr(texture), tlut_ptr(lut), width(wd), height(ht), format(fmt), tlut_format(lut_fmt), tlut_name(lut_name), tlut_size(lut_size) { GX_InitTlutObj(&tlut_obj, tlut_ptr, tlut_format, tlut_size); GX_InitTexObjCI(&obj, img_ptr, width, height, format, wrap_s, wrap_t, mipmap, tlut_name); }