Added apthooks and updated gx2 renderer NO ACTIONS TODAY

This commit is contained in:
Lyelye150 2025-11-11 12:44:58 -05:00
parent ac0eaae17f
commit f340de7d72
10 changed files with 139 additions and 60 deletions

View File

@ -652,6 +652,7 @@ if (ISLE_BUILD_APP)
endif() endif()
if (WIIU) if (WIIU)
target_sources(isle PRIVATE target_sources(isle PRIVATE
ISLE/wiiu/apthooks.cpp
ISLE/wiiu/config.cpp ISLE/wiiu/config.cpp
) )
endif() endif()

View File

@ -78,6 +78,7 @@
#endif #endif
#ifdef __WIIU__ #ifdef __WIIU__
#include "wiiu/apthooks.h"
#include "wiiu/config.h" #include "wiiu/config.h"
#endif #endif
@ -294,6 +295,12 @@ void IsleApp::SetupVideoFlags(
} }
} }
#ifdef __WUT__
int main(int argc, char* argv[]) {
return 0;
}
#endif
SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv) SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv)
{ {
*appstate = NULL; *appstate = NULL;
@ -364,6 +371,9 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char** argv)
#endif #endif
#ifdef __3DS__ #ifdef __3DS__
N3DS_SetupAptHooks(); N3DS_SetupAptHooks();
#endif
#ifdef __WIIU__
WIIU_SetupAptHooks();
#endif #endif
return SDL_APP_CONTINUE; return SDL_APP_CONTINUE;
} }
@ -419,6 +429,10 @@ SDL_AppResult SDL_AppIterate(void* appstate)
g_isle->MoveVirtualMouseViaJoystick(); g_isle->MoveVirtualMouseViaJoystick();
} }
#ifdef __WIIU__
WIIU_ProcessCallbacks();
#endif
return SDL_APP_CONTINUE; return SDL_APP_CONTINUE;
} }

87
ISLE/wiiu/apthooks.cpp Normal file
View File

@ -0,0 +1,87 @@
#include "apthooks.h"
#include "legomain.h"
#include "misc.h"
#include <coreinit/thread.h>
#include <coreinit/time.h>
#include <gx2/draw.h>
#include <gx2/mem.h>
#include <gx2/state.h>
#include <proc_ui/procui.h>
#include <whb/gfx.h>
#include <SDL3/SDL_log.h>
static bool running = true;
static bool inBackground = false;
#ifdef USE_GX2
static void ReleaseGraphics()
{
SDL_Log("[APTHooks] Releasing GX2 resources...\n");
WHBGfxFinishRender();
GX2Flush();
GX2Shutdown();
}
static void RestoreGraphics()
{
SDL_Log("[APTHooks] Restoring GX2 resources...\n");
WHBGfxInit();
}
#endif
void WIIU_ProcessCallbacks()
{
ProcUIStatus status = ProcUIProcessMessages(true);
switch (status)
{
case PROCUI_STATUS_IN_FOREGROUND:
if (inBackground) {
inBackground = false;
RestoreGraphics();
Lego()->Resume();
SDL_Log("[APTHooks] App resumed\n");
}
break;
case PROCUI_STATUS_IN_BACKGROUND:
if (!inBackground) {
inBackground = true;
Lego()->Pause();
ReleaseGraphics();
SDL_Log("[APTHooks] App backgrounded\n");
}
break;
case PROCUI_STATUS_RELEASE_FOREGROUND:
Lego()->Pause();
ReleaseGraphics();
SDL_Log("[APTHooks] Yielding to system\n");
ProcUIDrawDoneRelease();
break;
case PROCUI_STATUS_EXITING:
Lego()->CloseMainWindow();
running = false;
SDL_Log("[APTHooks] App exiting\n");
break;
default:
break;
}
}
bool WIIU_AppIsRunning()
{
return running;
}
void WIIU_SetupAptHooks()
{
SDL_Log("[APTHooks] Initializing lifecycle hooks\n");
running = true;
inBackground = false;
ProcUIInit(nullptr);
}

10
ISLE/wiiu/apthooks.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef WIIU_APTHOOKS_H
#define WIIU_APTHOOKS_H
#include <wut.h>
void WIIU_SetupAptHooks();
void WIIU_ProcessCallbacks();
bool WIIU_AppIsRunning();
#endif

View File

@ -1,8 +0,0 @@
#pragma once
#include <gx2/mem.h>
#include <gx2r/buffer.h>
inline uint32_t GX2RGetGpuAddr(const GX2RBuffer* buffer)
{
return (uint32_t) buffer->buffer;
}

View File

@ -5,6 +5,8 @@
#include <gfd.h> #include <gfd.h>
#include <gx2/draw.h> #include <gx2/draw.h>
#include <gx2/mem.h> #include <gx2/mem.h>
#include <gx2/clear.h>
#include <gx2/state.h>
#include <whb/gfx.h> #include <whb/gfx.h>
#include <whb/log_udp.h> #include <whb/log_udp.h>
#include <whb/proc.h> #include <whb/proc.h>
@ -14,34 +16,41 @@
#define D3D_OK S_OK #define D3D_OK S_OK
#endif #endif
static struct IsleGX2Backend { static struct GX2Backend {
bool initialized = false; bool initialized = false;
bool rendering = false; bool rendering = false;
void Init(const char* shaderPath) void Init()
{ {
if (initialized) return; if (initialized)
return;
WHBLogUdpInit(); WHBLogUdpInit();
WHBProcInit(); WHBProcInit();
WHBGfxInit(); WHBGfxInit();
WHBMountSdCard(); WHBMountSdCard();
initialized = true; initialized = true;
} }
void StartFrame() void StartFrame()
{ {
if (rendering) return; if (rendering)
return;
WHBGfxBeginRender(); WHBGfxBeginRender();
WHBGfxBeginRenderTV(); WHBGfxBeginRenderTV();
WHBGfxBeginRenderDRC();
rendering = true; rendering = true;
} }
void EndFrame() void EndFrame()
{ {
if (!rendering) return; if (!rendering)
WHBGfxFinishRenderTV(); return;
WHBGfxBeginRenderDRC();
WHBGfxFinishRenderDRC(); WHBGfxFinishRenderDRC();
WHBGfxFinishRenderTV();
WHBGfxFinishRender(); WHBGfxFinishRender();
rendering = false; rendering = false;
} }
@ -49,7 +58,12 @@ static struct IsleGX2Backend {
void Clear(float r, float g, float b) void Clear(float r, float g, float b)
{ {
StartFrame(); StartFrame();
WHBGfxClearColor(r, g, b, 1.0f);
GX2ColorBuffer* tvBuffer = WHBGfxGetTVColourBuffer();
GX2ColorBuffer* drcBuffer = WHBGfxGetDRCColourBuffer();
GX2ClearColor(tvBuffer, r, g, b, 1.0f);
GX2ClearColor(drcBuffer, r, g, b, 1.0f);
} }
void Flip() void Flip()
@ -59,20 +73,17 @@ static struct IsleGX2Backend {
void Shutdown() void Shutdown()
{ {
if (!initialized) return; if (!initialized)
return;
WHBUnmountSdCard(); WHBUnmountSdCard();
WHBGfxShutdown(); WHBGfxShutdown();
WHBProcShutdown(); WHBProcShutdown();
WHBLogUdpDeinit(); WHBLogUdpDeinit();
initialized = false; initialized = false;
} }
} g_backend; } g_backend;
// ------------------------------------
// GX2Renderer Implementation
// ------------------------------------
GX2Renderer::GX2Renderer(DWORD width, DWORD height) GX2Renderer::GX2Renderer(DWORD width, DWORD height)
{ {
m_width = width; m_width = width;
@ -80,7 +91,7 @@ GX2Renderer::GX2Renderer(DWORD width, DWORD height)
m_virtualWidth = width; m_virtualWidth = width;
m_virtualHeight = height; m_virtualHeight = height;
g_backend.Init("content/renderer.gsh"); g_backend.Init();
} }
GX2Renderer::~GX2Renderer() GX2Renderer::~GX2Renderer()
@ -94,10 +105,7 @@ HRESULT GX2Renderer::BeginFrame()
return D3D_OK; return D3D_OK;
} }
void GX2Renderer::EnableTransparency() void GX2Renderer::EnableTransparency() {}
{
// GX2 blending can be configured here if needed
}
HRESULT GX2Renderer::FinalizeFrame() HRESULT GX2Renderer::FinalizeFrame()
{ {
@ -121,13 +129,3 @@ void GX2Renderer::Resize(int width, int height, const ViewportTransform& viewpor
m_height = height; m_height = height;
m_viewportTransform = viewportTransform; m_viewportTransform = viewportTransform;
} }
void GX2Renderer::PushLights(const SceneLight* vertices, size_t count) {}
void GX2Renderer::SetProjection(const D3DRMMATRIX4D&, D3DVALUE, D3DVALUE) {}
void GX2Renderer::SetFrustumPlanes(const Plane*) {}
Uint32 GX2Renderer::GetTextureId(IDirect3DRMTexture*, bool, float, float) { return 0; }
Uint32 GX2Renderer::GetMeshId(IDirect3DRMMesh*, const MeshGroup*) { return 0; }
void GX2Renderer::SubmitDraw(DWORD, const D3DRMMATRIX4D&, const D3DRMMATRIX4D&, const D3DRMMATRIX4D&, const Matrix3x3&, const Appearance&) {}
void GX2Renderer::Draw2DImage(Uint32, const SDL_Rect&, const SDL_Rect&, FColor) {}
void GX2Renderer::Download(SDL_Surface*) {}
void GX2Renderer::SetDither(bool) {}

View File

@ -1,6 +0,0 @@
#version 450
layout(location = 0) in vec4 vColour;
layout(location = 0) out vec4 outColour;
void main() {
outColour = vColour;
}

View File

@ -1,8 +0,0 @@
#version 450
layout(location = 0) in vec4 aPosition;
layout(location = 1) in vec4 aColour;
layout(location = 0) out vec4 vColour;
void main() {
gl_Position = aPosition;
vColour = aColour;
}

View File

@ -14,7 +14,6 @@ class GX2Renderer : public Direct3DRMRenderer {
GX2Renderer(DWORD width, DWORD height); GX2Renderer(DWORD width, DWORD height);
~GX2Renderer() override; ~GX2Renderer() override;
// --- Overrides from Direct3DRMRenderer ---
void PushLights(const SceneLight* vertices, size_t count) override; void PushLights(const SceneLight* vertices, size_t count) override;
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override; void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
void SetFrustumPlanes(const Plane* frustumPlanes) override; void SetFrustumPlanes(const Plane* frustumPlanes) override;
@ -39,7 +38,6 @@ class GX2Renderer : public Direct3DRMRenderer {
void SetDither(bool dither) override; void SetDither(bool dither) override;
}; };
// --- Enum device helper ---
inline static void GX2Renderer_EnumDevice(LPD3DENUMDEVICESCALLBACK cb, void* ctx) inline static void GX2Renderer_EnumDevice(LPD3DENUMDEVICESCALLBACK cb, void* ctx)
{ {
D3DDEVICEDESC halDesc = {}; D3DDEVICEDESC halDesc = {};

View File

@ -1,7 +0,0 @@
#include "d3drmrenderer_gx2.h"
GX2Renderer::GX2Renderer(DWORD width, DWORD height) : Direct3DRMRenderer(width, height)
{
}
GX2Renderer::~GX2Renderer() = default;