Blender V5.0
sequencer_strips_batch.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_array.hh"
13#include "GPU_shader_shared.hh"
14
15namespace blender::gpu {
16class Shader;
17class UniformBuf;
18} // namespace blender::gpu
19struct View2D;
20
21namespace blender::gpu {
22class Batch;
23}
24
25namespace blender::ed::vse {
26
27/* Utility to draw VSE timeline strip widgets in batches, with a dedicated
28 * shader. Internally, strip data for drawing is encoded into a uniform
29 * buffer. Strip coordinates are converted into pixel space, to avoid
30 * precision issues at large frames. Drawing assumes that a pixel space
31 * projection matrix is set. */
33 SeqContextDrawData context_;
35 gpu::UniformBuf *ubo_context_ = nullptr;
36 gpu::UniformBuf *ubo_strips_ = nullptr;
37 gpu::Shader *shader_ = nullptr;
38 gpu::Batch *batch_ = nullptr;
39 int binding_context_ = 0;
40 int binding_strips_ = 0;
41 int strips_count_ = 0;
42
43 float2 view_mask_min_;
44 float2 view_mask_size_;
45 float2 view_cur_min_;
46 float2 view_cur_inv_size_;
47
48 public:
49 StripsDrawBatch(const View2D *v2d);
51
52 SeqStripDrawData &add_strip(float content_start,
53 float content_end,
54 float top,
55 float bottom,
56 float content_top,
57 float left_handle,
58 float right_handle,
59 float handle_width,
60 bool single_image);
61
62 void flush_batch();
63
64 /* Same math as `UI_view2d_view_to_region_*` but avoiding divisions,
65 * and without relying on View2D data type. */
66 float pos_to_pixel_space_x(float x) const
67 {
68 return (view_mask_min_.x + (x - view_cur_min_.x) * view_cur_inv_size_.x) * view_mask_size_.x;
69 }
70 float pos_to_pixel_space_y(float y) const
71 {
72 return (view_mask_min_.y + (y - view_cur_min_.y) * view_cur_inv_size_.y) * view_mask_size_.y;
73 }
74 float size_to_pixel_space_x(float x) const
75 {
76 return x * view_cur_inv_size_.x * view_mask_size_.x;
77 }
78
80 {
81 return ubo_context_;
82 }
83};
84
85uint color_pack(const uchar rgba[4]);
86float calc_strip_round_radius(float pixely);
87
88} // namespace blender::ed::vse
unsigned char uchar
unsigned int uint
SeqStripDrawData & add_strip(float content_start, float content_end, float top, float bottom, float content_top, float left_handle, float right_handle, float handle_width, bool single_image)
gpu::UniformBuf * get_ubo_context() const
uint top
float calc_strip_round_radius(float pixely)
uint color_pack(const uchar rgba[4])
VecBase< float, 2 > float2