Blender  V3.3
gizmo_draw_utils.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2014 Blender Foundation. All rights reserved. */
3 
8 #include "BLI_listbase.h"
9 
10 #include "BKE_context.h"
11 
12 #include "ED_screen.h"
13 #include "ED_view3d.h"
14 
15 #include "GPU_batch.h"
16 #include "GPU_immediate.h"
17 
18 #include "MEM_guardedalloc.h"
19 
20 #include "RNA_access.h"
21 
22 #include "WM_api.h"
23 #include "WM_types.h"
24 
25 /* only for own init/exit calls (wm_gizmotype_init/wm_gizmotype_free) */
26 #include "wm.h"
27 
28 /* own includes */
29 #include "gizmo_library_intern.h"
30 
32  const bool UNUSED(select),
33  const float color[4])
34 {
35  /* TODO: store the Batches inside the GizmoGeomInfo and updated it when geom changes
36  * So we don't need to re-created and discard it every time */
37 
38  GPUVertBuf *vbo;
39  GPUIndexBuf *el;
40  GPUBatch *batch;
41  GPUIndexBufBuilder elb = {0};
42 
43  GPUVertFormat format = {0};
45 
46  /* Elements */
47  GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, info->ntris, info->nverts);
48  for (int i = 0; i < info->ntris; i++) {
49  const ushort *idx = &info->indices[i * 3];
50  GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
51  }
52  el = GPU_indexbuf_build(&elb);
53 
55  GPU_vertbuf_data_alloc(vbo, info->nverts);
56 
57  GPU_vertbuf_attr_fill(vbo, pos_id, info->verts);
58 
61 
63 
64  /* We may want to re-visit this, for now disable
65  * since it causes issues leaving the GL state modified. */
66 #if 0
69 #endif
70 
72 
73 #if 0
76 #endif
77 
79 }
80 
82  const float color[4], const float (*verts)[3], uint vert_count, uint pos, uint primitive_type)
83 {
85 
86  if (primitive_type == GPU_PRIM_LINE_LOOP) {
87  /* Line loop alternative for Metal/Vulkan. */
88  immBegin(GPU_PRIM_LINES, vert_count * 2);
89  immVertex3fv(pos, verts[0]);
90  for (int i = 1; i < vert_count; i++) {
91  immVertex3fv(pos, verts[i]);
92  immVertex3fv(pos, verts[i]);
93  }
94  immVertex3fv(pos, verts[0]);
95  immEnd();
96  }
97  else if (primitive_type == GPU_PRIM_TRI_FAN) {
98  /* NOTE(Metal): Tri-fan alternative for Metal. Triangle List is more efficient for small
99  * primitive counts. */
100  int tri_count = vert_count - 2;
101  immBegin(GPU_PRIM_TRIS, tri_count * 3);
102  for (int i = 0; i < tri_count; i++) {
103  immVertex3fv(pos, verts[0]);
104  immVertex3fv(pos, verts[i + 1]);
105  immVertex3fv(pos, verts[i + 2]);
106  }
107  immEnd();
108  }
109  else {
110  immBegin(primitive_type, vert_count);
111  for (int i = 0; i < vert_count; i++) {
112  immVertex3fv(pos, verts[i]);
113  }
114  immEnd();
115  }
116 }
unsigned int uint
Definition: BLI_sys_types.h:67
unsigned short ushort
Definition: BLI_sys_types.h:68
#define UNUSED(x)
GPUBatch
Definition: GPU_batch.h:78
void GPU_batch_discard(GPUBatch *)
Definition: gpu_batch.cc:109
void GPU_batch_program_set_builtin(GPUBatch *batch, eGPUBuiltinShader shader_id)
Definition: gpu_batch.cc:287
GPUBatch * GPU_batch_create_ex(GPUPrimType prim, GPUVertBuf *vert, GPUIndexBuf *elem, eGPUBatchFlag owns_flag)
Definition: gpu_batch.cc:43
void GPU_batch_draw(GPUBatch *batch)
Definition: gpu_batch.cc:223
#define GPU_batch_uniform_4fv(batch, name, val)
Definition: GPU_batch.h:152
@ GPU_BATCH_OWNS_INDEX
Definition: GPU_batch.h:39
@ GPU_BATCH_OWNS_VBO
Definition: GPU_batch.h:30
void immUniformColor4fv(const float rgba[4])
void immVertex3fv(uint attr_id, const float data[3])
void immBegin(GPUPrimType, uint vertex_len)
void immEnd(void)
struct GPUIndexBuf GPUIndexBuf
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
GPUIndexBuf * GPU_indexbuf_build(GPUIndexBufBuilder *)
void GPU_indexbuf_add_tri_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3)
@ GPU_PRIM_TRI_FAN
Definition: GPU_primitive.h:25
@ GPU_PRIM_LINE_LOOP
Definition: GPU_primitive.h:23
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:20
@ GPU_PRIM_TRIS
Definition: GPU_primitive.h:21
@ GPU_SHADER_3D_UNIFORM_COLOR
Definition: GPU_shader.h:230
void GPU_face_culling(eGPUFaceCullTest culling)
Definition: gpu_state.cc:44
@ GPU_CULL_NONE
Definition: GPU_state.h:108
@ GPU_CULL_BACK
Definition: GPU_state.h:110
@ GPU_DEPTH_LESS_EQUAL
Definition: GPU_state.h:86
@ GPU_DEPTH_NONE
Definition: GPU_state.h:83
void GPU_depth_test(eGPUDepthTest test)
Definition: gpu_state.cc:65
#define GPU_vertbuf_create_with_format(format)
struct GPUVertBuf GPUVertBuf
void GPU_vertbuf_data_alloc(GPUVertBuf *, uint v_len)
void GPU_vertbuf_attr_fill(GPUVertBuf *, uint a_idx, const void *data)
@ 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 Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input 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 a color
__forceinline const avxb select(const avxb &m, const avxb &t, const avxb &f)
Definition: avxb.h:154
static float verts[][3]
void wm_gizmo_vec_draw(const float color[4], const float(*verts)[3], uint vert_count, uint pos, uint primitive_type)
void wm_gizmo_geometryinfo_draw(const GizmoGeomInfo *info, const bool UNUSED(select), const float color[4])
uint pos
struct @653::@655 batch
format
Definition: logImageCore.h:38
const ushort * indices
const float(* verts)[3]