GPU: Add more safeguard for BGL calls

This makes sure no BGL call before window drawing locks the GPUState.
This commit is contained in:
Clément Foucault 2020-10-09 17:00:00 +02:00
parent 16ca295278
commit 2d94b0d6b0
Notes: blender-bot 2023-02-14 07:31:32 +01:00
Referenced by issue #81587, Consistent crash in Embree SSE42, SSE2 code in older Intel CPU.
2 changed files with 20 additions and 11 deletions

View File

@ -330,23 +330,28 @@ void GPU_apply_state(void)
void GPU_bgl_start(void)
{
Context *ctx = Context::get();
if (ctx && ctx->state_manager) {
StateManager &state_manager = *(Context::get()->state_manager);
if (state_manager.use_bgl == false) {
/* Expected by many addons (see T80169, T81289).
* This will reset the blend function. */
GPU_blend(GPU_BLEND_NONE);
state_manager.apply_state();
state_manager.use_bgl = true;
}
if (!(ctx && ctx->state_manager)) {
return;
}
StateManager &state_manager = *(Context::get()->state_manager);
if (state_manager.use_bgl == false) {
/* Expected by many addons (see T80169, T81289).
* This will reset the blend function. */
GPU_blend(GPU_BLEND_NONE);
state_manager.apply_state();
state_manager.use_bgl = true;
}
}
/* Just turn off the bgl safeguard system. Can be called even without GPU_bgl_start. */
void GPU_bgl_end(void)
{
Context *ctx = Context::get();
if (ctx && ctx->state_manager) {
StateManager &state_manager = *ctx->state_manager;
if (!(ctx && ctx->state_manager)) {
return;
}
StateManager &state_manager = *ctx->state_manager;
if (state_manager.use_bgl == true) {
state_manager.use_bgl = false;
/* Resync state tracking. */
state_manager.force_state();

View File

@ -863,6 +863,10 @@ static void wm_draw_window(bContext *C, wmWindow *win)
{
bScreen *screen = WM_window_get_active_screen(win);
bool stereo = WM_stereo3d_enabled(win, false);
/* Avoid any BGL call issued before this to alter the window drawin. */
GPU_bgl_end();
/* Draw area regions into their own framebuffer. This way we can redraw
* the areas that need it, and blit the rest from existing framebuffers. */
wm_draw_window_offscreen(C, win, stereo);