This commit is contained in:
2026-02-15 01:09:28 -06:00
parent af9904c892
commit 92a753560b
9 changed files with 110 additions and 124 deletions

View File

@@ -198,7 +198,6 @@ function sceneRender()
0, 0,
1, 1
)
-- centerX = math.floor(screenGetWidth() / 2)
-- centerY = math.floor(screenGetHeight() / 2)

BIN
assets/ui/minogram.dpt Normal file

Binary file not shown.

View File

@@ -16,27 +16,41 @@ errorret_t assetTextureLoad(void *data, void *output) {
assettexture_t *assetData = (assettexture_t *)data;
texture_t *texture = (texture_t *)output;
// Read header and version (first 4 bytes)
if(
assetData->header[0] != 'D' ||
assetData->header[1] != 'P' ||
assetData->header[2] != 'T'
) {
errorThrow("Invalid texture header");
}
// Version (can only be 1 atm)
if(assetData->version != 0x01) {
errorThrow("Unsupported texture version");
}
// Fix endian
assetData->width = le32toh(assetData->width);
assetData->height = le32toh(assetData->height);
errorThrow("Hello World\n");
// const palette_t *pal = PALETTE_LIST[assetData->paletteIndex];
// assertNotNull(pal, "Palette index is out of bounds");
// Check dimensions.
if(
assetData->width == 0 || assetData->width > ASSET_TEXTURE_WIDTH_MAX ||
assetData->height == 0 || assetData->height > ASSET_TEXTURE_HEIGHT_MAX
) {
errorThrow("Invalid texture dimensions");
}
// textureInit(
// texture,
// assetData->width,
// assetData->height,
// TEXTURE_FORMAT_PALETTE,
// (texturedata_t){
// .palette = {
// .palette = pal,
// .data = assetData->palette
// }
// }
// );
textureInit(
texture,
assetData->width,
assetData->height,
TEXTURE_FORMAT_PALETTE,
(texturedata_t){
.paletteData = assetData->palette
}
);
// errorOk();
errorOk();
}

View File

@@ -16,6 +16,9 @@
#pragma pack(push, 1)
typedef struct {
char_t header[3];
uint8_t version;
uint32_t width;
uint32_t height;
uint8_t paletteIndex;

View File

@@ -31,8 +31,8 @@ void frameBufferInitBackbuffer() {
assertTrue(width > 0 && height > 0, "W/H must be greater than 0");
memoryZero(framebuffer, sizeof(framebuffer_t));
textureInit(&framebuffer->texture, width, height, GL_RGBA,(texturedata_t){
.rgba = { .colors = NULL }
textureInit(&framebuffer->texture, width, height, TEXTURE_FORMAT_RGBA,(texturedata_t){
.rgbaColors = NULL
});
glGenFramebuffersEXT(1, &framebuffer->id);

View File

@@ -15,7 +15,7 @@ texture_t DEFAULT_FONT_TEXTURE;
tileset_t DEFAULT_FONT_TILESET;
errorret_t textInit(void) {
// errorChain(assetLoad(DEFAULT_FONT_TILESET.image, &DEFAULT_FONT_TEXTURE));
errorChain(assetLoad("ui/minogram.dpt", &DEFAULT_FONT_TEXTURE));
errorOk();
}

View File

@@ -29,16 +29,8 @@ void textureInit(
texture->height = height;
texture->format = format;
#if PSP
assertTrue(
width == mathNextPowTwo(width),
"Width must be powers of 2 for PSP"
);
assertTrue(
height == mathNextPowTwo(height),
"Height must be powers of 2 for PSP"
);
#endif
assertTrue(width == mathNextPowTwo(width), "Width must be a power of 2.");
assertTrue(height == mathNextPowTwo(height), "Height must be a power of 2.");
#if DISPLAY_SDL2
glGenTextures(1, &texture->id);
@@ -48,56 +40,55 @@ void textureInit(
case TEXTURE_FORMAT_RGBA:
glTexImage2D(
GL_TEXTURE_2D, 0, format, width, height, 0,
format, GL_UNSIGNED_BYTE, (void*)data.rgba.colors
format, GL_UNSIGNED_BYTE, (void*)data.rgbaColors
);
break;
case TEXTURE_FORMAT_ALPHA: {
assertNotNull(data.alpha.data, "Alpha texture data cannot be NULL");
#if PSP
// PSP kinda broken with alpha textures, so we convert it to paletted
// texture here. We also crunch the amount of alpha values.
#define PSP_ALPHA_PALETTE_CRUNCH 4
#define PSP_ALPHA_PALETTE_COUNT (256 / PSP_ALPHA_PALETTE_CRUNCH)
// case TEXTURE_FORMAT_ALPHA: {
// assertNotNull(data.alpha.data, "Alpha texture data cannot be NULL");
// #if PSP
// // PSP kinda broken with alpha textures, so we convert it to paletted
// // texture here. We also crunch the amount of alpha values.
// #define PSP_ALPHA_PALETTE_CRUNCH 4
// #define PSP_ALPHA_PALETTE_COUNT (256 / PSP_ALPHA_PALETTE_CRUNCH)
color_t paletteColors[PSP_ALPHA_PALETTE_COUNT];
for(uint8_t i = 0; i < PSP_ALPHA_PALETTE_COUNT; i++) {
paletteColors[i].r = 0xFF;
paletteColors[i].g = 0xFF;
paletteColors[i].b = 0xFF;
paletteColors[i].a = i * PSP_ALPHA_PALETTE_CRUNCH;
}
// color_t paletteColors[PSP_ALPHA_PALETTE_COUNT];
// for(uint8_t i = 0; i < PSP_ALPHA_PALETTE_COUNT; i++) {
// paletteColors[i].r = 0xFF;
// paletteColors[i].g = 0xFF;
// paletteColors[i].b = 0xFF;
// paletteColors[i].a = i * PSP_ALPHA_PALETTE_CRUNCH;
// }
// Generate indexes, crunching the alpha values to fit.
uint8_t indexes[width * height];
for(int32_t i = 0; i < width * height; i++) {
uint8_t alpha = data.alpha.data[i] / PSP_ALPHA_PALETTE_CRUNCH;;
indexes[i] = alpha;
}
// // Generate indexes, crunching the alpha values to fit.
// uint8_t indexes[width * height];
// for(int32_t i = 0; i < width * height; i++) {
// uint8_t alpha = data.alpha.data[i] / PSP_ALPHA_PALETTE_CRUNCH;;
// indexes[i] = alpha;
// }
palette_t palette = {
.colorCount = PSP_ALPHA_PALETTE_COUNT,
.colors = paletteColors
};
// palette_t palette = {
// .colorCount = PSP_ALPHA_PALETTE_COUNT,
// .colors = paletteColors
// };
return textureInit(
texture, width, height, TEXTURE_FORMAT_PALETTE,
(texturedata_t){
.palette = { .palette = &palette, .data = indexes }
}
);
#else
glTexImage2D(
GL_TEXTURE_2D, 0, format, width, height, 0,
format, GL_UNSIGNED_BYTE, (void*)data.alpha.data
);
#endif
break;
}
// return textureInit(
// texture, width, height, TEXTURE_FORMAT_PALETTE,
// (texturedata_t){
// .palette = { .palette = &palette, .data = indexes }
// }
// );
// #else
// glTexImage2D(
// GL_TEXTURE_2D, 0, format, width, height, 0,
// format, GL_UNSIGNED_BYTE, (void*)data.alpha.data
// );
// #endif
// break;
// }
case TEXTURE_FORMAT_PALETTE:
assertNotNull(data.palette.data, "Palette texture data cannot be NULL");
assertNotNull(data.palette.palette, "Palette cannot be NULL");
assertNotNull(data.paletteData, "Palette texture data cannot be NULL");
// Get and validate the palette.
GLenum err = glGetError();
@@ -130,45 +121,35 @@ void textureInit(
#endif
if(!havePalTex) {
assertUnreachable("Paletted textures not supported on this platform");
// Not supported, convert to RGBA using lookup
color_t formatted[width * height];
for(int32_t i = 0; i < width * height; i++) {
uint8_t index = data.palette.data[i];
assertTrue(
index < data.palette.palette->colorCount,
"Palette index out of range"
);
formatted[i] = data.palette.palette->colors[index];
}
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, (void*)formatted
);
// color_t formatted[width * height];
// for(int32_t i = 0; i < width * height; i++) {
// uint8_t index = data..data[i];
// assertTrue(
// index < data.palette.palette->colorCount,
// "Palette index out of range"
// );
// formatted[i] = data.palette.palette->colors[index];
// }
// glTexImage2D(
// GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
// GL_RGBA, GL_UNSIGNED_BYTE, (void*)formatted
// );
} else {
// Supported.
#if PSP
// PSP requires the color table itself to be a power of two
assertTrue(
data.palette.palette->colorCount ==
mathNextPowTwo(data.palette.palette->colorCount),
"Palette color count must be a power of 2 for PSP"
);
#endif
glTexImage2D(
GL_TEXTURE_2D,
0, GL_COLOR_INDEX8_EXT,
width, height,
0, GL_COLOR_INDEX8_EXT,
GL_UNSIGNED_BYTE, (void*)data.palette.data
GL_UNSIGNED_BYTE, (void*)data.paletteData
);
glColorTableEXT(
GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA,
GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors
);
// glColorTableEXT(
// GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA,
// GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors
// );
}
break;
default:

View File

@@ -13,11 +13,10 @@
typedef enum {
#if DISPLAY_SDL2
TEXTURE_FORMAT_RGBA = GL_RGBA,
TEXTURE_FORMAT_ALPHA = GL_ALPHA,
TEXTURE_FORMAT_PALETTE = GL_COLOR_INDEX8_EXT,
#elif DOLPHIN
TEXTURE_FORMAT_RGBA = GX_TF_RGBA8,
TEXTURE_FORMAT_ALPHA = GX_TF_A8,
// TEXTURE_FORMAT_RGBA = GX_TF_RGBA8,
// TEXTURE_FORMAT_ALPHA = GX_TF_A8,
TEXTURE_FORMAT_PALETTE = GX_TF_CI8,
#endif
} textureformat_t;
@@ -40,18 +39,8 @@ typedef struct {
} texture_t;
typedef union {
struct {
color_t *colors;
} rgba;
struct {
const palette_t *palette;
uint8_t *data;
} palette;
struct {
uint8_t *data;
} alpha;
uint8_t *paletteData;
color_t *rgbaColors;
} texturedata_t;
extern const texture_t *TEXTURE_BOUND;

View File

@@ -663,17 +663,17 @@
// Width
const widthBytes = new Uint8Array(4);
widthBytes[0] = (imageWidth >> 24) & 0xFF;
widthBytes[1] = (imageWidth >> 16) & 0xFF;
widthBytes[2] = (imageWidth >> 8) & 0xFF;
widthBytes[3] = imageWidth & 0xFF;
widthBytes[3] = (imageWidth >> 24) & 0xFF;
widthBytes[2] = (imageWidth >> 16) & 0xFF;
widthBytes[1] = (imageWidth >> 8) & 0xFF;
widthBytes[0] = imageWidth & 0xFF;
// Height
const heightBytes = new Uint8Array(4);
heightBytes[0] = (imageHeight >> 24) & 0xFF;
heightBytes[1] = (imageHeight >> 16) & 0xFF;
heightBytes[2] = (imageHeight >> 8) & 0xFF;
heightBytes[3] = imageHeight & 0xFF;
heightBytes[3] = (imageHeight >> 24) & 0xFF;
heightBytes[2] = (imageHeight >> 16) & 0xFF;
heightBytes[1] = (imageHeight >> 8) & 0xFF;
heightBytes[0] = imageHeight & 0xFF;
// add indexed image data (imageWidth * imageHeight bytes)
const imageData = new Uint8Array(indexedImage.length);