summaryrefslogtreecommitdiff
path: root/include/JSystem/J3DGraphBase/J3DPacket.h
blob: 92b817ec23479cb6f479ad622bc17cbf6aedec40 (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
#ifndef J3DPACKET_H
#define J3DPACKET_H

#include "JSystem/J3DGraphBase/J3DSys.h"
#include "dolphin/gd/GDBase.h"
#include <stdint.h>

class J3DMatPacket;

class J3DDrawBuffer;
class J3DMaterial;
class J3DMaterialAnm;
class J3DModel;
class J3DMtxBuffer;
class J3DShape;
class J3DTexMtx;
class J3DTexMtxObj;
class J3DTexture;

enum J3DDiffFlag {
    J3DDiffFlag_MatColor         = 0x1,
    J3DDiffFlag_ColorChan        = 0x2,
    J3DDiffFlag_AmbColor         = 0x4,
    J3DDiffFlag_TexGen           = 0x1000,
    J3DDiffFlag_TevReg           = 0x1000000,
    J3DDiffFlag_KonstColor       = 0x2000000,  // is this right?
    J3DDiffFlag_TexCoordScale    = 0x4000000,
    J3DDiffFlag_TevStageIndirect = 0x8000000,
    J3DDiffFlag_Fog              = 0x10000000,
    J3DDiffFlag_Blend            = 0x20000000,
    J3DDiffFlag_Unk40000000      = 0x40000000,
    J3DDiffFlag_Changed          = 0x80000000,
};

#define J3D_DIFF_LIGHTOBJNUM(n) ((n & 0xF) << 4)
#define J3D_DIFF_TEXGENNUM(n)   ((n & 0xF) << 8)
#define J3D_DIFF_TEXNONUM(n)    ((n & 0xF) << 16)
#define J3D_DIFF_TEVSTAGENUM(n) ((n & 0xF) << 20)

#define J3D_DIFF_FLAG(MatColor, ColorChan, AmbColor, LightNum, TexGenNum, TexGen, TexCoordNum, TevStageNum, TevReg, KColor, TexCoordScale, TevStageInd, Fog, Blend) \
    ( \
        (MatColor << 0) | \
        (ColorChan << 1) | \
        (AmbColor << 2) | \
        ((LightNum & 0xF) << 4) | \
        ((TexGenNum & 0xF) << 8) | \
        (TexGen << 12) | \
        ((TexCoordNum & 0xF) << 16) | \
        ((TevStageNum & 0xF) << 20) | \
        (TevReg << 24) | \
        (KColor << 25) | \
        (TexCoordScale << 26) | \
        (TevStageInd << 27) | \
        (Fog << 28) | \
        (Blend << 29) \
    )

inline u32 getDiffFlag_LightObjNum(u32 diffFlags) {
    return (diffFlags & 0xf0) >> 4;
}

inline u32 getDiffFlag_TexGenNum(u32 diffFlags) {
    return (diffFlags & 0xf00) >> 8;
}

inline int calcDifferedBufferSize_TexMtxSize(u32 param_1) {
  return param_1 * 0x35;
}

inline int calcDifferedBufferSize_TexGenSize(u32 param_1) {
    return param_1 * 0x3d + 10;
}

inline u32 getDiffFlag_TexNoNum(u32 diffFlags) {
    return (diffFlags & 0xf0000) >> 0x10;
}

inline int calcDifferedBufferSize_TexNoSize(u32 param_1) {
    return param_1 * 0x37;
}

inline u32 calcDifferedBufferSize_TexNoAndTexCoordScaleSize(u32 param_1) {
    u32 res = param_1 * 0x37;
    res += ((param_1 + 1) >> 1) * 0x37;
    return res;
}

inline u32 getDiffFlag_TevStageNum(u32 diffFlags) {
    return (diffFlags & 0xf00000) >> 0x14;
}

inline int calcDifferedBufferSize_TevStageSize(u32 param_1) {
    return param_1 * 10;
}

inline int calcDifferedBufferSize_TevStageDirectSize(u32 param_1) {
    return param_1 * 5;
}

/**
 * @ingroup jsystem-j3d
 * 
 */
class J3DDisplayListObj {
public:
    J3DDisplayListObj() {
        mpDisplayList[0] = NULL;
        mpDisplayList[1] = NULL;
        mSize = 0;
        mMaxSize = 0;
    }

    J3DError newDisplayList(u32);
    J3DError newSingleDisplayList(u32);
    int single_To_Double();
    void setSingleDisplayList(void*, u32);
    void swapBuffer();
    void callDL() const;
    void beginDL();
    u32 endDL();
    void beginPatch();
    u32 endPatch();

    u8* getDisplayList(int idx) { return (u8*)mpDisplayList[idx]; }
    u32 getDisplayListSize() { return mSize; }

    static GDLObj sGDLObj;
    static s32 sInterruptFlag;

    /* 0x0 */ void* mpDisplayList[2];
    /* 0x8 */ u32 mSize;
    /* 0xC */ u32 mMaxSize;
};  // Size: 0x10

/**
 * @ingroup jsystem-j3d
 * 
 */
class J3DPacket {
public:
    J3DPacket() {
        mpNextPacket = NULL;
        mpFirstChild = NULL;
        mpUserArea = NULL;
    }

    void addChildPacket(J3DPacket*);
    
    J3DPacket* getNextPacket() const { return mpNextPacket; }
    void setNextPacket(J3DPacket* i_packet) { mpNextPacket = i_packet; }

    void drawClear() {
        mpNextPacket = NULL;
        mpFirstChild = NULL;
    }

    void* getUserArea() const { return mpUserArea; }
    void setUserArea(uintptr_t area) { mpUserArea = (void*)area; }

    virtual int entry(J3DDrawBuffer*);
    virtual void draw();
    virtual ~J3DPacket() {}

public:
    /* 0x04 */ J3DPacket* mpNextPacket;
    /* 0x08 */ J3DPacket* mpFirstChild;
    /* 0x0C */ void* mpUserArea;
};  // Size: 0x10

/**
 * @ingroup jsystem-j3d
 * 
 */
class J3DDrawPacket : public J3DPacket {
public:
    J3DDrawPacket();
    ~J3DDrawPacket();
    J3DError newDisplayList(u32);
    J3DError newSingleDisplayList(u32);
    virtual void draw();

    J3DDisplayListObj* getDisplayListObj() { return mpDisplayListObj; }
    void setDisplayListObj(J3DDisplayListObj* pObj) { mpDisplayListObj = pObj; }

    void beginPatch() { mpDisplayListObj->beginPatch(); }
    void endPatch() { mpDisplayListObj->endPatch(); }

    void callDL() const { mpDisplayListObj->callDL(); }
    void beginDL() { mpDisplayListObj->beginDL(); }
    void endDL() { mpDisplayListObj->endDL(); }

    void* getDisplayList(int i) { return mpDisplayListObj->mpDisplayList[i]; }
    u32 getDisplayListSize() const { return mpDisplayListObj->mSize; } 

    enum {
        LOCKED = 0x01,
    };

    bool checkFlag(u32 flag) const { return (mFlags & flag) ? true : false; }
    void onFlag(u32 flag) { mFlags |= flag; }
    void offFlag(u32 flag) { mFlags &= ~flag; }
    void lock() { onFlag(LOCKED); }
    void unlock() { offFlag(LOCKED); }
    J3DTexMtxObj* getTexMtxObj() { return mpTexMtxObj; }
    bool isLocked() const { return checkFlag(1); }

public:
    /* 0x10 */ u32 mFlags;
    /* 0x14 */ char unk_0x14[0x20 - 0x14];
    /* 0x20 */ J3DDisplayListObj* mpDisplayListObj;
    /* 0x24 */ J3DTexMtxObj* mpTexMtxObj;
};  // Size: 0x28

/**
 * @ingroup jsystem-j3d
 * 
 */
class J3DShapePacket : public J3DDrawPacket {
public:
    J3DShapePacket();
    u32 calcDifferedBufferSize(u32);
    int newDifferedDisplayList(u32);
    void prepareDraw() const;
    void drawFast();

    virtual ~J3DShapePacket();
    virtual void draw();

    void setShape(J3DShape* pShape) {
        J3D_ASSERT_NULLPTR(523, pShape != NULL);
        mpShape = pShape;
    }

    void setModel(J3DModel* pModel) {
        J3D_ASSERT_NULLPTR(533, pModel != NULL);
        mpModel = pModel;
    }

    void setMtxBuffer(J3DMtxBuffer* pMtxBuffer) { mpMtxBuffer = pMtxBuffer; }
    void setBaseMtxPtr(Mtx* pMtx) { mpBaseMtxPtr = pMtx; }

    J3DShape* getShape() const { return mpShape; }
    J3DModel* getModel() const { return mpModel; }
    Mtx* getBaseMtxPtr() const { return mpBaseMtxPtr; }

public:
    /* 0x28 */ J3DShape* mpShape;
    /* 0x2C */ J3DMtxBuffer* mpMtxBuffer;
    /* 0x30 */ Mtx* mpBaseMtxPtr;
    /* 0x34 */ u32 mDiffFlag;
    /* 0x38 */ J3DModel* mpModel;
};  // Size: 0x3C

/**
 * @ingroup jsystem-j3d
 * 
 */
class J3DMatPacket : public J3DDrawPacket {
public:
    J3DMatPacket();
    void addShapePacket(J3DShapePacket*);
    void beginDiff();
    void endDiff();
    bool isSame(J3DMatPacket*) const;

    J3DMaterial* getMaterial() const { return mpMaterial; }
    J3DShapePacket* getShapePacket() const { return mpShapePacket; }
    void setShapePacket(J3DShapePacket* packet) { mpShapePacket = packet; }

    void setMaterial(J3DMaterial* pMaterial) {
        J3D_ASSERT_NULLPTR(646, pMaterial != NULL);
        mpMaterial = pMaterial;
    }

    void setTexture(J3DTexture* pTexture) {
        J3D_ASSERT_NULLPTR(651, pTexture != NULL);
        mpTexture = pTexture;
    }

    void setInitShapePacket(J3DShapePacket* packet) { mpInitShapePacket = packet; }
    void setMaterialID(u32 id) { mDiffFlag = id; }
    void setMaterialAnmID(J3DMaterialAnm* materialAnm) { mpMaterialAnm = materialAnm; }
    BOOL isChanged() { return mDiffFlag & J3DDiffFlag_Changed; }
    bool isEnabled_Diff() { return mpInitShapePacket->getDisplayListObj() != NULL; }

    virtual ~J3DMatPacket();
    virtual int entry(J3DDrawBuffer*);
    virtual void draw();

public:
    /* 0x28 */ J3DShapePacket* mpInitShapePacket;
    /* 0x2C */ J3DShapePacket* mpShapePacket;
    /* 0x30 */ J3DMaterial* mpMaterial;
    /* 0x34 */ u32 mDiffFlag;
    /* 0x38 */ J3DTexture* mpTexture;
    /* 0x3C */ J3DMaterialAnm* mpMaterialAnm;
};  // Size: 0x40

#endif /* J3DPACKET_H */