diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-02-15 04:54:52 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-02-15 14:28:26 +0300 |
commit | 9f03718a5bdf77137c308a3c76c83254b33f7cca (patch) | |
tree | 02a572bd525ad61df69cd38e6e7713abb8d22518 /source/blender/draw | |
parent | ee2a71876308c891d19cb7df87ef85e2321d0420 (diff) |
Clay Engine: drawaxis names drawn with shaders & instance
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/intern/draw_cache.c | 64 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache.h | 1 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_mode_pass.c | 28 |
3 files changed, 83 insertions, 10 deletions
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index dfb7ff22639..6ebb9008b67 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -48,6 +48,7 @@ static struct DRWShapeCache{ Batch *drw_empty_sphere; Batch *drw_empty_cone; Batch *drw_arrows; + Batch *drw_axis_names; Batch *drw_lamp; Batch *drw_lamp_sunrays; } SHC = {NULL}; @@ -74,6 +75,8 @@ void DRW_shape_cache_free(void) Batch_discard_all(SHC.drw_empty_cone); if (SHC.drw_arrows) Batch_discard_all(SHC.drw_arrows); + if (SHC.drw_axis_names) + Batch_discard_all(SHC.drw_axis_names); if (SHC.drw_lamp) Batch_discard_all(SHC.drw_lamp); if (SHC.drw_lamp_sunrays) @@ -420,6 +423,67 @@ Batch *DRW_cache_arrows_get(void) return SHC.drw_arrows; } +Batch *DRW_cache_axis_names_get(void) +{ + if (!SHC.drw_axis_names) { + const float size = 0.1f; + float v1[3], v2[3]; + + /* Position Only 3D format */ + static VertexFormat format = { 0 }; + static unsigned pos_id; + if (format.attrib_ct == 0) { + /* Using 3rd component as axis indicator */ + pos_id = add_attrib(&format, "pos", GL_FLOAT, 3, KEEP_FLOAT); + } + + /* Line */ + VertexBuffer *vbo = VertexBuffer_create_with_format(&format); + VertexBuffer_allocate_data(vbo, 14); + + /* X */ + copy_v3_fl3(v1, -size, size, 0.0f); + copy_v3_fl3(v2, size, -size, 0.0f); + setAttrib(vbo, pos_id, 0, v1); + setAttrib(vbo, pos_id, 1, v2); + + copy_v3_fl3(v1, size, size, 0.0f); + copy_v3_fl3(v2, -size, -size, 0.0f); + setAttrib(vbo, pos_id, 2, v1); + setAttrib(vbo, pos_id, 3, v2); + + /* Y */ + copy_v3_fl3(v1, -size + 0.25f * size, size, 1.0f); + copy_v3_fl3(v2, 0.0f, 0.0f, 1.0f); + setAttrib(vbo, pos_id, 4, v1); + setAttrib(vbo, pos_id, 5, v2); + + copy_v3_fl3(v1, size - 0.25f * size, size, 1.0f); + copy_v3_fl3(v2, -size + 0.25f * size, -size, 1.0f); + setAttrib(vbo, pos_id, 6, v1); + setAttrib(vbo, pos_id, 7, v2); + + /* Z */ + copy_v3_fl3(v1, -size, size, 2.0f); + copy_v3_fl3(v2, size, size, 2.0f); + setAttrib(vbo, pos_id, 8, v1); + setAttrib(vbo, pos_id, 9, v2); + + copy_v3_fl3(v1, size, size, 2.0f); + copy_v3_fl3(v2, -size, -size, 2.0f); + setAttrib(vbo, pos_id, 10, v1); + setAttrib(vbo, pos_id, 11, v2); + + copy_v3_fl3(v1, -size, -size, 2.0f); + copy_v3_fl3(v2, size, -size, 2.0f); + setAttrib(vbo, pos_id, 12, v1); + setAttrib(vbo, pos_id, 13, v2); + + SHC.drw_axis_names = Batch_create(GL_LINES, vbo, NULL); + } + return SHC.drw_axis_names; +} + /* Lamps */ Batch *DRW_cache_lamp_get(void) { diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h index 0e467bddbfa..b101b00473f 100644 --- a/source/blender/draw/intern/draw_cache.h +++ b/source/blender/draw/intern/draw_cache.h @@ -44,6 +44,7 @@ struct Batch *DRW_cache_circle_get(void); struct Batch *DRW_cache_empty_sphere_get(void); struct Batch *DRW_cache_empty_cone_get(void); struct Batch *DRW_cache_arrows_get(void); +struct Batch *DRW_cache_axis_names_get(void); /* Lamps */ struct Batch *DRW_cache_lamp_get(void); diff --git a/source/blender/draw/intern/draw_mode_pass.c b/source/blender/draw/intern/draw_mode_pass.c index e1a6ff34c13..7ad00fffcd9 100644 --- a/source/blender/draw/intern/draw_mode_pass.c +++ b/source/blender/draw/intern/draw_mode_pass.c @@ -48,6 +48,7 @@ static DRWShadingGroup *cone; static DRWShadingGroup *single_arrow; static DRWShadingGroup *single_arrow_line; static DRWShadingGroup *arrows; +static DRWShadingGroup *axis_names; /* Lamps */ static DRWShadingGroup *lamp_center; @@ -130,6 +131,19 @@ static DRWShadingGroup *shgroup_instance_screenspace(DRWPass *pass, struct Batch return grp; } +static DRWShadingGroup *shgroup_instance_axis_names(DRWPass *pass, struct Batch *geom) +{ + GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SCREENSPACE_AXIS); + + DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom); + DRW_shgroup_attrib_float(grp, "color", 3); + DRW_shgroup_attrib_float(grp, "size", 1); + DRW_shgroup_attrib_float(grp, "InstanceModelMatrix", 16); + DRW_shgroup_uniform_vec3(grp, "screen_vecs", DRW_viewport_screenvecs_get(), 2); + + return grp; +} + static DRWShadingGroup *shgroup_instance(DRWPass *pass, struct Batch *geom) { GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE); @@ -211,6 +225,9 @@ void DRW_pass_setup_common(DRWPass **wire_overlay, DRWPass **wire_outline, DRWPa geom = DRW_cache_arrows_get(); arrows = shgroup_instance(*non_meshes, geom); + geom = DRW_cache_axis_names_get(); + axis_names = shgroup_instance_axis_names(*non_meshes, geom); + /* Lamps */ lampCenterSize = (U.obcenter_dia + 1.5f) * U.pixelsize; lampCircleRad = U.pixelsize * 9.0f; @@ -231,16 +248,6 @@ void DRW_pass_setup_common(DRWPass **wire_overlay, DRWPass **wire_outline, DRWPa lamp_groundline = shgroup_groundlines_uniform_color(*non_meshes, colorLamp); lamp_groundpoint = shgroup_groundpoints_uniform_color(*non_meshes, colorLamp); - /* Stipple Wires */ - grp = DRW_shgroup_create(sh, *non_meshes); - DRW_shgroup_state_set(grp, DRW_STATE_STIPPLE_2); - - grp = DRW_shgroup_create(sh, *non_meshes); - DRW_shgroup_state_set(grp, DRW_STATE_STIPPLE_3); - - grp = DRW_shgroup_create(sh, *non_meshes); - DRW_shgroup_state_set(grp, DRW_STATE_STIPPLE_4); - /* Relationship Lines */ relationship_lines = shgroup_dynlines_uniform_color(*non_meshes, colorWire); DRW_shgroup_state_set(relationship_lines, DRW_STATE_STIPPLE_3); @@ -502,6 +509,7 @@ static void DRW_draw_empty(Object *ob) break; case OB_ARROWS: DRW_shgroup_dynamic_call_add(arrows, color, &ob->empty_drawsize, ob->obmat); + DRW_shgroup_dynamic_call_add(axis_names, color, &ob->empty_drawsize, ob->obmat); /* TODO Missing axes names */ break; } |