diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-02-26 21:41:17 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-02-26 21:41:17 +0300 |
commit | 13261304a331b4cff37de477ddf19c915ed64b2c (patch) | |
tree | 3660f94436af2e4d44d8310247280ab456243543 /source/blender/gpu | |
parent | 0940e89e604d85d717f792b73e30e5e96a42e7c6 (diff) |
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.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/gpu/GPU_batch.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/GPU_shader.h | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_batch_presets.c | 11 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader.c | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_viewport.c | 8 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl | 12 |
7 files changed, 34 insertions, 4 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 189ca8e6a33..5c0115d967a 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -150,6 +150,7 @@ data_to_c_simple(shaders/gpu_shader_image_modulate_alpha_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_image_alpha_color_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_image_color_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_image_depth_linear_frag.glsl SRC) +data_to_c_simple(shaders/gpu_shader_image_depth_copy_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_image_interlace_frag.glsl SRC) data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_3D_vert.glsl SRC) diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h index d2f3409dc07..5807af7b359 100644 --- a/source/blender/gpu/GPU_batch.h +++ b/source/blender/gpu/GPU_batch.h @@ -58,6 +58,8 @@ void gpu_batch_init(void); void gpu_batch_exit(void); /* gpu_batch_presets.c */ +/* Only use by draw manager. Use the presets function instead for interface. */ +Gwn_Batch *gpu_batch_sphere(int lat_res, int lon_res) ATTR_WARN_UNUSED_RESULT; /* Replacement for gluSphere */ Gwn_Batch *GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT; Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) ATTR_WARN_UNUSED_RESULT; diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index ca6e8343401..def0b0bfbc7 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -134,6 +134,7 @@ typedef enum GPUBuiltinShader { GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR, GPU_SHADER_3D_IMAGE_MODULATE_ALPHA, GPU_SHADER_3D_IMAGE_DEPTH, + GPU_SHADER_3D_IMAGE_DEPTH_COPY, /* stereo 3d */ GPU_SHADER_2D_IMAGE_INTERLACE, /* points */ diff --git a/source/blender/gpu/intern/gpu_batch_presets.c b/source/blender/gpu/intern/gpu_batch_presets.c index 9db04832a51..21d6906083a 100644 --- a/source/blender/gpu/intern/gpu_batch_presets.c +++ b/source/blender/gpu/intern/gpu_batch_presets.c @@ -31,6 +31,7 @@ #include "BLI_utildefines.h" #include "BLI_math.h" +#include "BLI_threads.h" #include "GPU_batch.h" #include "gpu_shader_private.h" @@ -71,7 +72,7 @@ static void batch_sphere_lat_lon_vert( } /* Replacement for gluSphere */ -static Gwn_Batch *batch_sphere(int lat_res, int lon_res) +Gwn_Batch *gpu_batch_sphere(int lat_res, int lon_res) { const float lon_inc = 2 * M_PI / lon_res; const float lat_inc = M_PI / lat_res; @@ -146,6 +147,7 @@ static Gwn_Batch *batch_sphere_wire(int lat_res, int lon_res) Gwn_Batch *GPU_batch_preset_sphere(int lod) { BLI_assert(lod >= 0 && lod <= 2); + BLI_assert(BLI_thread_is_main()); if (lod == 0) { return g_presets_3d.batch.sphere_low; @@ -161,6 +163,7 @@ Gwn_Batch *GPU_batch_preset_sphere(int lod) Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) { BLI_assert(lod >= 0 && lod <= 1); + BLI_assert(BLI_thread_is_main()); if (lod == 0) { return g_presets_3d.batch.sphere_wire_low; @@ -182,9 +185,9 @@ void gpu_batch_presets_init(void) } /* Hard coded resolution */ - g_presets_3d.batch.sphere_low = batch_sphere(8, 16); - g_presets_3d.batch.sphere_med = batch_sphere(16, 10); - g_presets_3d.batch.sphere_high = batch_sphere(32, 24); + g_presets_3d.batch.sphere_low = gpu_batch_sphere(8, 16); + g_presets_3d.batch.sphere_med = gpu_batch_sphere(16, 10); + g_presets_3d.batch.sphere_high = gpu_batch_sphere(32, 24); g_presets_3d.batch.sphere_wire_low = batch_sphere_wire(6, 8); g_presets_3d.batch.sphere_wire_med = batch_sphere_wire(8, 16); diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c index c25d03dff2f..b06ee56c21f 100644 --- a/source/blender/gpu/intern/gpu_shader.c +++ b/source/blender/gpu/intern/gpu_shader.c @@ -77,6 +77,7 @@ extern char datatoc_gpu_shader_image_interlace_frag_glsl[]; extern char datatoc_gpu_shader_image_mask_uniform_color_frag_glsl[]; extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[]; extern char datatoc_gpu_shader_image_depth_linear_frag_glsl[]; +extern char datatoc_gpu_shader_image_depth_copy_frag_glsl[]; extern char datatoc_gpu_shader_3D_vert_glsl[]; extern char datatoc_gpu_shader_3D_normal_vert_glsl[]; extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[]; @@ -712,6 +713,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader) datatoc_gpu_shader_image_modulate_alpha_frag_glsl }, [GPU_SHADER_3D_IMAGE_DEPTH] = { datatoc_gpu_shader_3D_image_vert_glsl, datatoc_gpu_shader_image_depth_linear_frag_glsl }, + [GPU_SHADER_3D_IMAGE_DEPTH_COPY] = { datatoc_gpu_shader_3D_image_vert_glsl, + datatoc_gpu_shader_image_depth_copy_frag_glsl }, [GPU_SHADER_2D_IMAGE_INTERLACE] = { datatoc_gpu_shader_2D_image_vert_glsl, datatoc_gpu_shader_image_interlace_frag_glsl }, diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c index fc045805874..83b9a8f0b0e 100644 --- a/source/blender/gpu/intern/gpu_viewport.c +++ b/source/blender/gpu/intern/gpu_viewport.c @@ -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); diff --git a/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl new file mode 100644 index 00000000000..10f4dfd5a87 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl @@ -0,0 +1,12 @@ + +in vec2 texCoord_interp; +out vec4 fragColor; + +uniform sampler2D image; + +void main() +{ + float depth = texture(image, texCoord_interp).r; + fragColor = vec4(depth); + gl_FragDepth = depth; +} |