Blender V5.3
gizmo_draw_utils.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2014 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "GPU_batch.hh"
10#include "GPU_immediate.hh"
11
12/* only for separate init/exit calls (wm_gizmotype_init/wm_gizmotype_free) */
13
14/* own includes */
16
17namespace blender {
18
20 const bool /*select*/,
21 const float color[4])
22{
23 /* TODO: store the Batches inside the GizmoGeomInfo and updated it when geom changes
24 * So we don't need to re-created and discard it every time */
25
26 GPUVertFormat format = {0};
27 uint pos_id = GPU_vertformat_attr_add(&format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
28
29 /* Elements */
30 GPUIndexBufBuilder elb = {0};
31 GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, info->ntris, info->nverts);
32 for (int i = 0; i < info->ntris; i++) {
33 const ushort *idx = &info->indices[i * 3];
34 GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
35 }
37
38 gpu::VertBuf *vbo = GPU_vertbuf_create_with_format(format);
39 GPU_vertbuf_data_alloc(*vbo, info->nverts);
40
41 GPU_vertbuf_attr_fill(vbo, pos_id, info->verts);
42
43 gpu::Batch *batch = GPU_batch_create_ex(
46
47 GPU_batch_uniform_4fv(batch, "color", color);
48
49/* We may want to re-visit this, for now disable
50 * since it causes issues leaving the GL state modified. */
51#if 0
54#endif
55
56 GPU_batch_draw(batch);
57
58#if 0
61#endif
62
63 GPU_batch_discard(batch);
64}
65
67 const float color[4], const float (*verts)[3], uint vert_count, uint pos, uint primitive_type)
68{
70
71 if (primitive_type == GPU_PRIM_LINE_LOOP) {
72 /* Line loop alternative for Metal/Vulkan. */
73 immBegin(GPU_PRIM_LINES, vert_count * 2);
74 immVertex3fv(pos, verts[0]);
75 for (int i = 1; i < vert_count; i++) {
76 immVertex3fv(pos, verts[i]);
77 immVertex3fv(pos, verts[i]);
78 }
79 immVertex3fv(pos, verts[0]);
80 immEnd();
81 }
82 else if (primitive_type == GPU_PRIM_TRI_FAN) {
83 /* NOTE(Metal): Tri-fan alternative for Metal. Triangle List is more efficient for small
84 * primitive counts. */
85 int tri_count = vert_count - 2;
86 immBegin(GPU_PRIM_TRIS, tri_count * 3);
87 for (int i = 0; i < tri_count; i++) {
88 immVertex3fv(pos, verts[0]);
89 immVertex3fv(pos, verts[i + 1]);
90 immVertex3fv(pos, verts[i + 2]);
91 }
92 immEnd();
93 }
94 else {
95 immBegin(GPUPrimType(primitive_type), vert_count);
96 for (int i = 0; i < vert_count; i++) {
97 immVertex3fv(pos, verts[i]);
98 }
99 immEnd();
100 }
101}
102
103} // namespace blender
#define GPU_batch_uniform_4fv(batch, name, val)
Definition GPU_batch.hh:275
BMesh Iterators.
@ GPU_CULL_NONE
Definition GPU_state.hh:157
@ GPU_CULL_BACK
Definition GPU_state.hh:159
void wm_gizmo_geometryinfo_draw(const GizmoGeomInfo *info, const bool, const float color[4])
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
Definition gpu_batch.cc:53
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
void immEnd()
unsigned int uint
Definition BKE_text.h:55
unsigned short ushort
Definition BKE_text.h:56
void immBegin(GPUPrimType, uint vertex_len)
@ GPU_PRIM_LINE_LOOP
void GPU_batch_discard(gpu::Batch *batch)
void immUniformColor4fv(const float rgba[4])
gpu::IndexBuf * GPU_indexbuf_build(GPUIndexBufBuilder *)
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:135
void wm_gizmo_vec_draw(const float color[4], const float(*verts)[3], uint vert_count, uint pos, uint primitive_type)
void GPU_batch_draw(gpu::Batch *batch)
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:44
@ GPU_BATCH_OWNS_INDEX
Definition GPU_batch.hh:48
void GPU_indexbuf_add_tri_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
void immVertex3fv(uint attr_id, const float data[3])
void GPU_vertbuf_attr_fill(gpu::VertBuf *, uint a_idx, const void *data)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
void GPU_face_culling(GPUFaceCullTest culling)
Definition gpu_state.cc:49
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
const float(* verts)[3]