diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-01-24 23:13:02 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-01-24 23:13:02 +0300 |
commit | 6d8394d38b17e602535c75a866332f4427adbfad (patch) | |
tree | c583181880d07af3f07e6e0164239c730ff90885 /source/blender/draw/intern | |
parent | a4fe338dd8c6822d27b8858bae5fa9a54972719c (diff) |
DRW: support clipping for camera objects
Diffstat (limited to 'source/blender/draw/intern')
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 10 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_builtin_shader.c | 11 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.c | 9 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_common.h | 12 |
4 files changed, 28 insertions, 14 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 395d9483deb..884b35c4acb 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -94,16 +94,6 @@ typedef struct BoundSphere { float center[3], radius; } BoundSphere; -/** - * Support selecting shaders with different options compiled in. - * Needed for clipping support because it means using a separate set of shaders. - */ -typedef enum eDRW_ShaderSlot { - DRW_SHADER_SLOT_DEFAULT = 0, - DRW_SHADER_SLOT_CLIPPED = 1, -} eDRW_ShaderSlot; -#define DRW_SHADER_SLOT_LEN 2 - /* declare members as empty (unused) */ typedef char DRWViewportEmptyList; diff --git a/source/blender/draw/intern/draw_builtin_shader.c b/source/blender/draw/intern/draw_builtin_shader.c index 5c0c005cb9d..6a70b91d67a 100644 --- a/source/blender/draw/intern/draw_builtin_shader.c +++ b/source/blender/draw/intern/draw_builtin_shader.c @@ -44,6 +44,8 @@ extern char datatoc_drw_shader_3D_smooth_color_vert_glsl[]; extern char datatoc_gpu_shader_uniform_color_frag_glsl[]; extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[]; extern char datatoc_gpu_shader_depth_only_frag_glsl[]; +extern char datatoc_gpu_shader_flat_color_frag_glsl[]; +extern char datatoc_gpu_shader_instance_camera_vert_glsl[]; /* cache of built-in shaders (each is created on first use) */ static struct { @@ -88,6 +90,15 @@ static GPUShader *drw_shader_get_builtin_shader_clipped(eGPUBuiltinShader shader .frag = (const char *[]){datatoc_gpu_shader_depth_only_frag_glsl, NULL}, .defs = (const char *[]){world_clip_def, NULL}}); break; + case GPU_SHADER_CAMERA: + if (r_test_only) { + break; + } + shader = DRW_shader_create_from_arrays({ + .vert = (const char *[]){world_clip_lib, datatoc_gpu_shader_instance_camera_vert_glsl, NULL}, + .frag = (const char *[]){datatoc_gpu_shader_flat_color_frag_glsl, NULL}, + .defs = (const char *[]){world_clip_def, NULL}}); + break; default: /* Unsupported, caller asserts. */ if (r_test_only) { diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index 437e6f63095..e7a129071b6 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -38,6 +38,7 @@ #include "BKE_colorband.h" #include "draw_common.h" +#include "draw_builtin_shader.h" #if 0 #define UI_COLOR_RGB_FROM_U8(r, g, b, v4) \ @@ -515,9 +516,9 @@ DRWShadingGroup *shgroup_instance_outline(DRWPass *pass, struct GPUBatch *geom, return grp; } -DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct GPUBatch *geom) +DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot) { - GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_CAMERA); + GPUShader *sh_inst = DRW_shader_get_builtin_shader(GPU_SHADER_CAMERA, shader_slot); DRW_shgroup_instance_format(g_formats.instance_camera, { {"color", DRW_ATTRIB_FLOAT, 3}, @@ -528,7 +529,9 @@ DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct GPUBatch *geom) }); DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_camera); - + if (shader_slot == DRW_SHADER_SLOT_CLIPPED) { + DRW_shgroup_world_clip_planes_from_rv3d(grp, DRW_context_state_get()->rv3d); + } return grp; } diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index 854a8abbea9..2190db8bf31 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -39,6 +39,16 @@ struct ModifierData; struct ParticleSystem; struct PTCacheEdit; +/** + * Support selecting shaders with different options compiled in. + * Needed for clipping support because it means using a separate set of shaders. + */ +typedef enum eDRW_ShaderSlot { + DRW_SHADER_SLOT_DEFAULT = 0, + DRW_SHADER_SLOT_CLIPPED = 1, +} eDRW_ShaderSlot; +#define DRW_SHADER_SLOT_LEN 2 + #define UBO_FIRST_COLOR colorWire #define UBO_LAST_COLOR colorGridAxisZ @@ -144,7 +154,7 @@ struct DRWShadingGroup *shgroup_instance_scaled(struct DRWPass *pass, struct GPU struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct GPUBatch *geom); struct DRWShadingGroup *shgroup_instance_alpha(struct DRWPass *pass, struct GPUBatch *geom); struct DRWShadingGroup *shgroup_instance_outline(struct DRWPass *pass, struct GPUBatch *geom, int *baseid); -struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct GPUBatch *geom); +struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct GPUBatch *geom, eDRW_ShaderSlot shader_slot); struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct GPUBatch *geom); struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct GPUBatch *geom); struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass); |