Skip to content

Commit

Permalink
J3DPEBlockFull::reset is closer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrkol committed Feb 8, 2025
1 parent 7770e3d commit c1f04cc
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 59 deletions.
28 changes: 28 additions & 0 deletions include/JSystem/J3D/J3DGraphBase/J3DComponents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ struct J3DFog : public J3DFogInfo {
}
};

inline u16 calcAlphaCmpID(u32 comp0, u32 op, u32 comp1)
{
return (comp0 << 5) + ((op & 0xff) << 3) + (comp1 & 0xff);
}

struct J3DAlphaComp {
J3DAlphaComp()
{
Expand All @@ -294,6 +299,13 @@ struct J3DAlphaComp {
return *this;
}

void setAlphaCompInfo(const J3DAlphaCompInfo& info)
{
mAlphaCmpID = calcAlphaCmpID(info.mComp0, info.mOp, info.mComp1);
mRef0 = info.mRef0;
mRef1 = info.mRef1;
}

GXCompare getComp0() const
{
return GXCompare(j3dAlphaCmpTable[mAlphaCmpID * 3]);
Expand Down Expand Up @@ -326,6 +338,11 @@ class J3DBlend : public J3DBlendInfo {
public:
J3DBlend() { *(J3DBlendInfo*)this = j3dDefaultBlendInfo; }

void setBlendInfo(const J3DBlendInfo& info)
{
J3DBlendInfo::operator=(info);
}

J3DBlend& operator=(const J3DBlend& other)
{
mBlendMode = other.mBlendMode;
Expand All @@ -342,6 +359,11 @@ class J3DBlend : public J3DBlendInfo {
}
};

inline u16 calcZModeID(u8 param_0, u8 param_1, u8 param_2)
{
return (param_1 * 2) + (param_0 * 0x10) + param_2;
}

class J3DZMode {
public:
J3DZMode() { mZModeID = j3dDefaultZModeID; }
Expand All @@ -350,6 +372,12 @@ class J3DZMode {
u8 getFunc() const { return j3dZModeTable[mZModeID * 3 + 1]; }
u8 getUpdateEnable() const { return j3dZModeTable[mZModeID * 3 + 2]; }

void setZModeInfo(const J3DZModeInfo& info)
{
mZModeID
= calcZModeID(info.mCompareEnable, info.mFunc, info.mUpdateEnable);
}

void load() const
{
if (mZModeID != 0xFFFF)
Expand Down
12 changes: 12 additions & 0 deletions include/JSystem/J3D/J3DGraphBase/J3DStruct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,16 @@ struct J3DZModeInfo {
/* 0x03 */ u8 pad;
};

struct J3DAlphaCompInfo {
/* 0x0 */ u8 mComp0;
/* 0x1 */ u8 mRef0;
/* 0x2 */ u8 mOp;
/* 0x3 */ u8 mComp1;
/* 0x4 */ u8 mRef1;

/* 0x5 */ u8 field_0x5;
/* 0x6 */ u8 field_0x6;
/* 0x7 */ u8 field_0x7;
};

#endif /* J3DSTRUCT_H */
45 changes: 12 additions & 33 deletions src/JSystem/J3D/J3DGraphBase/J3DMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,45 +747,24 @@ void J3DPEBlockFull::reset(J3DPEBlock* block)
// TODO: ton of stupid inlines missing here
switch (block->getType()) {
case 'PEOP':
mAlphaComp.mRef0 = 0;
mAlphaComp.mRef1 = 0;
mAlphaComp.mAlphaCmpID = 0xE7;

mBlend.mBlendMode = 0;
mBlend.mSrcFactor = 1;
mBlend.mDstFactor = 0;
mBlend.mLogicOp = 3;

mZMode.mZModeID = 0x17;

mAlphaComp.setAlphaCompInfo(
(J3DAlphaCompInfo) { 7, 0, 0, 7, 0, 0, 0, 0 });
mBlend.setBlendInfo((J3DBlendInfo) { 0, 1, 0, 3 });
mZMode.setZModeInfo((J3DZModeInfo) { 1, 3, 1, 0 });
mZCompLoc = 1;
break;
case 'PEED':
mAlphaComp.mRef0 = 0x80;
mAlphaComp.mRef1 = 0XFF;
mAlphaComp.mAlphaCmpID = 0XC3;

mBlend.mBlendMode = 0;
mBlend.mSrcFactor = 1;
mBlend.mDstFactor = 0;
mBlend.mLogicOp = 3;

mZMode.mZModeID = 0x17;

mAlphaComp.setAlphaCompInfo(
(J3DAlphaCompInfo) { 6, 0x80, 0, 3, 0xff, 0, 0, 0 });
mBlend.setBlendInfo((J3DBlendInfo) { 0, 1, 0, 3 });
mZMode.setZModeInfo((J3DZModeInfo) { 1, 3, 1, 0 });
mZCompLoc = 0;
break;
case 'PEXL':
mAlphaComp.mRef0 = 0;
mAlphaComp.mRef1 = 0;
mAlphaComp.mAlphaCmpID = 0XE7;

mBlend.mBlendMode = 1;
mBlend.mSrcFactor = 4;
mBlend.mDstFactor = 5;
mBlend.mLogicOp = 3;

mZMode.mZModeID = 0x16;

mAlphaComp.setAlphaCompInfo(
(J3DAlphaCompInfo) { 7, 0, 0, 7, 0, 0, 0, 0 });
mBlend.setBlendInfo((J3DBlendInfo) { 1, 4, 5, 3 });
mZMode.setZModeInfo((J3DZModeInfo) { 1, 3, 0, 0 });
mZCompLoc = 1;
break;
case 'PEFL':
Expand Down
52 changes: 26 additions & 26 deletions src/JSystem/J3D/J3DGraphBase/J3DTevs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,32 +256,6 @@ void J3DGDSetTexLookupMode(GXTexMapID id, GXTexWrapMode wrapS,

void loadCullMode(u8) { }

void loadTexNo(u32 param_1, const u16& param_2)
{
ResTIMG* img = &j3dSys.getTexture()->mResources[param_2];
J3DSys::sTexCoordScaleTable[param_1].field_0x00 = img->width;
J3DSys::sTexCoordScaleTable[param_1].field_0x02 = img->height;
J3DGDSetTexImgAttr((GXTexMapID)param_1, img->width, img->height,
(GXTexFmt)(img->format & 0xf));
J3DGDSetTexImgPtr((GXTexMapID)param_1, (u8*)img + img->imageDataOffset);

J3DGDSetTexLookupMode(
(GXTexMapID)param_1, (GXTexWrapMode)img->wrapS,
(GXTexWrapMode)img->wrapT, (GXTexFilter)img->minFilter,
(GXTexFilter)img->magFilter, img->minLod * 0.125f, img->maxLod * 0.125f,
img->lodBias * 0.01f, img->biasClamp, img->doEdgeLod,
(GXAnisotropy)img->maxAnisotropy);

if (img->isIndexTexture == true) {
GXTlutSize tlutSize = img->numColors > 16 ? GX_TLUT_256 : GX_TLUT_16;

J3DGDLoadTlut((u8*)img + img->paletteOffset, (param_1 << 15) + 0xC0000,
tlutSize);
J3DGDSetTexTlut((GXTexMapID)param_1, (param_1 << 15) + 0xC0000,
(GXTlutFmt)img->colorFormat);
}
}

void J3DLightObj::load(u32 id) const
{
GXLightID light = (GXLightID)(1 << id);
Expand Down Expand Up @@ -388,6 +362,32 @@ void J3DTexMtx::load(u32 id) const
(GXTexMtxType)mProjection);
}

void loadTexNo(u32 param_1, const u16& param_2)
{
ResTIMG* img = &j3dSys.getTexture()->mResources[param_2];
J3DSys::sTexCoordScaleTable[param_1].field_0x00 = img->width;
J3DSys::sTexCoordScaleTable[param_1].field_0x02 = img->height;
J3DGDSetTexImgAttr((GXTexMapID)param_1, img->width, img->height,
(GXTexFmt)(img->format & 0xf));
J3DGDSetTexImgPtr((GXTexMapID)param_1, (u8*)img + img->imageDataOffset);

J3DGDSetTexLookupMode(
(GXTexMapID)param_1, (GXTexWrapMode)img->wrapS,
(GXTexWrapMode)img->wrapT, (GXTexFilter)img->minFilter,
(GXTexFilter)img->magFilter, img->minLod * 0.125f, img->maxLod * 0.125f,
img->lodBias * 0.01f, img->biasClamp, img->doEdgeLod,
(GXAnisotropy)img->maxAnisotropy);

if (img->isIndexTexture == true) {
GXTlutSize tlutSize = img->numColors > 16 ? GX_TLUT_256 : GX_TLUT_16;

J3DGDLoadTlut((u8*)img + img->paletteOffset, (param_1 << 15) + 0xC0000,
tlutSize);
J3DGDSetTexTlut((GXTexMapID)param_1, (param_1 << 15) + 0xC0000,
(GXTlutFmt)img->colorFormat);
}
}

void loadDither(u8) { }

void loadNBTScale(J3DNBTScale& param_0)
Expand Down

0 comments on commit c1f04cc

Please sign in to comment.