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); }
void Texture::Apply(u8 &tlutName, u8 map_id, u8 wrap_s, u8 wrap_t) const { if( !loaded ) { gprintf( "Texture::Apply(): not loaded yet\n" ); return; } if(tlutName >= 20 || map_id >= 8) { gprintf( "Texture::Apply(): bad parameters\n" ); return; } // create a temporary texture object to not modify the original with the wrap_s and wrap_t parameters GXTexObj tempTexObj; for(int i = 0; i < 8; ++i) tempTexObj.val[i] = texobj.val[i]; // assume that if there is a palette header, then this format is a CIx one if(palette) { // seek to/read palette data u8 *tlut_data = (u8 *) (((u8 *) header) + palette->offset); // load tlut GXTlutObj tlutobj; GX_InitTlutObj(&tlutobj, tlut_data, palette->format, palette->num_items ); GX_LoadTlut(&tlutobj, tlutName); GX_InitTexObjTlut(&tempTexObj, tlutName); tlutName++; } GX_InitTexObjWrapMode(&tempTexObj, wrap_s, wrap_t); GX_LoadTexObj(&tempTexObj, map_id); }