Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_sequencer/sequencer_draw.c
| Show First 20 Lines • Show All 1,962 Lines • ▼ Show 20 Lines | static void seq_draw_sfra_efra(Scene *scene, View2D *v2d) | ||||
| GPU_blend(false); | GPU_blend(false); | ||||
| } | } | ||||
| typedef struct CacheDrawData { | typedef struct CacheDrawData { | ||||
| struct View2D *v2d; | struct View2D *v2d; | ||||
| float stripe_offs; | float stripe_offs; | ||||
| float stripe_ht; | float stripe_ht; | ||||
| int cache_flag; | |||||
| GPUVertBuf *raw_vbo; | GPUVertBuf *raw_vbo; | ||||
| GPUVertBuf *preprocessed_vbo; | GPUVertBuf *preprocessed_vbo; | ||||
| GPUVertBuf *composite_vbo; | GPUVertBuf *composite_vbo; | ||||
| GPUVertBuf *final_out_vbo; | GPUVertBuf *final_out_vbo; | ||||
| size_t raw_vert_count; | size_t raw_vert_count; | ||||
| size_t preprocessed_vert_count; | size_t preprocessed_vert_count; | ||||
| size_t composite_vert_count; | size_t composite_vert_count; | ||||
| size_t final_out_vert_count; | size_t final_out_vert_count; | ||||
| } CacheDrawData; | } CacheDrawData; | ||||
| /* Called as a callback */ | /* Called as a callback */ | ||||
| static bool draw_cache_view_cb( | static bool draw_cache_view_init_cb(void *userdata, size_t item_count) | ||||
| { | |||||
| if (item_count == 0) { | |||||
| return true; | |||||
| } | |||||
| CacheDrawData *drawdata = userdata; | |||||
| /* We can not get item count per cache type, so using total item count is safe. */ | |||||
| size_t max_vert_count = item_count * 6; | |||||
| GPU_vertbuf_data_alloc(drawdata->raw_vbo, max_vert_count); | |||||
| GPU_vertbuf_data_alloc(drawdata->preprocessed_vbo, max_vert_count); | |||||
| GPU_vertbuf_data_alloc(drawdata->composite_vbo, max_vert_count); | |||||
| GPU_vertbuf_data_alloc(drawdata->final_out_vbo, max_vert_count); | |||||
| return false; | |||||
| } | |||||
| /* Called as a callback */ | |||||
| static bool draw_cache_view_iter_cb( | |||||
| void *userdata, struct Sequence *seq, int nfra, int cache_type, float UNUSED(cost)) | void *userdata, struct Sequence *seq, int nfra, int cache_type, float UNUSED(cost)) | ||||
| { | { | ||||
| CacheDrawData *drawdata = userdata; | CacheDrawData *drawdata = userdata; | ||||
| struct View2D *v2d = drawdata->v2d; | struct View2D *v2d = drawdata->v2d; | ||||
| float stripe_bot, stripe_top, stripe_offs, stripe_ht; | float stripe_bot, stripe_top, stripe_offs, stripe_ht; | ||||
| GPUVertBuf *vbo; | GPUVertBuf *vbo; | ||||
| size_t *vert_count; | size_t *vert_count; | ||||
| switch (cache_type) { | |||||
| case SEQ_CACHE_STORE_FINAL_OUT: | if ((cache_type & SEQ_CACHE_STORE_FINAL_OUT) && | ||||
| (drawdata->cache_flag & SEQ_CACHE_VIEW_FINAL_OUT)) { | |||||
| stripe_ht = UI_view2d_region_to_view_y(v2d, 4.0f * UI_DPI_FAC * U.pixelsize) - v2d->cur.ymin; | stripe_ht = UI_view2d_region_to_view_y(v2d, 4.0f * UI_DPI_FAC * U.pixelsize) - v2d->cur.ymin; | ||||
| stripe_bot = UI_view2d_region_to_view_y(v2d, V2D_SCROLL_HANDLE_HEIGHT); | stripe_bot = UI_view2d_region_to_view_y(v2d, V2D_SCROLL_HANDLE_HEIGHT); | ||||
| stripe_top = stripe_bot + stripe_ht; | stripe_top = stripe_bot + stripe_ht; | ||||
| vbo = drawdata->final_out_vbo; | vbo = drawdata->final_out_vbo; | ||||
| vert_count = &drawdata->final_out_vert_count; | vert_count = &drawdata->final_out_vert_count; | ||||
| break; | } | ||||
| else if ((cache_type & SEQ_CACHE_STORE_RAW) && (drawdata->cache_flag & SEQ_CACHE_VIEW_RAW)) { | |||||
| case SEQ_CACHE_STORE_RAW: | |||||
| stripe_offs = drawdata->stripe_offs; | stripe_offs = drawdata->stripe_offs; | ||||
| stripe_ht = drawdata->stripe_ht; | stripe_ht = drawdata->stripe_ht; | ||||
| stripe_bot = seq->machine + SEQ_STRIP_OFSBOTTOM + stripe_offs; | stripe_bot = seq->machine + SEQ_STRIP_OFSBOTTOM + stripe_offs; | ||||
| stripe_top = stripe_bot + stripe_ht; | stripe_top = stripe_bot + stripe_ht; | ||||
| vbo = drawdata->raw_vbo; | vbo = drawdata->raw_vbo; | ||||
| vert_count = &drawdata->raw_vert_count; | vert_count = &drawdata->raw_vert_count; | ||||
| break; | } | ||||
| else if ((cache_type & SEQ_CACHE_STORE_PREPROCESSED) && | |||||
| case SEQ_CACHE_STORE_PREPROCESSED: | (drawdata->cache_flag & SEQ_CACHE_VIEW_PREPROCESSED)) { | ||||
| stripe_offs = drawdata->stripe_offs; | stripe_offs = drawdata->stripe_offs; | ||||
| stripe_ht = drawdata->stripe_ht; | stripe_ht = drawdata->stripe_ht; | ||||
| stripe_bot = seq->machine + SEQ_STRIP_OFSBOTTOM + (stripe_offs + stripe_ht) + stripe_offs; | stripe_bot = seq->machine + SEQ_STRIP_OFSBOTTOM + (stripe_offs + stripe_ht) + stripe_offs; | ||||
| stripe_top = stripe_bot + stripe_ht; | stripe_top = stripe_bot + stripe_ht; | ||||
| vbo = drawdata->preprocessed_vbo; | vbo = drawdata->preprocessed_vbo; | ||||
| vert_count = &drawdata->preprocessed_vert_count; | vert_count = &drawdata->preprocessed_vert_count; | ||||
| break; | } | ||||
| else if ((cache_type & SEQ_CACHE_STORE_COMPOSITE) && | |||||
| case SEQ_CACHE_STORE_COMPOSITE: | (drawdata->cache_flag & SEQ_CACHE_VIEW_COMPOSITE)) { | ||||
| stripe_offs = drawdata->stripe_offs; | stripe_offs = drawdata->stripe_offs; | ||||
| stripe_ht = drawdata->stripe_ht; | stripe_ht = drawdata->stripe_ht; | ||||
| stripe_top = seq->machine + SEQ_STRIP_OFSTOP - stripe_offs; | stripe_top = seq->machine + SEQ_STRIP_OFSTOP - stripe_offs; | ||||
| stripe_bot = stripe_top - stripe_ht; | stripe_bot = stripe_top - stripe_ht; | ||||
| vbo = drawdata->composite_vbo; | vbo = drawdata->composite_vbo; | ||||
| vert_count = &drawdata->composite_vert_count; | vert_count = &drawdata->composite_vert_count; | ||||
| break; | } | ||||
| else { | |||||
| default: | return false; | ||||
| return true; | |||||
| } | } | ||||
| int cfra = seq->start + nfra; | int cfra = seq->start + nfra; | ||||
| float vert_pos[6][2]; | float vert_pos[6][2]; | ||||
| copy_v2_fl2(vert_pos[0], cfra, stripe_bot); | copy_v2_fl2(vert_pos[0], cfra, stripe_bot); | ||||
| copy_v2_fl2(vert_pos[1], cfra, stripe_top); | copy_v2_fl2(vert_pos[1], cfra, stripe_top); | ||||
| copy_v2_fl2(vert_pos[2], cfra + 1, stripe_top); | copy_v2_fl2(vert_pos[2], cfra + 1, stripe_top); | ||||
| copy_v2_v2(vert_pos[3], vert_pos[2]); | copy_v2_v2(vert_pos[3], vert_pos[2]); | ||||
| copy_v2_v2(vert_pos[4], vert_pos[0]); | copy_v2_v2(vert_pos[4], vert_pos[0]); | ||||
| copy_v2_fl2(vert_pos[5], cfra + 1, stripe_bot); | copy_v2_fl2(vert_pos[5], cfra + 1, stripe_bot); | ||||
| for (int i = 0; i < 6; i++) { | for (int i = 0; i < 6; i++) { | ||||
| GPU_vertbuf_vert_set(vbo, *vert_count + i, vert_pos[i]); | GPU_vertbuf_vert_set(vbo, *vert_count + i, vert_pos[i]); | ||||
| } | } | ||||
| *vert_count += 6; | *vert_count += 6; | ||||
| return false; | return false; | ||||
| } | } | ||||
| static void draw_cache_view_batch( | static void draw_cache_view_batch( | ||||
| GPUVertBuf *vbo, size_t vert_count, float col_r, float col_g, float col_b, float col_a) | GPUVertBuf *vbo, size_t vert_count, float col_r, float col_g, float col_b, float col_a) | ||||
| { | { | ||||
| GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, NULL, GPU_BATCH_OWNS_VBO); | GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_TRIS, vbo, NULL, GPU_BATCH_OWNS_VBO); | ||||
| if (vert_count > 0) { | |||||
| GPU_vertbuf_data_len_set(vbo, vert_count); | GPU_vertbuf_data_len_set(vbo, vert_count); | ||||
| GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_UNIFORM_COLOR); | GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_UNIFORM_COLOR); | ||||
| GPU_batch_uniform_4f(batch, "color", col_r, col_g, col_b, col_a); | GPU_batch_uniform_4f(batch, "color", col_r, col_g, col_b, col_a); | ||||
| if (vert_count > 0) { | |||||
| GPU_batch_draw(batch); | GPU_batch_draw(batch); | ||||
| } | } | ||||
| GPU_batch_discard(batch); | GPU_batch_discard(batch); | ||||
| } | } | ||||
| static void draw_cache_view(const bContext *C) | static void draw_cache_view(const bContext *C) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (scene->ed->cache_flag & SEQ_CACHE_VIEW_COMPOSITE) { | ||||
| float bg_color[4] = {1.0f, 0.6f, 0.0f, 0.1f}; | float bg_color[4] = {1.0f, 0.6f, 0.0f, 0.1f}; | ||||
| immUniformColor4f(bg_color[0], bg_color[1], bg_color[2], bg_color[3]); | immUniformColor4f(bg_color[0], bg_color[1], bg_color[2], bg_color[3]); | ||||
| immRectf(pos, seq->startdisp, stripe_bot, seq->enddisp, stripe_top); | immRectf(pos, seq->startdisp, stripe_bot, seq->enddisp, stripe_top); | ||||
| } | } | ||||
| } | } | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| size_t cache_num_items = BKE_sequencer_cache_get_num_items(scene); | |||||
| if (cache_num_items > 0) { | |||||
| GPUVertFormat format = {0}; | GPUVertFormat format = {0}; | ||||
| GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| CacheDrawData userdata; | CacheDrawData userdata; | ||||
| userdata.v2d = v2d; | userdata.v2d = v2d; | ||||
| userdata.stripe_offs = stripe_offs; | userdata.stripe_offs = stripe_offs; | ||||
| userdata.stripe_ht = stripe_ht; | userdata.stripe_ht = stripe_ht; | ||||
| userdata.cache_flag = scene->ed->cache_flag; | |||||
| userdata.raw_vert_count = 0; | userdata.raw_vert_count = 0; | ||||
| userdata.preprocessed_vert_count = 0; | userdata.preprocessed_vert_count = 0; | ||||
| userdata.composite_vert_count = 0; | userdata.composite_vert_count = 0; | ||||
| userdata.final_out_vert_count = 0; | userdata.final_out_vert_count = 0; | ||||
| userdata.raw_vbo = GPU_vertbuf_create_with_format(&format); | userdata.raw_vbo = GPU_vertbuf_create_with_format(&format); | ||||
| userdata.preprocessed_vbo = GPU_vertbuf_create_with_format(&format); | userdata.preprocessed_vbo = GPU_vertbuf_create_with_format(&format); | ||||
| userdata.composite_vbo = GPU_vertbuf_create_with_format(&format); | userdata.composite_vbo = GPU_vertbuf_create_with_format(&format); | ||||
| userdata.final_out_vbo = GPU_vertbuf_create_with_format(&format); | userdata.final_out_vbo = GPU_vertbuf_create_with_format(&format); | ||||
| /* We can not get item count per cache type, so using total item count is safe. */ | BKE_sequencer_cache_iterate(scene, &userdata, draw_cache_view_init_cb, draw_cache_view_iter_cb); | ||||
| size_t max_vert_count = cache_num_items * 6; | |||||
| GPU_vertbuf_data_alloc(userdata.raw_vbo, max_vert_count); | |||||
| GPU_vertbuf_data_alloc(userdata.preprocessed_vbo, max_vert_count); | |||||
| GPU_vertbuf_data_alloc(userdata.composite_vbo, max_vert_count); | |||||
| GPU_vertbuf_data_alloc(userdata.final_out_vbo, max_vert_count); | |||||
| BKE_sequencer_cache_iterate(scene, &userdata, draw_cache_view_cb); | |||||
| draw_cache_view_batch(userdata.raw_vbo, userdata.raw_vert_count, 1.0f, 0.1f, 0.02f, 0.4f); | draw_cache_view_batch(userdata.raw_vbo, userdata.raw_vert_count, 1.0f, 0.1f, 0.02f, 0.4f); | ||||
| draw_cache_view_batch( | draw_cache_view_batch( | ||||
| userdata.preprocessed_vbo, userdata.preprocessed_vert_count, 0.1f, 0.1f, 0.75f, 0.4f); | userdata.preprocessed_vbo, userdata.preprocessed_vert_count, 0.1f, 0.1f, 0.75f, 0.4f); | ||||
| draw_cache_view_batch( | draw_cache_view_batch( | ||||
| userdata.composite_vbo, userdata.composite_vert_count, 1.0f, 0.6f, 0.0f, 0.4f); | userdata.composite_vbo, userdata.composite_vert_count, 1.0f, 0.6f, 0.0f, 0.4f); | ||||
| draw_cache_view_batch( | draw_cache_view_batch( | ||||
| userdata.final_out_vbo, userdata.final_out_vert_count, 1.0f, 0.4f, 0.2f, 0.4f); | userdata.final_out_vbo, userdata.final_out_vert_count, 1.0f, 0.4f, 0.2f, 0.4f); | ||||
| } | |||||
| GPU_blend(false); | GPU_blend(false); | ||||
| } | } | ||||
| /* Draw Timeline/Strip Editor Mode for Sequencer */ | /* Draw Timeline/Strip Editor Mode for Sequencer */ | ||||
| void draw_timeline_seq(const bContext *C, ARegion *region) | void draw_timeline_seq(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ▲ Show 20 Lines • Show All 118 Lines • Show Last 20 Lines | |||||