Blender V5.0
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 &format, "pos", blender::gpu::VertAttrType::SFLOAT_32_32_32);
27
28 /* Elements */
29 GPUIndexBufBuilder elb = {0};
30 GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, info->ntris, info->nverts);
31 for (int i = 0; i < info->ntris; i++) {
32 const ushort *idx = &info->indices[i * 3];
33 GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
34 }
36
38 GPU_vertbuf_data_alloc(*vbo, info->nverts);
39
40 GPU_vertbuf_attr_fill(vbo, pos_id, info->verts);
41
42 blender::gpu::Batch *batch = GPU_batch_create_ex(
45
46 GPU_batch_uniform_4fv(batch, "color", color);
47
48/* We may want to re-visit this, for now disable
49 * since it causes issues leaving the GL state modified. */
50#if 0
53#endif
54
56
57#if 0
60#endif
61
63}
64
66 const float color[4], const float (*verts)[3], uint vert_count, uint pos, uint primitive_type)
67{
68 immUniformColor4fv(color);
69
70 if (primitive_type == GPU_PRIM_LINE_LOOP) {
71 /* Line loop alternative for Metal/Vulkan. */
72 immBegin(GPU_PRIM_LINES, vert_count * 2);
74 for (int i = 1; i < vert_count; i++) {
77 }
79 immEnd();
80 }
81 else if (primitive_type == GPU_PRIM_TRI_FAN) {
82 /* NOTE(Metal): Tri-fan alternative for Metal. Triangle List is more efficient for small
83 * primitive counts. */
84 int tri_count = vert_count - 2;
85 immBegin(GPU_PRIM_TRIS, tri_count * 3);
86 for (int i = 0; i < tri_count; i++) {
88 immVertex3fv(pos, verts[i + 1]);
89 immVertex3fv(pos, verts[i + 2]);
90 }
91 immEnd();
92 }
93 else {
94 immBegin(GPUPrimType(primitive_type), vert_count);
95 for (int i = 0; i < vert_count; i++) {
97 }
98 immEnd();
99 }
100}
unsigned int uint
unsigned short ushort
void GPU_batch_discard(blender::gpu::Batch *batch)
void GPU_batch_program_set_builtin(blender::gpu::Batch *batch, GPUBuiltinShader shader_id)
blender::gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, blender::gpu::VertBuf *vertex_buf, blender::gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
Definition gpu_batch.cc:51
@ GPU_BATCH_OWNS_INDEX
Definition GPU_batch.hh:46
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:42
void GPU_batch_draw(blender::gpu::Batch *batch)
#define GPU_batch_uniform_4fv(batch, name, val)
Definition GPU_batch.hh:279
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
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:114
@ GPU_DEPTH_NONE
Definition GPU_state.hh:111
void GPU_face_culling(GPUFaceCullTest culling)
Definition gpu_state.cc:47
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:68
@ GPU_CULL_NONE
Definition GPU_state.hh:136
@ GPU_CULL_BACK
Definition GPU_state.hh:138
void GPU_vertbuf_attr_fill(blender::gpu::VertBuf *, uint a_idx, const void *data)
static blender::gpu::VertBuf * GPU_vertbuf_create_with_format(const GPUVertFormat &format)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
uint GPU_vertformat_attr_add(GPUVertFormat *format, blender::StringRef name, blender::gpu::VertAttrType type)
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)
struct @021025263243242147216143265077100330027142264337::@225245033123204053237120173316075113304004012000 batch
uint pos
format
const ushort * indices
const float(* verts)[3]
i
Definition text_draw.cc:230