From 66980e247ba9442f4f5c852270fa334ddb00aedb Mon Sep 17 00:00:00 2001 From: "Daniel K. O. (dkosmari)" Date: Fri, 19 Dec 2025 06:52:57 -0300 Subject: [PATCH 1/4] Fixed format string. --- source/gfx/gfx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/gfx/gfx.c b/source/gfx/gfx.c index 5bc9078..df33e02 100644 --- a/source/gfx/gfx.c +++ b/source/gfx/gfx.c @@ -200,7 +200,7 @@ static BOOL initBucketHeap() { sGfxHeapForeground = MEMCreateExpHeapEx(base, size, 0); if (!sGfxHeapForeground) { - WHBLogPrintf("%s: MEMCreateExpHeapEx(0x%08X, 0x%X, 0)", __FUNCTION__, base, size); + WHBLogPrintf("%s: MEMCreateExpHeapEx(%p, 0x%X, 0)", __FUNCTION__, base, size); return FALSE; } @@ -476,4 +476,4 @@ BOOL GfxInitShaderAttribute(WHBGfxShaderGroup *group, attrib->mask = GfxGetAttribFormatSel(format); attrib->endianSwap = GX2_ENDIAN_SWAP_DEFAULT; return TRUE; -} \ No newline at end of file +} From 52609226238621550692265a7d8da3f0f852ed23 Mon Sep 17 00:00:00 2001 From: "Daniel K. O. (dkosmari)" Date: Fri, 19 Dec 2025 07:17:59 -0300 Subject: [PATCH 2/4] Added WEBP support. --- Makefile | 2 +- source/gfx/SplashScreenDrawer.cpp | 12 ++++- source/gfx/WEBPTexture.cpp | 73 +++++++++++++++++++++++++++++++ source/gfx/WEBPTexture.h | 7 +++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 source/gfx/WEBPTexture.cpp create mode 100644 source/gfx/WEBPTexture.h diff --git a/Makefile b/Makefile index 3a59eae..024ee56 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ CXXFLAGS := $(CFLAGS) -std=c++23 -fno-rtti ASFLAGS := -g $(ARCH) LDFLAGS = -g $(ARCH) $(RPXSPECS) --entry=_start -Wl,-Map,$(notdir $*.map) -LIBS := -lpng -lturbojpeg -lwut -lz +LIBS := -lpng -lturbojpeg -lwebp -lwut -lz ifeq ($(DEBUG),1) CXXFLAGS += -DDEBUG -g diff --git a/source/gfx/SplashScreenDrawer.cpp b/source/gfx/SplashScreenDrawer.cpp index e9f9793..45e4aff 100644 --- a/source/gfx/SplashScreenDrawer.cpp +++ b/source/gfx/SplashScreenDrawer.cpp @@ -3,6 +3,7 @@ #include "PNGTexture.h" #include "ShaderSerializer.h" #include "TGATexture.h" +#include "WEBPTexture.h" #include "gfx.h" #include "utils/logger.h" #include "utils/utils.h" @@ -137,6 +138,8 @@ static GX2Texture *LoadImageAsTexture(const std::filesystem::path &filename) { return JPEG_LoadTexture(buffer); } else if (ext == ".tga") { return TGA_LoadTexture(buffer); + } else if (ext == ".webp") { + return WEBP_LoadTexture(buffer); } } return nullptr; @@ -153,6 +156,9 @@ SplashScreenDrawer::SplashScreenDrawer(const std::filesystem::path &splash_base_ if (!mTexture) { mTexture = LoadImageAsTexture(splash_base_path / "splash.tga"); } + if (!mTexture) { + mTexture = LoadImageAsTexture(splash_base_path / "splash.webp"); + } if (!mTexture) { // try to load a random one from "splashes/*" try { @@ -162,7 +168,11 @@ SplashScreenDrawer::SplashScreenDrawer(const std::filesystem::path &splash_base_ continue; } auto ext = ToLower(entry.path().extension()); - if (ext == ".png" || ext == ".tga" || ext == ".jpg" || ext == ".jpeg") { + if (ext == ".png" || + ext == ".tga" || + ext == ".jpg" || + ext == ".jpeg" || + ext == ".webp") { candidates.push_back(entry.path()); } } diff --git a/source/gfx/WEBPTexture.cpp b/source/gfx/WEBPTexture.cpp new file mode 100644 index 0000000..1fee629 --- /dev/null +++ b/source/gfx/WEBPTexture.cpp @@ -0,0 +1,73 @@ +#include "WEBPTexture.h" +#include "utils/logger.h" +#include +#include +#include +#include + +GX2Texture *WEBP_LoadTexture(std::span data) { + GX2Texture *texture = nullptr; + int width, height; + + if (!WebPGetInfo(data.data(), data.size(), &width, &height)) { + DEBUG_FUNCTION_LINE_ERR("Failed to parse WEBP header\n"); + goto error; + } + + texture = static_cast(std::malloc(sizeof(GX2Texture))); + if (!texture) { + DEBUG_FUNCTION_LINE_ERR("Failed to allocate texture\n"); + goto error; + } + + std::memset(texture, 0, sizeof(GX2Texture)); + texture->surface.width = width; + texture->surface.height = height; + texture->surface.depth = 1; + texture->surface.mipLevels = 1; + texture->surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8; + texture->surface.aa = GX2_AA_MODE1X; + texture->surface.use = GX2_SURFACE_USE_TEXTURE; + texture->surface.dim = GX2_SURFACE_DIM_TEXTURE_2D; + texture->surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED; + texture->surface.swizzle = 0; + texture->viewFirstMip = 0; + texture->viewNumMips = 1; + texture->viewFirstSlice = 0; + texture->viewNumSlices = 1; + texture->compMap = 0x0010203; + GX2CalcSurfaceSizeAndAlignment(&texture->surface); + GX2InitTextureRegs(texture); + + if (texture->surface.imageSize == 0) { + DEBUG_FUNCTION_LINE_ERR("Texture is empty\n"); + goto error; + } + + texture->surface.image = std::aligned_alloc(texture->surface.alignment, + texture->surface.imageSize); + if (!texture->surface.image) { + DEBUG_FUNCTION_LINE_ERR("Failed to allocate surface for texture\n"); + goto error; + } + + if (!WebPDecodeRGBAInto(data.data(), data.size(), + reinterpret_cast(texture->surface.image), + texture->surface.imageSize, + texture->surface.pitch * 4)) { + DEBUG_FUNCTION_LINE_ERR("Failed to decode WEBP image\n"); + goto error; + } + + GX2Invalidate(GX2_INVALIDATE_MODE_CPU | GX2_INVALIDATE_MODE_TEXTURE, + texture->surface.image, texture->surface.imageSize); + + return texture; + +error: + if (texture) { + std::free(texture->surface.image); + } + std::free(texture); + return nullptr; +} diff --git a/source/gfx/WEBPTexture.h b/source/gfx/WEBPTexture.h new file mode 100644 index 0000000..b3180f0 --- /dev/null +++ b/source/gfx/WEBPTexture.h @@ -0,0 +1,7 @@ +#pragma once + +#include +#include +#include + +GX2Texture *WEBP_LoadTexture(std::span data); From aee29a1d46441719ba91191bc8b9e88698abc0be Mon Sep 17 00:00:00 2001 From: "Daniel K. O. (dkosmari)" Date: Fri, 19 Dec 2025 08:25:07 -0300 Subject: [PATCH 3/4] Fixed formatting. --- source/gfx/WEBPTexture.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/gfx/WEBPTexture.cpp b/source/gfx/WEBPTexture.cpp index 1fee629..c00b81d 100644 --- a/source/gfx/WEBPTexture.cpp +++ b/source/gfx/WEBPTexture.cpp @@ -51,10 +51,10 @@ GX2Texture *WEBP_LoadTexture(std::span data) { goto error; } - if (!WebPDecodeRGBAInto(data.data(), data.size(), - reinterpret_cast(texture->surface.image), - texture->surface.imageSize, - texture->surface.pitch * 4)) { + if (!WebPDecodeRGBAInto(data.data(), data.size(), + reinterpret_cast(texture->surface.image), + texture->surface.imageSize, + texture->surface.pitch * 4)) { DEBUG_FUNCTION_LINE_ERR("Failed to decode WEBP image\n"); goto error; } From 92f426f49659cd694dfddafd2fbc71e7409c923c Mon Sep 17 00:00:00 2001 From: "Daniel K. O. (dkosmari)" Date: Fri, 19 Dec 2025 08:27:31 -0300 Subject: [PATCH 4/4] Fixed formatting again. --- source/gfx/WEBPTexture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/gfx/WEBPTexture.cpp b/source/gfx/WEBPTexture.cpp index c00b81d..262045b 100644 --- a/source/gfx/WEBPTexture.cpp +++ b/source/gfx/WEBPTexture.cpp @@ -52,7 +52,7 @@ GX2Texture *WEBP_LoadTexture(std::span data) { } if (!WebPDecodeRGBAInto(data.data(), data.size(), - reinterpret_cast(texture->surface.image), + reinterpret_cast(texture->surface.image), texture->surface.imageSize, texture->surface.pitch * 4)) { DEBUG_FUNCTION_LINE_ERR("Failed to decode WEBP image\n");