Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache.c
| Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | static struct DRWShapeCache { | ||||
| GPUBatch *drw_bone_arrows; | GPUBatch *drw_bone_arrows; | ||||
| GPUBatch *drw_camera; | GPUBatch *drw_camera; | ||||
| GPUBatch *drw_camera_frame; | GPUBatch *drw_camera_frame; | ||||
| GPUBatch *drw_camera_tria; | GPUBatch *drw_camera_tria; | ||||
| GPUBatch *drw_camera_focus; | GPUBatch *drw_camera_focus; | ||||
| GPUBatch *drw_particle_cross; | GPUBatch *drw_particle_cross; | ||||
| GPUBatch *drw_particle_circle; | GPUBatch *drw_particle_circle; | ||||
| GPUBatch *drw_particle_axis; | GPUBatch *drw_particle_axis; | ||||
| GPUBatch *drw_gpencil_axes; | |||||
| } SHC = {NULL}; | } SHC = {NULL}; | ||||
| void DRW_shape_cache_free(void) | void DRW_shape_cache_free(void) | ||||
| { | { | ||||
| uint i = sizeof(SHC) / sizeof(GPUBatch *); | uint i = sizeof(SHC) / sizeof(GPUBatch *); | ||||
| GPUBatch **batch = (GPUBatch **)&SHC; | GPUBatch **batch = (GPUBatch **)&SHC; | ||||
| while (i--) { | while (i--) { | ||||
| GPU_BATCH_DISCARD_SAFE(*batch); | GPU_BATCH_DISCARD_SAFE(*batch); | ||||
| ▲ Show 20 Lines • Show All 389 Lines • ▼ Show 20 Lines | if (!SHC.drw_line_endpoints) { | ||||
| /* Position Only 3D format */ | /* Position Only 3D format */ | ||||
| static GPUVertFormat format = { 0 }; | static GPUVertFormat format = { 0 }; | ||||
| static struct { uint pos; } attr_id; | static struct { uint pos; } attr_id; | ||||
| if (format.attr_len == 0) { | if (format.attr_len == 0) { | ||||
| attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| } | } | ||||
| GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format); | GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format); | ||||
campbellbarton: Seems arbitrary? should it be 24? Use `ARRAY_SIZE(indices)` | |||||
| GPU_vertbuf_data_alloc(vbo, 2); | GPU_vertbuf_data_alloc(vbo, 2); | ||||
| GPU_vertbuf_attr_set(vbo, attr_id.pos, 0, v1); | GPU_vertbuf_attr_set(vbo, attr_id.pos, 0, v1); | ||||
| GPU_vertbuf_attr_set(vbo, attr_id.pos, 1, v2); | GPU_vertbuf_attr_set(vbo, attr_id.pos, 1, v2); | ||||
| SHC.drw_line_endpoints = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO); | SHC.drw_line_endpoints = GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO); | ||||
| } | } | ||||
| return SHC.drw_line_endpoints; | return SHC.drw_line_endpoints; | ||||
| Show All 22 Lines | if (!SHC.drw_screenspace_circle) { | ||||
| } | } | ||||
| SHC.drw_screenspace_circle = GPU_batch_create_ex(GPU_PRIM_LINE_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO); | SHC.drw_screenspace_circle = GPU_batch_create_ex(GPU_PRIM_LINE_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO); | ||||
| } | } | ||||
| return SHC.drw_screenspace_circle; | return SHC.drw_screenspace_circle; | ||||
| #undef CIRCLE_RESOL | #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 | /** \name Common Object API | ||||
| * \{ */ | * \{ */ | ||||
| GPUBatch *DRW_cache_object_wire_outline_get(Object *ob) | GPUBatch *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,836 Lines • Show Last 20 Lines | |||||
Seems arbitrary? should it be 24? Use ARRAY_SIZE(indices)