summaryrefslogtreecommitdiff
path: root/src/JSystem/J2DGraph/J2DPicture.cpp
blob: d16ad1cec5a376395538b38e4f104d001086c07b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
//
// Generated by dtk
// Translation Unit: J2DPicture.cpp
//

#include "JSystem/J2DGraph/J2DPicture.h"
#include "JSystem/JKernel/JKRFileLoader.h"
#include "JSystem/JSupport/JSURandomInputStream.h"
#include "JSystem/JUtility/JUTResource.h"
#include "JSystem/JUtility/JUTPalette.h"
#include "JSystem/JUtility/JUTTexture.h"
#include "dolphin/types.h"

/* 802D2D94-802D2E1C       .text __ct__10J2DPictureFv */
J2DPicture::J2DPicture() {
    mpTexture[0] = NULL;
    mNumTexture = 0;
    mpPalette = NULL;
    initinfo();
}

/* 802D2E1C-802D326C       .text __ct__10J2DPictureFP7J2DPaneP20JSURandomInputStream */
J2DPicture::J2DPicture(J2DPane* parent, JSURandomInputStream* stream) : mpPalette(NULL) {
    J2DPaneHeader header;

    s32 pos = stream->getPosition();
    stream->read(&header, sizeof(J2DPaneHeader));
    mMagic = header.mMagic;
    pos += header.mSize;

    makePaneStream(parent, stream);
    JUTResReference ref;
    ResTIMG* timg;
    ResTLUT* tlut;
    u8 num = stream->readU8();
    timg = (ResTIMG*)ref.getResource(stream, 'TIMG', NULL);
    tlut = (ResTLUT*)ref.getResource(stream, 'TLUT', NULL);
    mBinding = stream->read8b();
    num -= 3;
    if (num) {
        mFlag = stream->read8b();
        num--;
    } else {
        mFlag = 0;
    }
    if (num) {
        stream->read8b();
        num--;
    }
    mColorBlack = JUtility::TColor(0);
    mColorWhite = JUtility::TColor(-1);
    if (num) {
        mColorBlack = JUtility::TColor(stream->readU32());
        num--;
    }
    if (num) {
        mColorWhite = JUtility::TColor(stream->readU32());
        num--;
    }
    setCornerColor(JUtility::TColor(-1), JUtility::TColor(-1), JUtility::TColor(-1), JUtility::TColor(-1));
    for (int i = 0; num > 0 && i < 4; i++) {
        mCornerColor[i] = JUtility::TColor(stream->readU32());
        num--;
    }
    stream->seek(pos, JSUStreamSeekFrom_SET);
    mpTexture[0] = NULL;
    mNumTexture = 0;
    mValidTexture = 1;
    if (timg) {
        mpTexture[0] = new JUTTexture(timg, 0);
        mNumTexture++;
    }
    if (tlut) {
        mpPalette = new JUTPalette(GX_TLUT0, tlut);
        mpTexture[0]->attachPalette(mpPalette);
    }
    setBlendRatio(1.0f, 1.0f, 1.0f, 1.0f);
}

/* 802D326C-802D3320       .text __ct__10J2DPictureFPC7ResTIMG */
J2DPicture::J2DPicture(const ResTIMG* pTimg) {
    mpTexture[0] = NULL;
    mNumTexture = 0;
    if (pTimg) {
        insert(pTimg, mNumTexture, 1.0f);
    }
    mpPalette = NULL;
    initinfo();
}

/* 802D3320-802D33D4       .text __ct__10J2DPictureFPCc */
J2DPicture::J2DPicture(const char* name) {
    mpTexture[0] = NULL;
    mNumTexture = 0;
    if (name) {
        insert(name, mNumTexture, 1.0f);
    }
    mpPalette = NULL;
    initinfo();
}

/* 802D33D4-802D3474       .text __ct__10J2DPictureFUlRCQ29JGeometry8TBox2<f>PC7ResTIMGPC7ResTLUT */
J2DPicture::J2DPicture(u32 param_1, const JGeometry::TBox2<f32>& bounds, const ResTIMG* pTimg, const ResTLUT* pTlut) : J2DPane(param_1, bounds), mpPalette(NULL) {
    private_initiate(pTimg, pTlut);
    initinfo();
}

/* 802D3474-802D3530       .text initiate__10J2DPictureFPC7ResTIMGPC7ResTLUT */
void J2DPicture::initiate(const ResTIMG* pTimg, const ResTLUT* pTlut) {
    private_initiate(pTimg, pTlut);
    if (!mpTexture[0]) {
        return;
    }
    mBounds = JGeometry::TBox2<f32>(0.0f, 0.0f, mpTexture[0]->getWidth(), mpTexture[0]->getHeight());
    calcMtx();
}

/* 802D3530-802D35FC       .text private_initiate__10J2DPictureFPC7ResTIMGPC7ResTLUT */
void J2DPicture::private_initiate(const ResTIMG* pTimg, const ResTLUT* pTlut) {
    mpTexture[0] = NULL;
    mValidTexture = 1;
    mNumTexture = 0;
    if (pTimg) {
        mpTexture[0] = new JUTTexture(pTimg, 0);
        mNumTexture++;
    }
    mpPalette = NULL;
    if (pTlut) {
        mpPalette = new JUTPalette(GX_TLUT0, (ResTLUT*)pTlut);
        mpTexture[0]->attachPalette(mpPalette);
    }
}

/* 802D35FC-802D3774       .text initinfo__10J2DPictureFv */
void J2DPicture::initinfo() {
    mMagic = 'PIC1';
    mBinding = J2DBind_Bottom | J2DBind_Top | J2DBind_Right | J2DBind_Left;
    mFlag &= 4;
    mFlag &= 3;
    setBlendRatio(1.0f, 1.0f, 1.0f, 1.0f);
    mColorBlack = JUtility::TColor(0);
    mColorWhite = JUtility::TColor(-1);
    setCornerColor(JUtility::TColor(-1), JUtility::TColor(-1), JUtility::TColor(-1), JUtility::TColor(-1));
}

/* 802D3774-802D3824       .text __dt__10J2DPictureFv */
J2DPicture::~J2DPicture() {
    for (int i = 0; i < mNumTexture; i++) {
        if (mValidTexture & 1 << i) {
            delete mpTexture[i];
        }
    }
    delete mpPalette;
}

/* 802D3824-802D3A08       .text insert__10J2DPictureFPC7ResTIMGUcf */
bool J2DPicture::insert(const ResTIMG* pTimg, u8 idx, f32 param_3) {
    if (!pTimg || mNumTexture >= 4 || idx >= 4 || idx > mNumTexture) {
        return false;
    }
    JUTTexture* texture = new JUTTexture(pTimg, 0);
    for (u8 i = 3; idx < i; i--) {
        mpTexture[i] = mpTexture[i - 1];
        mBlendKonstColorF[i] = mBlendKonstColorF[i - 1];
        mBlendKonstAlphaF[i] = mBlendKonstAlphaF[i - 1];
    }
    mValidTexture = (mValidTexture & ((1 << idx) - 1)) | ((mValidTexture & ~((1 << idx) - 1)) << 1);
    mpTexture[idx] = texture;
    mValidTexture |= (1 << idx);
    mBlendKonstColorF[idx] = param_3;
    mBlendKonstAlphaF[idx] = param_3;
    if (mNumTexture == 0 && mpTexture[0]) {
        mBounds = JGeometry::TBox2<f32>(0.0f, 0.0f, mpTexture[0]->getWidth(), mpTexture[0]->getHeight());
        calcMtx();
    }
    mNumTexture++;
    setBlendKonstColor();
    setBlendKonstAlpha();
    return true;
}

/* 802D3A08-802D3A68       .text insert__10J2DPictureFPCcUcf */
bool J2DPicture::insert(const char* name, u8 idx, f32 param_3) {
    return insert((ResTIMG*)JKRGetNameResource(name, NULL), idx, param_3);
}

/* 802D3A68-802D3B78       .text remove__10J2DPictureFUc */
bool J2DPicture::remove(u8 idx) {
    if (mNumTexture <= idx || mNumTexture == 1) {
        return false;
    }
    if (mValidTexture & 1 << idx) {
        delete mpTexture[idx];
    }
    for (u8 i = idx; i < mNumTexture - 1; i++) {
        mpTexture[i] = mpTexture[i + 1];
        mBlendKonstColorF[i] = mBlendKonstColorF[i + 1];
        mBlendKonstAlphaF[i] = mBlendKonstAlphaF[i + 1];
    }
    mValidTexture = mValidTexture & (1 << idx) - 1 | ((mValidTexture & ~((1 << (idx + 1)) - 1)) >> 1);
    mNumTexture--;
    setBlendKonstColor();
    setBlendKonstAlpha();
    return true;
}

/* 802D3B78-802D3C34       .text changeTexture__10J2DPictureFPC7ResTIMGUc */
const ResTIMG * J2DPicture::changeTexture(const ResTIMG* timg, u8 idx) {
    if (idx >= mNumTexture)
        return NULL;
    if (getTexture(idx) == NULL || timg == NULL)
        return NULL;
    const ResTIMG * oldImg = getTexture(idx)->getTexInfo();
    getTexture(idx)->storeTIMG(timg, (u8)0);
    return oldImg;
}

/* 802D3C34-802D3C84       .text changeTexture__10J2DPictureFPCcUc */
const ResTIMG * J2DPicture::changeTexture(const char* name, u8 param_2) {
    return changeTexture((ResTIMG*)JKRGetNameResource(name, NULL), param_2);
}

/* 802D3C84-802D3CEC       .text drawSelf__10J2DPictureFff */
void J2DPicture::drawSelf(f32 x, f32 y) {
    Mtx mtx;
    MTXIdentity(mtx);
    drawSelf(x, y, &mtx);
}

/* 802D3CEC-802D3D54       .text drawSelf__10J2DPictureFffPA3_A4_f */
void J2DPicture::drawSelf(f32 x, f32 y, Mtx* mtx) {
    if (!mpTexture[0]) {
        return;
    }
    drawFullSet(mScreenBounds.i.x + x, mScreenBounds.i.y + y, mBounds.getWidth(), mBounds.getHeight(), J2DBinding(mBinding), getMirror(), isTumble(), mtx);
}

/* 802D3D54-802D4074       .text drawFullSet__10J2DPictureFffff10J2DBinding9J2DMirrorbPA3_A4_f */
void J2DPicture::drawFullSet(f32 x, f32 y, f32 width, f32 height, J2DBinding binding, J2DMirror mirror, bool rotate90, Mtx* mtx) {
    bool bindLeft;
    bool bindRight;
    bool bindTop;
    bool bindBottom;

    if (!rotate90) {
        if (mirror & J2DMirror_X)
            bindLeft = binding & J2DBind_Right;
        else
            bindLeft = binding & J2DBind_Left;

        if (mirror & J2DMirror_X)
            bindRight = binding & J2DBind_Left;
        else
            bindRight = binding & J2DBind_Right;

        if (mirror & J2DMirror_Y)
            bindTop = binding & J2DBind_Bottom;
        else
            bindTop = binding & J2DBind_Top;

        if (mirror & J2DMirror_Y)
            bindBottom = binding & J2DBind_Top;
        else
            bindBottom = binding & J2DBind_Bottom;
    } else {
        if (mirror & J2DMirror_X)
            bindLeft = binding & J2DBind_Bottom;
        else
            bindLeft = binding & J2DBind_Top;

        if (mirror & J2DMirror_X)
            bindRight = binding & J2DBind_Top;
        else
            bindRight = binding & J2DBind_Bottom;

        if (mirror & J2DMirror_Y)
            bindTop = binding & J2DBind_Left;
        else
            bindTop = binding & J2DBind_Right;

        if (mirror & J2DMirror_Y)
            bindBottom = binding & J2DBind_Right;
        else
            bindBottom = binding & J2DBind_Left;
    }

    f32 rectWidth;
    f32 rectHeight;
    f32 texWidth = mpTexture[0]->getWidth();
    f32 texHeight = mpTexture[0]->getHeight();

    rectWidth = !rotate90 ? width : height;
    rectHeight = !rotate90 ? height : width;

    f32 s0, t0, s1, t1;
    if (bindLeft) {
        s0 = 0.0f;
        s1 = bindRight ? 1.0f : (rectWidth / texWidth);
    } else if (bindRight) {
        s0 = 1.0f - (rectWidth / texWidth);
        s1 = 1.0f;
    } else {
        s0 = 0.5f - (rectWidth / texWidth) / 2.0f;
        s1 = 0.5f + (rectWidth / texWidth) / 2.0f;
    }

    if (bindTop) {
        t0 = 0.0f;
        t1 = bindBottom ? 1.0f : (rectHeight / texHeight);
    } else if (bindBottom) {
        t0 = 1.0f - (rectHeight / texHeight);
        t1 = 1.0f;
    } else {
        t0 = 0.5f - (rectHeight / texHeight) / 2.0f;
        t1 = 0.5f + (rectHeight / texHeight) / 2.0f;
    }

    if (mirror & J2DMirror_X) {
        swap(s0, s1);
    }
    if (mirror & J2DMirror_Y) {
        swap(t0, t1);
    }

    if (!rotate90) {
        drawTexCoord(0.0f, 0.0f, width, height, s0, t0, s1, t0, s0, t1, s1, t1, mtx);
    } else {
        drawTexCoord(0.0f, 0.0f, width, height, s0, t1, s0, t0, s1, t1, s1, t0, mtx);
    }
}

/* 802D4074-802D4490       .text draw__10J2DPictureFffffbbb */
void J2DPicture::draw(f32 x, f32 y, f32 width, f32 height, bool mirrorX, bool mirrorY, bool rotate90) {
    if (!mVisible) {
        return;
    }
    for (u8 i = 0; i < mNumTexture; i++) {
        if (i < mNumTexture) {
            mpTexture[i]->load((GXTexMapID)i);
        }
    }
    GXSetNumTexGens(mNumTexture);
    mDrawAlpha = mAlpha;
    JUtility::TColor color[4];
    getNewColor(color);
    setTevMode();
    makeMatrix(x, y);
    GXLoadPosMtxImm(mMtx, GX_PNMTX0);
    GXSetCurrentMtx(GX_PNMTX0);
    GXClearVtxDesc();
    GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
    GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT);
    GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT);
    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
    GXBegin(GX_QUADS, GX_VTXFMT0, 4);
    GXPosition3f32(0.0f, 0.0f, 0.0f);
    GXColor1u32(color[0]);
    if (!rotate90) {
        GXTexCoord2s16(mirrorX ? 0x8000 : 0, mirrorY ? 0x8000 : 0);
    } else {
        GXTexCoord2s16(mirrorX ? 0x8000 : 0, mirrorY ? 0 : 0x8000);
    }
    GXPosition3f32(width, 0.0f, 0.0f);
    GXColor1u32(color[1]);
    if (!rotate90) {
        GXTexCoord2s16(mirrorX ? 0 : 0x8000, mirrorY ? 0x8000 : 0);
    } else {
        GXTexCoord2s16(mirrorX ? 0x8000 : 0, mirrorY ? 0x8000 : 0);
    }
    GXPosition3f32(width, height, 0.0f);
    GXColor1u32(color[3]);
    if (!rotate90) {
        GXTexCoord2s16(mirrorX ? 0 : 0x8000, mirrorY ? 0 : 0x8000);
    } else {
        GXTexCoord2s16(mirrorX ? 0 : 0x8000, mirrorY ? 0x8000 : 0);
    }
    GXPosition3f32(0.0f, height, 0.0f);
    GXColor1u32(color[2]);
    if (!rotate90) {
        GXTexCoord2s16(mirrorX ? 0x8000 : 0, mirrorY ? 0 : 0x8000);
    } else {
        GXTexCoord2s16(mirrorX ? 0 : 0x8000, mirrorY ? 0 : 0x8000);
    }
    GXEnd();
    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_U16, 0x0f);
    GXSetNumTexGens(0);
    GXSetNumTevStages(1);
    GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
    GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
    Mtx m;
    MTXIdentity(m);
    GXLoadPosMtxImm(m, GX_PNMTX0);
    GXSetVtxDesc(GX_VA_TEX0, GX_NONE);
}

/* 802D4490-802D4874       .text drawOut__10J2DPictureFRCQ29JGeometry8TBox2<f>RCQ29JGeometry8TBox2<f> */
void J2DPicture::drawOut(const JGeometry::TBox2<f32>& posBox, const JGeometry::TBox2<f32>& texRect) {
    if (!mVisible) {
        return;
    }
    for (u8 i = 0; i < mNumTexture; i++) {
        if (i < mNumTexture) {
            mpTexture[i]->load((GXTexMapID)i);
        }
    }
    GXSetNumTexGens(mNumTexture);

    f32 s0 = (posBox.i.x - texRect.i.x) / texRect.getWidth();
    f32 s1 = (posBox.f.x - texRect.f.x) / texRect.getWidth() + 1.0f;

    f32 t0 = (posBox.i.y - texRect.i.y) / texRect.getHeight();
    f32 t1 = (posBox.f.y - texRect.f.y) / texRect.getHeight() + 1.0f;

    mDrawAlpha = mAlpha;
    JUtility::TColor color[4];
    getNewColor(color);
    setTevMode();
    GXClearVtxDesc();
    GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
    GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT);
    GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT);
    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
    GXBegin(GX_QUADS, GX_VTXFMT0, 4);

    GXPosition3f32((s16)posBox.i.x, (s16)posBox.i.y, 0.0f);
    GXColor1u32(color[0]);
    GXTexCoord2f32(s0, t0);

    GXPosition3f32((s16)posBox.f.x, (s16)posBox.i.y, 0.0f);
    GXColor1u32(color[1]);
    GXTexCoord2f32(s1, t0);

    GXPosition3f32((s16)posBox.f.x, (s16)posBox.f.y, 0.0f);
    GXColor1u32(color[3]);
    GXTexCoord2f32(s1, t1);

    GXPosition3f32((s16)posBox.i.x, (s16)posBox.f.y, 0.0f);
    GXColor1u32(color[2]);
    GXTexCoord2f32(s0, t1);

    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U16, 15);
    GXSetNumTexGens(0);
    GXSetNumTevStages(1);
    GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
    GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
    GXSetVtxDesc(GX_VA_TEX0, GX_NONE);
}

/* 802D4874-802D4B3C       .text drawTexCoord__10J2DPictureFffffffffffffPA3_A4_f */
void J2DPicture::drawTexCoord(f32 x, f32 y, f32 width, f32 height, f32 s0, f32 t0, f32 s1, f32 t1, f32 s2, f32 t2, f32 s3, f32 t3, Mtx* mtx) {
    for (u8 i = 0; i < mNumTexture; i++) {
        if (i < mNumTexture) {
            mpTexture[i]->load(GXTexMapID(i));
        }
    }
    f32 x2 = x + width;
    f32 y2 = y + height;
    GXSetNumTexGens(mNumTexture);
    JUtility::TColor colors[4];
    getNewColor(colors);
    setTevMode();
    Mtx stack_108;
    MTXConcat(*mtx, mDrawMtx, stack_108);
    GXLoadPosMtxImm(stack_108, GX_PNMTX0);
    GXClearVtxDesc();
    GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
    GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT);
    GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT);
    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
    GXBegin(GX_QUADS, GX_VTXFMT0, 4);
    GXPosition3f32(x, y, 0.0f);
    GXColor1u32(colors[0]);
    GXTexCoord2f32(s0, t0);
    GXPosition3f32(x2, y, 0.0f);
    GXColor1u32(colors[1]);
    GXTexCoord2f32(s1, t1);
    GXPosition3f32(x2, y2, 0.0f);
    GXColor1u32(colors[3]);
    GXTexCoord2f32(s3, t3);
    GXPosition3f32(x, y2, 0.0f);
    GXColor1u32(colors[2]);
    GXTexCoord2f32(s2, t2);
    GXEnd();
    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U16, 0xf);
    GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0);
}

/* 802D4B3C-802D4F44       .text setTevMode__10J2DPictureFv */
void J2DPicture::setTevMode() {
    u8 i;
    for (i = 0; i < mNumTexture; i++) {
        GXSetTevOrder(GXTevStageID(i), GXTexCoordID(i), GXTexMapID(i), GX_COLOR_NULL);
    }
    GXSetTevColor(GX_TEVREG2, JUtility::TColor());
    GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_TEXC, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO);
    if (mpTexture[0]->getTransparency()) {
        GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO);
    } else {
        GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_A2, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO);
    }
    GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
    GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
    GXSetTevKColor(GX_KCOLOR0, mBlendKonstColor);
    GXSetTevKColor(GX_KCOLOR2, mBlendKonstAlpha);
    for (i = 1; i < mNumTexture; i++) {
        GXSetTevKColorSel(GXTevStageID(i), GXTevKColorSel(0x20 - i * 4));
        GXSetTevKAlphaSel(GXTevStageID(i), GXTevKAlphaSel(0x22 - i * 4));
        GXSetTevColorIn(GXTevStageID(i), GX_CC_CPREV, GX_CC_TEXC, GX_CC_KONST, GX_CC_ZERO);
        if (mpTexture[i]->getTransparency()) {
            GXSetTevAlphaIn(GXTevStageID(i), GX_CA_APREV, GX_CA_TEXA, GX_CA_KONST, GX_CA_ZERO);
        } else {
            GXSetTevAlphaIn(GXTevStageID(i), GX_CA_APREV, GX_CA_A2, GX_CA_KONST, GX_CA_ZERO);
        }
        GXSetTevColorOp(GXTevStageID(i), GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
        GXSetTevAlphaOp(GXTevStageID(i), GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
    }
    if (mColorBlack != 0 || mColorWhite != 0xffffffff) {
        GXSetTevOrder(GXTevStageID(i), GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR_NULL);
        GXSetTevColor(GX_TEVREG0, mColorBlack);
        GXSetTevColor(GX_TEVREG1, mColorWhite);
        GXSetTevColorIn(GXTevStageID(i), GX_CC_C0, GX_CC_C1, GX_CC_CPREV, GX_CC_ZERO);
        GXSetTevAlphaIn(GXTevStageID(i), GX_CA_A0, GX_CA_A1, GX_CA_APREV, GX_CA_ZERO);
        GXSetTevColorOp(GXTevStageID(i), GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
        GXSetTevAlphaOp(GXTevStageID(i), GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
        i++;
    }
    if (mDrawAlpha != 0xff || mCornerColor[0] != 0xffffffff || mCornerColor[1] != 0xffffffff || mCornerColor[2] != 0xffffffff || mCornerColor[3] != 0xffffffff) {
        GXSetTevOrder(GXTevStageID(i), GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
        GXSetTevColorIn(GXTevStageID(i), GX_CC_ZERO, GX_CC_CPREV, GX_CC_RASC, GX_CC_ZERO);
        GXSetTevAlphaIn(GXTevStageID(i), GX_CA_ZERO, GX_CA_APREV, GX_CA_RASA, GX_CA_ZERO);
        GXSetTevColorOp(GXTevStageID(i), GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
        GXSetTevAlphaOp(GXTevStageID(i), GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
        i++;
    }
    GXSetNumTevStages(u8(i));
    GXSetBlendMode(GX_BM_BLEND, GX_BL_SRC_ALPHA, GX_BL_INV_SRC_ALPHA, GX_LO_SET);
    for (i = 0; i < mNumTexture; i++) {
        GXSetTexCoordGen(GXTexCoordID(i), GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
    }
    GXSetNumChans(1);
}

/* 802D4F44-802D4F58       .text swap__10J2DPictureFRfRf */
void J2DPicture::swap(f32& f1, f32& f2) {
    f32 tmp = f1;
    f1 = f2;
    f2 = tmp;
}

/* 802D4F58-802D5028       .text setBlendKonstColor__10J2DPictureFv */
void J2DPicture::setBlendKonstColor() {
    int var3 = 0;

    for (u8 i = 1; i < mNumTexture; i++) {
        f32 tmp = 0.0f;
        for (u8 j = 0; j < i; j++) {
            tmp += mBlendKonstColorF[j];
        }
        f32 tmp2 = tmp + mBlendKonstColorF[i];
        if (tmp2 != 0.0f) {
            var3 |= (u8)(255.0f * (1.0f - tmp / tmp2)) << (i - 1) * 8;
        }
    }
    mBlendKonstColor = var3;
}

/* 802D5028-802D50F8       .text setBlendKonstAlpha__10J2DPictureFv */
void J2DPicture::setBlendKonstAlpha() {
    int var3 = 0;

    for (u8 i = 1; i < mNumTexture; i++) {
        f32 tmp = 0.0f;
        for (u8 j = 0; j < i; j++) {
            tmp += mBlendKonstAlphaF[j];
        }
        f32 tmp2 = tmp + mBlendKonstAlphaF[i];
        if (tmp2 != 0.0f) {
            var3 |= (u8)(255.0f * (1.0f - tmp / tmp2)) << (i - 1) * 8;
        }
    }
    mBlendKonstAlpha = var3;
}

/* 802D50F8-802D51D8       .text getNewColor__10J2DPictureFPQ28JUtility6TColor */
void J2DPicture::getNewColor(JUtility::TColor* param_1) {
    param_1[0] = mCornerColor[0];
    param_1[1] = mCornerColor[1];
    param_1[2] = mCornerColor[2];
    param_1[3] = mCornerColor[3];

    if (mDrawAlpha == 0xff) {
        return;
    }
    param_1[0].a = (param_1[0].a * mDrawAlpha) / 0xff;
    param_1[1].a = (param_1[1].a * mDrawAlpha) / 0xff;
    param_1[2].a = (param_1[2].a * mDrawAlpha) / 0xff;
    param_1[3].a = (param_1[3].a * mDrawAlpha) / 0xff;
}