This patch proposes to optimize Auto Depth and operations involving
occlusion in Grease Pencil
Current issue:
When AutoDepth is enabled, at each Zoom event, the 3DView is redrawn to
get a customized depth buffer.
With this depth buffer created, a maximum of 4 GPU_framebuffer_read_depth
operations are performed with buffers of different sizes, each having to
create and destroy a temporary framebuffer due to different context.
Grease Pencil and Annotations have similar issues. However,
occlusion operations in these cases call the read depth operation on
the GPU for each point.
Main solution:
This patch proposes to reuse the viewport's depthbuffer for Auto Depth.
The only differences I identified are that, in the custom depth buffer,
Grease Pencil objects are not drawn and objects "in_front" are drawn
as if they were not "in_front".
With this patch now Grease Pencil are drawn and objects "in_front"
are prioritized.
This patch also proposes the use of a cached depth buffer for operations
in Grease Pencil and Annotation.
Other changes in the patch:
- The gl_clip_alpha property, found in the users' preferences, is not used, so it was removed.
- ED_view3d_backbuf_depth_validate, ED_view3d_draw_depth and ED_view3d_draw_depth_gpencil were unified in ED_view3d_depth_override with modes (modified from ED_view3d_autodist_init)
- ED_view3d_depth_read_cached was created to replace ED_view3d_autodist_depth and use the depth buffer salved in cache (rv3d->depths)
- ED_view3d_depth_read_cached_seg was created to replace ED_view3d_autodist_depth_seg and use the depth buffer salved in cache (rv3d->depths)
- GreasePencil and Anotations operations now use the depth buffer salved in cache
- The BLI_array_iter_nearest_to_point_v2 utility has been created. It is used to find closest values to a point in the selection buffer and the depth buffer
- The V3D_INVALID_BACKBUF flag has been replaced with V3D_RUNTIME_DEPTHBUF_OVERRIDDEN
