DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
visualvu1.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 185
4
5#include <cstring>
6
7#include "dataalloc.hpp"
8#include "dataset.hpp"
9#include "mathutil.hpp"
10#include "mdt.hpp"
11#include "mglib.hpp"
12#include "renderinfo.hpp"
13#include "texture.hpp"
14#include "tim2.hpp"
15#include "visual.hpp"
16
17void SetTextureInfo(CTexture *tex, char *name, TM2_head *head) {
18 TM2_picture *picture = (TM2_picture *) ((u_char *) head + 16);
19 int width = head->image_width;
20 int height = head->image_height;
21 int bpp;
22 int psm = SCE_GS_PSMCT32;
23 u_char *clut;
24 u_char *image;
25 int tw;
26 int th;
27 int pow2;
28 int k;
29 int tbw;
30
31 switch (head->image_type) {
32 case TIM2_RGB16:
33 psm = SCE_GS_PSMCT16;
34 bpp = 2;
35 break;
36 case TIM2_RGB24:
37 psm = SCE_GS_PSMCT24;
38 bpp = 3;
39 break;
40 case TIM2_RGB32:
41 bpp = 4;
42 break;
43 case TIM2_IDTEX4:
44 psm = SCE_GS_PSMT4;
45 bpp = 0;
46 break;
47 case TIM2_IDTEX8:
48 psm = SCE_GS_PSMT8;
49 bpp = 1;
50 break;
51 }
52
53 clut = 0;
54 image = (u_char *) picture + picture->header_size;
55
56 if (bpp < 2) {
57 clut = image + picture->image_size;
58 }
59
60 u_char *mip[4] = {0, 0, 0, 0};
61
62 if (picture->mipmap_count > 1) {
63 u_char *next = image + picture->mipmap_size[0];
64
65 for (int m = 1; m < picture->mipmap_count; m++) {
66 mip[m] = next;
67 next += picture->mipmap_size[m];
68 }
69 }
70
71 strcpy(tex->name, name);
72 tex->width = width;
73 tex->height = height;
74 tex->bpp = bpp;
75 tex->image[0] = (u_int *) image;
76
77 for (int m = 1; m < 4; m++) {
78 tex->image[m] = (u_int *) mip[m];
79 }
80
81 tex->clut = (u_int *) clut;
82
83 tw = 0;
84 th = 0;
85 pow2 = width;
86
87 while (pow2 >= 2) {
88 pow2 >>= 1;
89 tw++;
90 }
91
92 for (pow2 = 1, k = 0; k < tw; k++) {
93 pow2 <<= 1;
94 }
95
96 if (width != pow2) {
97 tw++;
98 }
99
100 pow2 = height;
101
102 while (pow2 >= 2) {
103 pow2 >>= 1;
104 th++;
105 }
106
107 for (pow2 = 1, k = 0; k < th; k++) {
108 pow2 <<= 1;
109 }
110
111 if (height != pow2) {
112 th++;
113 }
114
115 tbw = width >> 6;
116
117 if (tbw <= 0) {
118 tbw = 1;
119 }
120
121 if (tex->bpp > 1) {
122 tex->tex0 = SCE_GS_SET_TEX0(0, tbw, psm, tw, th, 1, 0, 0, 0, 0, 0, 0);
123 } else {
124 tex->tex0 = SCE_GS_SET_TEX0(0, tbw, psm, tw, th, 1, 0, 0, 0, 0, 0, 1);
125 }
126}
127
128void SetTextureInfo(CTexture *tex, char *name, u_char *buffer) {
129 u_int i;
130 IMG_head *head = (IMG_head *) buffer;
131 IMG_entry *entry = (IMG_entry *) (head + 1);
132
133 for (i = 0; i < head->pictures; i++, entry++) {
134 if (name != 0 && name[0] != 0) {
135 if (strcmp(entry->name, name) != 0) {
136 continue;
137 }
138 }
139
140 SetTextureInfo(tex, entry->name, (TM2_head *) ((u_char *) head + entry->offset));
141 }
142}
143
152 unk_00 = 0;
153 unk_04 = 0;
154}
155
166
167int CVisualVu1::RemakeData(unsigned int *data) {
168 return 0;
169}
170#ifndef PORT
174static inline float InverseLength(float *vector) {
175 register float *source = vector;
176 register int root;
177 register float length = 0.0f;
178
179 asm {
180 lqc2 vf4, 0(source)
181 vmul.xyz vf4, vf4, vf4
182 vnop
183 vnop
184 vnop
185 vmr32.xy vf5, vf4
186 vnop
187 vnop
188 vnop
189 vmr32.x vf6, vf5
190 vnop
191 vnop
192 vnop
193 vadd.x vf7, vf4, vf5
194 vnop
195 vnop
196 vnop
197 vadd.x vf5, vf6, vf7
198 vrsqrt Q, vf0w, vf5x
199 vwaitq
200 cfc2.ni root, $vi22
201 mtc1 root, length
202 }
203
204 return length;
205}
206#endif
210static inline bool IsOff(int flag) {
211 return !flag;
212}
213
221int CVisualVu1::DrawVu1(sceVif1Packet *packet, float (*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2) {
222 sceVif1PkTerminate(packet);
223 int size;
224 sceVif1PkReserve(packet, size = CVisualVu1::DrawVu1((u_int *) packet->pCurrent, matrix, info, program, draw_state, unknown1, unknown2));
225 return size;
226}
227
231static int SetShadowData(u_int *packet, float (*matrix)[4]) {
232 packet[0] = 0;
233 packet[1] = 0;
234 packet[2] = 0;
235 packet[3] = 0x6C080029;
236 packet[4] = 0x8001;
237 packet[5] = 0x102E8000;
238 packet[6] = 0xE;
239 packet[7] = 0;
240 packet[8] = 0x68;
241 packet[9] = 0x80;
242 packet[10] = 0x42;
243 packet[11] = 0;
244 packet[12] = 0x8001;
245 packet[13] = 0x102E8000;
246 packet[14] = 0xE;
247 packet[15] = 0;
248 packet[16] = 0x62;
249 packet[17] = 0x80;
250 packet[18] = 0x42;
251 packet[19] = 0;
252 ((u_long128 *) packet)[5] = ((u_long128 *) matrix)[0];
253 ((u_long128 *) packet)[6] = ((u_long128 *) matrix)[1];
254 ((u_long128 *) packet)[7] = ((u_long128 *) matrix)[2];
255 ((u_long128 *) packet)[8] = ((u_long128 *) matrix)[3];
256 return 0x24;
257}
258
259int SetMaterial(u_int *packet, MDT_MATERIAL *material) {
260 if (material == NULL) {
261 return 0x14;
262 }
263
264 packet[0] = 0;
265 packet[1] = 0;
266 packet[2] = 0;
267 packet[3] = 0x6C040025;
268 u_int last_row[4] = {3, 0, 0, 0};
269 ((u_long128 *) packet)[1] = *(u_long128 *) material->diffuse;
270 ((u_long128 *) packet)[2] = *(u_long128 *) material->ambient;
271 ((u_long128 *) packet)[3] = *(u_long128 *) material->specular;
272 ((u_long128 *) packet)[4] = *(u_long128 *) last_row;
273 return 0x14;
274}
275
276int SetTEX0(u_int *packet, u_long tex0, u_long tex1) {
277 packet[0] = 0;
278 packet[1] = 0;
279 packet[2] = 0;
280
281 if (tex1 == 0) {
282 tex1 = *(u_long *) &mgTEX1Env;
283 }
284
285 if (tex1 != 0) {
286 packet[3] = 0x50000003;
287 packet[4] = 0x8002;
288 packet[5] = 0x10000000;
289 packet[6] = 0xE;
290 packet[7] = 0;
291 packet += 8;
292 } else {
293 packet[3] = 0x50000002;
294 packet[4] = 0x8001;
295 packet[5] = 0x10000000;
296 packet[6] = 0xE;
297 packet[7] = 0;
298 packet += 8;
299 }
300
301 packet[0] = (u_int) tex0;
302 packet[1] = (u_int) ((tex0 >> 32) & 0xFFFFFFFF);
303 packet[2] = SCE_GS_TEX0_1;
304 packet[3] = 0;
305
306 if (tex1 != 0) {
307 packet[4] = (u_int) tex1;
308 packet[5] = (u_int) ((tex1 >> 32) & 0xFFFFFFFF);
309 packet[6] = SCE_GS_TEX1_1;
310 packet[7] = 0;
311 return 0x10;
312 }
313
314 return 0xC;
315}
316
326 vu_data = NULL;
327 vu_size = 0;
328 unk_00 = 0;
329 unk_04 = 0;
330}
331
342
351 this->data = data;
352}
353
362 return data;
363}
364
374 copy_on_draw = false;
375 data = NULL;
376 vu_data_buffer[1] = NULL;
377 vu_data_buffer[0] = NULL;
378}
379
390
398int CVisualVu1::DrawVu1(u_int *packet, float (*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2) {
399 u_int *start;
400 u_int *header;
401 sceVu0FVECTOR shadow_point;
402 sceVu0FVECTOR shadow_normal;
403 sceVu0FMATRIX shadow_matrix;
404 sceVu0FMATRIX screen_matrix;
405 sceVu0FMATRIX normal_matrix;
406 sceVu0FVECTOR eye;
407 sceVu0FMATRIX inverse;
408 sceVu0FMATRIX clip_matrix;
409 u_int *tag;
410 u_int *unpack;
411 u_int *unpack_data;
412 bool lighting;
413 u_int fog_color;
414 float inv_len_x;
415 float inv_len_y;
416 float inv_len_z;
417
418 if (vu_data == NULL || vu_size == 0) {
419 return 0;
420 }
421
422 sceVu0CopyVector(shadow_point, info->shadow_point);
423 sceVu0CopyVector(shadow_normal, info->shadow_normal);
424
425 if (program == 6 || program == 4 || program == 0) {
426 MulMatrix(screen_matrix, info->view_screen, matrix);
427 } else {
428 MulMatrix(screen_matrix, info->view_scaled, matrix);
429 }
430
431 start = packet;
432 tag = packet;
433 *packet++ = 0x10000000;
434 *packet++ = 0;
435 *packet++ = 0;
436 *packet++ = 0;
437 header = packet;
438 *packet++ = 0;
439 *packet++ = 0;
440 *packet++ = 0;
441 *packet++ = 0x50000004;
442 *packet++ = 0x8003;
443 *packet++ = 0x10000000;
444 *packet++ = 0xE;
445 *packet++ = 0;
446 *packet++ = 0;
447 *packet++ = 0;
448 *packet++ = 0x1A;
449 *packet++ = 0;
450 lighting = false;
451
452 if (IsOff(info->shadow_pass) && IsOff(info->unlit)) {
453 lighting = true;
454 }
455
456 *packet++ = ((program == 15) << 8) | ((!info->shadow_pass << 3) | (((((info->fog_enabled != 0 && !info->shadow_pass)) << 5) | 0x40) | (lighting * 16)));
457 *packet++ = 0;
458 *packet++ = 0x1B;
459 *packet++ = 0;
460 fog_color = info->fog_red;
461 fog_color |= info->fog_green << 8;
462 fog_color |= info->fog_blue << 16;
463 *packet++ = fog_color;
464 *packet++ = 0;
465 *packet++ = 0x3D;
466 *packet++ = 0;
467 *packet++ = 0;
468 *packet++ = 0x0300003C;
469 *packet++ = 0x020000AA;
470 unpack = packet;
471 packet++;
472 unpack_data = packet;
473 *packet++ = program * 2;
474 *packet++ = info->eye_in_model;
475 *packet++ = info->clip_flags;
476 *packet++ = 0;
477 *(u_long128 *) packet = *(u_long128 *) screen_matrix[0];
478 packet += 4;
479 *(u_long128 *) packet = *(u_long128 *) screen_matrix[1];
480 packet += 4;
481 *(u_long128 *) packet = *(u_long128 *) screen_matrix[2];
482 packet += 4;
483 *(u_long128 *) packet = *(u_long128 *) screen_matrix[3];
484 packet += 4;
485
486 // The normal matrix is the model matrix with its axes rescaled to unit length.
487 inv_len_x = InverseLength(matrix[0]);
488 inv_len_y = InverseLength(matrix[1]);
489 inv_len_z = InverseLength(matrix[2]);
490
491 if (info->shadow_pass != 0) {
492 sceVu0ScaleVector(normal_matrix[0], matrix[0], inv_len_x * inv_len_x);
493 sceVu0ScaleVector(normal_matrix[1], matrix[1], inv_len_y * inv_len_y);
494 sceVu0ScaleVector(normal_matrix[2], matrix[2], inv_len_z * inv_len_z);
495 } else {
496 sceVu0ScaleVector(normal_matrix[0], matrix[0], inv_len_x);
497 sceVu0ScaleVector(normal_matrix[1], matrix[1], inv_len_y);
498 sceVu0ScaleVector(normal_matrix[2], matrix[2], inv_len_z);
499 }
500
501 normal_matrix[0][3] = 0.0f;
502 normal_matrix[1][3] = 0.0f;
503 normal_matrix[2][3] = 0.0f;
504 *(u_long128 *) packet = *(u_long128 *) normal_matrix[0];
505 packet += 4;
506 *(u_long128 *) packet = *(u_long128 *) normal_matrix[1];
507 packet += 4;
508 *(u_long128 *) packet = *(u_long128 *) normal_matrix[2];
509 packet += 4;
510 *(u_long128 *) packet = *(u_long128 *) normal_matrix[3];
511 packet += 4;
512
513 if (unknown2 == 0) {
514 *(u_long128 *) packet = *(u_long128 *) info->light_direction[0];
515 packet += 4;
516 *(u_long128 *) packet = *(u_long128 *) info->light_direction[1];
517 packet += 4;
518 *(u_long128 *) packet = *(u_long128 *) info->light_direction[2];
519 packet += 4;
520 *(u_long128 *) packet = *(u_long128 *) info->light_direction[3];
521 packet += 4;
522 *(u_long128 *) packet = *(u_long128 *) info->light_color[0];
523 packet += 4;
524 *(u_long128 *) packet = *(u_long128 *) info->light_color[1];
525 packet += 4;
526 *(u_long128 *) packet = *(u_long128 *) info->light_color[2];
527 packet += 4;
528 *(u_long128 *) packet = *(u_long128 *) info->light_color[3];
529 packet += 4;
530 *(u_long128 *) packet = *(u_long128 *) info->ambient;
531 packet += 4;
532 *(u_long128 *) packet = *(u_long128 *) info->scale;
533 packet += 4;
534 *(u_long128 *) packet = *(u_long128 *) info->offset;
535 packet += 4;
536 *(u_long128 *) packet = *(u_long128 *) info->clip_max;
537 packet += 4;
538 *(u_long128 *) packet = *(u_long128 *) info->clip_min;
539 packet += 4;
540 *packet++ = *(u_int *) &info->fog_a;
541 *packet++ = *(u_int *) &info->fog_near;
542 *packet++ = *(u_int *) &info->fog_far;
543 *packet++ = *(u_int *) &info->fog_b;
544
545 if (info->eye_in_model != 0) {
546 eye[0] = info->position[0];
547 eye[1] = info->position[1];
548 eye[2] = info->position[2];
549 eye[3] = 1.0f;
550 sceVu0CopyMatrix(inverse, matrix);
551 sceVu0InversMatrix(inverse, inverse);
552 sceVu0ApplyMatrix(eye, inverse, eye);
553 *(u_long128 *) packet = *(u_long128 *) eye;
554 packet += 4;
555 } else {
556 packet += 4;
557 }
558
559 MulMatrix(clip_matrix, info->perspective, info->view_scaled);
560 MulMatrix(clip_matrix, clip_matrix, matrix);
561 *(u_long128 *) packet = *(u_long128 *) clip_matrix[0];
562 packet += 4;
563 *(u_long128 *) packet = *(u_long128 *) clip_matrix[1];
564 packet += 4;
565 *(u_long128 *) packet = *(u_long128 *) clip_matrix[2];
566 packet += 4;
567 *(u_long128 *) packet = *(u_long128 *) clip_matrix[3];
568 packet += 4;
569 *(u_long128 *) packet = *(u_long128 *) info->viewport[0];
570 packet += 4;
571 *(u_long128 *) packet = *(u_long128 *) info->viewport[1];
572 packet += 4;
573 *(u_long128 *) packet = *(u_long128 *) info->viewport[2];
574 packet += 4;
575 *(u_long128 *) packet = *(u_long128 *) info->viewport[3];
576 packet += 4;
577
578 if (info->shadow_pass != 0) {
579 MulMatrix(shadow_matrix, info->shadow, matrix);
580 MulMatrix(shadow_matrix, info->view_scaled, shadow_matrix);
581 MulMatrix(shadow_matrix, info->perspective, shadow_matrix);
582 }
583
584 if (info->shadow_pass == 0) {
585 *packet++ = 0x8000;
586 *packet++ = 0x302EC000;
587 *packet++ = 0x412;
588 *packet++ = 0;
589 } else {
590 *packet++ = 0x8000;
591 *packet++ = 0x3022C000;
592 *packet++ = 0x412;
593 *packet++ = 0;
594 }
595
596 *packet++ = 0x8001;
597 *packet++ = 0x102E8000;
598 *packet++ = 0xE;
599 *packet++ = 0;
600 *packet++ = 0;
601 *packet++ = 0;
602 *packet++ = 0x3F;
603 *packet++ = 0;
604 }
605
606 *unpack = (((packet - unpack_data) >> 2) << 16) | 0x6C000000;
607
608 if (info->shadow_pass != 0) {
609 packet += SetShadowData(packet, shadow_matrix);
610 }
611
612 *tag |= (packet - header) >> 2;
613 *packet++ = vu_size | 0x30000000;
614 *packet++ = (u_int) vu_data;
615 *packet++ = 0;
616 *packet++ = 0;
617 *packet++ = 0x10000003;
618 *packet++ = 0;
619 *packet++ = 0;
620 *packet++ = 0;
621 *packet++ = 0;
622 *packet++ = 0;
623 *packet++ = 0;
624 *packet++ = 0x50000002;
625 *packet++ = 0x8001;
626 *packet++ = 0x10000000;
627 *packet++ = 0xE;
628 *packet++ = 0;
629 *packet++ = 1;
630 *packet++ = 0;
631 *packet++ = 0x1A;
632 *packet++ = 0;
633 return packet - start;
634}
635
643static int SetVuData(int count, u_long128 *block, u_int *index, u_long128 *vertex, u_long128 *normal, u_long128 *uv, u_long128 *colour, int prim) {
644 u_int *header = (u_int *) block;
645 u_int *cursor = (u_int *) block;
646 u_long128 *vertex_out;
647 u_long128 *normal_out;
648 u_long128 *uv_out;
649 u_long128 *colour_out;
650
651 header[0] = count | 0x8000;
652
653 if (prim != 4) {
654 cursor[1] = 0x302DC000;
655 cursor += 2;
656 } else {
657 cursor[1] = 0x302E4000;
658 cursor += 2;
659 }
660
661 cursor[0] = 0x412;
662 cursor[1] = 0;
663 cursor[2] = count;
664 cursor[3] = prim;
665
666 if (colour != NULL) {
667 cursor[4] = 0x100;
668 } else {
669 cursor[4] = 0;
670 }
671
672 vertex_out = &block[2];
673 normal_out = &vertex_out[count];
674 uv_out = &normal_out[count];
675 colour_out = &uv_out[count];
676
677 for (int i = count; i > 0; i--) {
678 *vertex_out++ = vertex[index[0]];
679 *normal_out++ = normal[index[1]];
680 *uv_out++ = uv[index[2]];
681 index += 3;
682
683 if (colour != NULL) {
684 *colour_out++ = colour[*index];
685 index++;
686 }
687 }
688
689 int size = count * 3 + 2;
690
691 if (colour != NULL) {
692 size = count * 4 + 2;
693 }
694
695 return size;
696}
697
705int CVisualVu1::CreateVUdataFromMDT(u_int *block, u_int *data, int unknown0, int unknown1) {
706 int first;
707 int strip;
708 int word;
709 int stride;
710 u_long128 *colour;
711 int remaining;
712 u_int *index;
713 MDT_MATERIAL *material_entry;
714 MDT_HEADER *header;
715 u_int *mesh;
716 u_long128 *vertex;
717 u_long128 *normal;
718 u_long128 *uv;
719 MDT_MATERIAL *materials;
720 int strips;
721 int prim;
722 int material;
723 int unpack;
724 int qwc;
725 int limit;
726 int handle;
727 int continued;
728 int size;
729 int count;
730
731 header = (MDT_HEADER *) data;
732 first = 1;
733 word = 0;
734 u_int end[4] = {0x13000000, 0, 0, 0};
735
736 vu_data = block;
737 mesh = (u_int *) ((u_char *) data + header->mesh_ofs);
738 vertex = (u_long128 *) ((u_char *) data + header->vertex_ofs);
739 normal = (u_long128 *) ((u_char *) data + header->normal[1]);
740 uv = (u_long128 *) ((u_char *) data + header->uv[1]);
741
742 if (header->uv[1] <= 0) {
743 uv = vertex;
744 }
745
746 colour = (u_long128 *) ((u_char *) data + header->colour_ofs);
747
748 if (header->colour_ofs <= 0) {
749 stride = 3;
750 colour = NULL;
751 } else {
752 stride = 4;
753 }
754
755 materials = (MDT_MATERIAL *) ((u_char *) data + header->info_ofs);
756 index = mesh + 4;
757 strips = mesh[2];
758
759 for (strip = 0; strip < strips; strip++) {
760 remaining = index[1];
761 prim = index[0];
762 material = index[2];
763 material_entry = &materials[material];
764 index += 3;
765
766 if (material != -1) {
767 handle = TexManager.GetTextureHandle(material_entry->texture, -1);
768 word += SetTEX0(&block[word], TexManager.GetTexture(handle)->tex0, TexManager.GetTexture(handle)->tex1);
769 word += SetMaterial(&block[word], material_entry);
770 }
771
772 limit = 0x36;
773
774 if (colour != NULL) {
775 limit = 0x21;
776 }
777
778 continued = 0;
779
780 while (remaining > 0) {
781 count = limit;
782
783 if (remaining < limit) {
784 count = remaining;
785 }
786
787 qwc = 0;
788 block[word] = 0;
789 block[(u_int) (word + 1)] = 0;
790 block[(u_int) (word + 2)] = 0;
791 unpack = word + 3;
792 block[unpack] = 0x6C008000;
793 word += 4;
794 size = SetVuData(count, (u_long128 *) &block[word], index, vertex, normal, uv, colour, prim);
795
796 // A strip that carries on in the next chunk repeats its last two vertices.
797 if (prim == 4 && limit < remaining) {
798 index -= stride * 2;
799 remaining += 2;
800 }
801
802 index += count * stride;
803 qwc += size;
804 word += size * 4;
805 block[(u_int) unpack] |= qwc << 16;
806 block[word] = 0;
807 block[(u_int) (word + 1)] = 0;
808 block[(u_int) (word + 2)] = 0;
809
810 if (!continued) {
811 if (first) {
812 block[(u_int) (word + 3)] = 0x14000000;
813 word += 4;
814 first = 0;
815 } else {
816 block[(u_int) (word + 3)] = 0x14000001;
817 word += 4;
818 }
819
820 continued = 1;
821 } else {
822 block[(u_int) (word + 3)] = 0x17000000;
823 word += 4;
824 }
825
826 remaining -= limit;
827 }
828
829 *(u_long128 *) &block[word] = *(u_long128 *) end;
830 word += 4;
831 }
832
833 vu_size = word >> 2;
834 return vu_size;
835}
836
837int CVisualVu1::CreateVUdataFromMDTRemake(u_int *block, u_int *data, int unknown0) {
838 int strip;
839 MDT_HEADER *header = (MDT_HEADER *) data;
840 int word = 0;
841 int quads = 0;
842
843 vu_data = block;
844 u_int *mesh = (u_int *) ((u_char *) data + header->mesh_ofs);
845 int stride;
846 u_long128 *vertex = (u_long128 *) ((u_char *) data + header->vertex_ofs);
847 u_long128 *colour = (u_long128 *) ((u_char *) data + header->colour_ofs);
848
849 if (header->colour_ofs <= 0) {
850 stride = 3;
851 colour = NULL;
852 } else {
853 stride = 4;
854 }
855
856 MDT_MATERIAL *materials = (MDT_MATERIAL *) ((u_char *) data + header->info_ofs);
857 u_int *index = mesh + 4;
858 int strips = mesh[2];
859
860 for (strip = 0; strip < strips; strip++) {
861 int remaining = index[1];
862 int prim = index[0];
863 int material = index[2];
864 MDT_MATERIAL *material_entry = &materials[material];
865 index += 3;
866
867 if (material != -1) {
868 word += 16;
869 word += SetMaterial(&block[word], material_entry);
870 }
871
872 int count;
873 int limit = 0x36;
874
875 if (colour != NULL) {
876 limit = 0x21;
877 }
878
879 count = 0;
880
881 while (remaining > 0) {
882 count = limit;
883
884 if (remaining < limit) {
885 count = remaining;
886 }
887
888 word += 4;
889 int i;
890 u_long128 *out;
891 u_int *source = index;
892 index += count * stride;
893 out = (u_long128 *) &block[word] + 2;
894 u_long128 *colour_out = out + count * 3;
895 int size;
896
897 if (colour == NULL) {
898 for (i = count; i > 0; i--) {
899 *out++ = vertex[source[0]];
900 source += 3;
901 }
902
903 size = count * 3 + 2;
904 } else {
905 for (i = count; i > 0; i--) {
906 *out++ = vertex[source[0]];
907 *colour_out++ = colour[source[3]];
908 source += 4;
909 }
910
911 size = count * 4 + 2;
912 }
913
914 if (prim == 4 && limit < remaining) {
915 index -= stride * 2;
916 remaining += 2;
917 }
918
919 quads += size;
920 word += size * 4;
921 word += 4;
922 remaining -= limit;
923 }
924
925 word += 4;
926 }
927
928 vu_size = word >> 2;
929 return vu_size;
930}
931
939int CVisualMDTVu1::DrawVu1(u_int *packet, float (*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2) {
940 int result;
941
942 result = 0;
943 vu_data = vu_data_buffer[DBuffID];
944
945 if (copy_on_draw != 0) {
946 vu_data = (u_int *) ActiveData->Alloc64(vu_size);
947 memcpy(vu_data, vu_data_buffer[DBuffID], vu_size * 16);
948 }
949
950 result += CVisualVu1::DrawVu1(packet, matrix, info, program, draw_state, unknown1, unknown2);
951 vu_data = vu_data_buffer[DBuffID];
952 return result;
953}
954
962int CVisualMDTVu1::DrawVu1(sceVif1Packet *packet, float (*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2) {
963 vu_data = vu_data_buffer[DBuffID];
964 return CVisualVu1::DrawVu1(packet, matrix, info, program, draw_state, unknown1, unknown2);
965}
966
968 if (this->data == NULL) {
969 return 0;
970 }
971
972 return CreateVUdataFromMDTRemake(vu_data_buffer[DBuffID], this->data, 1);
973}
short height
Definition texture.hpp:54
short bpp
Definition texture.hpp:55
u_int * image[4]
Definition texture.hpp:59
char name[32]
Definition texture.hpp:56
u_int * clut
Definition texture.hpp:60
short width
Definition texture.hpp:53
u_long tex1
Definition texture.hpp:58
u_long tex0
Definition texture.hpp:57
virtual int DrawVu1(u_int *packet, float(*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2)
u_int * data
Definition visual.hpp:145
u_int * vu_data_buffer[2]
Definition visual.hpp:147
virtual u_int * GetMDTDataAddress()
virtual int RemakeData(u_int *data)
virtual void SetMDTDataAddress(u_int *data)
virtual void Initialize()
virtual int RemakeData(u_int *data)
u_int * vu_data
Definition visual.hpp:74
virtual int DrawVu1(u_int *packet, float(*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2)
int CreateVUdataFromMDT(u_int *block, u_int *data, int unknown0, int unknown1)
virtual void Initialize()
u_int vu_size
Definition visual.hpp:75
int CreateVUdataFromMDTRemake(u_int *block, u_int *data, int unknown0)
virtual void Initialize()
Definition texture.hpp:17
char name[32]
Definition texture.hpp:18
u_int offset
Definition texture.hpp:19
u_int pictures
Definition texture.hpp:13
int uv[3]
Definition mdt.hpp:20
int vertex_ofs
Definition mdt.hpp:14
int normal[2]
Definition mdt.hpp:15
int mesh_ofs
Definition mdt.hpp:19
int colour_ofs
Definition mdt.hpp:17
int info_ofs
Definition mdt.hpp:21
sceVu0FVECTOR diffuse
Definition mdt.hpp:28
char texture[44]
Definition mdt.hpp:32
sceVu0FVECTOR ambient
Definition mdt.hpp:29
sceVu0FMATRIX light_color
sceVu0FVECTOR scale
sceVu0FMATRIX light_direction
sceVu0FMATRIX perspective
float fog_far
sceVu0FVECTOR clip_min
u_char fog_blue
sceVu0FMATRIX view_screen
u_char fog_red
u_char fog_green
float fog_near
sceVu0FVECTOR shadow_point
sceVu0FMATRIX shadow
sceVu0FVECTOR position
sceVu0FMATRIX viewport
sceVu0FMATRIX view_scaled
sceVu0FVECTOR clip_max
sceVu0FVECTOR ambient
sceVu0FVECTOR shadow_normal
sceVu0FVECTOR offset
u_char image_type
Definition tim2.hpp:35
u_short image_width
Definition tim2.hpp:36
u_short image_height
Definition tim2.hpp:37
u_short header_size
Definition tim2.hpp:46
u_char mipmap_count
Definition tim2.hpp:49
u_int mipmap_size[8]
Definition tim2.hpp:57
u_int image_size
Definition tim2.hpp:45