Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache.c
| Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | static struct DRWShapeCache { | ||||
| Gwn_Batch *drw_bone_arrows; | Gwn_Batch *drw_bone_arrows; | ||||
| Gwn_Batch *drw_camera; | Gwn_Batch *drw_camera; | ||||
| Gwn_Batch *drw_camera_frame; | Gwn_Batch *drw_camera_frame; | ||||
| Gwn_Batch *drw_camera_tria; | Gwn_Batch *drw_camera_tria; | ||||
| Gwn_Batch *drw_camera_focus; | Gwn_Batch *drw_camera_focus; | ||||
| Gwn_Batch *drw_particle_cross; | Gwn_Batch *drw_particle_cross; | ||||
| Gwn_Batch *drw_particle_circle; | Gwn_Batch *drw_particle_circle; | ||||
| Gwn_Batch *drw_particle_axis; | Gwn_Batch *drw_particle_axis; | ||||
| Gwn_Batch *drw_gpencil_axes; | |||||
| } SHC = {NULL}; | } SHC = {NULL}; | ||||
| void DRW_shape_cache_free(void) | void DRW_shape_cache_free(void) | ||||
| { | { | ||||
| uint i = sizeof(SHC) / sizeof(Gwn_Batch *); | uint i = sizeof(SHC) / sizeof(Gwn_Batch *); | ||||
| Gwn_Batch **batch = (Gwn_Batch **)&SHC; | Gwn_Batch **batch = (Gwn_Batch **)&SHC; | ||||
| while (i--) { | while (i--) { | ||||
| GWN_BATCH_DISCARD_SAFE(*batch); | GWN_BATCH_DISCARD_SAFE(*batch); | ||||
| ▲ Show 20 Lines • Show All 379 Lines • ▼ Show 20 Lines | if (!SHC.drw_screenspace_circle) { | ||||
| } | } | ||||
| SHC.drw_screenspace_circle = GWN_batch_create_ex(GWN_PRIM_LINE_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO); | SHC.drw_screenspace_circle = GWN_batch_create_ex(GWN_PRIM_LINE_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO); | ||||
| } | } | ||||
| return SHC.drw_screenspace_circle; | return SHC.drw_screenspace_circle; | ||||
| #undef CIRCLE_RESOL | #undef CIRCLE_RESOL | ||||
| } | } | ||||
| /** \} */ | /* Grease Pencil object */ | ||||
| Gwn_Batch *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 } | |||||
campbellbarton: Seems arbitrary? should it be 24? Use `ARRAY_SIZE(indices)` | |||||
| }; | |||||
| 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 Gwn_VertFormat format = { 0 }; | |||||
| static unsigned pos_id; | |||||
| if (format.attrib_ct == 0) { | |||||
| pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); | |||||
| } | |||||
| Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format); | |||||
| /* alloc 30 elements for cube and 3 axis */ | |||||
| GWN_vertbuf_data_alloc(vbo, ARRAY_SIZE(indices) + 6); | |||||
| /* draw axis */ | |||||
| for (axis = 0; axis < 3; axis++) { | |||||
| v1[axis] = 1.0f; | |||||
| v2[axis] = -1.0f; | |||||
| GWN_vertbuf_attr_set(vbo, pos_id, axis * 2, v1); | |||||
| GWN_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) { | |||||
| GWN_vertbuf_attr_set(vbo, pos_id, i + 6, verts[indices[i]]); | |||||
| } | |||||
| SHC.drw_gpencil_axes = GWN_batch_create(GWN_PRIM_LINES, vbo, NULL); | |||||
| } | |||||
| return SHC.drw_gpencil_axes; | |||||
| } | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Common Object API | /** \name Common Object API | ||||
| * \{ */ | * \{ */ | ||||
| Gwn_Batch *DRW_cache_object_wire_outline_get(Object *ob) | Gwn_Batch *DRW_cache_object_wire_outline_get(Object *ob) | ||||
| { | { | ||||
| switch (ob->type) { | switch (ob->type) { | ||||
| case OB_MESH: | case OB_MESH: | ||||
| return DRW_cache_mesh_wire_outline_get(ob); | return DRW_cache_mesh_wire_outline_get(ob); | ||||
| /* TODO, should match 'DRW_cache_object_surface_get' */ | /* TODO, should match 'DRW_cache_object_surface_get' */ | ||||
| ▲ Show 20 Lines • Show All 2,698 Lines • Show Last 20 Lines | |||||
Seems arbitrary? should it be 24? Use ARRAY_SIZE(indices)