diff options
Diffstat (limited to 'src/d')
| -rw-r--r-- | src/d/d_gfx.cpp | 163 | ||||
| -rw-r--r-- | src/d/d_gfx_measures.cpp | 61 | ||||
| -rw-r--r-- | src/d/d_sc_title.cpp | 4 | ||||
| -rw-r--r-- | src/d/d_stage_mgr.cpp | 6 | ||||
| -rw-r--r-- | src/d/lyt/d2d.cpp | 5 | ||||
| -rw-r--r-- | src/d/lyt/d_lyt_common_a_btn.cpp | 10 | ||||
| -rw-r--r-- | src/d/lyt/d_lyt_cursor_stick.cpp | 2 | ||||
| -rw-r--r-- | src/d/lyt/d_textbox.cpp | 4 |
8 files changed, 238 insertions, 17 deletions
diff --git a/src/d/d_gfx.cpp b/src/d/d_gfx.cpp new file mode 100644 index 00000000..3ef697c3 --- /dev/null +++ b/src/d/d_gfx.cpp @@ -0,0 +1,163 @@ +#include "d/d_gfx.h" + +#include "common.h" +#include "d/d_d2d.h" +#include "d/d_heap.h" +#include "d/d_sys.h" +#include "egg/gfx/eggDrawGX.h" +#include "egg/gfx/eggGfxEngine.h" +#include "egg/gfx/eggScreen.h" +#include "egg/gfx/eggTextureBuffer.h" +#include "m/m2d.h" +#include "m/m3d/m3d.h" +#include "m/m_heap.h" +#include "m/m_mtx.h" +#include "m/m_video.h" +#include "rvl/GX/GXTexture.h" +#include "rvl/GX/GXTransform.h" +#include "rvl/GX/GXTypes.h" +#include "rvl/GX/GXVert.h" +#include "rvl/MTX/mtx.h" +#include "rvl/MTX/mtx44.h" +#include "toBeSorted/d_d3d.h" + +dGfx_c *dGfx_c::sInstance; + +dGfx_c::dGfx_c() : mpTextureBuffer(nullptr), field_0x08(0), field_0x09(0) { + mDrawCallback = nullptr; + + d3d::create(mHeap::g_gameHeaps[0]); + initGfxConstants(); + EGG::GfxEngine::Configuration cfg; + u32 texBufSize = cfg.bufferSize; + texBufSize += GXGetTexBufferSize( + mVideo::m_video->pRenderMode->fbWidth, mVideo::m_video->pRenderMode->efbHeight, GX_TF_RGB5A3, GX_FALSE, 1 + ); + EGG::TextureBuffer::setIncludesHeader(true); + { + mHeap guard(mHeap::g_gameHeaps[0]); + EGG::TextureBuffer::initialize(texBufSize, dSys_c::ms_RootHeapMem2); + } + m2d::create(dHeap::layoutHeap.heap, 0); + d2d::create(dHeap::layoutExHeap.heap); + sInstance = this; +} + +EGG::TextureBuffer *dGfx_c::getTextureBuffer() { + EGG::TextureBuffer *ret = nullptr; + if (mpTextureBuffer == nullptr) { + mpTextureBuffer = EGG::TextureBuffer::alloc( + mVideo::m_video->pRenderMode->fbWidth, mVideo::m_video->pRenderMode->efbHeight, GX_TF_RGBA8 + ); + mpTextureBuffer->onCapFlag(0x20); // TODO + ret = mpTextureBuffer; + } + field_0x08++; + return ret; +} + +void dGfx_c::releaseTextureBuffer() { + field_0x08--; + if (field_0x08 == 0 && mpTextureBuffer != nullptr) { + mpTextureBuffer->free(); + mpTextureBuffer = nullptr; + } +} + +void dGfx_c::drawBefore() { + if (mDrawCallback != nullptr) { + (mDrawCallback)(); + } + d2d::drawBefore(); + m3d::clear(); + m2d::reset(); +} + +void dGfx_c::drawLetterbox() { + if (field_0x09 != 0 && isTvMode4To3()) { + EGG::Screen screen(*EGG::Screen::GetRoot()); + screen.SetNearFar(-1.0f, 1.0f); + screen.SetProjectionGX(); + EGG::DrawGX::BeginDrawScreen(true, false, true); + + mMtx_c mtx1; + mMtx_c mtx2; + mMtx_c mtx3; + + mtx1.transS(0.0f, 0.0f, 0.0f); + MTXScale(mtx2, getCurrentScreenWidthF(), getEFBHeightDifferenceF(), 0.0f); + MTXConcat(mtx1, mtx2, mtx1); + EGG::DrawGX::DrawDL17(mtx1, EGG::DrawGX::BLACK); + + mtx1.transS(0.0f, getCurrentScreenHeightF() - getEFBHeightDifferenceF() - 1.0f, 0.0f); + MTXScale(mtx3, getCurrentScreenWidthF(), getEFBHeightDifferenceF() + 1.0f, 0.0f); + MTXConcat(mtx1, mtx3, mtx1); + EGG::DrawGX::DrawDL17(mtx1, EGG::DrawGX::BLACK); + } +} + +void dGfx_c::create(EGG::Heap *heap) { + new (heap) dGfx_c(); +} + +void dGfx_c::drawCapTexture(EGG::TextureBuffer *buf, nw4r::ut::Color *clr) { + if (buf == nullptr) { + return; + } + + s32 width = mVideo::m_video->pRenderMode->fbWidth; + s32 height = mVideo::m_video->pRenderMode->efbHeight; + s32 offsetY = 0; + + if (buf->getHeight() == getEFBHeightLimit()) { + height = getEFBHeight(); + offsetY = getLetterboxAmount(); + } + GXSetViewport(0.0f, offsetY, width, height, 0.0f, 1.0f); + GXSetScissor(0, offsetY, width, height); + GXSetScissorBoxOffset(0, 0); + + Mtx44 mtx; + MTXOrtho(mtx, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); + GXSetProjection(mtx, GX_ORTHOGRAPHIC); + buf->load(GX_TEXMAP0); + GXSetNumChans(0); + GXSetNumTexGens(1); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, GX_FALSE, GX_DUALMTX_IDENT); + GXSetNumIndStages(0); + GXSetNumTevStages(1); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_C0, GX_CC_TEXC, GX_CC_ZERO); + GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO); + GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV); + GXSetZCompLoc(1); + GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ONE, GX_LO_SET); + GXSetZMode(GX_FALSE, GX_ALWAYS, GX_FALSE); + GXSetAlphaCompare(GX_ALWAYS, 0, GX_AOP_OR, GX_ALWAYS, 0); + + GXSetFog(GX_FOG_NONE, (GXColor){0}, 0.0, 0.0, 0.0, 0.0); + GXSetFogRangeAdj(GX_FALSE, 0, 0); + GXSetCullMode(GX_CULL_NONE); + GXSetTevColor(GX_TEVREG0, *clr); + GXLoadPosMtxImm(mMtx_c::Identity, 0); + GXSetCurrentMtx(0); + GXClearVtxDesc(); + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_U8, 0); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U8, 0); + + GXBegin(GX_QUADS, GX_VTXFMT0, 4); + + GXPosition2u8(0, 0); + GXPosition2u8(0, 0); + GXPosition2u8(1, 0); + GXPosition2u8(1, 0); + GXPosition2u8(1, 1); + GXPosition2u8(1, 1); + GXPosition2u8(0, 1); + GXPosition2u8(0, 1); + + GXEnd(); +} diff --git a/src/d/d_gfx_measures.cpp b/src/d/d_gfx_measures.cpp new file mode 100644 index 00000000..b1988319 --- /dev/null +++ b/src/d/d_gfx_measures.cpp @@ -0,0 +1,61 @@ +#include "d/d_gfx.h" + +#include "common.h" +#include "egg/gfx/eggScreen.h" + +s32 dGfx_c::g_CurrentScreenWidth_s32; +s32 dGfx_c::g_CurrentScreenHeight_s32; +s32 dGfx_c::g_CurrentScreenWidthLimit_s32; +s32 dGfx_c::g_CurrentScreenHeightLimit_s32; +s32 dGfx_c::g_CurrentScreenLeft_s32; +s32 dGfx_c::g_CurrentScreenRight_s32; +s32 dGfx_c::g_CurrentScreenTop_s32; +s32 dGfx_c::g_CurrentScreenBottom_s32; + +s32 dGfx_c::g_CurrentEFBHeight_s32; +s32 dGfx_c::g_CurrentEFBHeightLimit_s32; +s32 dGfx_c::g_CurrentLetterBoxAmount_s32; + +f32 dGfx_c::g_CurrentScreenWidth_f32; +f32 dGfx_c::g_CurrentScreenHeight_f32; +f32 dGfx_c::g_CurrentScreenWidthLimit_f32; +f32 dGfx_c::g_CurrentScreenHeightLimit_f32; +f32 dGfx_c::g_CurrentScreenLeft_f32; +f32 dGfx_c::g_CurrentScreenRight_f32; +f32 dGfx_c::g_CurrentScreenTop_f32; +f32 dGfx_c::g_CurrentScreenBottom_f32; + +f32 dGfx_c::g_CurrentScreenAspect; + +f32 dGfx_c::g_CurrentEFBHeight_f32; +f32 dGfx_c::g_CurrentEFBHeightLimit_f32; +f32 dGfx_c::g_CurrentEFBHeightDifference_f32; +f32 dGfx_c::g_CurrentHeightScaled_f32; +f32 dGfx_c::g_CurrentEFBHeightDifference2_f32; + +s32 dGfx_c::g_Width4x3_s32; +s32 dGfx_c::g_Width4x3Limit_s32; +s32 dGfx_c::g_Width16x9_s32; +s32 dGfx_c::g_Width4x3Left_s32; +s32 dGfx_c::g_Width4x3Right_s32; + +f32 dGfx_c::g_Width4x3_f32; +f32 dGfx_c::g_Width4x3Limit_f32; +f32 dGfx_c::g_Width16x9_f32; +f32 dGfx_c::g_Width4x3Left_f32; +f32 dGfx_c::g_Width4x3Right_f32; + +f32 dGfx_c::g_16x9to4x3WidthScale; +f32 dGfx_c::g_CurrentScreenTo4x3WidthScale = 1.0f; + +void dGfx_c::initGfxConstants() { + // TODO - awful function +} + +bool dGfx_c::isTvMode4To3() { + return EGG::Screen::GetTVMode() == EGG::Screen::TV_MODE_4_3; +} + +bool dGfx_c::isTvModeWidescreen() { + return EGG::Screen::GetTVMode() != EGG::Screen::TV_MODE_4_3; +} diff --git a/src/d/d_sc_title.cpp b/src/d/d_sc_title.cpp index 8aaa9a1a..73e578d7 100644 --- a/src/d/d_sc_title.cpp +++ b/src/d/d_sc_title.cpp @@ -87,8 +87,8 @@ int dScTitle_c::create() { } if (ret == SUCCEEDED) { - dSys::setFrameRate(2); - dSys::setClearColor(mColor(0x00000000)); + dSys_c::setFrameRate(2); + dSys_c::setClearColor(mColor(0x00000000)); dPad::ex_c::setAutoSleepTime(); dPad::ex_c::fn_80058C90(0); SaveRelated::create(); diff --git a/src/d/d_stage_mgr.cpp b/src/d/d_stage_mgr.cpp index 06888883..f300116f 100644 --- a/src/d/d_stage_mgr.cpp +++ b/src/d/d_stage_mgr.cpp @@ -240,7 +240,7 @@ void dStageMgr_c::initializeState_SceneChangeSave() { fn_80285600(LYT_SAVE_MGR, 3, 0); } dBase_c::s_NextExecuteControlFlags |= 1; - dSys::setFrameRate(2); + dSys_c::setFrameRate(2); } void dStageMgr_c::executeState_SceneChangeSave() { @@ -260,7 +260,7 @@ void dStageMgr_c::finalizeState_SceneChangeSave() { } void dStageMgr_c::initializeState_RestartSceneWait() { - dSys::setFrameRate(2); + dSys_c::setFrameRate(2); } void dStageMgr_c::executeState_RestartSceneWait() { @@ -291,5 +291,5 @@ void dStageMgr_c::executeState_RestartScene() { void dStageMgr_c::finalizeState_RestartScene() { commitAllFlagManagers(); - dSys::setFrameRate(1); + dSys_c::setFrameRate(1); } diff --git a/src/d/lyt/d2d.cpp b/src/d/lyt/d2d.cpp index c5135e28..8712443f 100644 --- a/src/d/lyt/d2d.cpp +++ b/src/d/lyt/d2d.cpp @@ -1,6 +1,7 @@ #include "d/lyt/d2d.h" #include "d/d_font_manager.h" +#include "d/d_gfx.h" #include "d/d_message.h" #include "d/d_lyt_hio.h" #include "d/lyt/d_textbox.h" @@ -199,15 +200,13 @@ void Multi_c::calcAfter() { mLayout.CalculateMtx(mDrawInfo); } -extern "C" bool NeedsScreenAdjustment(); - // Largely copied from m2d::Simple_c::draw void Multi_c::draw() { nw4r::ut::Rect r = mLayout.GetLayoutRect(); f32 near = 0.0f; f32 far = 500.0f; EGG::Screen s; - bool needsAdjust = NeedsScreenAdjustment(); + bool needsAdjust = dGfx_c::isTvModeWidescreen(); f32 f1 = EGG::Screen::GetSizeXMax(EGG::Screen::TV_MODE_16_9); f32 f2 = EGG::Screen::GetSizeXMax(EGG::Screen::TV_MODE_4_3); diff --git a/src/d/lyt/d_lyt_common_a_btn.cpp b/src/d/lyt/d_lyt_common_a_btn.cpp index d32f69c3..f45d7cd1 100644 --- a/src/d/lyt/d_lyt_common_a_btn.cpp +++ b/src/d/lyt/d_lyt_common_a_btn.cpp @@ -104,7 +104,7 @@ void dLytCommonABtn_c::gotoStateInvisible() { inAnim.bind(false); inAnim.setAnimEnable(true); inAnim.setFrame(0.0f); - if (dSys::getFrameRate() == 1) { + if (dSys_c::getFrameRate() == 1) { inAnim.setRate(0.5f); } else { inAnim.setRate(1.0f); @@ -144,7 +144,7 @@ void dLytCommonABtn_c::goToStateVisible() { d2d::AnmGroup_c &anm = mAnm[A_BTN_ANIM_LOOP]; anm.bind(false); anm.setFrame(0.0f); - if (dSys::getFrameRate() == 1) { + if (dSys_c::getFrameRate() == 1) { anm.setRate(0.5f); } else { anm.setRate(1.0f); @@ -169,7 +169,7 @@ void dLytCommonABtn_c::goToStateDecideOut() { d2d::AnmGroup_c &anm = mAnm[A_BTN_ANIM_OUT]; anm.bind(false); anm.setFrame(0.0f); - if (dSys::getFrameRate() == 1) { + if (dSys_c::getFrameRate() == 1) { anm.setRate(0.5f); } else { anm.setRate(1.0f); @@ -180,7 +180,7 @@ void dLytCommonABtn_c::goToStateDecideOut() { anm.bind(false); anm.setAnimEnable(true); anm.setFrame(0.0f); - if (dSys::getFrameRate() == 1) { + if (dSys_c::getFrameRate() == 1) { anm.setRate(0.5f); } else { anm.setRate(1.0f); @@ -214,7 +214,7 @@ void dLytCommonABtn_c::executeStateDecideOut() { anmOut.bind(false); anmOut.setAnimEnable(true); anmOut.setFrame(0.0f); - if (dSys::getFrameRate() == 1) { + if (dSys_c::getFrameRate() == 1) { anmOut.setRate(0.5f); } else { anmOut.setRate(1.0f); diff --git a/src/d/lyt/d_lyt_cursor_stick.cpp b/src/d/lyt/d_lyt_cursor_stick.cpp index ab633eab..a5749057 100644 --- a/src/d/lyt/d_lyt_cursor_stick.cpp +++ b/src/d/lyt/d_lyt_cursor_stick.cpp @@ -120,7 +120,7 @@ bool dLytCursorStick_c::drawDirectly_() { return true; } -bool dLytCursorStick_c::setPriority(u8 priority) { +void dLytCursorStick_c::setPriority(u8 priority) { mLyt.setPriority(priority); } diff --git a/src/d/lyt/d_textbox.cpp b/src/d/lyt/d_textbox.cpp index 1f14ab02..7f77feb6 100644 --- a/src/d/lyt/d_textbox.cpp +++ b/src/d/lyt/d_textbox.cpp @@ -152,8 +152,6 @@ static void CalcStringRectImpl( } while (remain > 0); } -extern "C" bool NeedsScreenAdjustment(); - static int CalcLineRectImpl( nw4r::ut::Rect *pRect, nw4r::ut::TextWriterBase<wchar_t> *pTextWriter, const wchar_t *str, int length, f32 maxWidth, bool *pbOver, bool *pbWideScreenUnk @@ -187,7 +185,7 @@ static int CalcLineRectImpl( pTextWriter->SetCursorX(x); // ?????????? - if (pbWideScreenUnk != nullptr && ((u32 *)context.str)[0] == 0 && NeedsScreenAdjustment()) { + if (pbWideScreenUnk != nullptr && ((u32 *)context.str)[0] == 0 && dGfx_c::isTvModeWidescreen()) { *pbWideScreenUnk = true; } operation = pTextWriter->GetTagProcessor()->CalcRect(&rect, code, &context); |
