From 38dfc3ae3245b1a3b11e2cd92aac0d4d72b7d6ef Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 22 Aug 2023 19:28:53 +1000 Subject: [PATCH] Dreamcast: Implement moving clouds --- src/Graphics_Dreamcast.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Graphics_Dreamcast.c b/src/Graphics_Dreamcast.c index faaf22a76..4de7580a6 100644 --- a/src/Graphics_Dreamcast.c +++ b/src/Graphics_Dreamcast.c @@ -333,8 +333,9 @@ void Gfx_SetFogMode(FogFunc func) { /*########################################################################################################################* *---------------------------------------------------------Matrices--------------------------------------------------------* *#########################################################################################################################*/ -static GLenum matrix_modes[] = { GL_PROJECTION, GL_MODELVIEW, GL_TEXTURE }; -static int lastMatrix; +static GLenum matrix_modes[] = { GL_PROJECTION, GL_MODELVIEW }; +static int lastMatrix, textureOffset; +float textureOffsetX, textureOffsetY; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); } @@ -346,13 +347,32 @@ void Gfx_LoadIdentityMatrix(MatrixType type) { glLoadIdentity(); } -static struct Matrix texMatrix = Matrix_IdentityValue; + void Gfx_EnableTextureOffset(float x, float y) { - texMatrix.row4.X = x; texMatrix.row4.Y = y; - Gfx_LoadMatrix(2, &texMatrix); + textureOffset = true; + textureOffsetX = x; + textureOffsetY = y; } -void Gfx_DisableTextureOffset(void) { Gfx_LoadIdentityMatrix(2); } +void Gfx_DisableTextureOffset(void) { + textureOffset = false; +} +static CC_NOINLINE void ShiftTextureCoords(int count) { + for (int i = 0; i < count; i++) + { + struct VertexTextured* v = (struct VertexTextured*)gfx_vertices + i; + v->U += textureOffsetX; + v->V += textureOffsetY; + } +} +static CC_NOINLINE void UnshiftTextureCoords(int count) { + for (int i = 0; i < count; i++) + { + struct VertexTextured* v = (struct VertexTextured*)gfx_vertices + i; + v->U -= textureOffsetX; + v->V -= textureOffsetY; + } +} /*########################################################################################################################* @@ -420,7 +440,10 @@ void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) { void Gfx_DrawVb_IndexedTris(int verticesCount) { SetupVertices(0); + + if (textureOffset) ShiftTextureCoords(verticesCount); glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, gfx_indices); + if (textureOffset) UnshiftTextureCoords(verticesCount); } void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {