GPUImmediate: Make activation / deactivation implicit
This avoids unecessary complexity. Also makes the GPUImmediate threadsafe by using a threadlocal imm variable.
This commit is contained in:
@@ -439,7 +439,6 @@ static void loggerwindow_do_draw(LoggerWindow *lw)
|
|||||||
|
|
||||||
GHOST_ActivateWindowDrawingContext(lw->win);
|
GHOST_ActivateWindowDrawingContext(lw->win);
|
||||||
GPU_context_active_set(lw->gpu_context);
|
GPU_context_active_set(lw->gpu_context);
|
||||||
immActivate();
|
|
||||||
|
|
||||||
glClearColor(1, 1, 1, 1);
|
glClearColor(1, 1, 1, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|||||||
@@ -2767,17 +2767,11 @@ void DRW_opengl_context_create(void)
|
|||||||
BLI_assert(DST.gl_context == NULL); /* Ensure it's called once */
|
BLI_assert(DST.gl_context == NULL); /* Ensure it's called once */
|
||||||
|
|
||||||
DST.gl_context_mutex = BLI_ticket_mutex_alloc();
|
DST.gl_context_mutex = BLI_ticket_mutex_alloc();
|
||||||
if (!G.background) {
|
|
||||||
immDeactivate();
|
|
||||||
}
|
|
||||||
/* This changes the active context. */
|
/* This changes the active context. */
|
||||||
DST.gl_context = WM_opengl_context_create();
|
DST.gl_context = WM_opengl_context_create();
|
||||||
WM_opengl_context_activate(DST.gl_context);
|
WM_opengl_context_activate(DST.gl_context);
|
||||||
/* Be sure to create gpu_context too. */
|
/* Be sure to create gpu_context too. */
|
||||||
DST.gpu_context = GPU_context_create(0);
|
DST.gpu_context = GPU_context_create(0);
|
||||||
if (!G.background) {
|
|
||||||
immActivate();
|
|
||||||
}
|
|
||||||
/* So we activate the window's one afterwards. */
|
/* So we activate the window's one afterwards. */
|
||||||
wm_window_reset_drawable();
|
wm_window_reset_drawable();
|
||||||
}
|
}
|
||||||
@@ -2794,25 +2788,15 @@ void DRW_opengl_context_destroy(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRW_opengl_context_enable_ex(bool restore)
|
void DRW_opengl_context_enable_ex(bool UNUSED(restore))
|
||||||
{
|
{
|
||||||
if (DST.gl_context != NULL) {
|
if (DST.gl_context != NULL) {
|
||||||
/* IMPORTANT: We dont support immediate mode in render mode!
|
/* IMPORTANT: We dont support immediate mode in render mode!
|
||||||
* This shall remain in effect until immediate mode supports
|
* This shall remain in effect until immediate mode supports
|
||||||
* multiple threads. */
|
* multiple threads. */
|
||||||
BLI_ticket_mutex_lock(DST.gl_context_mutex);
|
BLI_ticket_mutex_lock(DST.gl_context_mutex);
|
||||||
if (BLI_thread_is_main() && restore) {
|
|
||||||
if (!G.background) {
|
|
||||||
immDeactivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WM_opengl_context_activate(DST.gl_context);
|
WM_opengl_context_activate(DST.gl_context);
|
||||||
GPU_context_active_set(DST.gpu_context);
|
GPU_context_active_set(DST.gpu_context);
|
||||||
if (BLI_thread_is_main() && restore) {
|
|
||||||
if (!G.background) {
|
|
||||||
immActivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,12 +145,6 @@ void immUniformThemeColorBlendShade(int color_id1, int color_id2, float fac, int
|
|||||||
void immUniformThemeColorBlend(int color_id1, int color_id2, float fac);
|
void immUniformThemeColorBlend(int color_id1, int color_id2, float fac);
|
||||||
void immThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset);
|
void immThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset);
|
||||||
|
|
||||||
/* These are called by the system -- not part of drawing API. */
|
|
||||||
void immInit(void);
|
|
||||||
void immActivate(void);
|
|
||||||
void immDeactivate(void);
|
|
||||||
void immDestroy(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -39,12 +39,7 @@
|
|||||||
|
|
||||||
using namespace blender::gpu;
|
using namespace blender::gpu;
|
||||||
|
|
||||||
static Immediate *imm = NULL;
|
static thread_local Immediate *imm = NULL;
|
||||||
|
|
||||||
void immInit(void)
|
|
||||||
{
|
|
||||||
/* TODO Remove */
|
|
||||||
}
|
|
||||||
|
|
||||||
void immActivate(void)
|
void immActivate(void)
|
||||||
{
|
{
|
||||||
@@ -56,11 +51,6 @@ void immDeactivate(void)
|
|||||||
imm = NULL;
|
imm = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void immDestroy(void)
|
|
||||||
{
|
|
||||||
/* TODO Remove */
|
|
||||||
}
|
|
||||||
|
|
||||||
GPUVertFormat *immVertexFormat(void)
|
GPUVertFormat *immVertexFormat(void)
|
||||||
{
|
{
|
||||||
GPU_vertformat_clear(&imm->vertex_format);
|
GPU_vertformat_clear(&imm->vertex_format);
|
||||||
|
|||||||
@@ -63,4 +63,7 @@ class Immediate {
|
|||||||
virtual void end(void) = 0;
|
virtual void end(void) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::gpu
|
} // namespace blender::gpu
|
||||||
|
|
||||||
|
void immActivate(void);
|
||||||
|
void immDeactivate(void);
|
||||||
@@ -54,10 +54,6 @@ void GPU_init(void)
|
|||||||
|
|
||||||
gpu_batch_init();
|
gpu_batch_init();
|
||||||
|
|
||||||
if (!G.background) {
|
|
||||||
immInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef GPU_STANDALONE
|
#ifndef GPU_STANDALONE
|
||||||
gpu_pbvh_init();
|
gpu_pbvh_init();
|
||||||
#endif
|
#endif
|
||||||
@@ -69,10 +65,6 @@ void GPU_exit(void)
|
|||||||
gpu_pbvh_exit();
|
gpu_pbvh_exit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!G.background) {
|
|
||||||
immDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
gpu_batch_exit();
|
gpu_batch_exit();
|
||||||
|
|
||||||
gpu_material_library_exit();
|
gpu_material_library_exit();
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "GHOST_C-api.h"
|
#include "GHOST_C-api.h"
|
||||||
|
|
||||||
#include "gpu_context_private.hh"
|
#include "gpu_context_private.hh"
|
||||||
|
#include "gpu_immediate_private.hh"
|
||||||
|
|
||||||
#include "gl_debug.hh"
|
#include "gl_debug.hh"
|
||||||
#include "gl_immediate.hh"
|
#include "gl_immediate.hh"
|
||||||
@@ -151,10 +152,13 @@ void GLContext::activate(void)
|
|||||||
/* Not really following the state but we should consider
|
/* Not really following the state but we should consider
|
||||||
* no ubo bound when activating a context. */
|
* no ubo bound when activating a context. */
|
||||||
bound_ubo_slots = 0;
|
bound_ubo_slots = 0;
|
||||||
|
|
||||||
|
immActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext::deactivate(void)
|
void GLContext::deactivate(void)
|
||||||
{
|
{
|
||||||
|
immDeactivate();
|
||||||
is_active_ = false;
|
is_active_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1292,7 +1292,6 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
|
|||||||
/* initialize OpenGL immediate mode */
|
/* initialize OpenGL immediate mode */
|
||||||
g_WS.gpu_context = GPU_context_create(g_WS.ghost_window);
|
g_WS.gpu_context = GPU_context_create(g_WS.ghost_window);
|
||||||
GPU_init();
|
GPU_init();
|
||||||
immActivate();
|
|
||||||
|
|
||||||
/* initialize the font */
|
/* initialize the font */
|
||||||
BLF_init();
|
BLF_init();
|
||||||
@@ -1579,8 +1578,6 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
|
|||||||
|
|
||||||
GPU_shader_free_builtin_shaders();
|
GPU_shader_free_builtin_shaders();
|
||||||
|
|
||||||
immDeactivate();
|
|
||||||
|
|
||||||
if (g_WS.gpu_context) {
|
if (g_WS.gpu_context) {
|
||||||
GPU_context_active_set(g_WS.gpu_context);
|
GPU_context_active_set(g_WS.gpu_context);
|
||||||
GPU_context_discard(g_WS.gpu_context);
|
GPU_context_discard(g_WS.gpu_context);
|
||||||
|
|||||||
@@ -56,8 +56,6 @@ void wm_surface_clear_drawable(void)
|
|||||||
WM_opengl_context_release(g_drawable->ghost_ctx);
|
WM_opengl_context_release(g_drawable->ghost_ctx);
|
||||||
GPU_context_active_set(NULL);
|
GPU_context_active_set(NULL);
|
||||||
|
|
||||||
immDeactivate();
|
|
||||||
|
|
||||||
if (g_drawable->deactivate) {
|
if (g_drawable->deactivate) {
|
||||||
g_drawable->deactivate();
|
g_drawable->deactivate();
|
||||||
}
|
}
|
||||||
@@ -79,7 +77,6 @@ void wm_surface_set_drawable(wmSurface *surface, bool activate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GPU_context_active_set(surface->gpu_ctx);
|
GPU_context_active_set(surface->gpu_ctx);
|
||||||
immActivate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_surface_make_drawable(wmSurface *surface)
|
void wm_surface_make_drawable(wmSurface *surface)
|
||||||
|
|||||||
@@ -1099,13 +1099,11 @@ static void wm_window_set_drawable(wmWindowManager *wm, wmWindow *win, bool acti
|
|||||||
GHOST_ActivateWindowDrawingContext(win->ghostwin);
|
GHOST_ActivateWindowDrawingContext(win->ghostwin);
|
||||||
}
|
}
|
||||||
GPU_context_active_set(win->gpuctx);
|
GPU_context_active_set(win->gpuctx);
|
||||||
immActivate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_window_clear_drawable(wmWindowManager *wm)
|
void wm_window_clear_drawable(wmWindowManager *wm)
|
||||||
{
|
{
|
||||||
if (wm->windrawable) {
|
if (wm->windrawable) {
|
||||||
immDeactivate();
|
|
||||||
wm->windrawable = NULL;
|
wm->windrawable = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user