Blender
V3.3
source
blender
draw
engines
image
image_batches.hh
Go to the documentation of this file.
1
/* SPDX-License-Identifier: GPL-2.0-or-later
2
* Copyright 2021 Blender Foundation. */
3
8
#pragma once
9
10
#include "
image_texture_info.hh
"
11
13
class
BatchUpdater
{
14
TextureInfo
&info;
15
16
GPUVertFormat
format
= {0};
17
int
pos_id;
18
int
uv_id;
19
20
public
:
21
BatchUpdater
(
TextureInfo
&info) : info(info)
22
{
23
}
24
25
void
update_batch
()
26
{
27
ensure_clear_batch();
28
ensure_format();
29
init_batch();
30
}
31
32
void
discard_batch
()
33
{
34
GPU_BATCH_DISCARD_SAFE
(info.
batch
);
35
}
36
37
private
:
38
void
ensure_clear_batch()
39
{
40
GPU_BATCH_CLEAR_SAFE
(info.
batch
);
41
if
(info.
batch
==
nullptr
) {
42
info.
batch
=
GPU_batch_calloc
();
43
}
44
}
45
46
void
init_batch()
47
{
48
GPUVertBuf
*vbo = create_vbo();
49
GPU_batch_init_ex
(info.
batch
,
GPU_PRIM_TRI_FAN
, vbo,
nullptr
,
GPU_BATCH_OWNS_VBO
);
50
}
51
52
GPUVertBuf
*create_vbo()
53
{
54
GPUVertBuf
*vbo =
GPU_vertbuf_create_with_format
(&
format
);
55
GPU_vertbuf_data_alloc
(vbo, 4);
56
float
pos
[4][2];
57
fill_tri_fan_from_rctf(
pos
, info.
clipping_bounds
);
58
float
uv[4][2];
59
fill_tri_fan_from_rctf(uv, info.
clipping_uv_bounds
);
60
61
for
(
int
i = 0; i < 4; i++) {
62
GPU_vertbuf_attr_set
(vbo, pos_id, i,
pos
[i]);
63
GPU_vertbuf_attr_set
(vbo, uv_id, i, uv[i]);
64
}
65
66
return
vbo;
67
}
68
69
static
void
fill_tri_fan_from_rctf(
float
result
[4][2],
rctf
&rect)
70
{
71
result
[0][0] = rect.
xmin
;
72
result
[0][1] = rect.
ymin
;
73
result
[1][0] = rect.
xmax
;
74
result
[1][1] = rect.
ymin
;
75
result
[2][0] = rect.
xmax
;
76
result
[2][1] = rect.
ymax
;
77
result
[3][0] = rect.
xmin
;
78
result
[3][1] = rect.
ymax
;
79
}
80
81
void
ensure_format()
82
{
83
if
(
format
.attr_len == 0) {
84
GPU_vertformat_attr_add
(&
format
,
"pos"
,
GPU_COMP_F32
, 2,
GPU_FETCH_FLOAT
);
85
GPU_vertformat_attr_add
(&
format
,
"uv"
,
GPU_COMP_F32
, 2,
GPU_FETCH_FLOAT
);
86
87
pos_id =
GPU_vertformat_attr_id_get
(&
format
,
"pos"
);
88
uv_id =
GPU_vertformat_attr_id_get
(&
format
,
"uv"
);
89
}
90
}
91
};
result
double result
Definition:
BLI_expr_pylike_eval_test.cc:348
GPU_batch_calloc
GPUBatch * GPU_batch_calloc(void)
Definition:
gpu_batch.cc:36
GPU_batch_init_ex
void GPU_batch_init_ex(GPUBatch *batch, GPUPrimType prim, GPUVertBuf *vert, GPUIndexBuf *elem, eGPUBatchFlag owns_flag)
Definition:
gpu_batch.cc:53
GPU_BATCH_CLEAR_SAFE
#define GPU_BATCH_CLEAR_SAFE(batch)
Definition:
GPU_batch.h:224
GPU_BATCH_DISCARD_SAFE
#define GPU_BATCH_DISCARD_SAFE(batch)
Definition:
GPU_batch.h:216
GPU_BATCH_OWNS_VBO
@ GPU_BATCH_OWNS_VBO
Definition:
GPU_batch.h:30
GPU_PRIM_TRI_FAN
@ GPU_PRIM_TRI_FAN
Definition:
GPU_primitive.h:25
GPU_vertbuf_create_with_format
#define GPU_vertbuf_create_with_format(format)
Definition:
GPU_vertex_buffer.h:55
GPUVertBuf
struct GPUVertBuf GPUVertBuf
Definition:
GPU_vertex_buffer.h:50
GPU_vertbuf_data_alloc
void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len)
Definition:
gpu_vertex_buffer.cc:174
GPU_vertbuf_attr_set
void GPU_vertbuf_attr_set(GPUVertBuf *, uint a_idx, uint v_idx, const void *data)
Definition:
gpu_vertex_buffer.cc:192
GPU_FETCH_FLOAT
@ GPU_FETCH_FLOAT
Definition:
GPU_vertex_format.h:43
GPU_vertformat_attr_add
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
Definition:
gpu_vertex_format.cc:116
GPU_vertformat_attr_id_get
int GPU_vertformat_attr_id_get(const GPUVertFormat *, const char *name)
Definition:
gpu_vertex_format.cc:207
GPU_COMP_F32
@ GPU_COMP_F32
Definition:
GPU_vertex_format.h:36
BatchUpdater
Create GPUBatch for a IMAGE_ScreenSpaceTextureInfo.
Definition:
image_batches.hh:13
BatchUpdater::BatchUpdater
BatchUpdater(TextureInfo &info)
Definition:
image_batches.hh:21
BatchUpdater::discard_batch
void discard_batch()
Definition:
image_batches.hh:32
BatchUpdater::update_batch
void update_batch()
Definition:
image_batches.hh:25
pos
uint pos
Definition:
gpu_batch_presets.c:34
image_texture_info.hh
format
format
Definition:
logImageCore.h:38
GPUVertFormat
Definition:
GPU_vertex_format.h:72
TextureInfo
Definition:
image_texture_info.hh:15
TextureInfo::batch
GPUBatch * batch
Batch to draw the associated text on the screen.
Definition:
image_texture_info.hh:42
TextureInfo::clipping_uv_bounds
rctf clipping_uv_bounds
uv area of the texture in screen space.
Definition:
image_texture_info.hh:33
TextureInfo::clipping_bounds
rctf clipping_bounds
area of the texture in screen space.
Definition:
image_texture_info.hh:31
rctf
Definition:
DNA_vec_types.h:68
rctf::xmax
float xmax
Definition:
DNA_vec_types.h:69
rctf::xmin
float xmin
Definition:
DNA_vec_types.h:69
rctf::ymax
float ymax
Definition:
DNA_vec_types.h:70
rctf::ymin
float ymin
Definition:
DNA_vec_types.h:70
Generated on Tue Oct 22 2024 13:18:25 for Blender by
doxygen
1.9.1