diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-04-13 16:29:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-04-13 21:34:12 +0300 |
commit | 02273441dc2cebab122d6f6d1b0642a500a67409 (patch) | |
tree | bdcdf4d9ff8a1438704fc426f0d1dc859dee2437 /source/blender/draw/modes | |
parent | 1c01811cce00b799ee94aad24083ddf3954a5829 (diff) |
Draw Manager: lattice editmode drawing
Diffstat (limited to 'source/blender/draw/modes')
3 files changed, 100 insertions, 14 deletions
diff --git a/source/blender/draw/modes/edit_lattice_mode.c b/source/blender/draw/modes/edit_lattice_mode.c index ea6dbb65475..b641b22186a 100644 --- a/source/blender/draw/modes/edit_lattice_mode.c +++ b/source/blender/draw/modes/edit_lattice_mode.c @@ -39,6 +39,14 @@ extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ extern struct GlobalsUboStorage ts; /* draw_common.c */ +extern char datatoc_common_globals_lib_glsl[]; +extern char datatoc_edit_lattice_overlay_loosevert_vert_glsl[]; +extern char datatoc_edit_lattice_overlay_frag_glsl[]; + +extern char datatoc_gpu_shader_3D_vert_glsl[]; +extern char datatoc_gpu_shader_uniform_color_frag_glsl[]; +extern char datatoc_gpu_shader_point_uniform_color_frag_glsl[]; + /* *********** LISTS *********** */ /* All lists are per viewport specific datas. * They are all free when viewport changes engines @@ -50,7 +58,8 @@ typedef struct EDIT_LATTICE_PassList { /* Declare all passes here and init them in * EDIT_LATTICE_cache_init(). * Only contains (DRWPass *) */ - struct DRWPass *pass; + struct DRWPass *wire_pass; + struct DRWPass *vert_pass; } EDIT_LATTICE_PassList; typedef struct EDIT_LATTICE_FramebufferList { @@ -93,7 +102,10 @@ static struct { * Add sources to source/blender/draw/modes/shaders * init in EDIT_LATTICE_engine_init(); * free in EDIT_LATTICE_engine_free(); */ - struct GPUShader *custom_shader; + struct GPUShader *wire_sh; + + struct GPUShader *overlay_vert_sh; + } e_data = {NULL}; /* Engine data */ typedef struct g_data { @@ -131,8 +143,15 @@ static void EDIT_LATTICE_engine_init(void *vedata) * tex, 2); */ - if (!e_data.custom_shader) { - e_data.custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + if (!e_data.wire_sh) { + e_data.wire_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR); + } + + if (!e_data.overlay_vert_sh) { + e_data.overlay_vert_sh = DRW_shader_create_with_lib( + datatoc_edit_lattice_overlay_loosevert_vert_glsl, NULL, + datatoc_edit_lattice_overlay_frag_glsl, + datatoc_common_globals_lib_glsl, NULL); } } @@ -149,16 +168,17 @@ static void EDIT_LATTICE_cache_init(void *vedata) } { - /* Create a pass */ - DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE; - psl->pass = DRW_pass_create("My Pass", state); + psl->wire_pass = DRW_pass_create( + "Lattice Wire", + DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE); - stl->g_data->wire_shgrp = DRW_shgroup_create(e_data.custom_shader, psl->pass); + stl->g_data->wire_shgrp = DRW_shgroup_create(e_data.wire_sh, psl->wire_pass); - DRW_shgroup_uniform_vec4(stl->g_data->wire_shgrp, "color", ts.colorWireEdit, 1); + psl->vert_pass = DRW_pass_create( + "Lattice Verts", + DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH); - stl->g_data->vert_shgrp = DRW_shgroup_create(e_data.custom_shader, psl->pass); - DRW_shgroup_uniform_vec4(stl->g_data->vert_shgrp, "color", ts.colorVertexSelect, 1); + stl->g_data->vert_shgrp = DRW_shgroup_create(e_data.overlay_vert_sh, psl->vert_pass); } } @@ -181,7 +201,7 @@ static void EDIT_LATTICE_cache_populate(void *vedata, Object *ob) geom = DRW_cache_lattice_wire_get(ob); DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat); - geom = DRW_cache_lattice_verts_get(ob); + geom = DRW_cache_lattice_vert_overlay_get(ob); DRW_shgroup_call_add(stl->g_data->vert_shgrp, geom, ob->obmat); } } @@ -219,7 +239,8 @@ static void EDIT_LATTICE_draw_scene(void *vedata) */ /* ... or just render passes on default framebuffer. */ - DRW_draw_pass(psl->pass); + DRW_draw_pass(psl->wire_pass); + DRW_draw_pass(psl->vert_pass); /* If you changed framebuffer, double check you rebind * the default one with its textures attached before finishing */ @@ -231,7 +252,7 @@ static void EDIT_LATTICE_draw_scene(void *vedata) static void EDIT_LATTICE_engine_free(void) { // Currently built-in, dont free - // DRW_SHADER_FREE_SAFE(e_data.custom_shader); + DRW_SHADER_FREE_SAFE(e_data.overlay_vert_sh); } /* Create collection settings here. diff --git a/source/blender/draw/modes/shaders/edit_lattice_overlay_frag.glsl b/source/blender/draw/modes/shaders/edit_lattice_overlay_frag.glsl new file mode 100644 index 00000000000..57e96143c75 --- /dev/null +++ b/source/blender/draw/modes/shaders/edit_lattice_overlay_frag.glsl @@ -0,0 +1,26 @@ + +flat in int vertFlag; + +#define VERTEX_SELECTED (1 << 0) +#define VERTEX_ACTIVE (1 << 1) + +#if __VERSION__ == 120 + #define FragColor gl_FragColor +#else + out vec4 FragColor; +#endif + +void main() +{ + /* TODO: vertex size */ + + if ((vertFlag & VERTEX_SELECTED) != 0) { + FragColor = colorVertexSelect; + } + else if ((vertFlag & VERTEX_ACTIVE) != 0) { + FragColor = colorEditMeshActive; + } + else { + FragColor = colorVertex; + } +} diff --git a/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl b/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl new file mode 100644 index 00000000000..d3fc56d1ee9 --- /dev/null +++ b/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl @@ -0,0 +1,39 @@ + +/* Draw Lattice Vertices */ + +uniform mat4 ModelViewProjectionMatrix; +uniform vec2 viewportSize; + +in vec3 pos; +in int data; + +/* these are the same for all vertices + * and does not need interpolation */ +flat out int vertFlag; +flat out int clipCase; + +/* See fragment shader */ +noperspective out vec4 eData1; +flat out vec4 eData2; + +/* project to screen space */ +vec2 proj(vec4 pos) +{ + return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize; +} + +void main() +{ + clipCase = 0; + + vec4 pPos = ModelViewProjectionMatrix * vec4(pos, 1.0); + + /* only verterx position 0 is used */ + eData1 = eData2 = vec4(1e10); + eData2.zw = proj(pPos); + + vertFlag = data; + + gl_PointSize = sizeEdgeFix; + gl_Position = pPos; +} |