Blender
V4.3
source
blender
draw
engines
image
image_batches.hh
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2021 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9
#pragma once
10
11
#include "
image_texture_info.hh
"
12
13
namespace
blender::draw::image_engine
{
14
16
class
BatchUpdater
{
17
TextureInfo
&info;
18
19
GPUVertFormat
format = {0};
20
int
pos_id;
21
int
uv_id;
22
23
public
:
24
BatchUpdater
(
TextureInfo
&info) : info(info) {}
25
26
void
update_batch
()
27
{
28
ensure_clear_batch();
29
ensure_format();
30
init_batch();
31
}
32
33
private
:
34
void
ensure_clear_batch()
35
{
36
GPU_BATCH_CLEAR_SAFE
(info.
batch
);
37
if
(info.
batch
==
nullptr
) {
38
info.
batch
=
GPU_batch_calloc
();
39
}
40
}
41
42
void
init_batch()
43
{
44
gpu::VertBuf
*vbo = create_vbo();
45
GPU_batch_init_ex
(info.
batch
,
GPU_PRIM_TRI_FAN
, vbo,
nullptr
,
GPU_BATCH_OWNS_VBO
);
46
}
47
48
template
<
typename
DataType,
typename
RectType>
49
static
void
fill_tri_fan_from_rect(
DataType
result
[4][2], RectType &rect)
50
{
51
result
[0][0] = rect.xmin;
52
result
[0][1] = rect.ymin;
53
result
[1][0] = rect.xmax;
54
result
[1][1] = rect.ymin;
55
result
[2][0] = rect.xmax;
56
result
[2][1] = rect.ymax;
57
result
[3][0] = rect.xmin;
58
result
[3][1] = rect.ymax;
59
}
60
61
gpu::VertBuf *create_vbo()
62
{
63
gpu::VertBuf *vbo =
GPU_vertbuf_create_with_format
(format);
64
GPU_vertbuf_data_alloc
(*vbo, 4);
65
int
pos
[4][2];
66
fill_tri_fan_from_rect<int, rcti>(
pos
, info.clipping_bounds);
67
float
uv[4][2];
68
fill_tri_fan_from_rect<float, rctf>(uv, info.clipping_uv_bounds);
69
70
for
(
int
i = 0; i < 4; i++) {
71
GPU_vertbuf_attr_set
(vbo, pos_id, i,
pos
[i]);
72
GPU_vertbuf_attr_set
(vbo, uv_id, i, uv[i]);
73
}
74
75
return
vbo;
76
}
77
78
void
ensure_format()
79
{
80
if
(format.attr_len == 0) {
81
GPU_vertformat_attr_add
(&format,
"pos"
,
GPU_COMP_I32
, 2,
GPU_FETCH_INT
);
82
GPU_vertformat_attr_add
(&format,
"uv"
,
GPU_COMP_F32
, 2,
GPU_FETCH_FLOAT
);
83
84
pos_id =
GPU_vertformat_attr_id_get
(&format,
"pos"
);
85
uv_id =
GPU_vertformat_attr_id_get
(&format,
"uv"
);
86
}
87
}
88
};
89
90
}
// namespace blender::draw::image_engine
result
double result
Definition
BLI_expr_pylike_eval_test.cc:351
GPU_batch_init_ex
void GPU_batch_init_ex(blender::gpu::Batch *batch, GPUPrimType primitive_type, blender::gpu::VertBuf *vertex_buf, blender::gpu::IndexBuf *index_buf, eGPUBatchFlag owns_flag)
GPU_BATCH_CLEAR_SAFE
#define GPU_BATCH_CLEAR_SAFE(batch)
Definition
GPU_batch.hh:191
GPU_BATCH_OWNS_VBO
@ GPU_BATCH_OWNS_VBO
Definition
GPU_batch.hh:42
GPU_PRIM_TRI_FAN
@ GPU_PRIM_TRI_FAN
Definition
GPU_primitive.hh:23
GPU_vertbuf_create_with_format
#define GPU_vertbuf_create_with_format(format)
Definition
GPU_vertex_buffer.hh:164
GPU_vertbuf_attr_set
void GPU_vertbuf_attr_set(blender::gpu::VertBuf *, uint a_idx, uint v_idx, const void *data)
Definition
gpu_vertex_buffer.cc:204
GPU_vertbuf_data_alloc
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
Definition
gpu_vertex_buffer.cc:187
GPU_FETCH_FLOAT
@ GPU_FETCH_FLOAT
Definition
GPU_vertex_format.hh:44
GPU_FETCH_INT
@ GPU_FETCH_INT
Definition
GPU_vertex_format.hh:45
GPU_vertformat_attr_add
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
Definition
gpu_vertex_format.cc:124
GPU_vertformat_attr_id_get
int GPU_vertformat_attr_id_get(const GPUVertFormat *, const char *name)
Definition
gpu_vertex_format.cc:215
GPU_COMP_F32
@ GPU_COMP_F32
Definition
GPU_vertex_format.hh:35
GPU_COMP_I32
@ GPU_COMP_I32
Definition
GPU_vertex_format.hh:32
blender::draw::image_engine::BatchUpdater::update_batch
void update_batch()
Definition
image_batches.hh:26
blender::draw::image_engine::BatchUpdater::BatchUpdater
BatchUpdater(TextureInfo &info)
Definition
image_batches.hh:24
blender::gpu::VertBuf
Definition
GPU_vertex_buffer.hh:61
DataType
DataType
Definition
cycles/device/memory.h:40
GPU_batch_calloc
Batch * GPU_batch_calloc()
Definition
gpu_batch.cc:49
image_texture_info.hh
blender::draw::image_engine
Definition
image_batches.hh:13
pos
pos[]
Definition
overlay_armature_info.hh:107
GPUVertFormat
Definition
GPU_vertex_format.hh:73
blender::draw::image_engine::TextureInfo
Definition
image_texture_info.hh:19
blender::draw::image_engine::TextureInfo::batch
gpu::Batch * batch
Batch to draw the associated text on the screen.
Definition
image_texture_info.hh:43
Generated on Sat Oct 4 2025 05:32:23 for Blender by
doxygen
1.14.0