summaryrefslogtreecommitdiff
path: root/src/nw4r/lyt/lyt_texMap.cpp
blob: a1bf8c3f4086cd04b93cdc5eca90354253a2881d (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
#include "nw4r/lyt/lyt_texMap.h"

// NOTICE: This file seems to have been reworked. Not sure if all functions exist anymore, ReplaceImage doesnt even
// appear stripped in BBA, but is in tokyo friend park 2 DWARF. In NSMBW there seems to be more parameters for
// ReplaceImage as well. BBA map also shows calls to SetNoWrap from Set (GXTexObj variant), but the actual function
// shows no sign

namespace nw4r {
namespace lyt {

namespace {

// CountLeadingZeros__24@unnamed@lyt_texMap_cpp@FUl

} // namespace

// Get__Q34nw4r3lyt6TexMapCFP9_GXTexObj
void TexMap::Get(GXTexObj *pTexObj) const {
    if (detail::IsCITexelFormat(GetTexelFormat())) {
        u32 tlutName = GXGetTexObjTlut(pTexObj);
        GXInitTexObjCI(
            pTexObj, GetImage(), GetWidth(), GetHeight(), (GXCITexFmt)GetTexelFormat(), GetWrapModeS(), GetWrapModeT(),
            IsMipMap(), tlutName
        );
    } else {
        GXInitTexObj(
            pTexObj, GetImage(), GetWidth(), GetHeight(), GetTexelFormat(), GetWrapModeS(), GetWrapModeT(), IsMipMap()
        );
    }

    GXInitTexObjLOD(
        pTexObj, GetMinFilter(), GetMagFilter(), GetMinLOD(), GetMaxLOD(), GetLODBias(), IsBiasClampEnable(),
        IsEdgeLODEnable(), GetAnisotropy()
    );
}

// Get__Q34nw4r3lyt6TexMapCFP10_GXTlutObj
void TexMap::Get(GXTlutObj *pTLUTObj) const {
    GXInitTlutObj(pTLUTObj, GetPalette(), GetPaletteFormat(), GetPaletteEntryNum());
}

// Set__Q34nw4r3lyt6TexMapFRC9_GXTexObj
void TexMap::Set(const GXTexObj &pTexObj) {
    void *pImage;
    u16 width, height;
    GXTexFmt format;
    GXTexWrapMode wrapS, wrapT;
    u8 mipmap;
    GXGetTexObjAll(&pTexObj, &pImage, &width, &height, &format, &wrapS, &wrapT, &mipmap);
    SetImage(pImage);
    SetSize(width, height);
    SetTexelFormat(format);
    SetWrapMode(wrapS, wrapT);
    SetMipMap(mipmap);

    GXTexFilter minFilter, magFilter;
    f32 minLOD, maxLOD, LODBias;
    u8 biasClampEnable, edgeLODEnable;
    GXAnisotropy anisotropy;
    GXGetTexObjLODAll(
        &pTexObj, &minFilter, &magFilter, &minLOD, &maxLOD, &LODBias, &biasClampEnable, &edgeLODEnable, &anisotropy
    );
    SetFilter(minFilter, magFilter);
    SetLOD(minLOD, maxLOD);
    SetLODBias(LODBias);
    SetBiasClampEnable(biasClampEnable);
    SetEdgeLODEnable(edgeLODEnable);
    SetAnisotropy(anisotropy);
}

// Set__Q34nw4r3lyt6TexMapFRC10_GXTlutObj

// Set__Q34nw4r3lyt6TexMapFP10TPLPaletteUl
void TexMap::Set(TPLPalette *pal, u32 id) {
    // Not yet converted from offset to pointer (unbound)
    if ((unsigned int)pal->descriptors < 0x80000000) {
        TPLBind(pal);
    }

    Set(TPLGet(pal, id));
}

// Set__Q34nw4r3lyt6TexMapFPC13TPLDescriptor
void TexMap::Set(const TPLDescriptor *pTPLDesc) {
    TPLHeader *tplHead = pTPLDesc->texHeader;
    SetImage(tplHead->data);
    SetSize(tplHead->width, tplHead->height);
    SetTexelFormat(static_cast<GXTexFmt>(tplHead->format));

    bool bMipMap = (tplHead->minLod != tplHead->maxLod);
    SetMipMap(bMipMap);

    SetFilter(tplHead->minFilt, tplHead->magFilt);
    SetLOD(tplHead->minLod, tplHead->maxLod);
    SetLODBias(tplHead->lodBias);
    SetEdgeLODEnable(tplHead->edgeLodEnable);

    TPLClutHeader *pTPLCLUTHeader = pTPLDesc->clutHeader;
    if (pTPLCLUTHeader != NULL) {
        SetPalette(pTPLCLUTHeader->data);
        SetPaletteFormat(pTPLCLUTHeader->format);
        SetPaletteEntryNum(pTPLCLUTHeader->numEntries);
    } else {
        SetPalette(NULL);
        SetPaletteFormat(GX_TL_IA8);
        SetPaletteEntryNum(0);
    }
}

// ReplaceImage__Q34nw4r3lyt6TexMapFRC10_GXTlutObj
void TexMap::ReplaceImage(const GXTexObj &pTexObj) {
    void *pImage;
    u16 width, height;
    GXTexFmt format;
    GXTexWrapMode wrapS, wrapT;
    u8 mipmap;
    GXGetTexObjAll(&pTexObj, &pImage, &width, &height, &format, &wrapS, &wrapT, &mipmap);
    SetImage(pImage);
    SetSize(width, height);
    SetTexelFormat(format);
}

// ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUl
void TexMap::ReplaceImage(TPLPalette *pal, u32 id) {
    // Not yet converted from offset to pointer (unbound)
    if ((unsigned int)pal->descriptors < 0x80000000) {
        TPLBind(pal);
    }

    ReplaceImage(TPLGet(pal, id));
}

// ReplaceImage__Q34nw4r3lyt6TexMapFPC13TPLDescriptor
void TexMap::ReplaceImage(const TPLDescriptor *pTPLDesc) {
    TPLHeader *tplHead = pTPLDesc->texHeader;
    SetImage(tplHead->data);
    SetSize(tplHead->width, tplHead->height);
    SetTexelFormat(static_cast<GXTexFmt>(tplHead->format));

    TPLClutHeader *pTPLCLUTHeader = pTPLDesc->clutHeader;
    if (pTPLCLUTHeader != NULL) {
        SetPalette(pTPLCLUTHeader->data);
        SetPaletteFormat(pTPLCLUTHeader->format);
        SetPaletteEntryNum(pTPLCLUTHeader->numEntries);
    } else {
        SetPalette(NULL);
        SetPaletteFormat(GX_TL_IA8);
        SetPaletteEntryNum(0);
    }
}

// SetNoWrap__Q34nw4r3lyt6TexMapFRCQ34nw4r3lyt6TexMap
void TexMap::SetNoWrap(const TexMap &map) {
    GXTexWrapMode wrapS = GetWrapModeS();
    GXTexWrapMode wrapT = GetWrapModeT();

    Set(map);
    SetWrapMode(wrapS, wrapT);
}

// SetNoWrap__Q34nw4r3lyt6TexMapFRC9_GXTexObj
void TexMap::SetNoWrap(const GXTexObj &pTexObj) {
    void *pImage;
    u16 width, height;
    GXTexFmt format;
    GXTexWrapMode wrapS, wrapT;
    u8 mipmap;
    GXGetTexObjAll(&pTexObj, &pImage, &width, &height, &format, &wrapS, &wrapT, &mipmap);
    SetImage(pImage);
    SetSize(width, height);
    SetTexelFormat(format);
}

// SetNoWrap__Q34nw4r3lyt6TexMapFP10TPLPaletteUl
void TexMap::SetNoWrap(TPLPalette *pal, u32 id) {}

// SetNoWrap__Q34nw4r3lyt6TexMapFPC13TPLDescriptor
void TexMap::SetNoWrap(const TPLDescriptor *pDescriptor) {
    TPLHeader *tex = pDescriptor->texHeader;
    SetImage(tex->data);
    SetSize(tex->width, tex->height);
    SetTexelFormat(static_cast<GXTexFmt>(tex->format));

    bool bMipMap = (tex->minLod != tex->maxLod);
    SetMipMap(bMipMap);

    SetFilter(tex->minFilt, tex->magFilt);
    SetLOD(tex->minLod, tex->maxLod);
    SetLODBias(tex->lodBias);
    SetEdgeLODEnable(tex->edgeLodEnable);

    TPLClutHeader *clut = pDescriptor->clutHeader;
    if (clut != NULL) {
        SetPalette(clut->data);
        SetPaletteFormat(clut->format);
        SetPaletteEntryNum(clut->numEntries);
    } else {
        SetPalette(NULL);
        SetPaletteFormat(GX_TL_IA8);
        SetPaletteEntryNum(0);
    }
}

// SetTexParam__Q34nw4r3lyt6TexMapFPvUsUs9_GXTexFmt14_GXTexWrapMode14_GXTexWrapModeb

// SetLODParam__Q34nw4r3lyt6TexMapF12_GXTexFilter12_GXTexFilterfffbb13_GXAnisotropy

// SetPaletteParam__Q34nw4r3lyt6TexMapFPv10_GXTlutFmtUs

} // namespace lyt
} // namespace nw4r