master
Clément Foucault 4 years ago
parent 28ea459a61
commit ca8ffc523e

@ -2862,7 +2862,6 @@ void DRW_opengl_render_context_enable(void *re_gl_context)
void DRW_opengl_render_context_disable(void *re_gl_context)
{
GPU_flush();
WM_opengl_context_release(re_gl_context);
/* TODO get rid of the blocking. */
BLI_ticket_mutex_unlock(DST.gl_context_mutex);
@ -2880,6 +2879,7 @@ void DRW_gpu_render_context_enable(void *re_gpu_context)
/* Needs to be called BEFORE DRW_opengl_render_context_disable() */
void DRW_gpu_render_context_disable(void *UNUSED(re_gpu_context))
{
GPU_flush();
GPU_context_active_set(NULL);
}

@ -29,6 +29,7 @@
#include "BLI_string_utils.h"
#include "BLI_threads.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
@ -41,6 +42,8 @@
#include "WM_api.h"
#include "WM_types.h"
#include "wm_window.h"
#include "draw_manager.h"
extern char datatoc_gpu_shader_2D_vert_glsl[];
@ -73,6 +76,7 @@ typedef struct DRWShaderCompiler {
ThreadMutex compilation_lock;
void *gl_context;
GPUContext *gpu_context;
bool own_context;
int shaders_done; /* To compute progress. */
@ -102,10 +106,10 @@ static void drw_deferred_shader_compilation_exec(
{
DRWShaderCompiler *comp = (DRWShaderCompiler *)custom_data;
void *gl_context = comp->gl_context;
GPUContext *gpu_context = comp->gpu_context;
#if TRUST_NO_ONE
BLI_assert(gl_context != NULL);
#endif
BLI_assert(gpu_context != NULL);
const bool use_main_context_workaround = GPU_use_main_context_workaround();
if (use_main_context_workaround) {
@ -114,6 +118,7 @@ static void drw_deferred_shader_compilation_exec(
}
WM_opengl_context_activate(gl_context);
GPU_context_active_set(gpu_context);
while (true) {
BLI_spin_lock(&comp->list_lock);
@ -160,6 +165,7 @@ static void drw_deferred_shader_compilation_exec(
BLI_spin_unlock(&comp->list_lock);
}
GPU_context_active_set(NULL);
WM_opengl_context_release(gl_context);
if (use_main_context_workaround) {
GPU_context_main_unlock();
@ -188,7 +194,12 @@ static void drw_deferred_shader_compilation_free(void *custom_data)
if (comp->own_context) {
/* Only destroy if the job owns the context. */
WM_opengl_context_activate(comp->gl_context);
GPU_context_active_set(comp->gpu_context);
GPU_context_discard(comp->gpu_context);
WM_opengl_context_dispose(comp->gl_context);
wm_window_reset_drawable();
}
MEM_freeN(comp);
@ -238,6 +249,7 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred)
/* Do not recreate context, just pass ownership. */
if (old_comp->gl_context) {
comp->gl_context = old_comp->gl_context;
comp->gpu_context = old_comp->gpu_context;
old_comp->own_context = false;
comp->own_context = job_own_context;
}
@ -249,10 +261,15 @@ static void drw_deferred_shader_add(GPUMaterial *mat, bool deferred)
if (comp->gl_context == NULL) {
if (use_main_context) {
comp->gl_context = DST.gl_context;
comp->gpu_context = DST.gpu_context;
}
else {
comp->gl_context = WM_opengl_context_create();
comp->gpu_context = GPU_context_create(NULL);
GPU_context_active_set(NULL);
WM_opengl_context_activate(DST.gl_context);
GPU_context_active_set(DST.gpu_context);
}
comp->own_context = job_own_context;
}

Loading…
Cancel
Save