prog
This commit is contained in:
@@ -198,7 +198,6 @@ function sceneRender()
|
|||||||
0, 0,
|
0, 0,
|
||||||
1, 1
|
1, 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
-- centerX = math.floor(screenGetWidth() / 2)
|
-- centerX = math.floor(screenGetWidth() / 2)
|
||||||
-- centerY = math.floor(screenGetHeight() / 2)
|
-- centerY = math.floor(screenGetHeight() / 2)
|
||||||
|
|||||||
BIN
assets/ui/minogram.dpt
Normal file
BIN
assets/ui/minogram.dpt
Normal file
Binary file not shown.
@@ -16,27 +16,41 @@ errorret_t assetTextureLoad(void *data, void *output) {
|
|||||||
assettexture_t *assetData = (assettexture_t *)data;
|
assettexture_t *assetData = (assettexture_t *)data;
|
||||||
texture_t *texture = (texture_t *)output;
|
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
|
// Fix endian
|
||||||
assetData->width = le32toh(assetData->width);
|
assetData->width = le32toh(assetData->width);
|
||||||
assetData->height = le32toh(assetData->height);
|
assetData->height = le32toh(assetData->height);
|
||||||
|
|
||||||
errorThrow("Hello World\n");
|
|
||||||
|
|
||||||
// const palette_t *pal = PALETTE_LIST[assetData->paletteIndex];
|
// Check dimensions.
|
||||||
// assertNotNull(pal, "Palette index is out of bounds");
|
if(
|
||||||
|
assetData->width == 0 || assetData->width > ASSET_TEXTURE_WIDTH_MAX ||
|
||||||
|
assetData->height == 0 || assetData->height > ASSET_TEXTURE_HEIGHT_MAX
|
||||||
|
) {
|
||||||
|
errorThrow("Invalid texture dimensions");
|
||||||
|
}
|
||||||
|
|
||||||
// textureInit(
|
textureInit(
|
||||||
// texture,
|
texture,
|
||||||
// assetData->width,
|
assetData->width,
|
||||||
// assetData->height,
|
assetData->height,
|
||||||
// TEXTURE_FORMAT_PALETTE,
|
TEXTURE_FORMAT_PALETTE,
|
||||||
// (texturedata_t){
|
(texturedata_t){
|
||||||
// .palette = {
|
.paletteData = assetData->palette
|
||||||
// .palette = pal,
|
}
|
||||||
// .data = assetData->palette
|
);
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
// errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
char_t header[3];
|
||||||
|
uint8_t version;
|
||||||
|
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint8_t paletteIndex;
|
uint8_t paletteIndex;
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ void frameBufferInitBackbuffer() {
|
|||||||
assertTrue(width > 0 && height > 0, "W/H must be greater than 0");
|
assertTrue(width > 0 && height > 0, "W/H must be greater than 0");
|
||||||
|
|
||||||
memoryZero(framebuffer, sizeof(framebuffer_t));
|
memoryZero(framebuffer, sizeof(framebuffer_t));
|
||||||
textureInit(&framebuffer->texture, width, height, GL_RGBA,(texturedata_t){
|
textureInit(&framebuffer->texture, width, height, TEXTURE_FORMAT_RGBA,(texturedata_t){
|
||||||
.rgba = { .colors = NULL }
|
.rgbaColors = NULL
|
||||||
});
|
});
|
||||||
|
|
||||||
glGenFramebuffersEXT(1, &framebuffer->id);
|
glGenFramebuffersEXT(1, &framebuffer->id);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ texture_t DEFAULT_FONT_TEXTURE;
|
|||||||
tileset_t DEFAULT_FONT_TILESET;
|
tileset_t DEFAULT_FONT_TILESET;
|
||||||
|
|
||||||
errorret_t textInit(void) {
|
errorret_t textInit(void) {
|
||||||
// errorChain(assetLoad(DEFAULT_FONT_TILESET.image, &DEFAULT_FONT_TEXTURE));
|
errorChain(assetLoad("ui/minogram.dpt", &DEFAULT_FONT_TEXTURE));
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,16 +29,8 @@ void textureInit(
|
|||||||
texture->height = height;
|
texture->height = height;
|
||||||
texture->format = format;
|
texture->format = format;
|
||||||
|
|
||||||
#if PSP
|
assertTrue(width == mathNextPowTwo(width), "Width must be a power of 2.");
|
||||||
assertTrue(
|
assertTrue(height == mathNextPowTwo(height), "Height must be a power of 2.");
|
||||||
width == mathNextPowTwo(width),
|
|
||||||
"Width must be powers of 2 for PSP"
|
|
||||||
);
|
|
||||||
assertTrue(
|
|
||||||
height == mathNextPowTwo(height),
|
|
||||||
"Height must be powers of 2 for PSP"
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DISPLAY_SDL2
|
#if DISPLAY_SDL2
|
||||||
glGenTextures(1, &texture->id);
|
glGenTextures(1, &texture->id);
|
||||||
@@ -48,56 +40,55 @@ void textureInit(
|
|||||||
case TEXTURE_FORMAT_RGBA:
|
case TEXTURE_FORMAT_RGBA:
|
||||||
glTexImage2D(
|
glTexImage2D(
|
||||||
GL_TEXTURE_2D, 0, format, width, height, 0,
|
GL_TEXTURE_2D, 0, format, width, height, 0,
|
||||||
format, GL_UNSIGNED_BYTE, (void*)data.rgba.colors
|
format, GL_UNSIGNED_BYTE, (void*)data.rgbaColors
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TEXTURE_FORMAT_ALPHA: {
|
// case TEXTURE_FORMAT_ALPHA: {
|
||||||
assertNotNull(data.alpha.data, "Alpha texture data cannot be NULL");
|
// assertNotNull(data.alpha.data, "Alpha texture data cannot be NULL");
|
||||||
#if PSP
|
// #if PSP
|
||||||
// PSP kinda broken with alpha textures, so we convert it to paletted
|
// // PSP kinda broken with alpha textures, so we convert it to paletted
|
||||||
// texture here. We also crunch the amount of alpha values.
|
// // texture here. We also crunch the amount of alpha values.
|
||||||
#define PSP_ALPHA_PALETTE_CRUNCH 4
|
// #define PSP_ALPHA_PALETTE_CRUNCH 4
|
||||||
#define PSP_ALPHA_PALETTE_COUNT (256 / PSP_ALPHA_PALETTE_CRUNCH)
|
// #define PSP_ALPHA_PALETTE_COUNT (256 / PSP_ALPHA_PALETTE_CRUNCH)
|
||||||
|
|
||||||
color_t paletteColors[PSP_ALPHA_PALETTE_COUNT];
|
// color_t paletteColors[PSP_ALPHA_PALETTE_COUNT];
|
||||||
for(uint8_t i = 0; i < PSP_ALPHA_PALETTE_COUNT; i++) {
|
// for(uint8_t i = 0; i < PSP_ALPHA_PALETTE_COUNT; i++) {
|
||||||
paletteColors[i].r = 0xFF;
|
// paletteColors[i].r = 0xFF;
|
||||||
paletteColors[i].g = 0xFF;
|
// paletteColors[i].g = 0xFF;
|
||||||
paletteColors[i].b = 0xFF;
|
// paletteColors[i].b = 0xFF;
|
||||||
paletteColors[i].a = i * PSP_ALPHA_PALETTE_CRUNCH;
|
// paletteColors[i].a = i * PSP_ALPHA_PALETTE_CRUNCH;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Generate indexes, crunching the alpha values to fit.
|
// // Generate indexes, crunching the alpha values to fit.
|
||||||
uint8_t indexes[width * height];
|
// uint8_t indexes[width * height];
|
||||||
for(int32_t i = 0; i < width * height; i++) {
|
// for(int32_t i = 0; i < width * height; i++) {
|
||||||
uint8_t alpha = data.alpha.data[i] / PSP_ALPHA_PALETTE_CRUNCH;;
|
// uint8_t alpha = data.alpha.data[i] / PSP_ALPHA_PALETTE_CRUNCH;;
|
||||||
indexes[i] = alpha;
|
// indexes[i] = alpha;
|
||||||
}
|
// }
|
||||||
|
|
||||||
palette_t palette = {
|
// palette_t palette = {
|
||||||
.colorCount = PSP_ALPHA_PALETTE_COUNT,
|
// .colorCount = PSP_ALPHA_PALETTE_COUNT,
|
||||||
.colors = paletteColors
|
// .colors = paletteColors
|
||||||
};
|
// };
|
||||||
|
|
||||||
return textureInit(
|
// return textureInit(
|
||||||
texture, width, height, TEXTURE_FORMAT_PALETTE,
|
// texture, width, height, TEXTURE_FORMAT_PALETTE,
|
||||||
(texturedata_t){
|
// (texturedata_t){
|
||||||
.palette = { .palette = &palette, .data = indexes }
|
// .palette = { .palette = &palette, .data = indexes }
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
#else
|
// #else
|
||||||
glTexImage2D(
|
// glTexImage2D(
|
||||||
GL_TEXTURE_2D, 0, format, width, height, 0,
|
// GL_TEXTURE_2D, 0, format, width, height, 0,
|
||||||
format, GL_UNSIGNED_BYTE, (void*)data.alpha.data
|
// format, GL_UNSIGNED_BYTE, (void*)data.alpha.data
|
||||||
);
|
// );
|
||||||
#endif
|
// #endif
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
case TEXTURE_FORMAT_PALETTE:
|
case TEXTURE_FORMAT_PALETTE:
|
||||||
assertNotNull(data.palette.data, "Palette texture data cannot be NULL");
|
assertNotNull(data.paletteData, "Palette texture data cannot be NULL");
|
||||||
assertNotNull(data.palette.palette, "Palette cannot be NULL");
|
|
||||||
|
|
||||||
// Get and validate the palette.
|
// Get and validate the palette.
|
||||||
GLenum err = glGetError();
|
GLenum err = glGetError();
|
||||||
@@ -130,45 +121,35 @@ void textureInit(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!havePalTex) {
|
if(!havePalTex) {
|
||||||
|
assertUnreachable("Paletted textures not supported on this platform");
|
||||||
// Not supported, convert to RGBA using lookup
|
// Not supported, convert to RGBA using lookup
|
||||||
color_t formatted[width * height];
|
// color_t formatted[width * height];
|
||||||
for(int32_t i = 0; i < width * height; i++) {
|
// for(int32_t i = 0; i < width * height; i++) {
|
||||||
uint8_t index = data.palette.data[i];
|
// uint8_t index = data..data[i];
|
||||||
assertTrue(
|
// assertTrue(
|
||||||
index < data.palette.palette->colorCount,
|
// index < data.palette.palette->colorCount,
|
||||||
"Palette index out of range"
|
// "Palette index out of range"
|
||||||
);
|
// );
|
||||||
formatted[i] = data.palette.palette->colors[index];
|
// formatted[i] = data.palette.palette->colors[index];
|
||||||
}
|
// }
|
||||||
glTexImage2D(
|
// glTexImage2D(
|
||||||
GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
// GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, (void*)formatted
|
// GL_RGBA, GL_UNSIGNED_BYTE, (void*)formatted
|
||||||
);
|
// );
|
||||||
} else {
|
} 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(
|
glTexImage2D(
|
||||||
GL_TEXTURE_2D,
|
GL_TEXTURE_2D,
|
||||||
0, GL_COLOR_INDEX8_EXT,
|
0, GL_COLOR_INDEX8_EXT,
|
||||||
width, height,
|
width, height,
|
||||||
0, GL_COLOR_INDEX8_EXT,
|
0, GL_COLOR_INDEX8_EXT,
|
||||||
GL_UNSIGNED_BYTE, (void*)data.palette.data
|
GL_UNSIGNED_BYTE, (void*)data.paletteData
|
||||||
);
|
);
|
||||||
|
|
||||||
glColorTableEXT(
|
// glColorTableEXT(
|
||||||
GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA,
|
// GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA,
|
||||||
GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors
|
// GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -13,11 +13,10 @@
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
#if DISPLAY_SDL2
|
#if DISPLAY_SDL2
|
||||||
TEXTURE_FORMAT_RGBA = GL_RGBA,
|
TEXTURE_FORMAT_RGBA = GL_RGBA,
|
||||||
TEXTURE_FORMAT_ALPHA = GL_ALPHA,
|
|
||||||
TEXTURE_FORMAT_PALETTE = GL_COLOR_INDEX8_EXT,
|
TEXTURE_FORMAT_PALETTE = GL_COLOR_INDEX8_EXT,
|
||||||
#elif DOLPHIN
|
#elif DOLPHIN
|
||||||
TEXTURE_FORMAT_RGBA = GX_TF_RGBA8,
|
// TEXTURE_FORMAT_RGBA = GX_TF_RGBA8,
|
||||||
TEXTURE_FORMAT_ALPHA = GX_TF_A8,
|
// TEXTURE_FORMAT_ALPHA = GX_TF_A8,
|
||||||
TEXTURE_FORMAT_PALETTE = GX_TF_CI8,
|
TEXTURE_FORMAT_PALETTE = GX_TF_CI8,
|
||||||
#endif
|
#endif
|
||||||
} textureformat_t;
|
} textureformat_t;
|
||||||
@@ -40,18 +39,8 @@ typedef struct {
|
|||||||
} texture_t;
|
} texture_t;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
struct {
|
uint8_t *paletteData;
|
||||||
color_t *colors;
|
color_t *rgbaColors;
|
||||||
} rgba;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
const palette_t *palette;
|
|
||||||
uint8_t *data;
|
|
||||||
} palette;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint8_t *data;
|
|
||||||
} alpha;
|
|
||||||
} texturedata_t;
|
} texturedata_t;
|
||||||
|
|
||||||
extern const texture_t *TEXTURE_BOUND;
|
extern const texture_t *TEXTURE_BOUND;
|
||||||
|
|||||||
@@ -663,17 +663,17 @@
|
|||||||
|
|
||||||
// Width
|
// Width
|
||||||
const widthBytes = new Uint8Array(4);
|
const widthBytes = new Uint8Array(4);
|
||||||
widthBytes[0] = (imageWidth >> 24) & 0xFF;
|
widthBytes[3] = (imageWidth >> 24) & 0xFF;
|
||||||
widthBytes[1] = (imageWidth >> 16) & 0xFF;
|
widthBytes[2] = (imageWidth >> 16) & 0xFF;
|
||||||
widthBytes[2] = (imageWidth >> 8) & 0xFF;
|
widthBytes[1] = (imageWidth >> 8) & 0xFF;
|
||||||
widthBytes[3] = imageWidth & 0xFF;
|
widthBytes[0] = imageWidth & 0xFF;
|
||||||
|
|
||||||
// Height
|
// Height
|
||||||
const heightBytes = new Uint8Array(4);
|
const heightBytes = new Uint8Array(4);
|
||||||
heightBytes[0] = (imageHeight >> 24) & 0xFF;
|
heightBytes[3] = (imageHeight >> 24) & 0xFF;
|
||||||
heightBytes[1] = (imageHeight >> 16) & 0xFF;
|
heightBytes[2] = (imageHeight >> 16) & 0xFF;
|
||||||
heightBytes[2] = (imageHeight >> 8) & 0xFF;
|
heightBytes[1] = (imageHeight >> 8) & 0xFF;
|
||||||
heightBytes[3] = imageHeight & 0xFF;
|
heightBytes[0] = imageHeight & 0xFF;
|
||||||
|
|
||||||
// add indexed image data (imageWidth * imageHeight bytes)
|
// add indexed image data (imageWidth * imageHeight bytes)
|
||||||
const imageData = new Uint8Array(indexedImage.length);
|
const imageData = new Uint8Array(indexedImage.length);
|
||||||
|
|||||||
Reference in New Issue
Block a user