mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-22 01:52:43 +00:00
Fix djui hud texture unsupported formats (#995)
- `djui_hud_render_texture(_tile)` now accepts properly any `TextureInfo` - Removed `bitSize`, added `format` and `size` to `TextureInfo` - `texture_to_lua_table` can now convert any `Texture` into an RGBA table
This commit is contained in:
parent
a3bfd4a740
commit
c3e5843c53
33 changed files with 2331 additions and 2332 deletions
|
|
@ -129,7 +129,6 @@ override_disallowed_functions = {
|
|||
"src/game/camera.h": [ "update_camera", "init_camera", "stub_camera", "^reset_camera", "move_point_along_spline", "romhack_camera_init_settings", "romhack_camera_reset_settings" ],
|
||||
"src/game/behavior_actions.h": [ "bhv_dust_smoke_loop", "bhv_init_room" ],
|
||||
"src/pc/lua/utils/smlua_audio_utils.h": [ "smlua_audio_utils_override", "audio_custom_shutdown", "smlua_audio_custom_deinit", "audio_sample_destroy_pending_copies", "audio_custom_update_volume" ],
|
||||
"src/pc/djui/djui_hud_utils.h": [ "djui_hud_render_texture_raw", "djui_hud_render_texture_tile_raw" ],
|
||||
"src/pc/lua/utils/smlua_level_utils.h": [ "smlua_level_util_reset" ],
|
||||
"src/pc/lua/utils/smlua_text_utils.h": [ "smlua_text_utils_init", "smlua_text_utils_shutdown", "smlua_text_utils_dialog_get_unmodified"],
|
||||
"src/pc/lua/utils/smlua_anim_utils.h": [ "smlua_anim_util_reset", "smlua_anim_util_register_animation" ],
|
||||
|
|
|
|||
|
|
@ -11580,7 +11580,8 @@ function geo_get_current_held_object()
|
|||
end
|
||||
|
||||
--- @param tex Pointer_Texture
|
||||
--- Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, returns a table as a pure memory buffer. Supports rgba16 and rgba32 textures
|
||||
--- @return table
|
||||
--- Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, returns a 1-indexed table of RGBA pixels
|
||||
function texture_to_lua_table(tex)
|
||||
-- ...
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2260,7 +2260,8 @@
|
|||
--- @field public name string
|
||||
--- @field public width integer
|
||||
--- @field public height integer
|
||||
--- @field public bitSize integer
|
||||
--- @field public format integer
|
||||
--- @field public size integer
|
||||
|
||||
--- @class Vtx
|
||||
--- @field public x number
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ bool dynos_texture_get(const char* textureName, struct TextureInfo* outTextureIn
|
|||
bool dynos_texture_get_from_data(const Texture *tex, struct TextureInfo* outTextureInfo);
|
||||
void dynos_texture_override_set(const char* textureName, struct TextureInfo* overrideTextureInfo);
|
||||
void dynos_texture_override_reset(const char* textureName);
|
||||
u8 *dynos_texture_convert_to_rgba32(const Texture *tex, u32 width, u32 height, u8 fmt, u8 siz);
|
||||
|
||||
// -- movtexqcs -- //
|
||||
void dynos_movtexqc_register(const char* name, s16 level, s16 area, s16 type);
|
||||
|
|
|
|||
|
|
@ -653,15 +653,6 @@ struct DynosOption : NoCopy {
|
|||
};
|
||||
typedef bool (*DynosLoopFunc)(DynosOption *, void *);
|
||||
|
||||
struct BuiltinTexInfo {
|
||||
const char* identifier;
|
||||
const void* pointer;
|
||||
const char* path;
|
||||
s32 width;
|
||||
s32 height;
|
||||
s32 bitSize;
|
||||
};
|
||||
|
||||
struct LvlCmd {
|
||||
u8 mType;
|
||||
u8 mSize;
|
||||
|
|
@ -866,8 +857,8 @@ const char * DynOS_Builtin_Anim_GetFromData(const Animation *aData);
|
|||
const Texture* DynOS_Builtin_Tex_GetFromName(const char* aDataName);
|
||||
const char* DynOS_Builtin_Tex_GetFromData(const Texture* aData);
|
||||
const char* DynOS_Builtin_Tex_GetNameFromFileName(const char* aDataName);
|
||||
const struct BuiltinTexInfo* DynOS_Builtin_Tex_GetInfoFromName(const char* aDataName);
|
||||
const struct BuiltinTexInfo* DynOS_Builtin_Tex_GetInfoFromData(const Texture* aData);
|
||||
const struct TextureInfo* DynOS_Builtin_Tex_GetInfoFromName(const char* aDataName);
|
||||
const struct TextureInfo* DynOS_Builtin_Tex_GetInfoFromData(const Texture* aData);
|
||||
const void* DynOS_Builtin_Func_GetFromName(const char* aDataName, u8 aFuncType);
|
||||
const void* DynOS_Builtin_Func_GetFromIndex(s32 aIndex, u8 aFuncType);
|
||||
const char * DynOS_Builtin_Func_GetNameFromIndex(s32 aIndex, u8 aFuncType);
|
||||
|
|
|
|||
|
|
@ -164,6 +164,16 @@ void dynos_texture_override_reset(const char* textureName) {
|
|||
DynOS_Tex_Override_Reset(textureName);
|
||||
}
|
||||
|
||||
u8 *dynos_texture_convert_to_rgba32(const Texture *tex, u32 width, u32 height, u8 fmt, u8 siz) {
|
||||
switch (siz) {
|
||||
case G_IM_SIZ_4b: return DynOS_Tex_ConvertToRGBA32(tex, (width * height) / 2, fmt, siz, NULL);
|
||||
case G_IM_SIZ_8b: return DynOS_Tex_ConvertToRGBA32(tex, width * height, fmt, siz, NULL);
|
||||
case G_IM_SIZ_16b: return DynOS_Tex_ConvertToRGBA32(tex, width * height * 2, fmt, siz, NULL);
|
||||
case G_IM_SIZ_32b: return DynOS_Tex_ConvertToRGBA32(tex, width * height * 4, fmt, siz, NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// -- movtexqcs -- //
|
||||
|
||||
void dynos_movtexqc_register(const char* name, s16 level, s16 area, s16 type) {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -451,15 +451,10 @@ bool DynOS_Tex_AddCustom(const SysPath &aFilename, const char *aTexName) {
|
|||
}
|
||||
|
||||
#define CONVERT_TEXINFO(texName) { \
|
||||
/* translate bit size */ \
|
||||
switch (_Data->mRawSize) { \
|
||||
case G_IM_SIZ_8b: aOutTexInfo->bitSize = 8; break; \
|
||||
case G_IM_SIZ_16b: aOutTexInfo->bitSize = 16; break; \
|
||||
case G_IM_SIZ_32b: aOutTexInfo->bitSize = 32; break; \
|
||||
default: return false; \
|
||||
} \
|
||||
aOutTexInfo->width = _Data->mRawWidth; \
|
||||
aOutTexInfo->height = _Data->mRawHeight; \
|
||||
aOutTexInfo->format = _Data->mRawFormat; \
|
||||
aOutTexInfo->size = _Data->mRawSize; \
|
||||
aOutTexInfo->texture = _Data->mRawData.begin(); \
|
||||
aOutTexInfo->name = texName; \
|
||||
}
|
||||
|
|
@ -499,7 +494,7 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) {
|
|||
}
|
||||
|
||||
// check builtin textures
|
||||
const struct BuiltinTexInfo* info = DynOS_Builtin_Tex_GetInfoFromName(aTexName);
|
||||
const struct TextureInfo* info = DynOS_Builtin_Tex_GetInfoFromName(aTexName);
|
||||
if (!info) {
|
||||
for (DataNode<TexData>* _Node : DynosValidTextures()) { // check valid textures
|
||||
if (_Node->mName == aTexName) {
|
||||
|
|
@ -510,11 +505,7 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
aOutTexInfo->bitSize = info->bitSize;
|
||||
aOutTexInfo->width = info->width;
|
||||
aOutTexInfo->height = info->height;
|
||||
aOutTexInfo->texture = (Texture*)info->pointer;
|
||||
aOutTexInfo->name = aTexName;
|
||||
*aOutTexInfo = *info;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -527,13 +518,9 @@ bool DynOS_Tex_GetFromData(const Texture *aTex, struct TextureInfo* aOutTexInfo)
|
|||
}
|
||||
|
||||
// check builtin textures
|
||||
const struct BuiltinTexInfo* info = DynOS_Builtin_Tex_GetInfoFromData(aTex);
|
||||
const struct TextureInfo* info = DynOS_Builtin_Tex_GetInfoFromData(aTex);
|
||||
if (info) {
|
||||
aOutTexInfo->bitSize = info->bitSize;
|
||||
aOutTexInfo->width = info->width;
|
||||
aOutTexInfo->height = info->height;
|
||||
aOutTexInfo->texture = (Texture*)info->pointer;
|
||||
aOutTexInfo->name = info->identifier;
|
||||
*aOutTexInfo = *info;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2234,10 +2234,10 @@ Gets the current GraphNodeHeldObject
|
|||
## [texture_to_lua_table](#texture_to_lua_table)
|
||||
|
||||
### Description
|
||||
Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, returns a table as a pure memory buffer. Supports rgba16 and rgba32 textures
|
||||
Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, returns a 1-indexed table of RGBA pixels
|
||||
|
||||
### Lua Example
|
||||
`texture_to_lua_table(tex)`
|
||||
`local tableValue = texture_to_lua_table(tex)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
|
|
@ -2245,10 +2245,10 @@ Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, re
|
|||
| tex | `Pointer` <`Texture`> |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
- `table`
|
||||
|
||||
### C Prototype
|
||||
`void texture_to_lua_table(const Texture *tex);`
|
||||
`LuaTable texture_to_lua_table(const Texture *tex);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
|
|||
|
|
@ -2985,7 +2985,8 @@
|
|||
| name | `string` | read-only |
|
||||
| width | `integer` | read-only |
|
||||
| height | `integer` | read-only |
|
||||
| bitSize | `integer` | read-only |
|
||||
| format | `integer` | read-only |
|
||||
| size | `integer` | read-only |
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
|
|||
|
|
@ -80,11 +80,11 @@
|
|||
_g->words.w1 = _SHIFTL(x2, 16, 8) | _SHIFTL(y2, 8, 8); \
|
||||
}
|
||||
|
||||
#define gSetOverrideDjui(pkt, cmd, texture, w, h, bitSize) \
|
||||
#define gSetOverrideDjui(pkt, cmd, texture, w, h, fmt, siz) \
|
||||
{ \
|
||||
Gfx *_g = (Gfx *)(pkt); \
|
||||
_g->words.w0 = _SHIFTL(cmd, 24, 8) | _SHIFTL(w, 16, 8) | \
|
||||
_SHIFTL(h, 8, 8) | _SHIFTL(bitSize, 0, 8); \
|
||||
_SHIFTL(h, 8, 8) | _SHIFTL(fmt, 4, 4) | _SHIFTL(siz, 0, 4); \
|
||||
_g->words.w1 = (uintptr_t)(texture); \
|
||||
}
|
||||
|
||||
|
|
@ -137,8 +137,8 @@
|
|||
((height)-1) << G_TEXTURE_IMAGE_FRAC) \
|
||||
}
|
||||
|
||||
#define gDPSetTextureClippingDjui(pkt, x1, y1, x2, y2) gSetClippingDjui(pkt, G_TEXCLIP_DJUI, x1, y1, x2, y2)
|
||||
#define gDPSetTextureOverrideDjui(pkt, texture, w, h, bitSize) gSetOverrideDjui(pkt, G_TEXOVERRIDE_DJUI, texture, w, h, bitSize)
|
||||
#define gDPSetTextureClippingDjui(pkt, x1, y1, x2, y2) gSetClippingDjui(pkt, G_TEXCLIP_DJUI, x1, y1, x2, y2)
|
||||
#define gDPSetTextureOverrideDjui(pkt, texture, w, h, fmt, siz) gSetOverrideDjui(pkt, G_TEXOVERRIDE_DJUI, texture, w, h, fmt, siz)
|
||||
|
||||
/////////////////
|
||||
// G_SETENVRGB //
|
||||
|
|
|
|||
|
|
@ -577,11 +577,12 @@ struct MarioState
|
|||
|
||||
struct TextureInfo
|
||||
{
|
||||
Texture *texture;
|
||||
const Texture *texture;
|
||||
const char *name;
|
||||
u32 width;
|
||||
u32 height;
|
||||
u8 bitSize;
|
||||
u8 format;
|
||||
u8 size;
|
||||
};
|
||||
|
||||
#define PLAY_MODE_NORMAL 0
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ struct Character gCharacters[CT_MAX] = {
|
|||
.type = CT_MARIO,
|
||||
.name = "Mario",
|
||||
.hudHead = '(',
|
||||
.hudHeadTexture = { .texture = (Texture*)texture_hud_char_mario_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_mario_head" },
|
||||
.hudHeadTexture = { .texture = texture_hud_char_mario_head, .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b, .name = "texture_hud_char_mario_head" },
|
||||
.cameraHudHead = GLYPH_CAM_MARIO_HEAD,
|
||||
.modelId = MODEL_MARIO,
|
||||
.capModelId = MODEL_MARIOS_CAP,
|
||||
|
|
@ -101,7 +101,7 @@ struct Character gCharacters[CT_MAX] = {
|
|||
.type = CT_LUIGI,
|
||||
.name = "Luigi",
|
||||
.hudHead = ')',
|
||||
.hudHeadTexture = { .texture = (Texture*)texture_hud_char_luigi_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_luigi_head" },
|
||||
.hudHeadTexture = { .texture = texture_hud_char_luigi_head, .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b, .name = "texture_hud_char_luigi_head" },
|
||||
.cameraHudHead = GLYPH_CAM_LUIGI_HEAD,
|
||||
.modelId = MODEL_LUIGI,
|
||||
.capModelId = MODEL_LUIGIS_CAP,
|
||||
|
|
@ -167,7 +167,7 @@ struct Character gCharacters[CT_MAX] = {
|
|||
.type = CT_TOAD,
|
||||
.name = "Toad",
|
||||
.hudHead = '|',
|
||||
.hudHeadTexture = { .texture = (Texture*)texture_hud_char_toad_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_toad_head" },
|
||||
.hudHeadTexture = { .texture = texture_hud_char_toad_head, .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b, .name = "texture_hud_char_toad_head" },
|
||||
.cameraHudHead = GLYPH_CAM_TOAD_HEAD,
|
||||
.modelId = MODEL_TOAD_PLAYER,
|
||||
.capModelId = MODEL_TOADS_CAP,
|
||||
|
|
@ -233,7 +233,7 @@ struct Character gCharacters[CT_MAX] = {
|
|||
.type = CT_WALUIGI,
|
||||
.name = "Waluigi",
|
||||
.hudHead = ']',
|
||||
.hudHeadTexture = { .texture = (Texture*)texture_hud_char_waluigi_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_waluigi_head" },
|
||||
.hudHeadTexture = { .texture = texture_hud_char_waluigi_head, .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b, .name = "texture_hud_char_waluigi_head" },
|
||||
.cameraHudHead = GLYPH_CAM_WALUIGI_HEAD,
|
||||
.modelId = MODEL_WALUIGI,
|
||||
.capModelId = MODEL_WALUIGIS_CAP,
|
||||
|
|
@ -299,7 +299,7 @@ struct Character gCharacters[CT_MAX] = {
|
|||
.type = CT_WARIO,
|
||||
.name = "Wario",
|
||||
.hudHead = '[',
|
||||
.hudHeadTexture = { .texture = (Texture*)texture_hud_char_wario_head, .bitSize = 8, .width = 16, .height = 16, .name = "texture_hud_char_wario_head" },
|
||||
.hudHeadTexture = { .texture = texture_hud_char_wario_head, .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b, .name = "texture_hud_char_wario_head" },
|
||||
.cameraHudHead = GLYPH_CAM_WARIO_HEAD,
|
||||
.modelId = MODEL_WARIO,
|
||||
.capModelId = MODEL_WARIOS_CAP,
|
||||
|
|
|
|||
|
|
@ -239,11 +239,11 @@ void draw_skybox_tile_grid(Gfx **dlist, s8 background, s8 player, s8 colorIndex)
|
|||
// UGLY HACK: if the camera moves weird after a level transition this can go too high
|
||||
if (tileIndex < 0) { tileIndex = 0; }
|
||||
if (tileIndex > 79) { tileIndex = 79; }
|
||||
Texture* texture = NULL;
|
||||
const Texture* texture = NULL;
|
||||
if (background < 0 || background >= 10) {
|
||||
texture = gCustomSkyboxPtrList[tileIndex];
|
||||
} else {
|
||||
texture = (Texture*)(*(SkyboxTexture *) segmented_to_virtual(sSkyboxTextures[background]))[tileIndex];
|
||||
texture = (*(SkyboxTexture *) segmented_to_virtual(sSkyboxTextures[background]))[tileIndex];
|
||||
}
|
||||
|
||||
Vtx *vertices = make_skybox_rect(tileRow, tileColTmp, colorIndex, row, col);
|
||||
|
|
|
|||
|
|
@ -156,9 +156,9 @@ static void djui_cursor_update_position(void) {
|
|||
|
||||
// set cursor sprite
|
||||
if ((gInteractablePad.button & PAD_BUTTON_A) || (mouse_window_buttons & MOUSE_BUTTON_1)) {
|
||||
djui_image_set_image(sMouseCursor, gd_texture_hand_closed, 32, 32, 16);
|
||||
sMouseCursor->textureInfo.texture = gd_texture_hand_closed;
|
||||
} else {
|
||||
djui_image_set_image(sMouseCursor, gd_texture_hand_open, 32, 32, 16);
|
||||
sMouseCursor->textureInfo.texture = gd_texture_hand_open;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -191,7 +191,7 @@ void djui_cursor_update(void) {
|
|||
}
|
||||
|
||||
void djui_cursor_create(void) {
|
||||
sMouseCursor = djui_image_create(NULL, gd_texture_hand_open, 32, 32, 16);
|
||||
sMouseCursor = djui_image_create(NULL, gd_texture_hand_open, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_16b);
|
||||
djui_base_set_location(&sMouseCursor->base, 0, 0);
|
||||
djui_base_set_size(&sMouseCursor->base, 64, 64);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ static void djui_font_normal_render_char(char* c) {
|
|||
u32 tx = index % 64;
|
||||
u32 ty = index / 64;
|
||||
extern ALIGNED8 const Texture texture_font_jp[];
|
||||
djui_gfx_render_texture_tile(texture_font_jp, 512, 1024, 32, tx * 8, ty * 16, 8, 16, false, true);
|
||||
djui_gfx_render_texture_tile(texture_font_jp, 512, 1024, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 8, ty * 16, 8, 16, false, true);
|
||||
} else {
|
||||
u32 tx = index % 32;
|
||||
u32 ty = index / 32;
|
||||
extern ALIGNED8 const Texture texture_font_normal[];
|
||||
djui_gfx_render_texture_tile(texture_font_normal, 256, 128, 32, tx * 8, ty * 16, 8, 16, false, true);
|
||||
djui_gfx_render_texture_tile(texture_font_normal, 256, 128, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 8, ty * 16, 8, 16, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ static void djui_font_title_render_char(char* c) {
|
|||
u32 ty = index / 16;
|
||||
|
||||
extern ALIGNED8 const Texture texture_font_title[];
|
||||
djui_gfx_render_texture_tile(texture_font_title, 1024, 512, 32, tx * 64, ty * 64, 64, 64, false, true);
|
||||
djui_gfx_render_texture_tile(texture_font_title, 1024, 512, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 64, ty * 64, 64, 64, false, true);
|
||||
}
|
||||
|
||||
static f32 djui_font_title_char_width(char* text) {
|
||||
|
|
@ -129,7 +129,7 @@ static void djui_font_hud_render_char(char* text) {
|
|||
if (c == ' ') { return; }
|
||||
c = djui_unicode_get_base_char(text);
|
||||
u8 index = djui_font_hud_index(c);
|
||||
djui_gfx_render_texture(main_hud_lut[index], 16, 16, 16, djui_hud_get_filter());
|
||||
djui_gfx_render_texture(main_hud_lut[index], 16, 16, G_IM_FMT_RGBA, G_IM_SIZ_16b, djui_hud_get_filter());
|
||||
}
|
||||
|
||||
static f32 djui_font_hud_char_width(UNUSED char* text) {
|
||||
|
|
@ -163,12 +163,12 @@ static void djui_font_aliased_render_char(char* c) {
|
|||
u32 tx = index % 64;
|
||||
u32 ty = index / 64;
|
||||
extern ALIGNED8 const Texture texture_font_jp_aliased[];
|
||||
djui_gfx_render_texture_tile(texture_font_jp_aliased, 1024, 2048, 32, tx * 16, ty * 32, 16, 32, false, true);
|
||||
djui_gfx_render_texture_tile(texture_font_jp_aliased, 1024, 2048, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 16, ty * 32, 16, 32, false, true);
|
||||
} else {
|
||||
u32 tx = index % 32;
|
||||
u32 ty = index / 32;
|
||||
extern ALIGNED8 const Texture texture_font_aliased[];
|
||||
djui_gfx_render_texture_tile(texture_font_aliased, 512, 256, 32, tx * 16, ty * 32, 16, 32, false, true);
|
||||
djui_gfx_render_texture_tile(texture_font_aliased, 512, 256, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 16, ty * 32, 16, 32, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -204,7 +204,7 @@ static void djui_font_custom_hud_render_char(char* c) {
|
|||
u32 ty = index / 16;
|
||||
|
||||
extern ALIGNED8 const Texture texture_font_hud[];
|
||||
djui_gfx_render_texture_tile(texture_font_hud, 512, 512, 32, tx * 32, ty * 32, 32, 32, false, true);
|
||||
djui_gfx_render_texture_tile(texture_font_hud, 512, 512, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 32, ty * 32, 32, 32, false, true);
|
||||
}
|
||||
|
||||
static void djui_font_custom_hud_recolor_render_char(char* c) {
|
||||
|
|
@ -217,7 +217,7 @@ static void djui_font_custom_hud_recolor_render_char(char* c) {
|
|||
u32 ty = index / 16;
|
||||
|
||||
extern ALIGNED8 const Texture texture_font_hud_recolor[];
|
||||
djui_gfx_render_texture_tile(texture_font_hud_recolor, 512, 512, 32, tx * 32, ty * 32, 32, 32, false, true);
|
||||
djui_gfx_render_texture_tile(texture_font_hud_recolor, 512, 512, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 32, ty * 32, 32, 32, false, true);
|
||||
}
|
||||
|
||||
static f32 djui_font_custom_hud_char_width(char* text) {
|
||||
|
|
@ -266,12 +266,12 @@ static void djui_font_special_render_char(char* c) {
|
|||
u32 tx = index % 64;
|
||||
u32 ty = index / 64;
|
||||
extern ALIGNED8 const Texture texture_font_jp[];
|
||||
djui_gfx_render_texture_tile(texture_font_jp, 512, 1024, 32, tx * 8, ty * 16, 8, 16, false, true);
|
||||
djui_gfx_render_texture_tile(texture_font_jp, 512, 1024, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 8, ty * 16, 8, 16, false, true);
|
||||
} else {
|
||||
u32 tx = index % 32;
|
||||
u32 ty = index / 32;
|
||||
extern ALIGNED8 const Texture texture_font_special[];
|
||||
djui_gfx_render_texture_tile(texture_font_special, 256, 128, 32, tx * 8, ty * 16, 8, 16, false, true);
|
||||
djui_gfx_render_texture_tile(texture_font_special, 256, 128, G_IM_FMT_RGBA, G_IM_SIZ_32b, tx * 8, ty * 16, 8, 16, false, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ struct DjuiFont {
|
|||
f32 xOffset;
|
||||
f32 yOffset;
|
||||
f32 defaultFontScale;
|
||||
u8 textureBitSize;
|
||||
const Gfx* textBeginDisplayList;
|
||||
void (*render_char)(char*);
|
||||
f32 (*char_width)(char*);
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ static const Vtx vertex_djui_image[] = {
|
|||
|
||||
const Gfx dl_djui_image[] = {
|
||||
gsDPPipeSync(),
|
||||
gsSPClearGeometryMode(G_LIGHTING),
|
||||
gsSPClearGeometryMode(G_LIGHTING | G_CULL_BOTH),
|
||||
gsDPSetCombineMode(G_CC_FADEA, G_CC_FADEA),
|
||||
gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2),
|
||||
gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON),
|
||||
|
|
@ -104,32 +104,21 @@ const Gfx dl_djui_image[] = {
|
|||
gsSP2Triangles(0, 1, 2, 0x0, 0, 2, 3, 0x0),
|
||||
gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF),
|
||||
gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE),
|
||||
gsSPSetGeometryMode(G_LIGHTING | G_CULL_BACK),
|
||||
gsSPEndDisplayList(),
|
||||
};
|
||||
|
||||
static u8 djui_gfx_power_of_two(u32 value) {
|
||||
switch (value) {
|
||||
case 2: return 1;
|
||||
case 4: return 2;
|
||||
case 8: return 3;
|
||||
case 16: return 4;
|
||||
case 32: return 5;
|
||||
case 64: return 6;
|
||||
case 128: return 7;
|
||||
case 256: return 8;
|
||||
case 512: return 9;
|
||||
case 1024: return 10;
|
||||
default: return 11;
|
||||
}
|
||||
inline static u8 djui_gfx_power_of_two(u32 value) {
|
||||
return (u8) log2f(value);
|
||||
}
|
||||
|
||||
void djui_gfx_render_texture(const Texture* texture, u32 w, u32 h, u32 bitSize, bool filter) {
|
||||
void djui_gfx_render_texture(const Texture* texture, u32 w, u32 h, u8 fmt, u8 siz, bool filter) {
|
||||
gDPSetTextureFilter(gDisplayListHead++, filter ? G_TF_BILERP : G_TF_POINT);
|
||||
gDPSetTextureOverrideDjui(gDisplayListHead++, texture, djui_gfx_power_of_two(w), djui_gfx_power_of_two(h), bitSize);
|
||||
gDPSetTextureOverrideDjui(gDisplayListHead++, texture, djui_gfx_power_of_two(w), djui_gfx_power_of_two(h), fmt, siz);
|
||||
gSPDisplayList(gDisplayListHead++, dl_djui_image);
|
||||
}
|
||||
|
||||
void djui_gfx_render_texture_tile(const Texture* texture, u32 w, u32 h, u32 bitSize, u32 tileX, u32 tileY, u32 tileW, u32 tileH, bool filter, bool font) {
|
||||
void djui_gfx_render_texture_tile(const Texture* texture, u32 w, u32 h, u8 fmt, u8 siz, u32 tileX, u32 tileY, u32 tileW, u32 tileH, bool filter, bool font) {
|
||||
if (!gDisplayListHead) {
|
||||
LOG_ERROR("Retrieved a null displaylist head");
|
||||
return;
|
||||
|
|
@ -157,14 +146,14 @@ void djui_gfx_render_texture_tile(const Texture* texture, u32 w, u32 h, u32 bitS
|
|||
vtx[1] = (Vtx) {{{ 1 * aspect, -1, 0 }, 0, { ((tileX + tileW) * 2048.0f) / (f32)w + offsetX, ((tileY + tileH) * 2048.0f) / (f32)h + offsetY }, { 0xff, 0xff, 0xff, 0xff }}};
|
||||
vtx[3] = (Vtx) {{{ 0, 0, 0 }, 0, { ( tileX * 2048.0f) / (f32)w + offsetX, ( tileY * 2048.0f) / (f32)h + offsetY }, { 0xff, 0xff, 0xff, 0xff }}};
|
||||
|
||||
gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING);
|
||||
gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING | G_CULL_BOTH);
|
||||
gDPSetCombineMode(gDisplayListHead++, G_CC_FADEA, G_CC_FADEA);
|
||||
gDPSetRenderMode(gDisplayListHead++, G_RM_XLU_SURF, G_RM_XLU_SURF2);
|
||||
gDPSetTextureFilter(gDisplayListHead++, filter ? G_TF_BILERP : G_TF_POINT);
|
||||
|
||||
gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
|
||||
|
||||
gDPSetTextureOverrideDjui(gDisplayListHead++, texture, djui_gfx_power_of_two(w), djui_gfx_power_of_two(h), bitSize);
|
||||
gDPSetTextureOverrideDjui(gDisplayListHead++, texture, djui_gfx_power_of_two(w), djui_gfx_power_of_two(h), fmt, siz);
|
||||
gDPLoadTextureBlockWithoutTexture(gDisplayListHead++, NULL, G_IM_FMT_RGBA, G_IM_SIZ_16b, 64, 64, 0, G_TX_CLAMP, G_TX_CLAMP, 0, 0, 0, 0);
|
||||
|
||||
*(gDisplayListHead++) = (Gfx) gsSPExecuteDjui(G_TEXOVERRIDE_DJUI);
|
||||
|
|
@ -175,6 +164,7 @@ void djui_gfx_render_texture_tile(const Texture* texture, u32 w, u32 h, u32 bitS
|
|||
|
||||
gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF);
|
||||
gDPSetCombineMode(gDisplayListHead++, G_CC_SHADE, G_CC_SHADE);
|
||||
gSPSetGeometryMode(gDisplayListHead++, G_LIGHTING | G_CULL_BACK);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ void djui_gfx_displaylist_end(void);
|
|||
|
||||
f32 djui_gfx_get_scale(void);
|
||||
|
||||
void djui_gfx_render_texture(const Texture* texture, u32 w, u32 h, u32 bitSize, bool filter);
|
||||
void djui_gfx_render_texture_tile(const Texture* texture, u32 w, u32 h, u32 bitSize, u32 tileX, u32 tileY, u32 tileW, u32 tileH, bool filter, bool font);
|
||||
void djui_gfx_render_texture(const Texture* texture, u32 w, u32 h, u8 fmt, u8 siz, bool filter);
|
||||
void djui_gfx_render_texture_tile(const Texture* texture, u32 w, u32 h, u8 fmt, u8 siz, u32 tileX, u32 tileY, u32 tileW, u32 tileH, bool filter, bool font);
|
||||
|
||||
void gfx_get_dimensions(u32* width, u32* height);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,20 +51,20 @@ extern ALIGNED8 const u8 texture_hud_char_apostrophe[];
|
|||
extern ALIGNED8 const u8 texture_hud_char_double_quote[];
|
||||
|
||||
struct GlobalTextures gGlobalTextures = {
|
||||
.camera = { .texture = (Texture*)texture_hud_char_camera, "texture_hud_char_camera", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.lakitu = { .texture = (Texture*)texture_hud_char_lakitu, "texture_hud_char_lakitu", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.no_camera = { .texture = (Texture*)texture_hud_char_no_camera, "texture_hud_char_no_camera", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.arrow_up = { .texture = (Texture*)texture_hud_char_arrow_up, "texture_hud_char_arrow_up", .width = 8, .height = 8, .bitSize = 8 },
|
||||
.arrow_down = { .texture = (Texture*)texture_hud_char_arrow_down, "texture_hud_char_arrow_down", .width = 8, .height = 8, .bitSize = 8 },
|
||||
.coin = { .texture = (Texture*)texture_hud_char_coin, "texture_hud_char_coin", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.star = { .texture = (Texture*)texture_hud_char_star, "texture_hud_char_star", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.apostrophe = { .texture = (Texture*)texture_hud_char_apostrophe, "texture_hud_char_apostrophe", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.double_quote = { .texture = (Texture*)texture_hud_char_double_quote, "texture_hud_char_double_quote", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.mario_head = { .texture = (Texture*)texture_hud_char_mario_head, "texture_hud_char_mario_head", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.luigi_head = { .texture = (Texture*)texture_hud_char_luigi_head, "texture_hud_char_luigi_head", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.toad_head = { .texture = (Texture*)texture_hud_char_toad_head, "texture_hud_char_toad_head", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.waluigi_head = { .texture = (Texture*)texture_hud_char_waluigi_head, "texture_hud_char_waluigi_head", .width = 16, .height = 16, .bitSize = 8 },
|
||||
.wario_head = { .texture = (Texture*)texture_hud_char_wario_head, "texture_hud_char_wario_head", .width = 16, .height = 16, .bitSize = 8 }
|
||||
.camera = { .texture = texture_hud_char_camera, "texture_hud_char_camera", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.lakitu = { .texture = texture_hud_char_lakitu, "texture_hud_char_lakitu", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.no_camera = { .texture = texture_hud_char_no_camera, "texture_hud_char_no_camera", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.arrow_up = { .texture = texture_hud_char_arrow_up, "texture_hud_char_arrow_up", .width = 8, .height = 8, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.arrow_down = { .texture = texture_hud_char_arrow_down, "texture_hud_char_arrow_down", .width = 8, .height = 8, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.coin = { .texture = texture_hud_char_coin, "texture_hud_char_coin", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.star = { .texture = texture_hud_char_star, "texture_hud_char_star", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.apostrophe = { .texture = texture_hud_char_apostrophe, "texture_hud_char_apostrophe", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.double_quote = { .texture = texture_hud_char_double_quote, "texture_hud_char_double_quote", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.mario_head = { .texture = texture_hud_char_mario_head, "texture_hud_char_mario_head", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.luigi_head = { .texture = texture_hud_char_luigi_head, "texture_hud_char_luigi_head", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.toad_head = { .texture = texture_hud_char_toad_head, "texture_hud_char_toad_head", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.waluigi_head = { .texture = texture_hud_char_waluigi_head, "texture_hud_char_waluigi_head", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
.wario_head = { .texture = texture_hud_char_wario_head, "texture_hud_char_wario_head", .width = 16, .height = 16, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b }
|
||||
};
|
||||
|
||||
static void djui_hud_position_translate(f32* x, f32* y) {
|
||||
|
|
@ -499,7 +499,7 @@ static inline bool is_power_of_two(u32 n) {
|
|||
return (n > 0) && ((n & (n - 1)) == 0);
|
||||
}
|
||||
|
||||
void djui_hud_render_texture_raw(const Texture* texture, u32 bitSize, u32 width, u32 height, f32 x, f32 y, f32 scaleW, f32 scaleH) {
|
||||
static void djui_hud_render_texture_raw(const Texture* texture, u32 width, u32 height, u8 fmt, u8 siz, f32 x, f32 y, f32 scaleW, f32 scaleH) {
|
||||
if (!is_power_of_two(width) || !is_power_of_two(height)) {
|
||||
LOG_LUA_LINE("Tried to render DJUI HUD texture with NPOT width or height");
|
||||
return;
|
||||
|
|
@ -532,13 +532,13 @@ void djui_hud_render_texture_raw(const Texture* texture, u32 bitSize, u32 width,
|
|||
create_dl_scale_matrix(DJUI_MTX_NOPUSH, width * translatedW, height * translatedH, 1.0f);
|
||||
|
||||
// render
|
||||
djui_gfx_render_texture(texture, width, height, bitSize, sFilter);
|
||||
djui_gfx_render_texture(texture, width, height, fmt, siz, sFilter);
|
||||
|
||||
// pop
|
||||
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
|
||||
}
|
||||
|
||||
void djui_hud_render_texture_tile_raw(const Texture* texture, u32 bitSize, u32 width, u32 height, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH) {
|
||||
static void djui_hud_render_texture_tile_raw(const Texture* texture, u32 width, u32 height, u8 fmt, u8 siz, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH) {
|
||||
if (!texture) { return; }
|
||||
|
||||
gDjuiHudUtilsZ += 0.01f;
|
||||
|
|
@ -569,7 +569,7 @@ void djui_hud_render_texture_tile_raw(const Texture* texture, u32 bitSize, u32 w
|
|||
create_dl_scale_matrix(DJUI_MTX_NOPUSH, width * translatedW, height * translatedH, 1.0f);
|
||||
|
||||
// render
|
||||
djui_gfx_render_texture_tile(texture, width, height, bitSize, tileX, tileY, tileW, tileH, sFilter, false);
|
||||
djui_gfx_render_texture_tile(texture, width, height, fmt, siz, tileX, tileY, tileW, tileH, sFilter, false);
|
||||
|
||||
// pop
|
||||
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
|
||||
|
|
@ -577,12 +577,12 @@ void djui_hud_render_texture_tile_raw(const Texture* texture, u32 bitSize, u32 w
|
|||
|
||||
void djui_hud_render_texture(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH) {
|
||||
if (!texInfo) { return; }
|
||||
djui_hud_render_texture_raw(texInfo->texture, texInfo->bitSize, texInfo->width, texInfo->height, x, y, scaleW, scaleH);
|
||||
djui_hud_render_texture_raw(texInfo->texture, texInfo->width, texInfo->height, texInfo->format, texInfo->size, x, y, scaleW, scaleH);
|
||||
}
|
||||
|
||||
void djui_hud_render_texture_tile(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH) {
|
||||
if (!texInfo) { return; }
|
||||
djui_hud_render_texture_tile_raw(texInfo->texture, texInfo->bitSize, texInfo->width, texInfo->height, x, y, scaleW, scaleH, tileX, tileY, tileW, tileH);
|
||||
djui_hud_render_texture_tile_raw(texInfo->texture, texInfo->width, texInfo->height, texInfo->format, texInfo->size, x, y, scaleW, scaleH, tileX, tileY, tileW, tileH);
|
||||
}
|
||||
|
||||
void djui_hud_render_texture_interpolated(struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH) {
|
||||
|
|
@ -591,7 +591,7 @@ void djui_hud_render_texture_interpolated(struct TextureInfo* texInfo, f32 prevX
|
|||
|
||||
if (!texInfo) { return; }
|
||||
|
||||
djui_hud_render_texture_raw(texInfo->texture, texInfo->bitSize, texInfo->width, texInfo->height, prevX, prevY, prevScaleW, prevScaleH);
|
||||
djui_hud_render_texture_raw(texInfo->texture, texInfo->width, texInfo->height, texInfo->format, texInfo->size, prevX, prevY, prevScaleW, prevScaleH);
|
||||
|
||||
if (sInterpHudCount >= MAX_INTERP_HUD) { return; }
|
||||
struct InterpHud* interp = &sInterpHuds[sInterpHudCount++];
|
||||
|
|
@ -627,7 +627,7 @@ void djui_hud_render_texture_tile_interpolated(struct TextureInfo* texInfo, f32
|
|||
prevScaleH *= ((f32)tileH / (f32)texInfo->height);
|
||||
}
|
||||
|
||||
djui_hud_render_texture_tile_raw(texInfo->texture, texInfo->bitSize, texInfo->width, texInfo->height, prevX, prevY, prevScaleW, prevScaleH, tileX, tileY, tileW, tileH);
|
||||
djui_hud_render_texture_tile_raw(texInfo->texture, texInfo->width, texInfo->height, texInfo->format, texInfo->size, prevX, prevY, prevScaleW, prevScaleH, tileX, tileY, tileW, tileH);
|
||||
|
||||
if (sInterpHudCount >= MAX_INTERP_HUD) { return; }
|
||||
struct InterpHud* interp = &sInterpHuds[sInterpHudCount++];
|
||||
|
|
|
|||
|
|
@ -123,10 +123,8 @@ void djui_hud_print_text(const char* message, f32 x, f32 y, f32 scale);
|
|||
void djui_hud_print_text_interpolated(const char* message, f32 prevX, f32 prevY, f32 prevScale, f32 x, f32 y, f32 scale);
|
||||
/* |description|Renders a DJUI HUD texture onto the screen|descriptionEnd| */
|
||||
void djui_hud_render_texture(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH);
|
||||
void djui_hud_render_texture_raw(const Texture* texture, u32 bitSize, u32 width, u32 height, f32 x, f32 y, f32 scaleW, f32 scaleH);
|
||||
/* |description|Renders a DJUI HUD texture tile onto the screen|descriptionEnd| */
|
||||
void djui_hud_render_texture_tile(struct TextureInfo* texInfo, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH);
|
||||
void djui_hud_render_texture_tile_raw(const Texture* texture, u32 bitSize, u32 width, u32 height, f32 x, f32 y, f32 scaleW, f32 scaleH, u32 tileX, u32 tileY, u32 tileW, u32 tileH);
|
||||
/* |description|Renders an interpolated DJUI HUD texture onto the screen|descriptionEnd| */
|
||||
void djui_hud_render_texture_interpolated(struct TextureInfo* texInfo, f32 prevX, f32 prevY, f32 prevScaleW, f32 prevScaleH, f32 x, f32 y, f32 scaleW, f32 scaleH);
|
||||
/* |description|Renders an interpolated DJUI HUD texture tile onto the screen|descriptionEnd| */
|
||||
|
|
|
|||
|
|
@ -2,17 +2,6 @@
|
|||
#include "game/segment2.h"
|
||||
#include "pc/network/network.h"
|
||||
|
||||
////////////////
|
||||
// properties //
|
||||
////////////////
|
||||
|
||||
void djui_image_set_image(struct DjuiImage* image, const Texture* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize) {
|
||||
image->texture = texture;
|
||||
image->textureWidth = textureWidth;
|
||||
image->textureHeight = textureHeight;
|
||||
image->textureBitSize = textureBitSize;
|
||||
}
|
||||
|
||||
////////////
|
||||
// events //
|
||||
////////////
|
||||
|
|
@ -35,8 +24,9 @@ static bool djui_image_render(struct DjuiBase* base) {
|
|||
|
||||
// render
|
||||
if (!djui_gfx_add_clipping(base)) {
|
||||
const struct TextureInfo *info = &image->textureInfo;
|
||||
gDPSetEnvColor(gDisplayListHead++, base->color.r, base->color.g, base->color.b, base->color.a);
|
||||
djui_gfx_render_texture(image->texture, image->textureWidth, image->textureHeight, image->textureBitSize, false);
|
||||
djui_gfx_render_texture(info->texture, info->width, info->height, info->format, info->size, false);
|
||||
}
|
||||
|
||||
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
|
||||
|
|
@ -48,13 +38,17 @@ static void djui_image_destroy(struct DjuiBase* base) {
|
|||
free(image);
|
||||
}
|
||||
|
||||
struct DjuiImage* djui_image_create(struct DjuiBase* parent, const Texture* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize) {
|
||||
struct DjuiImage* djui_image_create(struct DjuiBase* parent, const Texture* texture, u16 width, u16 height, u8 fmt, u8 siz) {
|
||||
struct DjuiImage* image = calloc(1, sizeof(struct DjuiImage));
|
||||
struct DjuiBase* base = &image->base;
|
||||
|
||||
djui_base_init(parent, base, djui_image_render, djui_image_destroy);
|
||||
|
||||
djui_image_set_image(image, texture, textureWidth, textureHeight, textureBitSize);
|
||||
image->textureInfo.texture = texture;
|
||||
image->textureInfo.width = width;
|
||||
image->textureInfo.height = height;
|
||||
image->textureInfo.format = fmt;
|
||||
image->textureInfo.size = siz;
|
||||
|
||||
return image;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,7 @@
|
|||
|
||||
struct DjuiImage {
|
||||
struct DjuiBase base;
|
||||
const Texture* texture;
|
||||
u16 textureWidth;
|
||||
u16 textureHeight;
|
||||
u16 textureBitSize;
|
||||
struct TextureInfo textureInfo;
|
||||
};
|
||||
|
||||
void djui_image_set_image(struct DjuiImage* image, const Texture* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize);
|
||||
|
||||
struct DjuiImage* djui_image_create(struct DjuiBase* parent, const Texture* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize);
|
||||
struct DjuiImage* djui_image_create(struct DjuiBase* parent, const Texture* texture, u16 width, u16 height, u8 fmt, u8 siz);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ void djui_panel_main_create(struct DjuiBase* caller) {
|
|||
struct DjuiBase* body = djui_three_panel_get_body(panel);
|
||||
{
|
||||
if (!configExCoopTheme) {
|
||||
struct DjuiImage* logo = djui_image_create(body, texture_coopdx_logo, 2048, 1024, 32);
|
||||
struct DjuiImage* logo = djui_image_create(body, texture_coopdx_logo, 2048, 1024, G_IM_FMT_RGBA, G_IM_SIZ_32b);
|
||||
if (configDjuiThemeCenter) {
|
||||
djui_base_set_size(&logo->base, 550, 275);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -45,16 +45,16 @@ static void playerlist_update_row(u8 i, struct NetworkPlayer *np) {
|
|||
snprintf(sActNum, 7, "Done");
|
||||
}
|
||||
if (charIndex >= CT_MAX) { charIndex = 0; }
|
||||
djuiHeadIconImages[i]->texture = gCharacters[charIndex].hudHeadTexture.texture;
|
||||
djuiHeadIconImages[i]->textureInfo.texture = gCharacters[charIndex].hudHeadTexture.texture;
|
||||
|
||||
s16 pingValue = np->ping / 150;
|
||||
switch (pingValue) {
|
||||
case 0: djuiPingImages[i]->texture = texture_ping_full; break;
|
||||
case 1: djuiPingImages[i]->texture = texture_ping_four; break;
|
||||
case 2: djuiPingImages[i]->texture = texture_ping_three; break;
|
||||
case 3: djuiPingImages[i]->texture = texture_ping_two; break;
|
||||
case 4: djuiPingImages[i]->texture = texture_ping_one; break;
|
||||
default: djuiPingImages[i]->texture = texture_ping_empty; break;
|
||||
case 0: djuiPingImages[i]->textureInfo.texture = texture_ping_full; break;
|
||||
case 1: djuiPingImages[i]->textureInfo.texture = texture_ping_four; break;
|
||||
case 2: djuiPingImages[i]->textureInfo.texture = texture_ping_three; break;
|
||||
case 3: djuiPingImages[i]->textureInfo.texture = texture_ping_two; break;
|
||||
case 4: djuiPingImages[i]->textureInfo.texture = texture_ping_one; break;
|
||||
default: djuiPingImages[i]->textureInfo.texture = texture_ping_empty; break;
|
||||
}
|
||||
|
||||
u8 visible = np->connected;
|
||||
|
|
@ -141,11 +141,11 @@ void djui_panel_playerlist_create(UNUSED struct DjuiBase* caller) {
|
|||
djui_base_set_visible(&row->base, false);
|
||||
djuiRow[i] = row;
|
||||
|
||||
struct DjuiImage* i1 = djui_image_create(&row->base, texture_ping_empty, 16, 16, 8);
|
||||
struct DjuiImage* i1 = djui_image_create(&row->base, texture_ping_empty, 16, 16, G_IM_FMT_RGBA, G_IM_SIZ_16b);
|
||||
djui_base_set_size(&i1->base, 32, 32);
|
||||
djuiPingImages[i] = i1;
|
||||
|
||||
struct DjuiImage* i2 = djui_image_create(&row->base, texture_hud_char_mario_head, 16, 16, 8);
|
||||
struct DjuiImage* i2 = djui_image_create(&row->base, texture_hud_char_mario_head, 16, 16, G_IM_FMT_RGBA, G_IM_SIZ_16b);
|
||||
djui_base_set_size(&i2->base, 32, 32);
|
||||
djuiHeadIconImages[i] = i2;
|
||||
|
||||
|
|
|
|||
|
|
@ -145,13 +145,13 @@ struct DjuiSelectionbox* djui_selectionbox_create(struct DjuiBase* parent, const
|
|||
djui_text_set_drop_shadow(rectText, 64, 64, 64, 100);
|
||||
selectionbox->rectText = rectText;
|
||||
|
||||
struct DjuiImage* rectImage = djui_image_create(&rect->base, texture_selectionbox_back_icon, 16, 16, 16);
|
||||
struct DjuiImage* rectImage = djui_image_create(&rect->base, texture_selectionbox_back_icon, 16, 16, G_IM_FMT_RGBA, G_IM_SIZ_16b);
|
||||
djui_base_set_location(&rectImage->base, 0, 0);
|
||||
djui_base_set_size(&rectImage->base, 16, 16);
|
||||
djui_base_set_alignment(&rectImage->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_CENTER);
|
||||
selectionbox->rectImage = rectImage;
|
||||
|
||||
struct DjuiImage* rectImage2 = djui_image_create(&rect->base, texture_selectionbox_forward_icon, 16, 16, 16);
|
||||
struct DjuiImage* rectImage2 = djui_image_create(&rect->base, texture_selectionbox_forward_icon, 16, 16, G_IM_FMT_RGBA, G_IM_SIZ_16b);
|
||||
djui_base_set_location(&rectImage2->base, 0, 0);
|
||||
djui_base_set_size(&rectImage2->base, 16, 16);
|
||||
djui_base_set_alignment(&rectImage2->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_CENTER);
|
||||
|
|
|
|||
|
|
@ -2065,17 +2065,26 @@ void gfx_shutdown(void) {
|
|||
// v custom for djui v //
|
||||
/////////////////////////
|
||||
|
||||
static bool sDjuiClip = 0;
|
||||
static uint8_t sDjuiClipX1 = 0;
|
||||
static uint8_t sDjuiClipY1 = 0;
|
||||
static uint8_t sDjuiClipX2 = 0;
|
||||
static uint8_t sDjuiClipY2 = 0;
|
||||
static const struct {
|
||||
uint8_t LOAD_BLOCK;
|
||||
uint8_t SHIFT;
|
||||
uint8_t INCR;
|
||||
uint8_t LINE_BYTES;
|
||||
} G_IM_SIZ_[] = {
|
||||
[G_IM_SIZ_4b] = { G_IM_SIZ_4b_LOAD_BLOCK, G_IM_SIZ_4b_SHIFT, G_IM_SIZ_4b_INCR, G_IM_SIZ_4b_LINE_BYTES },
|
||||
[G_IM_SIZ_8b] = { G_IM_SIZ_8b_LOAD_BLOCK, G_IM_SIZ_8b_SHIFT, G_IM_SIZ_8b_INCR, G_IM_SIZ_8b_LINE_BYTES },
|
||||
[G_IM_SIZ_16b] = { G_IM_SIZ_16b_LOAD_BLOCK, G_IM_SIZ_16b_SHIFT, G_IM_SIZ_16b_INCR, G_IM_SIZ_16b_LINE_BYTES },
|
||||
[G_IM_SIZ_32b] = { G_IM_SIZ_32b_LOAD_BLOCK, G_IM_SIZ_32b_SHIFT, G_IM_SIZ_32b_INCR, G_IM_SIZ_32b_LINE_BYTES },
|
||||
};
|
||||
|
||||
static bool sDjuiOverride = false;
|
||||
static void* sDjuiOverrideTexture = NULL;
|
||||
static uint32_t sDjuiOverrideW = 0;
|
||||
static uint32_t sDjuiOverrideH = 0;
|
||||
static uint32_t sDjuiOverrideB = 0;
|
||||
static bool sDjuiClip = 0;
|
||||
static uint8_t sDjuiClipX1 = 0;
|
||||
static uint8_t sDjuiClipY1 = 0;
|
||||
static uint8_t sDjuiClipX2 = 0;
|
||||
static uint8_t sDjuiClipY2 = 0;
|
||||
|
||||
static bool sDjuiOverride = false;
|
||||
static struct TextureInfo sDjuiOverrideTexture;
|
||||
|
||||
static void OPTIMIZE_O3 djui_gfx_dp_execute_clipping(void) {
|
||||
if (!sDjuiClip) { return; }
|
||||
|
|
@ -2141,29 +2150,19 @@ static void OPTIMIZE_O3 djui_gfx_dp_execute_override(void) {
|
|||
if (!sDjuiOverride) { return; }
|
||||
sDjuiOverride = false;
|
||||
|
||||
// gsDPSetTextureImage
|
||||
uint8_t sizeLoadBlock = (sDjuiOverrideB == 32) ? 3 : 2;
|
||||
rdp.texture_to_load.addr = sDjuiOverrideTexture;
|
||||
rdp.texture_to_load.siz = sizeLoadBlock;
|
||||
const Texture *texture = sDjuiOverrideTexture.texture;
|
||||
uint32_t width = sDjuiOverrideTexture.width;
|
||||
uint32_t height = sDjuiOverrideTexture.height;
|
||||
uint8_t fmt = sDjuiOverrideTexture.format;
|
||||
uint8_t siz = sDjuiOverrideTexture.size;
|
||||
|
||||
// gsDPSetTile
|
||||
rdp.texture_tile.siz = sizeLoadBlock;
|
||||
if (siz > G_IM_SIZ_32b) { return; }
|
||||
|
||||
// gsDPLoadBlock
|
||||
uint32_t wordSizeShift = (sDjuiOverrideB == 32) ? 2 : 1;
|
||||
uint32_t lrs = (sDjuiOverrideW * sDjuiOverrideH) - 1;
|
||||
uint32_t sizeBytes = (lrs + 1) << wordSizeShift;
|
||||
gfx_update_loaded_texture(rdp.texture_to_load.tile_number, sizeBytes, rdp.texture_to_load.addr);
|
||||
|
||||
// gsDPSetTile
|
||||
uint32_t line = (((sDjuiOverrideW * 2) + 7) >> 3);
|
||||
rdp.texture_tile.line_size_bytes = line * 8;
|
||||
|
||||
// gsDPSetTileSize
|
||||
/*rdp.texture_tile.uls = 0;
|
||||
rdp.texture_tile.ult = 0;
|
||||
rdp.texture_tile.lrs = (sDjuiOverrideW - 1) << G_TEXTURE_IMAGE_FRAC;
|
||||
rdp.texture_tile.lrt = (sDjuiOverrideH - 1) << G_TEXTURE_IMAGE_FRAC;*/
|
||||
// This is gDPLoadTextureBlock, but with some shortcuts and without texture size limitations
|
||||
gfx_dp_set_texture_image(fmt, G_IM_SIZ_[siz].LOAD_BLOCK, width, texture);
|
||||
gfx_dp_set_tile(fmt, siz, 0, 0, G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0);
|
||||
gfx_dp_load_block(0, 0, 0, ((width * height + G_IM_SIZ_[siz].INCR) >> G_IM_SIZ_[siz].SHIFT) - 1, 0);
|
||||
gfx_dp_set_tile(fmt, siz, (((width * G_IM_SIZ_[siz].LINE_BYTES) + 7) >> 3), 0, G_TX_RENDERTILE, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
static void OPTIMIZE_O3 djui_gfx_dp_execute_djui(uint32_t opcode) {
|
||||
|
|
@ -2198,12 +2197,13 @@ static void OPTIMIZE_O3 djui_gfx_dp_set_clipping(uint32_t x1, uint32_t y1, uint3
|
|||
sDjuiClip = true;
|
||||
}
|
||||
|
||||
static void OPTIMIZE_O3 djui_gfx_dp_set_override(void* texture, uint32_t w, uint32_t h, uint32_t b) {
|
||||
sDjuiOverrideTexture = texture;
|
||||
sDjuiOverrideW = w;
|
||||
sDjuiOverrideH = h;
|
||||
sDjuiOverrideB = b;
|
||||
sDjuiOverride = (texture != NULL);
|
||||
static void OPTIMIZE_O3 djui_gfx_dp_set_override(void* texture, uint32_t w, uint32_t h, uint8_t fmt, uint8_t siz) {
|
||||
sDjuiOverrideTexture.texture = texture;
|
||||
sDjuiOverrideTexture.width = w;
|
||||
sDjuiOverrideTexture.height = h;
|
||||
sDjuiOverrideTexture.format = fmt;
|
||||
sDjuiOverrideTexture.size = siz;
|
||||
sDjuiOverride = (texture != NULL);
|
||||
}
|
||||
|
||||
/*static void OPTIMIZE_O3 djui_gfx_sp_simple_vertex(size_t n_vertices, size_t dest_index, const Vtx *vertices) {
|
||||
|
|
@ -2232,7 +2232,7 @@ void OPTIMIZE_O3 ext_gfx_run_dl(Gfx* cmd) {
|
|||
djui_gfx_dp_set_clipping(C0(16, 8), C0(8, 8), C1(16, 8), C1(8, 8));
|
||||
break;
|
||||
case G_TEXOVERRIDE_DJUI:
|
||||
djui_gfx_dp_set_override(seg_addr(cmd->words.w1), 1 << C0(16, 8), 1 << C0(8, 8), C0(0, 8));
|
||||
djui_gfx_dp_set_override(seg_addr(cmd->words.w1), 1 << C0(16, 8), 1 << C0(8, 8), C0(4, 4), C0(0, 4));
|
||||
break;
|
||||
case G_VTX_EXT:
|
||||
#ifdef F3DEX_GBI_2
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ static void init_loading_screen(void) {
|
|||
|
||||
// splash image
|
||||
} else {
|
||||
struct DjuiImage* splashImage = djui_image_create(base, texture_coopdx_logo, 2048, 1024, 32);
|
||||
struct DjuiImage* splashImage = djui_image_create(base, texture_coopdx_logo, 2048, 1024, G_IM_FMT_RGBA, G_IM_SIZ_32b);
|
||||
djui_base_set_location_type(&splashImage->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_alignment(&splashImage->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_TOP);
|
||||
djui_base_set_location(&splashImage->base, 0, -100);
|
||||
|
|
|
|||
|
|
@ -2635,13 +2635,14 @@ static struct LuaObjectField sSurfaceFields[LUA_SURFACE_FIELD_COUNT] = {
|
|||
{ "vertex3", LVT_COBJECT, offsetof(struct Surface, vertex3), true, LOT_VEC3S, 1, sizeof(Vec3s) },
|
||||
};
|
||||
|
||||
#define LUA_TEXTURE_INFO_FIELD_COUNT 5
|
||||
#define LUA_TEXTURE_INFO_FIELD_COUNT 6
|
||||
static struct LuaObjectField sTextureInfoFields[LUA_TEXTURE_INFO_FIELD_COUNT] = {
|
||||
{ "bitSize", LVT_U8, offsetof(struct TextureInfo, bitSize), true, LOT_NONE, 1, sizeof(u8) },
|
||||
{ "height", LVT_U32, offsetof(struct TextureInfo, height), true, LOT_NONE, 1, sizeof(u32) },
|
||||
{ "name", LVT_STRING_P, offsetof(struct TextureInfo, name), true, LOT_NONE, 1, sizeof(const char*) },
|
||||
{ "texture", LVT_TEXTURE_P, offsetof(struct TextureInfo, texture), true, LOT_POINTER, 1, sizeof(Texture*) },
|
||||
{ "width", LVT_U32, offsetof(struct TextureInfo, width), true, LOT_NONE, 1, sizeof(u32) },
|
||||
{ "format", LVT_U8, offsetof(struct TextureInfo, format), true, LOT_NONE, 1, sizeof(u8) },
|
||||
{ "height", LVT_U32, offsetof(struct TextureInfo, height), true, LOT_NONE, 1, sizeof(u32) },
|
||||
{ "name", LVT_STRING_P, offsetof(struct TextureInfo, name), true, LOT_NONE, 1, sizeof(const char*) },
|
||||
{ "size", LVT_U8, offsetof(struct TextureInfo, size), true, LOT_NONE, 1, sizeof(u8) },
|
||||
{ "texture", LVT_TEXTURE_P, offsetof(struct TextureInfo, texture), true, LOT_POINTER, 1, sizeof(const Texture*) },
|
||||
{ "width", LVT_U32, offsetof(struct TextureInfo, width), true, LOT_NONE, 1, sizeof(u32) },
|
||||
};
|
||||
|
||||
#define LUA_VTX_FIELD_COUNT 13
|
||||
|
|
|
|||
|
|
@ -434,11 +434,7 @@ int smlua_func_get_texture_info(lua_State* L) {
|
|||
lua_newtable(L);
|
||||
|
||||
lua_pushstring(L, "texture");
|
||||
smlua_push_pointer(L, LVT_TEXTURE_P, texInfo.texture, NULL);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "bitSize");
|
||||
lua_pushinteger(L, texInfo.bitSize);
|
||||
smlua_push_pointer(L, LVT_TEXTURE_P, (void *) texInfo.texture, NULL);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "width");
|
||||
|
|
@ -449,6 +445,14 @@ int smlua_func_get_texture_info(lua_State* L) {
|
|||
lua_pushinteger(L, texInfo.height);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "format");
|
||||
lua_pushinteger(L, texInfo.format);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "size");
|
||||
lua_pushinteger(L, texInfo.size);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "name");
|
||||
lua_pushstring(L, texInfo.name);
|
||||
lua_settable(L, -3);
|
||||
|
|
|
|||
|
|
@ -34606,7 +34606,7 @@ int smlua_func_texture_to_lua_table(lua_State* L) {
|
|||
Texture * tex = (Texture *)smlua_to_cpointer(L, 1, LVT_TEXTURE_P);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "texture_to_lua_table"); return 0; }
|
||||
|
||||
texture_to_lua_table(tex);
|
||||
smlua_push_lua_table(L, texture_to_lua_table(tex));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -247,16 +247,16 @@ extern const u8 texture_power_meter_two_segments[];
|
|||
extern const u8 texture_power_meter_one_segments[];
|
||||
|
||||
static struct TextureInfo sPowerMeterTexturesInfo[] = {
|
||||
{ (Texture*)texture_power_meter_left_side, "texture_power_meter_left_side", 32, 64, 8 },
|
||||
{ (Texture*)texture_power_meter_right_side, "texture_power_meter_right_side", 32, 64, 8 },
|
||||
{ (Texture*)texture_power_meter_one_segments, "texture_power_meter_one_segments", 32, 32, 8 },
|
||||
{ (Texture*)texture_power_meter_two_segments, "texture_power_meter_two_segments", 32, 32, 8 },
|
||||
{ (Texture*)texture_power_meter_three_segments, "texture_power_meter_three_segments", 32, 32, 8 },
|
||||
{ (Texture*)texture_power_meter_four_segments, "texture_power_meter_four_segments", 32, 32, 8 },
|
||||
{ (Texture*)texture_power_meter_five_segments, "texture_power_meter_five_segments", 32, 32, 8 },
|
||||
{ (Texture*)texture_power_meter_six_segments, "texture_power_meter_six_segments", 32, 32, 8 },
|
||||
{ (Texture*)texture_power_meter_seven_segments, "texture_power_meter_seven_segments", 32, 32, 8 },
|
||||
{ (Texture*)texture_power_meter_full, "texture_power_meter_full", 32, 32, 8 },
|
||||
{ .texture = texture_power_meter_left_side, .name = "texture_power_meter_left_side", .width = 32, .height = 64, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
{ .texture = texture_power_meter_right_side, .name = "texture_power_meter_right_side", .width = 32, .height = 64, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
{ .texture = texture_power_meter_one_segments, .name = "texture_power_meter_one_segments", .width = 32, .height = 32, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
{ .texture = texture_power_meter_two_segments, .name = "texture_power_meter_two_segments", .width = 32, .height = 32, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
{ .texture = texture_power_meter_three_segments, .name = "texture_power_meter_three_segments", .width = 32, .height = 32, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
{ .texture = texture_power_meter_four_segments, .name = "texture_power_meter_four_segments", .width = 32, .height = 32, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
{ .texture = texture_power_meter_five_segments, .name = "texture_power_meter_five_segments", .width = 32, .height = 32, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
{ .texture = texture_power_meter_six_segments, .name = "texture_power_meter_six_segments", .width = 32, .height = 32, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
{ .texture = texture_power_meter_seven_segments, .name = "texture_power_meter_seven_segments", .width = 32, .height = 32, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
{ .texture = texture_power_meter_full, .name = "texture_power_meter_full", .width = 32, .height = 32, .format = G_IM_FMT_RGBA, .size = G_IM_SIZ_16b },
|
||||
};
|
||||
|
||||
void hud_render_power_meter(s32 health, f32 x, f32 y, f32 width, f32 height) {
|
||||
|
|
@ -647,44 +647,43 @@ struct GraphNodeHeldObject* geo_get_current_held_object(void) {
|
|||
return gCurGraphNodeHeldObject;
|
||||
}
|
||||
|
||||
void texture_to_lua_table(const Texture *tex) {
|
||||
LuaTable texture_to_lua_table(const Texture *tex) {
|
||||
lua_State *L = gLuaState;
|
||||
if (!L || !tex) { return; }
|
||||
if (!L) { return 0; }
|
||||
|
||||
if (!tex) {
|
||||
lua_pushnil(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct TextureInfo texInfo;
|
||||
if (!dynos_texture_get_from_data(tex, &texInfo)) { return; }
|
||||
if (!dynos_texture_get_from_data(tex, &texInfo)) {
|
||||
lua_pushnil(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 bpp = texInfo.bitSize;
|
||||
if (bpp != 16 && bpp != 32) { return; }
|
||||
u8 *rgba = dynos_texture_convert_to_rgba32(texInfo.texture, texInfo.width, texInfo.height, texInfo.format, texInfo.size);
|
||||
if (!rgba) {
|
||||
lua_pushnil(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 bytesPerPixel = bpp / 8;
|
||||
const Texture *data = texInfo.texture;
|
||||
u32 texSize = texInfo.width * texInfo.height * bytesPerPixel;
|
||||
LUA_STACK_CHECK_BEGIN_NUM(L, 1);
|
||||
|
||||
lua_newtable(L);
|
||||
for (u32 i = 0; i < texSize; i += bytesPerPixel) {
|
||||
const u8 *pixel = rgba;
|
||||
for (u32 i = 0; i < texInfo.width * texInfo.height; ++i, pixel += 4) {
|
||||
lua_newtable(L);
|
||||
|
||||
if (bpp == 16) {
|
||||
u16 col = (data[i] << 8) | data[i + 1];
|
||||
u8 r = SCALE_5_8((col >> 11) & 0x1F);
|
||||
u8 g = SCALE_5_8((col >> 6) & 0x1F);
|
||||
u8 b = SCALE_5_8((col >> 1) & 0x1F);
|
||||
u8 a = 0xFF * (col & 0x1);
|
||||
|
||||
smlua_push_integer_field(-2, "r", r);
|
||||
smlua_push_integer_field(-2, "g", g);
|
||||
smlua_push_integer_field(-2, "b", b);
|
||||
smlua_push_integer_field(-2, "a", a);
|
||||
} else if (bpp == 32) {
|
||||
smlua_push_integer_field(-2, "r", data[i]);
|
||||
smlua_push_integer_field(-2, "g", data[i + 1]);
|
||||
smlua_push_integer_field(-2, "b", data[i + 2]);
|
||||
smlua_push_integer_field(-2, "a", data[i + 3]);
|
||||
}
|
||||
|
||||
lua_rawseti(L, -2, i / bytesPerPixel + 1);
|
||||
smlua_push_integer_field(-2, "r", pixel[0]);
|
||||
smlua_push_integer_field(-2, "g", pixel[1]);
|
||||
smlua_push_integer_field(-2, "b", pixel[2]);
|
||||
smlua_push_integer_field(-2, "a", pixel[3]);
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
free(rgba);
|
||||
|
||||
LUA_STACK_CHECK_END(L);
|
||||
return smlua_to_lua_table(L, -1);
|
||||
}
|
||||
|
||||
const char *get_texture_name(const Texture *tex) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "dialog_ids.h"
|
||||
#include "game/camera.h"
|
||||
#include "pc/lua/smlua_utils.h"
|
||||
|
||||
enum HudDisplayValue {
|
||||
HUD_DISPLAY_LIVES,
|
||||
|
|
@ -262,8 +263,8 @@ struct GraphNodeCamera* geo_get_current_camera(void);
|
|||
/* |description|Gets the current GraphNodeHeldObject|descriptionEnd|*/
|
||||
struct GraphNodeHeldObject* geo_get_current_held_object(void);
|
||||
|
||||
/* |description|Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, returns a table as a pure memory buffer. Supports rgba16 and rgba32 textures|descriptionEnd|*/
|
||||
void texture_to_lua_table(const Texture *tex);
|
||||
/* |description|Converts a texture's pixels to a Lua table. Returns nil if failed. Otherwise, returns a 1-indexed table of RGBA pixels|descriptionEnd|*/
|
||||
LuaTable texture_to_lua_table(const Texture *tex);
|
||||
|
||||
/* |description|Gets the name of the provided texture pointer `tex`|descriptionEnd|*/
|
||||
const char *get_texture_name(const Texture *tex);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue