NDS: Optimise rendering to be a little bit faster

This commit is contained in:
UnknownShadow200 2024-04-27 23:24:31 +10:00
parent d6c51983ac
commit ae3ac8cdb1
2 changed files with 27 additions and 18 deletions

View File

@ -468,19 +468,28 @@ static void Draw_ColouredTriangles(int verticesCount, int startVertex) {
static void Draw_TexturedTriangles(int verticesCount, int startVertex) {
glBegin(GL_QUADS);
int width = 0, height = 0;
glGetInt(GL_GET_TEXTURE_WIDTH, &width); width = inttof32(width);
glGetInt(GL_GET_TEXTURE_HEIGHT, &height); height = inttof32(height);
int width = 0, height = 0;
glGetInt(GL_GET_TEXTURE_WIDTH, &width);
glGetInt(GL_GET_TEXTURE_HEIGHT, &height);
// Original code used was
// U = mulf32(v->u, inttof32(width))
// which behind the scenes expands to
// W = width << 12
// U = ((int64)v->u * W) >> 12;
// and in this case, the bit shifts can be cancelled out
// to avoid calling __aeabi_lmul to perform the 64 bit multiplication
// therefore the code can be simplified to
// U = v->u * width
for (int i = 0; i < verticesCount; i++)
{
struct DSTexturedVertex* v = (struct DSTexturedVertex*)gfx_vertices + startVertex + i;
GFX_COLOR = v->rgb;
glTexCoord2t16(f32tot16(mulf32(v->u, width)), f32tot16(mulf32(v->v, height)));
GFX_VERTEX16 = v->xy;
GFX_VERTEX16 = v->z;
GFX_COLOR = v->rgb;
GFX_TEX_COORD = TEXTURE_PACK(f32tot16(v->u * width), f32tot16(v->v * height));
GFX_VERTEX16 = v->xy;
GFX_VERTEX16 = v->z;
}
glEnd();
}

View File

@ -30,7 +30,7 @@ extern u8 default_fontTiles[];
#define FONT_ASCII_OFFSET 32
static u16* conFontBgMap;
static int conFontCurPal;
static int conCursorX, conCursorY;
static int conCursorX, conCurrentRow;
static void consoleClear(void) {
for (int i = 0; i < CON_WIDTH * CON_HEIGHT; i++)
@ -38,17 +38,17 @@ static void consoleClear(void) {
conFontBgMap[i] = ' ' - FONT_ASCII_OFFSET;
}
conCursorX = 0;
conCursorY = 0;
conCursorX = 0;
conCurrentRow = 0;
}
static void consoleNewLine(void) {
conCursorX = 0;
conCursorY++;
if (conCursorY < CON_HEIGHT) return;
conCurrentRow++;
if (conCurrentRow < CON_HEIGHT) return;
// Shift entire screen upwards by one row
conCursorY--;
conCurrentRow--;
for (int y = 0; y < CON_HEIGHT - 1; y++)
{
@ -72,13 +72,12 @@ static void consolePrintChar(char c) {
consoleNewLine();
u16 value = conFontCurPal | (c - FONT_ASCII_OFFSET);
conFontBgMap[conCursorX + conCursorY * CON_WIDTH] = value;
conFontBgMap[conCursorX + conCurrentRow * CON_WIDTH] = value;
conCursorX++;
}
void consolePrintString(const char* ptr, int len) {
if (!conFontBgMap) return;
consoleClear();
for (int i = 0; i < len; i++)
{
@ -103,7 +102,7 @@ static void consoleLoadFont(u16* fontBgGfx) {
if (row & 0x20) gfx |= 0x00F00000;
if (row & 0x40) gfx |= 0x0F000000;
if (row & 0x80) gfx |= 0xF0000000;
((u32 *)conFontBgGfx)[i] = gfx;
((u32 *)fontBgGfx)[i] = gfx;
}
palette[16 * 16 - 1] = RGB15(31, 31, 31);
@ -328,9 +327,10 @@ void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) {
keyboardHide();
if (!keyboardOpen) return;
keyboardOpen = false;
ResetHBank(); // reset shared VRAM
ResetHBank(); // reset shared VRAM
videoBgEnableSub(0); // show console
consoleInit();
}