Fix #120789: Slowness when using image vectorscope opacity slider #120854

Merged
Aras Pranckevicius merged 1 commits from aras_p/blender:scopes_opacity_update_cb into main 2024-04-20 17:09:06 +02:00
3 changed files with 26 additions and 10 deletions

View File

@ -1414,11 +1414,10 @@ static void save_sample_line(
scopes->vecscope[idx + 0] = yuv[1];
scopes->vecscope[idx + 1] = yuv[2];
int color_idx = (idx / 2) * 4;
int color_idx = (idx / 2) * 3;
scopes->vecscope_rgb[color_idx + 0] = rgb[0];
scopes->vecscope_rgb[color_idx + 1] = rgb[1];
scopes->vecscope_rgb[color_idx + 2] = rgb[2];
scopes->vecscope_rgb[color_idx + 3] = scopes->vecscope_alpha;
/* Waveform. */
switch (scopes->wavefrm_mode) {
@ -1782,7 +1781,7 @@ void BKE_scopes_update(Scopes *scopes,
scopes->vecscope = static_cast<float *>(
MEM_callocN(scopes->waveform_tot * 2 * sizeof(float), "vectorscope point channel"));
scopes->vecscope_rgb = static_cast<float *>(
MEM_callocN(scopes->waveform_tot * 4 * sizeof(float), "vectorscope color channel"));
MEM_callocN(scopes->waveform_tot * 3 * sizeof(float), "vectorscope color channel"));
if (ibuf->float_buffer.data) {
cm_processor = IMB_colormanagement_display_processor_new(view_settings, display_settings);

View File

@ -609,17 +609,35 @@ static void waveform_draw_one(const float *waveform, int waveform_num, const flo
GPU_batch_discard(batch);
}
static void waveform_draw_rgb(const float *waveform, int waveform_num, const float *col)
struct WaveformColorVertex {
blender::float2 pos;
blender::float4 color;
};
static_assert(sizeof(WaveformColorVertex) == 24);
static void waveform_draw_rgb(const float *waveform,
int waveform_num,
const float *col,
float alpha)
{
GPUVertFormat format = {0};
const uint pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
const uint col_id = GPU_vertformat_attr_add(&format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
GPU_vertformat_attr_add(&format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
blender::gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(&format);
GPU_vertbuf_data_alloc(vbo, waveform_num);
GPU_vertbuf_attr_fill(vbo, pos_id, waveform);
GPU_vertbuf_attr_fill(vbo, col_id, col);
WaveformColorVertex *data = static_cast<WaveformColorVertex *>(GPU_vertbuf_get_data(vbo));
for (int i = 0; i < waveform_num; i++) {
memcpy(&data->pos, waveform, sizeof(data->pos));
memcpy(&data->color, col, sizeof(float) * 3);
data->color.w = alpha;
waveform += 2;
col += 3;
data++;
}
GPU_vertbuf_tag_dirty(vbo);
GPU_vertbuf_use(vbo);
blender::gpu::Batch *batch = GPU_batch_create_ex(
GPU_PRIM_POINTS, vbo, nullptr, GPU_BATCH_OWNS_VBO);
@ -1161,7 +1179,7 @@ void ui_draw_but_VECTORSCOPE(ARegion * /*region*/,
const float col[3] = {alpha, alpha, alpha};
if (scopes->vecscope_mode == SCOPES_VECSCOPE_RGB) {
GPU_blend(GPU_BLEND_ALPHA);
waveform_draw_rgb(scopes->vecscope, scopes->waveform_tot, scopes->vecscope_rgb);
waveform_draw_rgb(scopes->vecscope, scopes->waveform_tot, scopes->vecscope_rgb, alpha);
}
else if (scopes->vecscope_mode == SCOPES_VECSCOPE_LUMA) {
GPU_blend(GPU_BLEND_ADDITIVE);

View File

@ -1199,7 +1199,6 @@ static void rna_def_scopes(BlenderRNA *brna)
RNA_def_property_float_sdna(prop, "Scopes", "vecscope_alpha");
RNA_def_property_range(prop, 0, 1);
RNA_def_property_ui_text(prop, "Vectorscope Opacity", "Opacity of the points");
RNA_def_property_update(prop, 0, "rna_Scopes_update");
}
static void rna_def_colormanage(BlenderRNA *brna)