Blender V4.3
sequencer_quads_batch.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "BLI_color.hh"
13
14#include "GPU_batch.hh"
15#include "GPU_index_buffer.hh"
16#include "GPU_vertex_buffer.hh"
17
22static_assert(sizeof(ColorVertex) == 12);
23
25{
27 GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, quads_count * 2, quads_count * 4);
28 for (int i = 0; i < quads_count; i++) {
29 const uint i0 = i * 4 + 0;
30 const uint i1 = i * 4 + 1;
31 const uint i2 = i * 4 + 2;
32 const uint i3 = i * 4 + 3;
33 GPU_indexbuf_add_tri_verts(&elb, i0, i1, i2);
34 GPU_indexbuf_add_tri_verts(&elb, i2, i1, i3);
35 }
36 return GPU_indexbuf_build(&elb);
37}
38
61
63{
64 BLI_assert_msg(quads_num == 0 && lines_num == 0,
65 "SeqQuadsBatch is being destroyed without drawing quads/lines it contains");
66 GPU_batch_discard(batch_quads);
67 GPU_batch_discard(batch_lines);
68}
69
71{
72 if (quads_num > 0) {
73 GPU_vertbuf_tag_dirty(vbo_quads);
74 GPU_vertbuf_use(vbo_quads);
75 GPU_batch_draw_range(batch_quads, 0, quads_num * 6);
76 quads_num = 0;
77 verts_quads = nullptr;
78 }
79 if (lines_num > 0) {
80 GPU_vertbuf_tag_dirty(vbo_lines);
81 GPU_vertbuf_use(vbo_lines);
82 GPU_batch_draw_range(batch_lines, 0, lines_num * 2);
83 lines_num = 0;
84 verts_lines = nullptr;
85 }
86}
87
89 float y1,
90 float x2,
91 float y2,
92 float x3,
93 float y3,
94 float x4,
95 float y4,
96 const uchar color1[4],
97 const uchar color2[4],
98 const uchar color3[4],
99 const uchar color4[4])
100{
101 if (quads_num >= MAX_QUADS) {
102 draw();
103 }
104 if (quads_num == 0) {
105 verts_quads = vbo_quads->data<ColorVertex>().data();
106 BLI_assert(verts_quads != nullptr);
107 }
108
109 ColorVertex v0 = {blender::float2(x1, y1), color1};
110 ColorVertex v1 = {blender::float2(x2, y2), color2};
111 ColorVertex v2 = {blender::float2(x3, y3), color3};
112 ColorVertex v3 = {blender::float2(x4, y4), color4};
113
114 *verts_quads++ = v0;
115 *verts_quads++ = v1;
116 *verts_quads++ = v2;
117 *verts_quads++ = v3;
118
119 quads_num++;
120}
121
122void SeqQuadsBatch::add_wire_quad(float x1, float y1, float x2, float y2, const uchar color[4])
123{
124 if (lines_num + 4 > MAX_LINES) {
125 draw();
126 }
127 if (lines_num == 0) {
128 verts_lines = vbo_lines->data<ColorVertex>().data();
129 BLI_assert(verts_lines != nullptr);
130 }
131
132 ColorVertex v0 = {blender::float2(x1, y1), color};
133 ColorVertex v1 = {blender::float2(x1, y2), color};
134 ColorVertex v2 = {blender::float2(x2, y1), color};
135 ColorVertex v3 = {blender::float2(x2, y2), color};
136
137 /* Left */
138 *verts_lines++ = v0;
139 *verts_lines++ = v1;
140 /* Right */
141 *verts_lines++ = v2;
142 *verts_lines++ = v3;
143 /* Bottom */
144 *verts_lines++ = v0;
145 *verts_lines++ = v2;
146 /* Top */
147 *verts_lines++ = v1;
148 *verts_lines++ = v3;
149
150 lines_num += 4;
151}
152
154 float x1, float y1, float x2, float y2, const uchar color1[4], const uchar color2[4])
155{
156 if (lines_num + 1 > MAX_LINES) {
157 draw();
158 }
159 if (lines_num == 0) {
160 verts_lines = vbo_lines->data<ColorVertex>().data();
161 BLI_assert(verts_lines != nullptr);
162 }
163
164 ColorVertex v0 = {blender::float2(x1, y1), color1};
165 ColorVertex v1 = {blender::float2(x2, y2), color2};
166
167 *verts_lines++ = v0;
168 *verts_lines++ = v1;
169
170 lines_num++;
171}
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
unsigned char uchar
unsigned int uint
blender::gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, blender::gpu::VertBuf *vertex_buf, blender::gpu::IndexBuf *index_buf, eGPUBatchFlag owns_flag)
Definition gpu_batch.cc:56
void GPU_batch_discard(blender::gpu::Batch *batch)
void GPU_batch_program_set_builtin(blender::gpu::Batch *batch, eGPUBuiltinShader shader_id)
void GPU_batch_draw_range(blender::gpu::Batch *batch, int vertex_first, int vertex_count)
@ GPU_BATCH_OWNS_INDEX
Definition GPU_batch.hh:51
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:42
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
blender::gpu::IndexBuf * GPU_indexbuf_build(GPUIndexBufBuilder *)
void GPU_indexbuf_add_tri_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3)
@ GPU_PRIM_LINES
@ GPU_PRIM_TRIS
@ GPU_SHADER_3D_SMOOTH_COLOR
void GPU_vertbuf_use(blender::gpu::VertBuf *)
blender::gpu::VertBuf * GPU_vertbuf_create_with_format_ex(const GPUVertFormat &format, GPUUsageType usage)
void GPU_vertbuf_tag_dirty(blender::gpu::VertBuf *verts)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
@ GPU_USAGE_STREAM
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
void GPU_vertformat_clear(GPUVertFormat *)
@ GPU_COMP_F32
@ GPU_COMP_U8
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void add_line(float x1, float y1, float x2, float y2, const uchar color[4])
void add_wire_quad(float x1, float y1, float x2, float y2, const uchar color[4])
void add_quad(float x1, float y1, float x2, float y2, const uchar color[4])
format
ColorTheme4< uint8_t > ColorTheme4b
Definition BLI_color.hh:286
VecBase< float, 2 > float2
static blender::gpu::IndexBuf * create_quads_index_buffer(int quads_count)
blender::float2 pos
blender::ColorTheme4b color