diff options
Diffstat (limited to 'source/blender/draw/intern/draw_cache.c')
-rw-r--r-- | source/blender/draw/intern/draw_cache.c | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index bdfa3211f7c..ac84a847a1b 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -107,6 +107,7 @@ static struct DRWShapeCache { GPUBatch *drw_particle_cross; GPUBatch *drw_particle_circle; GPUBatch *drw_particle_axis; + GPUBatch *drw_gpencil_axes; } SHC = {NULL}; void DRW_shape_cache_free(void) @@ -551,12 +552,67 @@ GPUBatch *DRW_cache_screenspace_circle_get(void) #undef CIRCLE_RESOL } -/** \} */ +/* Grease Pencil object */ +GPUBatch *DRW_cache_gpencil_axes_get(void) +{ + if (!SHC.drw_gpencil_axes) { + int axis; + float v1[3] = { 0.0f, 0.0f, 0.0f }; + float v2[3] = { 0.0f, 0.0f, 0.0f }; + + /* cube data */ + const GLfloat verts[8][3] = { + { -0.25f, -0.25f, -0.25f }, + { -0.25f, -0.25f, 0.25f }, + { -0.25f, 0.25f, -0.25f }, + { -0.25f, 0.25f, 0.25f }, + { 0.25f, -0.25f, -0.25f }, + { 0.25f, -0.25f, 0.25f }, + { 0.25f, 0.25f, -0.25f }, + { 0.25f, 0.25f, 0.25f } + }; + + const GLubyte indices[24] = { 0, 1, 1, 3, 3, 2, 2, 0, 0, 4, 4, 5, 5, 7, 7, 6, 6, 4, 1, 5, 3, 7, 2, 6 }; + + /* Position Only 3D format */ + static GPUVertFormat format = { 0 }; + static uint pos_id; + if (format.attr_len == 0) { + pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); + } + + GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format); + + /* alloc 30 elements for cube and 3 axis */ + GPU_vertbuf_data_alloc(vbo, ARRAY_SIZE(indices) + 6); + + /* draw axis */ + for (axis = 0; axis < 3; axis++) { + v1[axis] = 1.0f; + v2[axis] = -1.0f; + + GPU_vertbuf_attr_set(vbo, pos_id, axis * 2, v1); + GPU_vertbuf_attr_set(vbo, pos_id, axis * 2 + 1, v2); + + /* reset v1 & v2 to zero for next axis */ + v1[axis] = v2[axis] = 0.0f; + } + + /* draw cube */ + for (int i = 0; i < 24; ++i) { + GPU_vertbuf_attr_set(vbo, pos_id, i + 6, verts[indices[i]]); + } + + SHC.drw_gpencil_axes = GPU_batch_create(GPU_PRIM_LINES, vbo, NULL); + } + return SHC.drw_gpencil_axes; +} + /* -------------------------------------------------------------------- */ /** \name Common Object API - * \{ */ +* \{ */ GPUBatch *DRW_cache_object_wire_outline_get(Object *ob) { |