DRW: Add new Draw Manager OpenGL Context.

This separate context allows two things:
- It allows viewports in multi-windows configuration.
- F12 render can use this context in a separate thread and do a non-blocking render.

The downside is that the context cannot be used while rendering so a request to refresh a viewport will lock the UI. This is something that will be adressed in the future.

Under the hood what does that mean:
- Not adding more mess with VAOs management in gawain.
- Doing depth only draw for operators / selection needs to be done in an offscreen buffer.
- The 3D cursor "autodis" operator is still reading the backbuffer so we need to copy the result to it.
- All FBOs needed by the drawmanager must to be created/destroyed with its context active.
- We cannot use batches created for UI in the DRW context and vice-versa. There is a clear separation of resources that enables the use of safe multi-threading.
This commit is contained in:
2018-02-26 19:41:17 +01:00
parent 0940e89e60
commit 13261304a3
20 changed files with 347 additions and 22 deletions

View File

@@ -345,6 +345,8 @@ void GPU_viewport_bind(GPUViewport *viewport, const rcti *rect)
int rect_w = BLI_rcti_size_x(rect) + 1;
int rect_h = BLI_rcti_size_y(rect) + 1;
DRW_opengl_context_enable();
if (dfbl->default_fb) {
if (rect_w != viewport->size[0] || rect_h != viewport->size[1] || U.ogl_multisamples != viewport->samples) {
gpu_viewport_buffers_free(
@@ -465,6 +467,7 @@ cleanup:
if (!ok) {
GPU_viewport_free(viewport);
MEM_freeN(viewport);
DRW_opengl_context_disable();
return;
}
@@ -523,7 +526,11 @@ void GPU_viewport_unbind(GPUViewport *viewport)
if (dfbl->default_fb) {
GPU_framebuffer_texture_unbind(NULL, NULL);
GPU_framebuffer_restore();
}
DRW_opengl_context_disable();
if (dfbl->default_fb) {
glEnable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST);
}
@@ -581,6 +588,7 @@ static void gpu_viewport_passes_free(PassList *psl, int psl_len)
}
}
/* Must be executed inside Drawmanager Opengl Context. */
void GPU_viewport_free(GPUViewport *viewport)
{
gpu_viewport_engines_data_free(viewport);