#codec #texture #game-cube #wii #graphics #gamedev

gctex

gctex is a Rust crate designed for encoding and decoding texture formats used in the Nintendo GameCube and Wii games. The library provides C bindings, making it useful in both Rust and C/C++ based projects.

15 releases

0.3.0 Oct 21, 2023
0.2.2 Oct 18, 2023
0.1.13 Sep 22, 2023
0.1.12 Aug 5, 2023
0.1.4 Jul 15, 2023

#336 in Graphics APIs

GPL-2.0-or-later

545KB
4.5K SLoC

C++ 3K SLoC // 0.1% comments Bitbake 716 SLoC Rust 654 SLoC // 0.0% comments

Contains (Windows DLL, 190KB) examples/c#/bindings/gctex_v13.dll

crates.io docs.rs

gctex

gctex is a Rust crate designed for encoding and decoding texture formats used in the Nintendo GameCube and Wii games. The library provides C bindings, making it useful in both Rust and C/C++ based projects.

Usage

Rust

The following snippet demonstrates how to encode a texture in CMPR format using Rust:

let src = vec![0; src_len];
let dst = gctex::encode(gctex::TextureFormat::CMPR, &src, width, height);

C# Bindings

See https://github.com/riidefi/RiiStudio/tree/master/source/gctex/examples/c%23

byte[] dst = new byte[dst_len];
byte[] src = new byte[src_len];
gctex.Encode(0xE /* CMPR */, dst, src, width, height);

C/C++

See https://github.com/riidefi/RiiStudio/tree/master/source/gctex/examples/c%2b%2b

#include "gctex.h"

unsigned char dst[dst_len];
unsigned char src[src_len];
rii_encode_cmpr(dst, sizeof(dst), src, sizeof(src), width, height);

The relevant header is available in include/gctex.h.

Supported Formats

All supported texture formats and their respective encoding and decoding sources are listed below.

Format Encoding Source Decoding Source
CMPR WSZST Dolphin Emulator
I4 Builtin Dolphin Emulator (SIMD)
I8 Builtin Dolphin Emulator (SIMD)
IA4 Builtin Dolphin Emulator
IA8 Builtin Dolphin Emulator (SIMD)
RGB565 Builtin Dolphin Emulator
RGB5A3 Builtin Dolphin Emulator (SIMD)
RGBA8 Builtin Dolphin Emulator (SIMD)

Please note, SIMD texture decoding for I4, I8 and IA8 formats uses SSE3 instructions with a fallback to SSE2 if necessary, and these are implemented based on the Dolphin Emulator's texture decoding logic.

License

This dynamically linked library is published under GPLv2.

No runtime deps

~0–2MB
~39K SLoC