Skip to content

Commit

Permalink
metal: Clear the framebuffer if presenting without any other operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 7, 2020
1 parent b7b8ef5 commit 061256a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/render/metal/SDL_render_metal.m
Expand Up @@ -1518,17 +1518,21 @@ - (void)dealloc
{ @autoreleasepool {
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;

METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);

if (data.mtlcmdencoder != nil) {
[data.mtlcmdencoder endEncoding];
}
if (data.mtlbackbuffer != nil) {
[data.mtlcmdbuffer presentDrawable:data.mtlbackbuffer];
}
if (data.mtlcmdbuffer != nil) {
[data.mtlcmdbuffer commit];
// If we don't have a command buffer, we can't present, so activate to get one.
if (data.mtlcmdencoder == nil) {
// We haven't even gotten a backbuffer yet? Clear it to black. Otherwise, load the existing data.
if (data.mtlbackbuffer == nil) {
MTLClearColor color = MTLClearColorMake(0.0f, 0.0f, 0.0f, 1.0f);
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionClear, &color, nil);
} else {
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
}
}

[data.mtlcmdencoder endEncoding];
[data.mtlcmdbuffer presentDrawable:data.mtlbackbuffer];
[data.mtlcmdbuffer commit];

data.mtlcmdencoder = nil;
data.mtlcmdbuffer = nil;
data.mtlbackbuffer = nil;
Expand Down

0 comments on commit 061256a

Please sign in to comment.