Skip to content

Commit 5710f5e

Browse files
committed
swapchain + uniforms fixes
1 parent 8ac9743 commit 5710f5e

File tree

1 file changed

+52
-34
lines changed

1 file changed

+52
-34
lines changed

src/FNA3D_Driver_SDL.c

+52-34
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,7 @@ void MOJOSHADER_sdlMapUniformBufferMemory(
550550

551551
void MOJOSHADER_sdlUnmapUniformBufferMemory(MOJOSHADER_sdlContext *ctx)
552552
{
553-
if (ctx->bound_program == NULL)
554-
{
555-
return; /* Ignore buffer updates until we have a real program linked */
556-
}
557-
558-
update_uniform_buffer(ctx, ctx->bound_program->vertexShader);
559-
update_uniform_buffer(ctx, ctx->bound_program->pixelShader);
553+
/* no-op! real work done in sdlUpdateUniformBuffers */
560554
}
561555

562556
int32_t MOJOSHADER_sdlGetUniformBufferSize(MOJOSHADER_sdlShader *shader)
@@ -573,6 +567,19 @@ int32_t MOJOSHADER_sdlGetUniformBufferSize(MOJOSHADER_sdlShader *shader)
573567
return buflen;
574568
}
575569

570+
void MOJOSHADER_sdlUpdateUniformBuffers(MOJOSHADER_sdlContext *ctx)
571+
{
572+
if (MOJOSHADER_sdlGetUniformBufferSize(ctx->bound_program->vertexShader) > 0)
573+
{
574+
update_uniform_buffer(ctx, ctx->bound_program->vertexShader);
575+
}
576+
577+
if (MOJOSHADER_sdlGetUniformBufferSize(ctx->bound_program->pixelShader) > 0)
578+
{
579+
update_uniform_buffer(ctx, ctx->bound_program->pixelShader);
580+
}
581+
}
582+
576583
int MOJOSHADER_sdlGetVertexAttribLocation(
577584
MOJOSHADER_sdlShader *vert,
578585
MOJOSHADER_usage usage, int index
@@ -1276,33 +1283,36 @@ static void SDLGPU_SwapBuffers(
12761283
&height
12771284
);
12781285

1279-
srcRegion.textureSlice.texture = renderer->fauxBackbufferColor;
1280-
srcRegion.textureSlice.layer = 0;
1281-
srcRegion.textureSlice.mipLevel = 0;
1282-
srcRegion.x = 0;
1283-
srcRegion.y = 0;
1284-
srcRegion.z = 0;
1285-
srcRegion.w = width;
1286-
srcRegion.h = height;
1287-
srcRegion.d = 1;
1288-
1289-
dstRegion.textureSlice.texture = swapchainTexture;
1290-
dstRegion.textureSlice.layer = 0;
1291-
dstRegion.textureSlice.mipLevel = 0;
1292-
dstRegion.x = 0;
1293-
dstRegion.y = 0;
1294-
dstRegion.z = 0;
1295-
srcRegion.w = width;
1296-
srcRegion.h = height;
1297-
srcRegion.d = 1;
1298-
1299-
SDL_GpuCopyTextureToTexture(
1300-
renderer->device,
1301-
renderer->commandBuffer,
1302-
&srcRegion,
1303-
&dstRegion,
1304-
SDL_GPU_TEXTUREWRITEOPTIONS_SAFE
1305-
);
1286+
if (swapchainTexture != NULL)
1287+
{
1288+
srcRegion.textureSlice.texture = renderer->fauxBackbufferColor;
1289+
srcRegion.textureSlice.layer = 0;
1290+
srcRegion.textureSlice.mipLevel = 0;
1291+
srcRegion.x = 0;
1292+
srcRegion.y = 0;
1293+
srcRegion.z = 0;
1294+
srcRegion.w = width;
1295+
srcRegion.h = height;
1296+
srcRegion.d = 1;
1297+
1298+
dstRegion.textureSlice.texture = swapchainTexture;
1299+
dstRegion.textureSlice.layer = 0;
1300+
dstRegion.textureSlice.mipLevel = 0;
1301+
dstRegion.x = 0;
1302+
dstRegion.y = 0;
1303+
dstRegion.z = 0;
1304+
srcRegion.w = width;
1305+
srcRegion.h = height;
1306+
srcRegion.d = 1;
1307+
1308+
SDL_GpuCopyTextureToTexture(
1309+
renderer->device,
1310+
renderer->commandBuffer,
1311+
&srcRegion,
1312+
&dstRegion,
1313+
SDL_GPU_TEXTUREWRITEOPTIONS_SAFE
1314+
);
1315+
}
13061316

13071317
SDLGPU_INTERNAL_FlushCommands(renderer);
13081318
}
@@ -1476,6 +1486,10 @@ static void SDLGPU_INTERNAL_EndPass(
14761486
renderer->device,
14771487
renderer->commandBuffer
14781488
);
1489+
1490+
renderer->currentGraphicsPipeline = NULL;
1491+
renderer->needNewGraphicsPipeline = 1;
1492+
renderer->renderPassInProgress = 0;
14791493
}
14801494
}
14811495

@@ -1596,6 +1610,8 @@ static void SDLGPU_INTERNAL_BeginRenderPass(
15961610
renderer->shouldClearStencilOnBeginPass = 0;
15971611

15981612
renderer->needNewGraphicsPipeline = 1;
1613+
1614+
renderer->renderPassInProgress = 1;
15991615
}
16001616

16011617
static void SDLGPU_SetRenderTargets(
@@ -2047,6 +2063,8 @@ static void SDLGPU_INTERNAL_BindGraphicsPipeline(
20472063
renderer->currentGraphicsPipeline = pipeline;
20482064
}
20492065

2066+
MOJOSHADER_sdlUpdateUniformBuffers(renderer->mojoshaderContext);
2067+
20502068
renderer->currentVertexShader = vertShader;
20512069
renderer->currentFragmentShader = fragShader;
20522070

0 commit comments

Comments
 (0)