Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM ghcr.io/wiiu-env/devkitppc:20241128
FROM ghcr.io/wiiu-env/devkitppc:20260204

WORKDIR project
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions source/crt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ void __init_wut_malloc();

void __init_wut_newlib();

void __init_wut_stdcpp();
void __init_wut_thread();

void __init_wut_devoptab();

Expand All @@ -12,8 +12,6 @@ void __fini_wut_malloc();

void __fini_wut_newlib();

void __fini_wut_stdcpp();

void __fini_wut_devoptab();

void __fini();
Expand All @@ -22,9 +20,9 @@ void __attribute__((weak)) __fini_wut_socket();

void __attribute__((weak))
__init_wut_() {
__init_wut_thread();
__init_wut_malloc();
__init_wut_newlib();
__init_wut_stdcpp();
__init_wut_devoptab();
if (&__init_wut_socket) __init_wut_socket();
}
Expand All @@ -33,7 +31,6 @@ void __attribute__((weak))
__fini_wut_() {
__fini();
__fini_wut_devoptab();
__fini_wut_stdcpp();
__fini_wut_newlib();
__fini_wut_malloc();
}
12 changes: 11 additions & 1 deletion source/gfx/SplashScreenDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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());
}
}
Expand Down
73 changes: 73 additions & 0 deletions source/gfx/WEBPTexture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "WEBPTexture.h"
#include "utils/logger.h"
#include <cstdlib>
#include <cstring>
#include <gx2/mem.h>
#include <webp/decode.h>

GX2Texture *WEBP_LoadTexture(std::span<uint8_t> 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<GX2Texture *>(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<uint8_t *>(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;
}
7 changes: 7 additions & 0 deletions source/gfx/WEBPTexture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <cstdint>
#include <gx2/texture.h>
#include <span>

GX2Texture *WEBP_LoadTexture(std::span<uint8_t> data);
4 changes: 2 additions & 2 deletions source/gfx/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -476,4 +476,4 @@ BOOL GfxInitShaderAttribute(WHBGfxShaderGroup *group,
attrib->mask = GfxGetAttribFormatSel(format);
attrib->endianSwap = GX2_ENDIAN_SWAP_DEFAULT;
return TRUE;
}
}