Blender
V5.0
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::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::VertAttrType::SINT_32_32);
82
GPU_vertformat_attr_add
(&format,
"uv"
, gpu::VertAttrType::SFLOAT_32_32);
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::image_engine
result
double result
Definition
BLI_expr_pylike_eval_test.cc:351
GPU_BATCH_CLEAR_SAFE
#define GPU_BATCH_CLEAR_SAFE(batch)
Definition
GPU_batch.hh:183
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, GPUBatchFlag owns_flag)
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
static blender::gpu::VertBuf * GPU_vertbuf_create_with_format(const GPUVertFormat &format)
Definition
GPU_vertex_buffer.hh:68
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:188
GPU_vertbuf_data_alloc
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
Definition
gpu_vertex_buffer.cc:171
GPU_vertformat_attr_id_get
int GPU_vertformat_attr_id_get(const GPUVertFormat *, blender::StringRef name)
Definition
gpu_vertex_format.cc:466
GPU_vertformat_attr_add
uint GPU_vertformat_attr_add(GPUVertFormat *format, blender::StringRef name, blender::gpu::VertAttrType type)
Definition
gpu_vertex_format.cc:388
blender::image_engine::BatchUpdater::BatchUpdater
BatchUpdater(TextureInfo &info)
Definition
image_batches.hh:24
blender::image_engine::BatchUpdater::update_batch
void update_batch()
Definition
image_batches.hh:26
DataType
DataType
Definition
cycles/device/memory.h:38
GPU_batch_calloc
Batch * GPU_batch_calloc()
Definition
gpu_batch.cc:44
pos
uint pos
Definition
gpu_batch_presets.cc:36
image_texture_info.hh
blender::image_engine
Definition
image_batches.hh:13
GPUVertFormat
Definition
GPU_vertex_format.hh:217
blender::image_engine::TextureInfo
Definition
image_texture_info.hh:23
blender::image_engine::TextureInfo::batch
gpu::Batch * batch
Batch to draw the associated text on the screen.
Definition
image_texture_info.hh:47
i
i
Definition
text_draw.cc:230
Generated on
for Blender by
doxygen
1.16.1