Files
test2/source/blender/editors/space_sequencer/sequencer_quads_batch.hh
Aras Pranckevicius df16f4931e VSE: speedup timeline drawing, and improve waveform display
Sequencer timeline UI repainting is 3x-4x faster now, for complex
timelines. On Sprite Fright Edit data set, with whole timeline visible
(2702 strips), repainting the timeline UI with all overlay options
(waveforms, offsets, thumbnails etc.):

- Windows (Ryzen 5950X, RTX 3080Ti, OpenGL): 62ms -> 18.6ms (16FPS -> 54FPS)
- Mac (M1 Max, Metal): 39.8ms -> 11.5ms (25FPS -> 86FPS)

This is achieved by:

- Avoiding tiny GPU draw calls (i.e. drawing one quad a time), instead
  batch all the quads / lines needed by the timeline display into
  series of about-1000 quads per draw.
- For retiming keys display, batch their keyframe point drawing too.
- For audio waveform overlay display, change it to draw batched quads
  instead of alternating between line strips and triangle strips. This
  actually changes how the waveform looks like (implements #115274)
  and fixes some visual issues with waveforms too.
- For fcurve overlays, also draw them as batched quads.

While at it, this also fixes an issue where while dragging strips over
other strips, their text labels would look as if they are behind the
background strips.

Pull Request: https://projects.blender.org/blender/blender/pulls/115311
2023-11-29 20:25:21 +01:00

68 lines
1.8 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spseq
*/
#pragma once
#include "BLI_sys_types.h"
struct GPUVertBuf;
struct GPUIndexBuf;
struct GPUBatch;
struct ColorVertex;
/**
* Flat-colored 2D geometry draw batching utility.
*
* Internally uses #GPU_SHADER_3D_FLAT_COLOR to draw single-colored rectangles, quads
* or lines. After adding a number of primitives with #add_quad, #add_wire_quad, #add_line,
* draw them using #draw. Note that #draw can be called behind the scenes if number of primitives
* is larger than the internal batch buffer size.
*/
class SeqQuadsBatch {
public:
SeqQuadsBatch();
~SeqQuadsBatch();
/** Draw all the previously added primitives. */
void draw();
/** Add an axis-aligned quad. */
void add_quad(float x1, float y1, float x2, float y2, const uchar color[4])
{
add_quad(x1, y1, x1, y2, x2, y1, x2, y2, color);
}
/** Add a quad. */
void add_quad(float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
float x4,
float y4,
const uchar color[4]);
/** Add four lines of an axis-aligned quad edges. */
void add_wire_quad(float x1, float y1, float x2, float y2, const uchar color[4]);
/** Add a line. */
void add_line(float x1, float y1, float x2, float y2, const uchar color[4]);
private:
static constexpr int MAX_QUADS = 1024;
static constexpr int MAX_LINES = 4096;
GPUVertBuf *vbo_quads = nullptr;
GPUIndexBuf *ibo_quads = nullptr;
GPUBatch *batch_quads = nullptr;
ColorVertex *verts_quads = nullptr;
int quads_num = 0;
GPUVertBuf *vbo_lines = nullptr;
GPUBatch *batch_lines = nullptr;
ColorVertex *verts_lines = nullptr;
int lines_num = 0;
};