Blender V4.5
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
18 const bool /*select*/,
19 const float color[4])
20{
21 /* TODO: store the Batches inside the GizmoGeomInfo and updated it when geom changes
22 * So we don't need to re-created and discard it every time */
23
26
27 /* Elements */
28 GPUIndexBufBuilder elb = {0};
29 GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, info->ntris, info->nverts);
30 for (int i = 0; i < info->ntris; i++) {
31 const ushort *idx = &info->indices[i * 3];
32 GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
33 }
35
37 GPU_vertbuf_data_alloc(*vbo, info->nverts);
38
39 GPU_vertbuf_attr_fill(vbo, pos_id, info->verts);
40
41 blender::gpu::Batch *batch = GPU_batch_create_ex(
44
45 GPU_batch_uniform_4fv(batch, "color", color);
46
47/* We may want to re-visit this, for now disable
48 * since it causes issues leaving the GL state modified. */
49#if 0
52#endif
53
55
56#if 0
59#endif
60
62}
63
65 const float color[4], const float (*verts)[3], uint vert_count, uint pos, uint primitive_type)
66{
67 immUniformColor4fv(color);
68
69 if (primitive_type == GPU_PRIM_LINE_LOOP) {
70 /* Line loop alternative for Metal/Vulkan. */
71 immBegin(GPU_PRIM_LINES, vert_count * 2);
73 for (int i = 1; i < vert_count; i++) {
76 }
78 immEnd();
79 }
80 else if (primitive_type == GPU_PRIM_TRI_FAN) {
81 /* NOTE(Metal): Tri-fan alternative for Metal. Triangle List is more efficient for small
82 * primitive counts. */
83 int tri_count = vert_count - 2;
84 immBegin(GPU_PRIM_TRIS, tri_count * 3);
85 for (int i = 0; i < tri_count; i++) {
87 immVertex3fv(pos, verts[i + 1]);
88 immVertex3fv(pos, verts[i + 2]);
89 }
90 immEnd();
91 }
92 else {
93 immBegin(GPUPrimType(primitive_type), vert_count);
94 for (int i = 0; i < vert_count; i++) {
96 }
97 immEnd();
98 }
99}
unsigned int uint
unsigned short ushort
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:51
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(blender::gpu::Batch *batch)
#define GPU_batch_uniform_4fv(batch, name, val)
Definition GPU_batch.hh:309
@ GPU_BATCH_OWNS_INDEX
Definition GPU_batch.hh:50
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:41
void immEnd()
void immUniformColor4fv(const float rgba[4])
void immVertex3fv(uint attr_id, const float data[3])
void immBegin(GPUPrimType, uint vertex_len)
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)
GPUPrimType
@ GPU_PRIM_TRI_FAN
@ GPU_PRIM_LINE_LOOP
@ GPU_PRIM_LINES
@ GPU_PRIM_TRIS
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_face_culling(eGPUFaceCullTest culling)
Definition gpu_state.cc:47
@ GPU_CULL_NONE
Definition GPU_state.hh:136
@ GPU_CULL_BACK
Definition GPU_state.hh:138
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:114
@ GPU_DEPTH_NONE
Definition GPU_state.hh:111
void GPU_depth_test(eGPUDepthTest test)
Definition gpu_state.cc:68
#define GPU_vertbuf_create_with_format(format)
void GPU_vertbuf_attr_fill(blender::gpu::VertBuf *, uint a_idx, const void *data)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, blender::StringRef name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
static float verts[][3]
void wm_gizmo_geometryinfo_draw(const GizmoGeomInfo *info, const bool, const float color[4])
void wm_gizmo_vec_draw(const float color[4], const float(*verts)[3], uint vert_count, uint pos, uint primitive_type)
uint pos
struct @064345207361167251075330302113175271221317160336::@113254110077376341056327177062323111323010325277 batch
format
const ushort * indices
const float(* verts)[3]
i
Definition text_draw.cc:230