EGG symbols maintenance

This commit is contained in:
robojumper
2025-06-30 22:35:29 +02:00
parent 810f61fe94
commit a8e9c4c345
15 changed files with 60 additions and 74 deletions
+8 -9
View File
@@ -2,23 +2,22 @@
#include "egg/core/eggHeap.h"
/* 804952d0 */ static void *MEM_AllocFor_Heap(MEMAllocator *alloc, u32 size) {
/* 804952d0 */ static void *AllocatorAllocForHeap_(MEMAllocator *alloc, u32 size) {
return static_cast<EGG::Heap *>(static_cast<EGG::Allocator *>(alloc)->heap)->alloc(size, alloc->heapParam1);
}
/* 804952f0 */ static void MEM_FreeFor_Heap(MEMAllocator *alloc, void *block) {
/* 804952f0 */ static void AllocatorFreeForHeap_(MEMAllocator *alloc, void *block) {
return static_cast<EGG::Heap *>(static_cast<EGG::Allocator *>(alloc)->heap)->free(block);
}
const MEMAllocatorFuncs eggAllocatorFuncs = {
&MEM_AllocFor_Heap,
&MEM_FreeFor_Heap,
};
// TODO this is used from eggHeap for some reason. Figure out
// the correct privacy boundary later.
/* 80495310 */ void MEMInitAllocatorFor_Heap(MEMAllocator *alloc, s32 align, void *heap) {
alloc->funcs = &eggAllocatorFuncs;
static const MEMAllocatorFuncs sAllocatorFunc = {
&AllocatorAllocForHeap_,
&AllocatorFreeForHeap_,
};
alloc->funcs = &sAllocatorFunc;
alloc->heap = heap;
alloc->heapParam1 = align;
alloc->heapParam2 = 0;
+12 -25
View File
@@ -27,19 +27,16 @@ void calcColorGradient(GXColor &outColor, const GXColor &c1, const GXColor &c2,
}
}
void makeGradient(int op, GXColor *outColor, int size, int start, int end, const GXColor &c1, const GXColor &c2) {
int start_p1 = start + 1;
// Weird instruction calculation
for (int i = 0; i < start_p1; i++) {
void makeGradient(int op, GXColor *outColor, u16 size, u16 start, u16 end, const GXColor &c1, const GXColor &c2) {
for (int i = 0; i < start + 1; i++) {
outColor[i] = c1;
}
int end_1 = end - 1;
for (int i = end_1; i < size; i++) {
for (int i = end - 1; i < size; i++) {
outColor[i] = c2;
}
for (int i = start_p1; i < end_1; i++) {
for (int i = start + 1; i < end - 1; i++) {
f32 ratio = (f32)(i - start) / (f32)(end - start);
switch (op) {
case 0: break;
@@ -188,6 +185,7 @@ void CpuTexture::fillNormalMapSphere(f32 f1, f32 f2) {
vec(0) = fx;
vec(1) = fy;
// TODO: std::sqrtf?
vec(2) = fz < Math<f32>::zero() ? Math<f32>::zero() : (f32)sqrt(fz);
PSVECNormalize(vec, vec);
@@ -202,24 +200,19 @@ void CpuTexture::fillNormalMapSphere(f32 f1, f32 f2) {
void CpuTexture::fillGradient(
int op, int unk, u16 start, u16 end, const GXColor &c1, const GXColor &c2, bool b1, bool b2
) {
// NONMATCHING - regswaps
GXColor gradient[1024];
GXColor colors[256];
bool swapMode = unk == 0x73 || unk == 0x53;
u16 width = swapMode ? mWidth : mHeight;
u16 height = swapMode ? mHeight : mWidth;
u16 mid = width / 2;
makeGradient(op, gradient, width, start, end, c1, c2);
if (b1) {
// Regswaps here
for (int i2 = mid, i = 0; i < width; i2++, i++) {
colors[i].r = gradient[i < mid ? i2 : i - mid].r;
colors[i].g = gradient[i < mid ? i2 : i - mid].g;
colors[i].b = gradient[i < mid ? i2 : i - mid].b;
colors[i].a = gradient[i < mid ? i2 : i - mid].a;
for (int i = 0; i < width; i++) {
colors[i] = gradient[i < mid ? i + mid : i - mid];
}
for (int i = 0; i < width; i++) {
@@ -295,16 +288,10 @@ void CpuTexture::setColor(u16 x, u16 y, GXColor color) {
}
case GX_TF_I8:
case GX_TF_Z8: {
// Regswaps here
int pix = (x & 0x7);
int pix_y = (y & 0x3) * 8;
int offset = (x & 0x7) + (y & 0x3) * 8; // pixel
offset += ((x >> 3) + ((y >> 2) * (getWidth() / 8))) * 32; // block
int block = (x >> 3);
int block_y = (y >> 2) * (getWidth() / 8);
pix = pix + pix_y + (block + block_y) * 0x20;
u8 *dat = static_cast<u8 *>(getBuffer()) + pix;
u8 *dat = static_cast<u8 *>(getBuffer()) + offset;
dat[0] = color.r;
break;
@@ -328,7 +315,6 @@ void CpuTexture::setColor(u16 x, u16 y, GXColor color) {
}
GXColor CpuTexture::getColor(u16 x, u16 y) const {
// NONMATCHING
GXColor c;
switch (getFormat()) {
case GX_TF_RGBA8:
@@ -343,6 +329,7 @@ GXColor CpuTexture::getColor(u16 x, u16 y) const {
}
case GX_TF_I8:
case GX_TF_Z8: {
// TODO - probably fake
int idx = (x & 0x7);
int pixel_idx = (y & 0x3) * 8;
int block_idx = ((getWidth() / 8) * (y >> 2) + (x >> 3));
+4 -4
View File
@@ -130,7 +130,7 @@ void DrawPathDOF::internalDraw(u16 idx) {
switch (idx) {
case 1:
StateEfb::fn_804B4310(StateEfb::BUFFER_0, reinterpret_cast<u32>(this));
StateEfb::popWorkBuffer(StateEfb::BUFFER_0, reinterpret_cast<u32>(this));
StateEfb::releaseEfb(StateEfb::BUFFER_3, reinterpret_cast<u32>(this));
break;
case 2:
@@ -149,7 +149,7 @@ void DrawPathDOF::internalDrawLite(u16 idx) {
switch (idx) {
case 0: {
TextureBuffer *capturedBuf = StateEfb::captureEfb(StateEfb::BUFFER_3, false, reinterpret_cast<u32>(this));
StateGX::GXSetPixelFmt_(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
StateGX::setPixelFormatGX(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
StateGX::ScopedColor colorGuard(true);
StateGX::ScopedAlpha alphaGuard(false);
StateGX::ScopedDither ditherGuard(false);
@@ -184,8 +184,8 @@ void DrawPathDOF::internalDrawLite(u16 idx) {
if (pTex2 != nullptr) {
pTex2->free();
}
afterDraw(floats[0], floats[1], width, height);
StateGX::GXSetPixelFmt_(StateGX::s_pixFormat, StateGX::s_zFmt16);
allocAndCaptureBlurBuffer(floats[0], floats[1], width, height);
StateGX::setPixelFormatGX(StateGX::s_pixFormat, StateGX::s_zFmt16);
break;
}
case 2: {
+4 -4
View File
@@ -129,7 +129,7 @@ u16 LightTextureManager::replaceModelTexture(int tex, nw4r::g3d::ResMdl mdl) con
u16 res = G3DUtility::SetTexture(mat, nullptr, mpTextures[tex]->getName(), &obj, false, buf, 0xFF, 2);
for (int j = 0; j < res; j++) {
if (buf[j].texCoordId != -1) {
fn_804AE340(mat, static_cast<GXTexCoordID>(buf[j].texCoordId));
setupEnvmap(mat, static_cast<GXTexCoordID>(buf[j].texCoordId));
}
}
count += res;
@@ -214,7 +214,7 @@ void LightTextureManager::drawAndCaptureTexture(f32 ox, f32 oy, f32 sx, f32 sy)
}
if (b1) {
StateGX::GXSetPixelFmt_(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
StateGX::setPixelFormatGX(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
}
nw4r::ut::Color c(StateGX::s_clearEfb);
@@ -234,7 +234,7 @@ void LightTextureManager::drawAndCaptureTexture(f32 ox, f32 oy, f32 sx, f32 sy)
}
if (b1) {
StateGX::GXSetPixelFmt_(StateGX::s_pixFormat, StateGX::s_zFmt16);
StateGX::setPixelFormatGX(StateGX::s_pixFormat, StateGX::s_zFmt16);
}
if ((mFlags & 0x40) == 0 && buf != nullptr) {
@@ -307,7 +307,7 @@ const void *LightTextureManager::getLtexFromLmap(const void *lmap, u16 index) {
return buf;
}
void LightTextureManager::fn_804AE340(nw4r::g3d::ResMat mat, GXTexCoordID id) {
void LightTextureManager::setupEnvmap(nw4r::g3d::ResMat mat, GXTexCoordID id) {
nw4r::g3d::ResTexSrt dat = mat.GetResTexSrt();
dat.SetMapMode(id, 1, -1, -1);
nw4r::g3d::ResMatTexCoordGen coordGen = mat.GetResMatTexCoordGen();
+2 -2
View File
@@ -38,14 +38,14 @@ void PostEffectBlur::draw(f32 width, f32 height) {
for (u8 i = 0; i < field_0x2C; i++) {
int maxNum = (field_0x38[i].field_0x00 - 1) / 8;
for (u8 b = 0; b <= maxNum; b++) {
drawInternal(i, b, f1, f2);
setMaterialMulti(i, b, f1, f2);
drawScreenInternal(mOffsetX, mOffsetY, width * mScaleX, height * mScaleY);
DrawGX::SetBlendMode(DrawGX::BLEND_2);
}
}
}
void PostEffectBlur::drawInternal(u8 kernelIdx, u8 p2, f32 f1, f32 f2) {
void PostEffectBlur::setMaterialMulti(u8 kernelIdx, u8 p2, f32 f1, f32 f2) {
// NONMATCHING
nw4r::math::MTX34 mtx;
const Stage &k = field_0x38[kernelIdx];
+4 -4
View File
@@ -191,14 +191,14 @@ void Screen::SetUnkFlag8() {
mFlags |= FLAG_0x08;
}
void Screen::OnDirectEfb() const {
void Screen::GetPosSizeInEfb() const {
f32 &x1 = mDataEfb.vp.x1;
f32 &y1 = mDataEfb.vp.y1;
if (mParent == nullptr) {
x1 = mPosition.x * sCanvasScale.x;
y1 = mPosition.y * sCanvasScale.y;
} else {
mParent->fn_804B2EE0(&x1, &y1, mPosition.x, mPosition.y);
mParent->ConvertToEfb(mPosition.x, mPosition.y, &x1, &y1);
}
// TODO: Make this work without temporaries?
@@ -242,7 +242,7 @@ void Screen::OnDirectEfb() const {
const Screen::DataEfb &Screen::GetDataEfb() const {
if (IsChangeEfb()) {
OnDirectEfb();
GetPosSizeInEfb();
mDataEfb.vp.z1 = 0.0f;
mDataEfb.vp.z2 = 1.0f;
SetDirty(false);
@@ -325,7 +325,7 @@ void Screen::SetTVModeDefault() {
SetTVMode(SCGetAspectRatio() == SC_ASPECT_STD ? TV_MODE_4_3 : TV_MODE_16_9);
}
void Screen::fn_804B2EE0(f32 *ox, f32 *oy, f32 a, f32 b) const {
void Screen::ConvertToEfb(f32 a, f32 b, f32 *ox, f32 *oy) const {
GetGlobalPos(ox, oy);
ConvertToCanvasLU(a, b, &a, &b);
*ox = ScaleByX((*ox + a));
+6 -6
View File
@@ -88,7 +88,7 @@ TextureBuffer *StateEfb::captureEfb(BufferType type, bool noTransparencyMaybe, u
if (spBufferSet[type].buf != nullptr) {
spBufferSet[type].buf->setPixModeSync(false);
}
doCapture = GetShouldCapture();
doCapture = isEnableDirtyBufferMode();
break;
}
@@ -151,7 +151,7 @@ void StateEfb::fn_804B4270(BufferType type, u32 userData) {
}
}
void StateEfb::fn_804B4310(BufferType type, u32 userData) {
void StateEfb::popWorkBuffer(bool b, u32 userData) {
if (sWorkBuffer != -1) {
BufferType i = static_cast<BufferType>(-1);
if (sWorkBuffer == 0) {
@@ -161,7 +161,7 @@ void StateEfb::fn_804B4310(BufferType type, u32 userData) {
}
if (spBufferSet[i].userData == userData) {
if (type == BUFFER_0) {
if (!b) {
StateGX::ScopedColor colorGuard(true);
StateGX::ScopedAlpha alphaGuard(true);
StateGX::ScopedDither ditherGuard(false);
@@ -186,9 +186,9 @@ void StateEfb::fn_804B4310(BufferType type, u32 userData) {
nw4r::math::MTX34 mtx;
PSMTXScale(mtx, parentScreen.GetSize().x, parentScreen.GetSize().y, 1.0f);
DrawGX::BeginDrawScreen(true, GetShouldCapture(), false);
DrawGX::BeginDrawScreen(true, isEnableDirtyBufferMode(), false);
DrawGX::SetBlendMode(DrawGX::BLEND_14);
if (GetShouldCapture()) {
if (isEnableDirtyBufferMode()) {
TextureBuffer *buf = spBufferSet[i].buf;
buf->setFilt(GX_NEAR, GX_NEAR);
buf->load(DrawGX::GetTexMapDefault());
@@ -218,7 +218,7 @@ f32 *StateEfb::fn_804B4550() {
return sUnkBuffer;
}
bool StateEfb::GetShouldCapture() {
bool StateEfb::isEnableDirtyBufferMode() {
return ((sFlag >> 2) & 1) != 0;
}
+2 -2
View File
@@ -66,7 +66,7 @@ void StateGX::initialize(u16 width, u16 height, GXColor color, GXPixelFmt pixelF
}
void StateGX::frameInit() {
GXSetPixelFmt_(s_pixFormat, s_zFmt16);
setPixelFormatGX(s_pixFormat, s_zFmt16);
if (BaseSystem::mConfigData->getDisplay() != nullptr) {
s_clearEfb = BaseSystem::mConfigData->getDisplay()->getClearColor();
}
@@ -230,7 +230,7 @@ void StateGX::resetGXCache() {
GXSetDstAlpha_(false, 0);
}
void StateGX::GXSetPixelFmt_(GXPixelFmt pixelFmt, GXZFmt16 zFmt) {
void StateGX::setPixelFormatGX(GXPixelFmt pixelFmt, GXZFmt16 zFmt) {
GXPixelFmt oldPixelFmt;
GXZFmt16 oldZFmt;