Wii U: Set matrix when switching shaders

This commit is contained in:
UnknownShadow200 2025-03-04 22:35:32 +11:00
parent 8559ccc404
commit 023411e444
3 changed files with 56 additions and 44 deletions

View File

@ -68,6 +68,14 @@ static void blockalloc_free(cc_uint8* table, int origin, int blocks) {
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------------General---------------------------------------------------------* *---------------------------------------------------------General---------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static CC_INLINE void CopyHWords(void* src, void* dst, int len) {
// VRAM must be written to in 16 bit units
u16* src_ = src;
u16* dst_ = dst;
for (int i = 0; i < len; i++) dst_[i] = src_[i];
}
void ResetGPU(void) { void ResetGPU(void) {
powerOn(POWER_3D_CORE | POWER_MATRIX); // Enable 3D core & geometry engine powerOn(POWER_3D_CORE | POWER_MATRIX); // Enable 3D core & geometry engine
@ -397,7 +405,7 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags,
} }
} }
swiCopy(buf, addr, (tex_size >> 1) | COPY_MODE_HWORD); CopyHWords(buf, addr, tex_size >> 1);
free(buf); free(buf);
} else if (tex_fmt == GL_RGB16) { } else if (tex_fmt == GL_RGB16) {
stride = bmp->width >> 2; stride = bmp->width >> 2;
@ -416,7 +424,7 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags,
tmp[x >> 1] |= idx << 4; tmp[x >> 1] |= idx << 4;
} }
} }
swiCopy(tmp, addr, stride | COPY_MODE_HWORD); CopyHWords(tmp, addr, stride);
} }
} else if (tex_fmt == GL_RGB256) { } else if (tex_fmt == GL_RGB256) {
stride = bmp->width >> 1; stride = bmp->width >> 1;
@ -429,14 +437,14 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags,
{ {
tmp[x] = FindInPalette(palette, pal_count, row[x]); tmp[x] = FindInPalette(palette, pal_count, row[x]);
} }
swiCopy(tmp, addr, stride | COPY_MODE_HWORD); CopyHWords(tmp, addr, stride);
} }
} else { } else {
stride = bmp->width; stride = bmp->width;
for (int y = 0; y < bmp->height; y++, addr += stride) { for (int y = 0; y < bmp->height; y++, addr += stride) {
cc_uint16* src = bmp->scan0 + y * rowWidth; cc_uint16* src = bmp->scan0 + y * rowWidth;
swiCopy(src, addr, stride | COPY_MODE_HWORD); CopyHWords(src, addr, stride);
} }
} }
@ -455,7 +463,7 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags,
offset = tex->palBase * PAL_BLOCK_SIZE; offset = tex->palBase * PAL_BLOCK_SIZE;
vramSetBankE(VRAM_E_LCD); vramSetBankE(VRAM_E_LCD);
swiCopy(palette, (u8*)VRAM_E + offset, pal_count | COPY_MODE_HWORD); CopyHWords(palette, (u8*)VRAM_E + offset, pal_count);
vramSetBankE(VRAM_E_TEX_PALETTE); vramSetBankE(VRAM_E_TEX_PALETTE);
tex->palFormat = tex_fmt == GL_RGB4 ? (offset >> 3) : (offset >> 4); tex->palFormat = tex_fmt == GL_RGB4 ? (offset >> 3) : (offset >> 4);

View File

@ -303,60 +303,26 @@ void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) {
void Gfx_UnlockDynamicVb(GfxResourceID vb) { Gfx_UnlockVb(vb); Gfx_BindVb(vb); } void Gfx_UnlockDynamicVb(GfxResourceID vb) { Gfx_UnlockVb(vb); Gfx_BindVb(vb); }
/*########################################################################################################################*
*-----------------------------------------------------Vertex rendering----------------------------------------------------*
*#########################################################################################################################*/
void Gfx_SetVertexFormat(VertexFormat fmt) {
if (fmt == gfx_format) return;
gfx_format = fmt;
gfx_stride = strideSizes[fmt];
group = fmt == VERTEX_FORMAT_TEXTURED ? &textureShader : &colorShader;
GX2SetFetchShader(&group->fetchShader);
GX2SetVertexShader(group->vertexShader);
GX2SetPixelShader(group->pixelShader);
}
void Gfx_DrawVb_Lines(int verticesCount) {
BindPendingTexture();
GX2DrawEx(GX2_PRIMITIVE_MODE_LINES, verticesCount, 0, 1);
}
void Gfx_DrawVb_IndexedTris(int verticesCount) {
BindPendingTexture();
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, verticesCount, 0, 1);
}
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex, DrawHints hints) {
BindPendingTexture();
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, verticesCount, startVertex, 1);
}
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
BindPendingTexture();
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, verticesCount, startVertex, 1);
}
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------------Matrices--------------------------------------------------------* *---------------------------------------------------------Matrices--------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static struct Matrix _view, _proj; static struct Matrix _view, _proj;
static struct Matrix _mvp __attribute__((aligned(64)));
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
if (type == MATRIX_VIEW) _view = *matrix; if (type == MATRIX_VIEW) _view = *matrix;
if (type == MATRIX_PROJ) _proj = *matrix; if (type == MATRIX_PROJ) _proj = *matrix;
// TODO dirty uniform // TODO dirty uniform
struct Matrix mvp __attribute__((aligned(64))); Matrix_Mul(&_mvp, &_view, &_proj);
Matrix_Mul(&mvp, &_view, &_proj);
if (!group) return; if (!group) return;
GX2SetVertexUniformReg(group->vertexShader->uniformVars[0].offset, 16, &mvp); GX2SetVertexUniformReg(group->vertexShader->uniformVars[0].offset, 16, &_mvp);
} }
void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) { void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) {
Gfx_LoadMatrix(MATRIX_VIEW, view); Gfx_LoadMatrix(MATRIX_VIEW, view);
Gfx_LoadMatrix(MATRIX_PROJ, proj); Gfx_LoadMatrix(MATRIX_PROJ, proj);
Matrix_Mul(mvp, view, proj); Mem_Copy(&_mvp, mvp, sizeof(struct Matrix));
} }
void Gfx_EnableTextureOffset(float x, float y) { void Gfx_EnableTextureOffset(float x, float y) {
@ -396,6 +362,43 @@ void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, f
} }
/*########################################################################################################################*
*-----------------------------------------------------Vertex rendering----------------------------------------------------*
*#########################################################################################################################*/
void Gfx_SetVertexFormat(VertexFormat fmt) {
if (fmt == gfx_format) return;
gfx_format = fmt;
gfx_stride = strideSizes[fmt];
group = fmt == VERTEX_FORMAT_TEXTURED ? &textureShader : &colorShader;
GX2SetFetchShader(&group->fetchShader);
GX2SetVertexShader(group->vertexShader);
GX2SetPixelShader(group->pixelShader);
GX2SetVertexUniformReg(group->vertexShader->uniformVars[0].offset, 16, &_mvp);
}
void Gfx_DrawVb_Lines(int verticesCount) {
BindPendingTexture();
GX2DrawEx(GX2_PRIMITIVE_MODE_LINES, verticesCount, 0, 1);
}
void Gfx_DrawVb_IndexedTris(int verticesCount) {
BindPendingTexture();
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, verticesCount, 0, 1);
}
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex, DrawHints hints) {
BindPendingTexture();
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, verticesCount, startVertex, 1);
}
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
BindPendingTexture();
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, verticesCount, startVertex, 1);
}
/*########################################################################################################################* /*########################################################################################################################*
*-----------------------------------------------------------Misc----------------------------------------------------------* *-----------------------------------------------------------Misc----------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/

View File

@ -104,6 +104,7 @@ void Window_Free(void) { }
#define OSSCREEN_TV_HEIGHT 720 #define OSSCREEN_TV_HEIGHT 720
#define OSSCREEN_DRC_WIDTH 854 #define OSSCREEN_DRC_WIDTH 854
#define OSSCREEN_DRC_HEIGHT 480 #define OSSCREEN_DRC_HEIGHT 480
static void LauncherInactiveChanged(void* obj); static void LauncherInactiveChanged(void* obj);
static void Init2DResources(void); static void Init2DResources(void);