From d43693f3ddf4345b3b77c8452f6442b769acaa0e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 9 Apr 2024 20:34:58 +1000 Subject: [PATCH] WiiU: WIP graphics stuff, doesn't actually work though --- misc/wiiu/Makefile | 12 +++++-- misc/wiiu/coloured.gsh | Bin 1144 -> 1312 bytes misc/wiiu/coloured.vsh | 5 +-- misc/wiiu/textured.gsh | Bin 0 -> 1780 bytes misc/wiiu/textured.vsh | 7 ++-- src/Graphics_WiiU.c | 72 +++++++++++++++++++++++++++++++++++++---- 6 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 misc/wiiu/textured.gsh diff --git a/misc/wiiu/Makefile b/misc/wiiu/Makefile index cf8bb2396..9af30ecae 100644 --- a/misc/wiiu/Makefile +++ b/misc/wiiu/Makefile @@ -32,7 +32,8 @@ include $(DEVKITPRO)/wut/share/wut_rules #------------------------------------------------------------------------------- TARGET := ClassiCube-wiiu BUILD := build-wiiu -SOURCES := src misc/wiiu third_party/bearssl/src +SOURCES := src third_party/bearssl/src +SHADERS := misc/wiiu DATA := data INCLUDES := third_party/bearssl/inc CONTENT := @@ -78,7 +79,8 @@ export DEPSDIR := $(CURDIR)/$(BUILD) CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) \ + $(foreach dir,$(SHADERS),$(notdir $(wildcard $(dir)/*.gsh))) export LD := $(CC) @@ -152,13 +154,17 @@ $(OUTPUT).elf : $(OFILES) $(OFILES_SRC) : $(HFILES_BIN) -#------------------------------------------------------------------------------- # you need a rule like this for each extension you use as binary data #------------------------------------------------------------------------------- %.bin.o %_bin.h : %.bin #------------------------------------------------------------------------------- @echo $(notdir $<) @$(bin2o) +#------------------------------------------------------------------------------- +%.gsh.o %_gsh.h : ../misc/wiiu/%.gsh +#------------------------------------------------------------------------------- + echo $(notdir $<) + $(bin2o) -include $(DEPENDS) diff --git a/misc/wiiu/coloured.gsh b/misc/wiiu/coloured.gsh index 3e94e41add881ffb89432761e472ed72275c4ae3..dc695190fc73e1491da6412e29497ed8c4f68183 100644 GIT binary patch literal 1312 zcmds1Jxc>Y5S`siV$`4(X(d}+VJApR!Egv3DA?M0Ac%sRfFgnslFrg1ePUr@VQ*<| zmEUlcKSJ(&FSi?FI20@t9C$n5JGV2tw{>{6CL#uy0TiHtF$Fu@*H8>VAIXFGoQYf& z^f9S4O$GRtn1P^oFjtTJr+);Ll?7l4=eeUYMQRwS`jl-_)$oUthOgw;mO6re85s4H z&4TR&`kc#yegS#j>gx2eCC6v`t>(FqA2bm?jN}b<%ZRN5A+UFYfgxul%TsN{kgAAd zO;QnZJ7=y%dv-Txgmz{PGh}nHZj{`Xq$e)|ZmJ{mKVH12nsjhJ@3BvAyoZ_sZ+Q3p zE_j6AY)nFj1C>a;s6(TYLc9uHl5)HYy^~bpruMDhw|?LHed`w^NhQEzpgk~J7#B34 zcM}PsoOzWnFWgt8WW>2?493k5+=({g_t_#!@+0`2q;kf7zJ9*ny#Lu=d<$+@$~pbw U|Bdy>|0~?%UQV2AT7mn009FgDdH?_b literal 1144 zcmZ=yt1x0Tz`)DU0OTiN2|qSq_yN-aJRg98FMMMmA0;*64`cHz= z)+vaA(noP&w)-ZZ>LoVwwAWMVjUmiI*dGAiXJxQ=5A3y-2bhND@d+)GAS zs5COtlm`JuvswUpW{%#sDDLgNMEEfG=9*~S`*{Tx+`DUHhzlKE@gD%Um-zWprI zMr<3t?$A7Nost7GkK$k+WJEpjue9g0|1K6* #include #include +#include #include #include #include @@ -14,15 +15,37 @@ #include #include #include +#include #include #include #include +#include "../build-wiiu/coloured_gsh.h" +#include "../build-wiiu/textured_gsh.h" + +static WHBGfxShaderGroup colorShader; +static WHBGfxShaderGroup textureShader; + +static void InitGfx(void) { + WHBGfxInit(); + + WHBGfxLoadGFDShaderGroup(&colorShader, 0, coloured_gsh); + WHBGfxInitShaderAttribute(&colorShader, "in_pos", 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + WHBGfxInitShaderAttribute(&colorShader, "in_col", 0, 12, GX2_ATTRIB_FORMAT_UNORM_8_8_8_8); + WHBGfxInitFetchShader(&colorShader); + + WHBGfxLoadGFDShaderGroup(&textureShader, 0, textured_gsh); + WHBGfxInitShaderAttribute(&textureShader, "in_pos", 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32); + WHBGfxInitShaderAttribute(&textureShader, "in_col", 0, 12, GX2_ATTRIB_FORMAT_UNORM_8_8_8_8); + WHBGfxInitShaderAttribute(&textureShader, "in_pos", 0, 16, GX2_ATTRIB_FORMAT_FLOAT_32_32); + WHBGfxInitFetchShader(&textureShader); +} void Gfx_Create(void) { + if (!Gfx.Created) InitGfx(); + Gfx.Created = true; - Gfx.MaxTexWidth = 512; - Gfx.MaxTexHeight = 512; - WHBGfxInit(); + Gfx.MaxTexWidth = 1024; + Gfx.MaxTexHeight = 1024; } cc_bool Gfx_TryRestoreContext(void) { @@ -63,8 +86,6 @@ void Gfx_BindTexture(GfxResourceID texId) { void Gfx_DeleteTexture(GfxResourceID* texId) { } -void Gfx_SetTexturing(cc_bool enabled) { } - void Gfx_EnableMipmaps(void) { } // TODO void Gfx_DisableMipmaps(void) { } // TODO @@ -172,6 +193,9 @@ void Gfx_DeleteVb(GfxResourceID* vb) { } void Gfx_BindVb(GfxResourceID vb) { + GX2RBuffer* buf = (GX2RBuffer*)vb; + GX2RSetAttributeBuffer(buf, 0, buf->elemSize, 0); + //GX2SetAttribBuffer(0, } void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) { @@ -206,27 +230,61 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) { Gfx_UnlockVb(vb); Gfx_BindVb(vb); /*########################################################################################################################* *-----------------------------------------------------Vertex rendering----------------------------------------------------* *#########################################################################################################################*/ +static WHBGfxShaderGroup* group; + 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) { } void Gfx_DrawVb_IndexedTris(int verticesCount) { + GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, verticesCount, 0, 1); } void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) { + GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, verticesCount, startVertex, 1); } void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { + GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, verticesCount, startVertex, 1); } /*########################################################################################################################* *---------------------------------------------------------Matrices--------------------------------------------------------* *#########################################################################################################################*/ +static struct Matrix _view, _proj; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - // TODO + if (type == MATRIX_VIEW) _view = *matrix; + if (type == MATRIX_PROJECTION) _proj = *matrix; + struct Matrix mvp __attribute__((aligned(64))); + Matrix_Mul(&mvp, &_view, &_proj); + if (!group) return; + + +static float transposed_mvp[4*4] __attribute__((aligned(64))); +float* m = &mvp; + + // Transpose matrix + for (int i = 0; i < 4; i++) + { + transposed_mvp[i * 4 + 0] = m[0 + i]; + transposed_mvp[i * 4 + 1] = m[4 + i]; + transposed_mvp[i * 4 + 2] = m[8 + i]; + transposed_mvp[i * 4 + 3] = m[12 + i]; + } + + //Platform_LogConst("MVP"); + GX2SetVertexUniformReg(group->vertexShader->uniformVars[0].offset, 16, &mvp); } void Gfx_LoadIdentityMatrix(MatrixType type) { @@ -316,4 +374,4 @@ void Gfx_GetApiInfo(cc_string* info) { void Gfx_OnWindowResize(void) { } -#endif +#endif \ No newline at end of file