summaryrefslogtreecommitdiff
path: root/src/JSystem/JUtility/JUTTexture.cpp
blob: a52ae0bfbb033d840190a52613638886f47f4949 (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
//
// Generated by dtk
// Translation Unit: JUTTexture.cpp
//

#include "JSystem/JSystem.h" // IWYU pragma: keep

#include "JSystem/JUtility/JUTTexture.h"
#include "JSystem/JUtility/JUTPalette.h"
#include "dolphin/gx/GX.h"
#include "dolphin/types.h"

/* 802C13FC-802C1470       .text __dt__10JUTTextureFv */
JUTTexture::~JUTTexture() {
    if (getCaptureFlag()) {
        delete[] field_0x3c;
    }
    if (getEmbPaletteDelFlag()) {
        delete mEmbPalette;
    }
}

/* 802C1470-802C15FC       .text storeTIMG__10JUTTextureFPC7ResTIMGUc */
void JUTTexture::storeTIMG(const ResTIMG* pTimg, u8 param_1) {
    GXTlut tlut;

    if (pTimg && param_1 < 0x10) {
        mTexInfo = pTimg;
        mTexData = (void*)((int)mTexInfo + mTexInfo->imageOffset);

        if (mTexInfo->imageOffset == 0) {
            mTexData = (void*)((int)mTexInfo + 0x20);
        }

        if (getEmbPaletteDelFlag()) {
            delete mEmbPalette;
        }
        mEmbPalette = NULL;
        mPalette = NULL;
        mTlutName = 0;
        mWrapS = mTexInfo->wrapS;
        mWrapT = mTexInfo->wrapT;
        mMinFilter = mTexInfo->minFilter;
        mMagFilter = mTexInfo->magFilter;
        mMinLOD = (s8)mTexInfo->minLOD;
        mMaxLOD = (s8)mTexInfo->maxLOD;
        mLODBias = mTexInfo->LODBias;

        if (mTexInfo->numColors == 0) {
            initTexObj();
        } else {
            if (mTexInfo->numColors > 0x100) {
                tlut = (GXTlut)((param_1 % 4) + GX_BIGTLUT0);
            } else {
                tlut = (GXTlut)param_1;
            }

            mEmbPalette = new JUTPalette(
                tlut, (GXTlutFmt)mTexInfo->colorFormat, (JUTTransparency)mTexInfo->alphaEnabled,
                mTexInfo->numColors, (void*)(&mTexInfo->format + mTexInfo->paletteOffset));

            mFlags = mFlags & 1 | 2;
            attachPalette(mEmbPalette);
        }
    }
}

/* 802C15FC-802C1654       .text attachPalette__10JUTTextureFP10JUTPalette */
void JUTTexture::attachPalette(JUTPalette* pPalette) {
    if (mTexInfo->indexTexture) {
        if (pPalette == NULL && mEmbPalette != NULL) {
            mPalette = mEmbPalette;
        } else {
            mPalette = pPalette;
        }
        GXTlut name = (GXTlut)mPalette->getTlutName();
        initTexObj(name);
    }
}

/* 802C1654-802C1740       .text initTexObj__10JUTTextureFv */
void JUTTexture::initTexObj() {
    GXBool mipmapEnabled;
    if (mTexInfo->mipmapEnabled != 0) {
        mipmapEnabled = 1;
    } else {
        mipmapEnabled = 0;
    }
    u8* image = ((u8*)mTexInfo);
    image += (mTexInfo->imageOffset ? mTexInfo->imageOffset : 0x20);
    GXInitTexObj(&mTexObj, image, mTexInfo->width, mTexInfo->height, (GXTexFmt)mTexInfo->format,
                 (GXTexWrapMode)mWrapS, (GXTexWrapMode)mWrapT, mipmapEnabled);
    GXInitTexObjLOD(&mTexObj, (GXTexFilter)mMinFilter, (GXTexFilter)mMagFilter, mMinLOD / 8.0f,
                    mMaxLOD / 8.0f, mLODBias / 100.0f, mTexInfo->biasClamp, mTexInfo->doEdgeLOD,
                    (GXAnisotropy)mTexInfo->maxAnisotropy);
}

/* 802C1740-802C183C       .text initTexObj__10JUTTextureF7_GXTlut */
void JUTTexture::initTexObj(GXTlut tlut) {
    GXBool mipmapEnabled;
    if (mTexInfo->mipmapEnabled != 0) {
        mipmapEnabled = 1;
    } else {
        mipmapEnabled = 0;
    }
    mTlutName = tlut;
    u8* image = ((u8*)mTexInfo);
    image += (mTexInfo->imageOffset ? mTexInfo->imageOffset : 0x20);
    GXInitTexObjCI(&mTexObj, image, mTexInfo->width, mTexInfo->height, (GXCITexFmt)mTexInfo->format,
                   (GXTexWrapMode)mWrapS, (GXTexWrapMode)mWrapT, mipmapEnabled, tlut);
    GXInitTexObjLOD(&mTexObj, (GXTexFilter)mMinFilter, (GXTexFilter)mMagFilter, mMinLOD / 8.0f,
                    mMaxLOD / 8.0f, mLODBias / 100.0f, mTexInfo->biasClamp, mTexInfo->doEdgeLOD,
                    (GXAnisotropy)mTexInfo->maxAnisotropy);
}

/* 802C183C-802C188C       .text load__10JUTTextureF11_GXTexMapID */
void JUTTexture::load(GXTexMapID id) {
    if (mPalette) {
        mPalette->load();
    }
    GXLoadTexObj(&mTexObj, id);
}