1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 221
16#include "dataalloc.hpp"
25#define TEXTURE_TEX0(tbp0, tbw, psm, tw, th, tcc, tfx, cbp, cpsm, csm, csa, cld) ((u_long) (tbp0) | ((u_long) (tbw) << 14) | ((u_long) (psm) << 20) | ((u_long) (tw) << 26) | ((u_long) (th) << 30) | ((u_long) (tcc) << 34) | ((u_long) (tfx) << 35) | ((u_long) (cbp) << 37) | ((u_long) (cpsm) << 51) | ((u_long) (csm) << 55) | ((u_long) (csa) << 56) | ((u_long) (cld) << 61))
30static u_long128 texData[100];
32static int BlockConv8to32(u_char *source, u_char *destination);
33static int Conv8to32(
int width,
int height, u_char *source, u_char *destination);
39void CTexture::Initialize() {
55CTextureBlock::CTextureBlock() {
59void CTextureBlock::Initialize() {
70void CTextureManager::Initialize(
int size) {
75 limit = TextureData.
limit;
76 SetBuffer((u_long128 *) (TextureData.
base + TextureData.
used * 16), limit);
78 for (i = 0; i < 72; i++) {
82 for (i = 0; i < 196; i++) {
90 for (i = 0; i < 72; i++) {
96 for (i = 0; i < 72; i++) {
108 textures[0].
tex0 = SCE_GS_SET_TEX0(mgTopVRAM, 10, 0, 10, 8, 1, 0, 0, 0, 0, 0, 0);
110 textures[0].
tex0 = SCE_GS_SET_TEX0(6720, 10, 0, 10, 8, 1, 0, 0, 0, 0, 0, 0);
118void CTextureManager::SetBuffer(u_long128 *buffer,
int size) {
124 misalignment = (int) this->buffer & 0x7f;
126 if (misalignment != 0) {
127 skipped_quads = (128 - misalignment) >> 4;
128 this->buffer = (u_long128 *) ((
int) this->buffer + skipped_quads * 16);
135int CTextureManager::SearchTextureName(
char *name,
int block) {
139 for (; i >= 0; i--, tex--) {
145 if (tex->
name[0] == 0) {
149 if (block >= 0 && block != tex->
block) {
154 entry_cursor = tex->
name;
156 while ((name_char = *name_cursor) != 0 && (entry_char = *entry_cursor) != 0) {
157 if (name_char != entry_char) {
165 if (name_char == 0 && *entry_cursor == 0) {
173int CTextureManager::GetTextureHandle(
char *name,
int block) {
174 int handle = SearchTextureName(name, block);
183CTexture *CTextureManager::GetTexture(
int handle) {
191CTexture *CTextureManager::GetTexture(
char *name,
int block) {
192 int handle = GetTextureHandle(name, block);
198 return GetTexture(handle);
201CTexture *CTextureManager::SearchTexture(
char *name) {
205 for (i = 1; i < 196; i++, tex++) {
207 printf(
"Texture Over!!\n");
213 if (tex->
name[0] == 0) {
218 SearchTextureName(name, -1);
222void CTextureManager::EnterTexture(
int block,
char *name, u_char *image,
int width,
int height,
int bpp, u_char *clut,
int clut_colors,
int mipmap, u_char *mip1, u_char *mip2, u_char *mip3, u_long tex1,
int swizzled) {
246 tex = SearchTexture(name);
248 if (image == 0 || mip1 == 0) {
257 psm = SCE_GS_PSMCT24;
260 psm = SCE_GS_PSMCT32;
275 for (power = 1, bit = 0; bit < tw; bit++) {
279 if (width != power) {
290 for (power = 1, bit = 0; bit < th; bit++) {
294 if (height != power) {
298 half_width = width >> 1;
299 half_height = height >> 1;
309 static int clut_adr = 16000;
311 image_size = width * height * bpp;
312 image_blocks = image_size >> 8;
313 destination = (u_int *) (this->buffer +
buffer_used);
324 vram_top += image_blocks;
327 if (psm == SCE_GS_PSMT8) {
335 tex->
image[0] = destination;
337 if (psm == SCE_GS_PSMT8 && swizzled == 0) {
338 Conv8to32(width, height, image, (u_char *) destination);
340 memcpy(destination, image, image_size);
343 vram_end += image_blocks;
347 destination = (u_int *) (this->buffer +
buffer_used);
348 tex->
image[1] = destination;
350 if (psm == SCE_GS_PSMT8 && swizzled == 0) {
351 Conv8to32(half_width, half_height, mip1, (u_char *) destination);
353 memcpy(destination, mip1, image_size >> 2);
356 mip_blocks = image_blocks >> 2;
357 vram_end += mip_blocks;
360 destination = (u_int *) (this->buffer +
buffer_used);
361 tex->
image[2] = destination;
363 if (psm == SCE_GS_PSMT8 && swizzled == 0) {
364 Conv8to32(width >> 2, height >> 2, mip2, (u_char *) destination);
366 memcpy(destination, mip2, image_size >> 4);
369 vram_end += mip_blocks >> 2;
373 if (psm == SCE_GS_PSMT8) {
376 u_int *clut_buffer = (u_int *) (this->buffer +
buffer_used);
377 tex->
clut = clut_buffer;
378 memcpy(clut_buffer, clut, 1024);
381 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, cbp, 0, 0, 0, 1);
384 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, 0, 0, 0, 0, 0);
392 if (psm != SCE_GS_PSMT8) {
393 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, 0, 0, 0, 0, 0);
395 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, cbp, 0, 0, 0, 1);
399 misalignment = vram_end % 32;
401 if (misalignment != 0) {
402 vram_end += 32 - misalignment;
410 printf(
"texture buffer over!!\n");
417 printf(
"VRAM is not enough\n");
418 printf(
"%s %d\n", name,
blocks[block].vram_end);
424 strcpy(tex->
name, name);
430 if (bpp > 0 && mipmap != 0) {
431 tex->
tex1 = SCE_GS_SET_TEX1(0, 2, 1, 5, 1, 0, -120);
435 tex->
tex1 = SCE_GS_SET_TEX1(0, 2, 1, 5, 1, lod->L, lod->K);
444void CTextureManager::EnterTextureEX(
int block,
char *name, u_char *image,
int width,
int height,
int bpp, u_char *clut,
int clut_colors,
int mipmap, u_char *mip1, u_char *mip2, u_char *mip3, u_long tex1,
int swizzled) {
464 tex = SearchTexture(name);
466 if (image == 0 || mip1 == 0) {
475 psm = SCE_GS_PSMCT24;
478 psm = SCE_GS_PSMCT32;
493 for (power = 1, bit = 0; bit < tw; bit++) {
497 if (width != power) {
508 for (power = 1, bit = 0; bit < th; bit++) {
512 if (height != power) {
524 image_blocks = (width * height * bpp) >> 8;
536 vram_top += image_blocks;
539 if (psm == SCE_GS_PSMT8) {
547 tex->
image[0] = (u_int *) image;
548 vram_end += image_blocks;
551 tex->
image[1] = (u_int *) mip1;
552 mip_blocks = image_blocks >> 2;
553 vram_end += mip_blocks;
554 tex->
image[2] = (u_int *) mip2;
555 vram_end += mip_blocks >> 2;
558 if (psm == SCE_GS_PSMT8) {
560 tex->
clut = (u_int *) clut;
562 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, cbp, 0, 0, 0, 1);
565 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, 0, 0, 0, 0, 0);
573 if (psm != SCE_GS_PSMT8) {
574 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, 0, 0, 0, 0, 0);
576 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, cbp, 0, 0, 0, 1);
580 misalignment = vram_end % 32;
582 if (misalignment != 0) {
583 vram_end += 32 - misalignment;
590 printf(
"VRAM is not enough\n");
591 printf(
"%s %d\n", name,
blocks[block].vram_end);
597 strcpy(tex->
name, name);
604 if (bpp > 0 && mipmap != 0) {
605 tex->
tex1 = SCE_GS_SET_TEX1(0, 2, 1, 5, 1, 0, -120);
609 tex->
tex1 = SCE_GS_SET_TEX1(0, 2, 1, 5, 1, lod->L, lod->K);
619void CTextureManager::EnterFixTexture(
char *name, u_char *image,
int width,
int height,
int bpp, u_char *clut,
int clut_colors,
int mipmap, u_char *mip1, u_char *mip2, u_char *mip3, u_long tex1,
int swizzled) {
648 tex = SearchTexture(name);
650 if (image == 0 || mip1 == 0) {
659 psm = SCE_GS_PSMCT24;
662 psm = SCE_GS_PSMCT32;
677 for (power = 1, bit = 0; bit < tw; bit++) {
681 if (width != power) {
692 for (power = 1, bit = 0; bit < th; bit++) {
696 if (height != power) {
700 half_width = width >> 1;
701 half_height = height >> 1;
702 quarter_width = half_width >> 1;
703 quarter_height = half_height >> 1;
710 swizzled_tbw = tbw >> 1;
711 mip1_tbw = swizzled_tbw;
717 mip2_tbw = mip1_tbw >> 1;
726 image_size = width * height * bpp;
727 image_blocks = image_size >> 8;
730 mip_blocks = image_blocks >> 2;
731 image_blocks = image_blocks + mip_blocks + (mip_blocks >> 2);
734 misalignment = image_blocks % 32;
736 if (misalignment != 0) {
737 image_blocks += 32 - misalignment;
743 sceGifPkInit(&packet, texData);
744 channel = sceDmaGetChan(2);
745 channel->chcr.TTE = 1;
746 sceGifPkReset(&packet);
752 tbp = upload_address;
755 if (psm != SCE_GS_PSMCT32) {
762 if (psm == SCE_GS_PSMT8 && swizzled != 0) {
763 sceGifPkRefLoadImage(&packet, upload_address, SCE_GS_PSMCT32, swizzled_tbw, (u_long128 *) image, image_size >> 4, 0, 0, half_width, half_height);
765 sceGifPkRefLoadImage(&packet, upload_address, psm, tbw, (u_long128 *) image, image_size >> 4, 0, 0, width, height);
768 upload_address += image_blocks;
772 sceGifPkRefLoadImage(&packet, upload_address, psm, mip1_tbw, (u_long128 *) mip1, (half_width * half_height * bpp) >> 4, 0, 0, half_width, half_height);
775 upload_address += image_blocks >> 2;
778 sceGifPkRefLoadImage(&packet, upload_address, psm, mip2_tbw, (u_long128 *) mip2, (quarter_width * quarter_height * bpp) >> 4, 0, 0, quarter_width, quarter_height);
782 if (psm == SCE_GS_PSMT8) {
785 sceGifPkRefLoadImage(&packet, cbp, SCE_GS_PSMCT32, 1, (u_long128 *) clut, 64, 0, 0, 16, 16);
786 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, cbp, 0, 0, 0, 1);
789 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, 0, 0, 0, 0, 0);
797 if (psm != SCE_GS_PSMT8) {
798 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, 0, 0, 0, 0, 0);
800 tex->
tex0 = TEXTURE_TEX0(tbp, tbw, psm, tw, th, 1, 0, cbp, 0, 0, 0, 1);
804 sceGifPkCnt(&packet, 0, 0, 0);
805 sceGifPkOpenGifTag(&packet, *(u_long128 *) &GiftagAD);
806 sceGifPkAddGsAD(&packet, 63, 0);
807 sceGifPkCloseGifTag(&packet);
808 sceGifPkEnd(&packet, 0, 0, 0);
809 sceGifPkTerminate(&packet);
811 channel->chcr.TTE = 1;
814 sceDmaSend(channel, (
void *) packet.pBase);
819 strcpy(tex->
name, name);
825 if (bpp > 0 && mipmap != 0) {
826 tex->
tex1 = SCE_GS_SET_TEX1(0, 2, 1, 5, 1, 0, -120);
830 tex->
tex1 = SCE_GS_SET_TEX1(0, 2, 1, 5, 1, lod->L, lod->K);
839void CTextureManager::EnterFixTextureZ(u_char *buffer) {
855 name = (
char *) (
buffer + 16);
885 tex = SearchTexture(name);
886 strcpy(tex->
name, name);
892 zbuffer = mgZBufferAdr;
893 tex->
tex0 = SCE_GS_SET_TEX0(zbuffer, 10, 27, 10, 8, 1, 0, 16352, 0, 0, 0, 1);
895 tex->
tex0 = SCE_GS_SET_TEX0(4480, 10, 27, 10, 8, 1, 0, 16352, 0, 0, 0, 1);
898 sceGifPkInit(&packet, texData);
899 channel = sceDmaGetChan(2);
900 channel->chcr.TTE = 1;
901 sceGifPkReset(&packet);
903 sceGifPkRefLoadImage(&packet, zbuffer, 27, 10, (u_long128 *) image, (width * height) >> 4, 0, 0, width, height);
905 sceGifPkRefLoadImage(&packet, 4480, 27, 10, (u_long128 *) image, (width * height) >> 4, 0, 0, width, height);
907 sceGifPkRefLoadImage(&packet, 16352, 0, bpp, (u_long128 *) clut, 64, 0, 0, 16, 16);
908 sceGifPkCnt(&packet, 0, 0, 0);
909 sceGifPkOpenGifTag(&packet, *(u_long128 *) &GiftagAD);
910 sceGifPkAddGsAD(&packet, 63, 0);
911 sceGifPkCloseGifTag(&packet);
912 sceGifPkEnd(&packet, 0, 0, 0);
913 sceGifPkTerminate(&packet);
915 channel->chcr.TTE = 1;
918 sceDmaSend(channel, (
void *) packet.pBase);
924void CTextureManager::EnterIMGFile(u_char *buffer,
int block,
int mipmap,
int extend) {
935 if (memcmp(
buffer,
"IM2", 3) == 0) {
941 for (i = 0; i < *(u_int *) (
buffer + 4); i++) {
983 u_char *mip[4] = {0, 0, 0, 0};
986 u_char *mip_image = image + picture->
mipmap_size[0];
988 for (
int level = 1; level < picture->
mipmap_count; level++) {
989 mip[level] = mip_image;
996 EnterTexture(block, (
char *) entry, image, width, height, bpp, clut, picture->
clut_colors, mipmap, mip[1], mip[2], mip[3], picture->
tex1, swizzled);
998 EnterFixTexture((
char *) entry, image, width, height, bpp, clut, picture->
clut_colors, mipmap, mip[1], mip[2], mip[3], picture->
tex1, swizzled);
1000 }
else if (block >= 0) {
1001 EnterTextureEX(block, (
char *) entry, image, width, height, bpp, clut, picture->
clut_colors, mipmap, mip[1], mip[2], mip[3], picture->
tex1, swizzled);
1010int LoadImage(u_int *packet,
int dbp,
int dpsm,
int dbw, u_long128 *source,
int qwc,
int dsax,
int dsay,
int rrw,
int rrh) {
1011 u_int *start = packet;
1016 packet[0] = 0x10000005;
1019 packet[3] = 0x50000005;
1021 packet[5] = 0x10000000;
1025 bitbltbuf = SCE_GS_SET_BITBLTBUF(0, 0, 0, dbp, dbw, dpsm);
1026 packet[8] = (u_int) (bitbltbuf & 0xffffffff);
1027 packet[9] = (u_int) ((bitbltbuf >> 32) & 0xffffffff);
1031 trxpos = SCE_GS_SET_TRXPOS(0, 0, dsax, dsay, 0);
1032 packet[12] = (u_int) (trxpos & 0xffffffff);
1033 packet[13] = (u_int) ((trxpos >> 32) & 0xffffffff);
1037 trxreg = SCE_GS_SET_TRXREG(rrw, rrh);
1038 packet[16] = (u_int) (trxreg & 0xffffffff);
1039 packet[17] = (u_int) ((trxreg >> 32) & 0xffffffff);
1056 packet[0] = 0x10000001;
1059 packet[3] = 0x50000001;
1060 packet[4] = count | 0x8000;
1061 packet[5] = 0x08000000;
1064 packet[8] = count | 0x30000000;
1065 packet[9] = (u_int) source;
1067 packet[11] = count | 0x50000000;
1073 return packet - start;
1076void CTextureManager::ReloadTexture(
sceVif1Packet *packet,
int block) {
1089 if (block < 0 || block >= 72) {
1098 sceVif1PkCnt(packet, 0);
1099 sceVif1PkOpenDirectCode(packet, 0);
1100 sceVif1PkOpenGifTag(packet, *(u_long128 *) &GiftagAD);
1101 sceVif1PkAddGsAD(packet, 63, 0);
1102 sceVif1PkCloseGifTag(packet);
1103 sceVif1PkCloseDirectCode(packet);
1104 sceVif1PkTerminate(packet);
1106 cursor = packet->pCurrent;
1110 for (i = 0; i < 72; i++) {
1122 if (
blocks[block].vram_end < reload_from || reload_from <= 0) {
1130 if (
blocks[block].loaded == 0) {
1139 if (tex->
block != block) {
1145 if (reload_from < (
int) tex0.TBP0 &&
blocks[block].
loaded != 0) {
1159 tex0.TBW = tex0.TBW >> 1;
1162 if (tex->
clut != 0) {
1163 cursor += LoadImage(cursor, tex0.CBP, tex0.CPSM, 1, (u_long128 *) tex->
clut, 64, 0, 0, 16, 16);
1167 for (level = 0; level < 4; level++) {
1168 if (tex->
image[level] == 0) {
1172 if (tex0.TBW == 0) {
1176 cursor += LoadImage(cursor, tex0.TBP0, tex0.PSM, tex0.TBW, (u_long128 *) tex->
image[level], (bpp * (width * height)) >> 4, 0, 0, width, height);
1177 tex0.TBP0 += (width * height) >> 6;
1178 tex0.TBW = tex0.TBW >> 1;
1184 sceVif1PkReserve(packet, cursor - start);
1187 sceVif1PkCnt(packet, 0);
1188 sceVif1PkOpenDirectCode(packet, 0);
1189 sceVif1PkOpenGifTag(packet, *(u_long128 *) &GiftagAD);
1190 sceVif1PkAddGsAD(packet, 63, 0);
1191 sceVif1PkCloseGifTag(packet);
1192 sceVif1PkCloseDirectCode(packet);
1195void CTextureManager::BeginEnterTextureBlock(
int block) {
1196 if (block < 0 || block >= 72) {
1201 if (
blocks[block].vram_top == 0) {
1205 if (
blocks[block].vram_end == 0) {
1210 if (
blocks[block].vram_top == 0) {
1214 if (
blocks[block].vram_end == 0) {
1224void CTextureManager::EndEnterTextureBlock(
int block) {
1225 if (block < 0 || block >= 72) {
1237 printf(
"texture buffer over!!\n");
1244 printf(
"fix texture over!!\n");
1251int CTextureManager::DeleteTextureBlock(
int block) {
1258 if (block >= 0 && block < 72) {
1259 blocks[block].Initialize();
1266 for (i = 0; i < 196; i++) {
1267 if (block < 0 ||
textures[i].block == block) {
1278int CTextureManager::CleanUpBuffer() {
1279 u_long128 *block_start[72];
1280 int block_order[72];
1284 for (i = 0; i < 72; i++) {
1289 for (i = 0; i < 71; i++) {
1290 for (j = i + 1; j < 72; j++) {
1291 u_long128 **lower = &block_start[i];
1292 u_long128 **upper = &block_start[j];
1293 int *lower_block = &block_order[i];
1294 int *upper_block = &block_order[j];
1296 if (*lower > *upper) {
1297 u_long128 *swap_start = *lower;
1298 int swap_block = *lower_block;
1300 *lower_block = *upper_block;
1301 *upper = swap_start;
1302 *upper_block = swap_block;
1309 for (i = 0; i < 72; i++) {
1310 int block_no = block_order[i];
1311 u_long128 *destination;
1318 if (block_no <= 0) {
1322 source = block_start[i];
1330 shift = (source - destination) * 16;
1334 for (k = 0; k < block_quads; k++) {
1335 *destination = *source;
1340 for (j = 0; j < 196 && shift != 0; j++) {
1344 if (tex->
block != block_no) {
1348 for (level = 0; level < 4; level++) {
1349 u_int **images = tex->
image;
1350 u_int **slot = &images[level];
1352 if (tex->
image[level] == 0) {
1356 *slot = (u_int *) ((
int) *slot - shift);
1359 if (tex->
clut != 0) {
1360 tex->
clut = (u_int *) ((
int) tex->
clut - shift);
1365 misalignment = block_quads % 8;
1367 if (misalignment != 0) {
1375int CTextureManager::CleanUpTextureList() {
1379 for (i = 1; i < 195; i++) {
1382 if (hole->
name[0] != 0) {
1386 for (j = i + 1; j < 196; j++) {
1389 if (tex->
name[0] == 0) {
1404static int GetStr(
char *text,
char *out) {
1411 while (*text !=
'#') {
1412 out[length] = *text;
1426static int GetDummyInfo(
char *text,
char *name,
int *width,
int *height,
int *bpp) {
1428 char height_text[8];
1438 int parsed_width = 32;
1439 int parsed_height = 32;
1441 char parsed_name[32] =
"";
1443 length = GetStr(text, parsed_name);
1451 length = GetStr(text, width_text);
1455 parsed_width = atoi(width_text);
1458 length = GetStr(text, height_text);
1462 parsed_height = atoi(height_text);
1465 length = GetStr(text, bpp_text);
1468 parsed_bpp = atoi(bpp_text);
1471 strcpy(name, parsed_name);
1472 *width = parsed_width;
1473 *height = parsed_height;
1478int CTextureManager::LoadTextureBlock(
int block, u_int *buffer) {
1479 return LoadTextureBlock(block,
file,
buffer);
1482int CTextureManager::LoadTextureBlock(
int block,
LOADTEXTURE_INFO *table, u_int *buffer) {
1487 for (i = 0; i < 72; i++) {
1488 if (block >= 0 && block != i) {
1501 if (info->
name == 0) {
1505 if (info->
name[0] == 0) {
1511 BeginEnterTextureBlock(i);
1520 if (GetDummyInfo(info->
name, name, &width, &height, &bpp) != 0) {
1521 TexManager.EnterTexture(info->
block_no, name, 0, width, height, bpp, 0, 0, 0, 0, 0, 0, 0, 0);
1522 }
else if (LoadFile2(info->
name,
buffer, 0, 0) != 0) {
1531 EndEnterTextureBlock(i);
1543 for (i = 0; i < 72; i++) {
1544 if (block >= 0 && block != i) {
1557 if (info->
name == 0) {
1561 if (info->
name[0] == 0) {
1567 BeginEnterTextureBlock(i);
1576 if (GetDummyInfo(info->
name, name, &width, &height, &bpp) != 0) {
1577 TexManager.EnterTexture(info->
block_no, name, 0, width, height, bpp, 0, 0, 0, 0, 0, 0, 0, 0);
1587 EndEnterTextureBlock(i);
1599 for (i = 0; i < 72; i++) {
1600 if (block >= 0 && block != i) {
1613 if (info->
name == 0) {
1617 if (info->
name[0] == 0) {
1623 BeginEnterTextureBlock(i);
1632 if (GetDummyInfo(info->
name, name, &width, &height, &bpp) != 0) {
1633 TexManager.EnterTextureEX(info->
block_no, name, 0, width, height, bpp, 0, 0, 0, 0, 0, 0, 0, 0);
1635 int mipmap = info->
mipmap;
1638 EnterIMGFile((u_char *) info->
name, entry_block, mipmap, begun);
1646 EndEnterTextureBlock(i);
1661static int PageConv8to32(
int width,
int height, u_char *source, u_char *destination) {
1662 static int block_table8[32] = {
1663 0, 1, 4, 5, 16, 17, 20, 21,
1664 2, 3, 6, 7, 18, 19, 22, 23,
1665 8, 9, 12, 13, 24, 25, 28, 29,
1666 10, 11, 14, 15, 26, 27, 30, 31};
1667 static int block_table32[32] = {
1668 0, 1, 4, 5, 16, 17, 20, 21,
1669 2, 3, 6, 7, 18, 19, 22, 23,
1670 8, 9, 12, 13, 24, 25, 28, 29,
1671 10, 11, 14, 15, 26, 27, 30, 31};
1672 int block_column[32];
1676 u_char *work_cursor;
1677 u_char *source_cursor;
1678 u_char *destination_cursor;
1689 for (i = 0; i < 4; i++) {
1690 for (j = 0; j < 8; j++) {
1691 block_column[block_table32[entry]] = j;
1692 block_row[block_table32[entry]] = i;
1697 blocks_across = width >> 4;
1698 blocks_down = height >> 4;
1700 memset(work8, 0, 256);
1701 memset(work32, 0, 256);
1703 for (i = 0; i < blocks_down; i++) {
1704 for (j = 0; j < blocks_across; j++) {
1705 work_cursor = work8;
1706 source_cursor = source + i * 2048 + j * 16;
1707 block_index = block_table8[i * blocks_across + j];
1709 for (k = 0; k < 16; k++) {
1710 memcpy(work_cursor, source_cursor, 16);
1712 source_cursor += 128;
1715 BlockConv8to32(work8, work32);
1717 work_cursor = work32;
1718 destination_cursor = destination + block_row[block_index] * 2048 + block_column[block_index] * 32;
1720 for (k = 0; k < 8; k++) {
1721 memcpy(destination_cursor, work_cursor, 32);
1723 destination_cursor += 256;
1735static int BlockConv8to32(u_char *source, u_char *destination) {
1736 static int lut[128] = {
1737 0, 36, 8, 44, 1, 37, 9, 45,
1738 2, 38, 10, 46, 3, 39, 11, 47,
1739 4, 32, 12, 40, 5, 33, 13, 41,
1740 6, 34, 14, 42, 7, 35, 15, 43,
1741 16, 52, 24, 60, 17, 53, 25, 61,
1742 18, 54, 26, 62, 19, 55, 27, 63,
1743 20, 48, 28, 56, 21, 49, 29, 57,
1744 22, 50, 30, 58, 23, 51, 31, 59,
1745 4, 32, 12, 40, 5, 33, 13, 41,
1746 6, 34, 14, 42, 7, 35, 15, 43,
1747 0, 36, 8, 44, 1, 37, 9, 45,
1748 2, 38, 10, 46, 3, 39, 11, 47,
1749 20, 48, 28, 56, 21, 49, 29, 57,
1750 22, 50, 30, 58, 23, 51, 31, 59,
1751 16, 52, 24, 60, 17, 53, 25, 61,
1752 18, 54, 26, 62, 19, 55, 27, 63};
1762 for (i = 0; i < 4; i++) {
1763 lut_index = (i & 1) * 64;
1765 for (j = 0; j < 16; j++) {
1766 for (k = 0; k < 4; k++) {
1767 source_index = lut[lut_index];
1769 destination[out_index] = source[source_index];
1780static int Conv8to32(
int width,
int height, u_char *source, u_char *destination) {
1782 u_char work32[8192];
1791 memset(work8, 0, 8192);
1792 memset(work32, 0, 8192);
1793 pages_x = ((width - 1) >> 7) + 1;
1794 pages_y = ((height - 1) >> 6) + 1;
1797 row_bytes = width * 2;
1804 row_count = height >> 1;
1810 for (i = 0; i < pages_y; i++) {
1811 for (j = 0; j < pages_x; j++) {
1812 u_char *source_cursor = source + i * (pages_x * (width << 6)) + width * j;
1813 u_char *work_cursor = work8;
1814 u_char *destination_cursor;
1815 u_char *work_out_cursor;
1817 for (k = 0; k < height; k++) {
1818 memcpy(work_cursor, source_cursor, width);
1819 source_cursor += width * pages_x;
1823 PageConv8to32(128, 64, work8, work32);
1825 destination_cursor = destination + i * (pages_x * (row_bytes * row_count)) + row_bytes * j;
1826 work_out_cursor = work32;
1828 for (k = 0; k < row_count; k++) {
1829 memcpy(destination_cursor, work_out_cursor, row_bytes);
1830 destination_cursor += row_bytes * pages_x;
1831 work_out_cursor += 256;
1839void CTextureManager::print_buff_info() {