Skip to content

Commit 6810037

Browse files
committed
Fix missed C2D function for multiple shader support
This took so long to debug...
1 parent ac78131 commit 6810037

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

source/base.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ void C2D_Flush(void)
204204

205205
void C2D_SceneSize(u32 width, u32 height, bool tilt)
206206
{
207-
C2Di_Context* ctx = C2Di_GetContext();
208-
if (!(ctx->flags & C2DiF_Active))
209-
return;
207+
C3D_Mtx projResult;
210208

211209
if (tilt)
212210
{
@@ -215,27 +213,40 @@ void C2D_SceneSize(u32 width, u32 height, bool tilt)
215213
height = temp;
216214
}
217215

218-
ctx->flags |= C2DiF_DirtyProj;
219-
ctx->sceneW = width;
220-
ctx->sceneH = height;
216+
bool constructed = false;
221217

222218
// Check for cached projection matrices
223219
if (height == GSP_SCREEN_WIDTH && tilt)
224220
{
225221
if (width == GSP_SCREEN_HEIGHT_TOP || width == GSP_SCREEN_HEIGHT_TOP_2X)
226222
{
227-
Mtx_Copy(&ctx->projMtx, &s_projTop);
228-
return;
223+
Mtx_Copy(&projResult, &s_projTop);
224+
constructed = true;
229225
}
230226
else if (width == GSP_SCREEN_HEIGHT_BOTTOM)
231227
{
232-
Mtx_Copy(&ctx->projMtx, &s_projBot);
233-
return;
228+
Mtx_Copy(&projResult, &s_projBot);
229+
constructed = true;
234230
}
235231
}
236232

237233
// Construct the projection matrix
238-
(tilt ? Mtx_OrthoTilt : Mtx_Ortho)(&ctx->projMtx, 0.0f, width, height, 0.0f, 1.0f, -1.0f, true);
234+
if (!constructed) {
235+
(tilt ? Mtx_OrthoTilt : Mtx_Ortho)(&projResult, 0.0f, width, height, 0.0f, 1.0f, -1.0f, true);
236+
}
237+
238+
for (int shaderId = 0; shaderId < C2D_NUM_SHADERS; shaderId++) {
239+
C2Di_Context* ctx = &__C2Di_Contexts[shaderId];
240+
241+
if (!(ctx->flags & C2DiF_Active))
242+
continue;
243+
244+
ctx->flags |= C2DiF_DirtyProj;
245+
ctx->sceneW = width;
246+
ctx->sceneH = height;
247+
248+
Mtx_Copy(&ctx->projMtx, &projResult);
249+
}
239250
}
240251

241252
void C2D_ViewReset(void)

source/main.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <stdio.h>
88
#include "program_shbin.h"
99

10-
static int uLoc_offsets;
10+
static int uLoc_offsets = -1;
1111

1212
float gameTime = 0;
1313
float timeStep = 0.08;
@@ -62,6 +62,10 @@ static void buildScanlineOffsetTable(void)
6262
else if (gameTime < -2*M_PI) gameTime += 2*M_PI;
6363

6464
// Update the uniforms
65+
if (uLoc_offsets == -1) {
66+
C2Di_Context* ctx = C2Di_GetContext();
67+
uLoc_offsets = shaderInstanceGetUniformLocation(ctx->program.geometryShader, "offsets");
68+
}
6569
C3D_FVUnifMtxNx4(GPU_GEOMETRY_SHADER, uLoc_offsets, (C3D_Mtx*) offsetTable, NUM_OFFSETS/4);
6670
}
6771

@@ -147,7 +151,7 @@ int main()
147151
gfxInitDefault();
148152
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
149153
C2D_Init(C2D_DEFAULT_MAX_OBJECTS/2);
150-
C2D_Prepare(C2D_ScanlineOffset);
154+
C2D_Prepare(C2D_Normal);
151155
consoleInit(GFX_BOTTOM, NULL);
152156

153157
// Create screens
@@ -163,9 +167,6 @@ int main()
163167
C2D_SpriteFromSheet(&sprites[i], spriteSheet, i);
164168
}
165169

166-
C2Di_Context* ctx = C2Di_GetContext();
167-
uLoc_offsets = shaderInstanceGetUniformLocation(ctx->program.geometryShader, "offsets");
168-
169170
// Main loop
170171
while (aptMainLoop())
171172
{
@@ -210,6 +211,7 @@ int main()
210211
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
211212
C2D_TargetClear(top, C2D_Color32f(0.3f, 0.7f, 1.0f, 1.0f));
212213
C2D_SceneBegin(top);
214+
// C2D_SceneTarget(top);
213215
C2D_Prepare(C2D_ScanlineOffset);
214216
buildScanlineOffsetTable();
215217

0 commit comments

Comments
 (0)