Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow developer to flush manually #840

Closed
ivan-ushakov opened this issue Jun 7, 2023 · 1 comment
Closed

Allow developer to flush manually #840

ivan-ushakov opened this issue Jun 7, 2023 · 1 comment

Comments

@ivan-ushakov
Copy link

Currently in macOS you flush OpenGL context after each onFrame call:

- (void)drawRect:(NSRect)rect {
    _SOKOL_UNUSED(rect);
    _sapp_timing_measure(&_sapp.timing);
    /* Catch any last-moment input events */
    _sapp_macos_poll_input_events();
    @autoreleasepool {
        _sapp_macos_frame();
    }
    #if !defined(SOKOL_METAL)
    [[_sapp.macos.view openGLContext] flushBuffer];
    #endif
}

In some cases this leads to blinking black screen if we don't have any draw commands during onFrame. Would be great to have something like:

SOKOL_API_IMPL void sapp_gl_flush(void) {
    #if defined(_SAPP_MACOS) && !defined(SOKOL_METAL)
    [[_sapp.macos.view openGLContext] flushBuffer];
    #endif
}
@floooh
Copy link
Owner

floooh commented Jun 10, 2023

Unfortunately this would be a hack that would only work by accident, and most likely only on macOS.

sokol_app.h basically expects that something is rendered in each frame (and if it's just an empty render pass which clears the screen). Failing to do this may result in all sorts of breakage: from black screen, to corrupted screen, to flickering because the last two rendered frames are alternated.

A proper solution is sketched out in this ticket: #301

(basically having a paused mode where sokol_app.h "somehow" preserves the last rendered frame, it's not clear yet whether that can be done on all platforms).

I'm closing this ticket. Until a proper solution is implement a workaround is to do your regular rendering into an offscreen render target, which is then rendered to the default framebuffer. If your app needs to "freeze", skip the expensive offscreen rendering, but keep the default render pass active which renders the last content of the offscreen render target to the screen.

@floooh floooh closed this as completed Jun 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants