[Bf-blender-cvs] [5e8030e6825] temp-drawcontext: DRW Opengl Context: Adress comments on D3057
Clément Foucault
noreply at git.blender.org
Sun Feb 11 02:46:53 CET 2018
Commit: 5e8030e6825160f9ad72b9c990d522ab71805063
Author: Clément Foucault
Date: Sun Feb 11 00:21:45 2018 +0100
Branches: temp-drawcontext
https://developer.blender.org/rB5e8030e6825160f9ad72b9c990d522ab71805063
DRW Opengl Context: Adress comments on D3057
- Rename DRW_ogl_ctx_* to DRW_opengl_context_*
- Replace ThreadRWMutex with ThreadMutex
- Remove g_active_window
===================================================================
M intern/ghost/GHOST_C-api.h
M intern/ghost/intern/GHOST_C-api.cpp
M source/blender/draw/DRW_engine.h
M source/blender/draw/intern/draw_manager.c
M source/blender/editors/render/render_opengl.c
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/editors/space_view3d/view3d_view.c
M source/blender/gpu/intern/gpu_viewport.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm_init_exit.c
M source/blender/windowmanager/intern/wm_window.c
===================================================================
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 0d40b7217d9..f743ceb0786 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -195,7 +195,7 @@ extern GHOST_WindowHandle GHOST_CreateWindow(
* \param systemhandle The handle to the system
* \return A handle to the new context ( == NULL if creation failed).
*/
-extern GHOST_ContextHandle GHOST_CreateOffscreenContext(GHOST_SystemHandle systemhandle);
+extern GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle);
/**
* Dispose of a context.
@@ -203,7 +203,7 @@ extern GHOST_ContextHandle GHOST_CreateOffscreenContext(GHOST_SystemHandle syste
* \param contexthandle Handle to the context to be disposed.
* \return Indication of success.
*/
-extern GHOST_TSuccess GHOST_DisposeOffscreenContext(GHOST_SystemHandle systemhandle,
+extern GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
GHOST_ContextHandle contexthandle);
/**
@@ -733,7 +733,7 @@ extern GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle);
* \param contexthandle The handle to the context
* \return A success indicator.
*/
-extern GHOST_TSuccess GHOST_ActivateOffscreenContext(GHOST_ContextHandle contexthandle);
+extern GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthandle);
/**
* Returns the status of the tablet
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 1306070ea01..a16ffdfecfd 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -132,14 +132,14 @@ void GHOST_GetAllDisplayDimensions(GHOST_SystemHandle systemhandle,
system->getAllDisplayDimensions(*width, *height);
}
-GHOST_ContextHandle GHOST_CreateOffscreenContext(GHOST_SystemHandle systemhandle)
+GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle)
{
GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
return (GHOST_ContextHandle) system->createOffscreenContext();
}
-GHOST_TSuccess GHOST_DisposeOffscreenContext(GHOST_SystemHandle systemhandle,
+GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
GHOST_ContextHandle contexthandle)
{
GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
@@ -729,7 +729,7 @@ GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandl
return window->activateDrawingContext();
}
-GHOST_TSuccess GHOST_ActivateOffscreenContext(GHOST_ContextHandle contexthandle)
+GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthandle)
{
GHOST_IContext *context = (GHOST_IContext *) contexthandle;
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index 9a27bbb7c86..9ed8f776f34 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -125,9 +125,9 @@ void EDIT_ARMATURE_collection_settings_create(struct IDProperty *properties);
void PAINT_WEIGHT_collection_settings_create(struct IDProperty *properties);
void PAINT_VERTEX_collection_settings_create(struct IDProperty *properties);
-void DRW_ogl_ctx_create(void);
-void DRW_ogl_ctx_destroy(void);
-void DRW_ogl_ctx_enable(void);
-void DRW_ogl_ctx_disable(void);
+void DRW_opengl_context_create(void);
+void DRW_opengl_context_destroy(void);
+void DRW_opengl_context_enable(void);
+void DRW_opengl_context_disable(void);
#endif /* __DRW_ENGINE_H__ */
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 256bb385308..be20871690d 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -380,7 +380,7 @@ ListBase DRW_engines = {NULL, NULL};
static void *g_ogl_context = NULL;
/* Mutex to lock the drw manager and avoid concurent context usage. */
-static ThreadRWMutex cache_rwlock = BLI_RWLOCK_INITIALIZER;
+static ThreadMutex cache_rwlock = BLI_MUTEX_INITIALIZER;
#ifdef USE_GPU_SELECT
static unsigned int g_DRW_select_id = (unsigned int)-1;
@@ -1265,17 +1265,11 @@ static void shgroup_dynamic_instance(DRWShadingGroup *shgroup)
glGenBuffers(1, &interface->instance_vbo);
glBindBuffer(GL_ARRAY_BUFFER, interface->instance_vbo);
- glBufferData(GL_ARRAY_BUFFER, buffer_size, data, GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, buffer_size, data, GL_DYNAMIC_DRAW);
}
static void shgroup_dynamic_batch_from_calls(DRWShadingGroup *shgroup)
{
- if ((shgroup->interface.instance_vbo || shgroup->batch_geom) &&
- (G.debug_value == 667))
- {
- return;
- }
-
if (shgroup->type == DRW_SHG_INSTANCE) {
shgroup_dynamic_instance(shgroup);
}
@@ -3651,9 +3645,10 @@ void DRW_render_to_image(RenderEngine *re, struct Depsgraph *depsgraph)
Render *render = re->re;
const EvaluationContext *eval_ctx = RE_GetEvalCtx(render);
/* Changing Context */
- BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE);
- /* IMPORTANT: We dont support immediate mode in render mode! */
- WM_context_activate(g_ogl_context);
+ DRW_opengl_context_enable();
+ /* IMPORTANT: We dont support immediate mode in render mode!
+ * This shall remain in effect until immediate mode supports
+ * multiple threads. */
/* Reset before using it. */
memset(&DST, 0x0, sizeof(DST));
@@ -3709,8 +3704,7 @@ void DRW_render_to_image(RenderEngine *re, struct Depsgraph *depsgraph)
GPU_framebuffer_restore();
/* Changing Context */
- wm_window_reset_drawable();
- BLI_rw_mutex_unlock(&cache_rwlock);
+ DRW_opengl_context_disable();
#ifdef DEBUG
/* Avoid accidental reuse. */
@@ -4157,7 +4151,7 @@ extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
extern struct GPUTexture *globals_ramp; /* draw_common.c */
void DRW_engines_free(void)
{
- DRW_ogl_ctx_enable();
+ DRW_opengl_context_enable();
DRW_TEXTURE_FREE_SAFE(g_select_buffer.texture_depth);
DRW_FRAMEBUFFER_FREE_SAFE(g_select_buffer.framebuffer);
@@ -4184,7 +4178,7 @@ void DRW_engines_free(void)
MEM_SAFE_FREE(RST.bound_texs);
MEM_SAFE_FREE(RST.bound_tex_slots);
- DRW_ogl_ctx_disable();
+ DRW_opengl_context_disable();
#ifdef WITH_CLAY_ENGINE
BLI_remlink(&R_engines, &DRW_engine_viewport_clay_type);
@@ -4196,38 +4190,45 @@ void DRW_engines_free(void)
/** \name Init/Exit (DRW_opengl_ctx)
* \{ */
-void DRW_ogl_ctx_create(void)
+void DRW_opengl_context_create(void)
{
BLI_assert(g_ogl_context == NULL); /* Ensure it's called once */
/* This changes the active context. */
- g_ogl_context = WM_context_create();
+ g_ogl_context = WM_opengl_context_create();
/* So we activate the window's one afterwards. */
wm_window_reset_drawable();
}
-void DRW_ogl_ctx_destroy(void)
+void DRW_opengl_context_destroy(void)
{
if (g_ogl_context != NULL) {
- WM_context_dispose(g_ogl_context);
+ WM_opengl_context_dispose(g_ogl_context);
}
}
-void DRW_ogl_ctx_enable(void)
+void DRW_opengl_context_enable(void)
{
if (g_ogl_context != NULL) {
- BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE);
- immDeactivate();
- WM_context_activate(g_ogl_context);
- immActivate();
+ /* IMPORTANT: We dont support immediate mode in render mode!
+ * This shall remain in effect until immediate mode supports
+ * multiple threads. */
+ BLI_mutex_lock(&cache_rwlock);
+ if (BLI_thread_is_main()) {
+ immDeactivate();
+ }
+ WM_opengl_context_activate(g_ogl_context);
+ if (BLI_thread_is_main()) {
+ immActivate();
+ }
}
}
-void DRW_ogl_ctx_disable(void)
+void DRW_opengl_context_disable(void)
{
if (g_ogl_context != NULL) {
wm_window_reset_drawable();
- BLI_rw_mutex_unlock(&cache_rwlock);
+ BLI_mutex_unlock(&cache_rwlock);
}
}
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 6c3d0d18ac6..07fb397b9cd 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -325,7 +325,7 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R
unsigned char *gp_rect;
unsigned char *render_rect = (unsigned char *)RE_RenderViewGetById(rr, oglrender->view_id)->rect32;
- DRW_ogl_ctx_enable();
+ DRW_opengl_context_enable();
GPU_offscreen_bind(oglrender->ofs, true);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -345,7 +345,7 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R
blend_color_mix_byte(&render_rect[i], &render_rect[i], &gp_rect[i]);
}
GPU_offscreen_unbind(oglrender->ofs, true);
- DRW_ogl_ctx_disable();
+ DRW_opengl_context_disable();
MEM_freeN(gp_rect);
}
@@ -656,9 +656,9 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
sizey = (scene->r.size * scene->r.ysch) / 100;
/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
- DRW_ogl_ctx_enable(); /* Offscreen creation needs to be done in DRW context. */
+ DRW_opengl_context_enable(); /* Offscreen creation needs to be done in DRW context. */
ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, true, err_out);
- DRW_ogl_ctx_disable();
+ DRW_opengl_context_disable();
if (!ofs) {
BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer, %s", err_out);
@@ -847,9 +847,9 @@ static void screen_opengl_render_end(bContext *C, OGLRender *oglrender)
if (oglrender->fx)
GPU_fx_compositor_destroy(oglrender->fx);
- DRW_ogl_ctx_enable();
+ DRW_opengl_context_enable();
GPU_offscreen_free(oglrender->ofs);
- DRW_ogl_ctx_disable();
+ DRW_opengl_context_disable();
if (oglrender->is_sequencer) {
MEM_freeN(oglrender->seq_data.ibufs_arr);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index c2169fa184b..d530503970c 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2127,7 +2127,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
}
const bool own_ofs = (ofs == NULL);
- DRW_ogl_ctx_enable();
+ DRW_opengl_context_enable();
if (own_ofs) {
/* bind */
@@ -2264,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list