Blender V4.3
sequencer_strips_batch.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "BLI_rect.h"
12
13#include "DNA_userdef_types.h"
14#include "DNA_view2d_types.h"
15
16#include "GPU_batch.hh"
17#include "GPU_batch_presets.hh"
18#include "GPU_shader_shared.hh"
19#include "GPU_uniform_buffer.hh"
20
21#include "UI_resources.hh"
22
23namespace blender::ed::seq {
24
25uint color_pack(const uchar rgba[4])
26{
27 return rgba[0] | (rgba[1] << 8u) | (rgba[2] << 16u) | (rgba[3] << 24u);
28}
29
30float calc_strip_round_radius(float pixely)
31{
32 float height_pixels = 1.0f / pixely;
33 if (height_pixels < 16.0f) {
34 return 0.0f;
35 }
36 if (height_pixels < 64.0f) {
37 return 4.0f;
38 }
39 if (height_pixels < 128.0f) {
40 return 6.0f;
41 }
42 return 8.0f;
43}
44
46{
47 view_mask_min_ = float2(v2d->mask.xmin, v2d->mask.ymin);
48 view_mask_size_ = float2(BLI_rcti_size_x(&v2d->mask), BLI_rcti_size_y(&v2d->mask));
49 view_cur_min_ = float2(v2d->cur.xmin, v2d->cur.ymin);
50 float2 view_cur_size = float2(BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur));
51 view_cur_inv_size_ = 1.0f / view_cur_size;
52
53 float pixely = view_cur_size.y / view_mask_size_.y;
54 context_.round_radius = calc_strip_round_radius(pixely);
55 context_.pixelsize = U.pixelsize;
56
57 uchar col[4];
59 col[3] = 255;
60 context_.col_back = color_pack(col);
61
63 binding_strips_ = GPU_shader_get_ubo_binding(shader_, "strip_data");
64 binding_context_ = GPU_shader_get_ubo_binding(shader_, "context_data");
65
66 ubo_context_ = GPU_uniformbuf_create_ex(sizeof(SeqContextDrawData), &context_, __func__);
68
69 batch_ = GPU_batch_preset_quad();
70}
71
73{
75
76 GPU_uniformbuf_unbind(ubo_strips_);
77 GPU_uniformbuf_free(ubo_strips_);
78 GPU_uniformbuf_unbind(ubo_context_);
79 GPU_uniformbuf_free(ubo_context_);
80}
81
83 float content_end,
84 float top,
85 float bottom,
86 float content_top,
87 float left_handle,
88 float right_handle,
89 float handle_width,
90 bool single_image)
91{
92 if (strips_count_ == GPU_SEQ_STRIP_DRAW_DATA_LEN) {
94 }
95
96 SeqStripDrawData &res = strips_[strips_count_];
97 strips_count_++;
98
99 memset(&res, 0, sizeof(res));
100 res.content_start = pos_to_pixel_space_x(content_start);
101 res.content_end = pos_to_pixel_space_x(content_end);
102 res.top = pos_to_pixel_space_y(top);
103 res.bottom = pos_to_pixel_space_y(bottom);
104 res.strip_content_top = pos_to_pixel_space_y(content_top);
105 res.left_handle = pos_to_pixel_space_x(left_handle);
106 res.right_handle = pos_to_pixel_space_x(right_handle);
107 res.handle_width = size_to_pixel_space_x(handle_width);
108 if (single_image) {
110 }
111 return res;
112}
113
115{
116 if (strips_count_ == 0) {
117 return;
118 }
119
120 GPU_uniformbuf_update(ubo_strips_, strips_.data());
121
122 GPU_shader_bind(shader_);
123 GPU_uniformbuf_bind(ubo_strips_, binding_strips_);
124 GPU_uniformbuf_bind(ubo_context_, binding_context_);
125
126 GPU_batch_set_shader(batch_, shader_);
127 GPU_batch_draw_instance_range(batch_, 0, strips_count_);
128 strips_count_ = 0;
129}
130
131} // namespace blender::ed::seq
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:193
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:189
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.h:197
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.h:201
unsigned char uchar
unsigned int uint
void GPU_batch_draw_instance_range(blender::gpu::Batch *batch, int instance_first, int instance_count)
void GPU_batch_set_shader(blender::gpu::Batch *batch, GPUShader *shader)
blender::gpu::Batch * GPU_batch_preset_quad()
int GPU_shader_get_ubo_binding(GPUShader *shader, const char *name)
void GPU_shader_bind(GPUShader *shader)
GPUShader * GPU_shader_get_builtin_shader(eGPUBuiltinShader shader)
@ GPU_SHADER_SEQUENCER_STRIPS
@ GPU_SEQ_FLAG_SINGLE_IMAGE
#define GPU_SEQ_STRIP_DRAW_DATA_LEN
GPUUniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
void GPU_uniformbuf_unbind(GPUUniformBuf *ubo)
#define GPU_uniformbuf_create(size)
void GPU_uniformbuf_update(GPUUniformBuf *ubo, const void *data)
void GPU_uniformbuf_free(GPUUniformBuf *ubo)
void GPU_uniformbuf_bind(GPUUniformBuf *ubo, int slot)
@ TH_BACK
void UI_GetThemeColorShade3ubv(int colorid, int offset, unsigned char col[3])
unsigned int U
Definition btGjkEpa3.h:78
const T * data() const
Definition BLI_array.hh:301
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)
uint col
uint color_pack(const uchar rgba[4])
float calc_strip_round_radius(float pixely)
VecBase< float, 2 > float2
float xmin
float ymin
int ymin
int xmin