Blender V4.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#include "MEM_guardedalloc.h"
13
14#include "WM_types.hh"
15
16/* only for separate init/exit calls (wm_gizmotype_init/wm_gizmotype_free) */
17
18/* own includes */
20
22 const bool /*select*/,
23 const float color[4])
24{
25 /* TODO: store the Batches inside the GizmoGeomInfo and updated it when geom changes
26 * So we don't need to re-created and discard it every time */
27
30
31 /* Elements */
32 GPUIndexBufBuilder elb = {0};
33 GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, info->ntris, info->nverts);
34 for (int i = 0; i < info->ntris; i++) {
35 const ushort *idx = &info->indices[i * 3];
36 GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
37 }
39
41 GPU_vertbuf_data_alloc(*vbo, info->nverts);
42
43 GPU_vertbuf_attr_fill(vbo, pos_id, info->verts);
44
45 blender::gpu::Batch *batch = GPU_batch_create_ex(
48
50
51/* We may want to re-visit this, for now disable
52 * since it causes issues leaving the GL state modified. */
53#if 0
56#endif
57
59
60#if 0
63#endif
64
66}
67
69 const float color[4], const float (*verts)[3], uint vert_count, uint pos, uint primitive_type)
70{
72
73 if (primitive_type == GPU_PRIM_LINE_LOOP) {
74 /* Line loop alternative for Metal/Vulkan. */
75 immBegin(GPU_PRIM_LINES, vert_count * 2);
77 for (int i = 1; i < vert_count; i++) {
80 }
82 immEnd();
83 }
84 else if (primitive_type == GPU_PRIM_TRI_FAN) {
85 /* NOTE(Metal): Tri-fan alternative for Metal. Triangle List is more efficient for small
86 * primitive counts. */
87 int tri_count = vert_count - 2;
88 immBegin(GPU_PRIM_TRIS, tri_count * 3);
89 for (int i = 0; i < tri_count; i++) {
91 immVertex3fv(pos, verts[i + 1]);
92 immVertex3fv(pos, verts[i + 2]);
93 }
94 immEnd();
95 }
96 else {
97 immBegin(GPUPrimType(primitive_type), vert_count);
98 for (int i = 0; i < vert_count; i++) {
100 }
101 immEnd();
102 }
103}
unsigned short ushort
unsigned int uint
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:56
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:307
@ GPU_BATCH_OWNS_INDEX
Definition GPU_batch.hh:51
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:42
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:133
@ GPU_CULL_BACK
Definition GPU_state.hh:135
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:111
@ GPU_DEPTH_NONE
Definition GPU_state.hh:108
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 *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
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 @157336070235062372277311340362362342103123126032::@262166344314164341202215145112231240022370055142 batch
format
const ushort * indices
const float(* verts)[3]