Blender  V2.93
gizmo_draw_utils.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2014 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "BLI_listbase.h"
25 
26 #include "BKE_context.h"
27 
28 #include "ED_screen.h"
29 #include "ED_view3d.h"
30 
31 #include "GPU_batch.h"
32 #include "GPU_immediate.h"
33 
34 #include "MEM_guardedalloc.h"
35 
36 #include "RNA_access.h"
37 
38 #include "WM_api.h"
39 #include "WM_types.h"
40 
41 /* only for own init/exit calls (wm_gizmotype_init/wm_gizmotype_free) */
42 #include "wm.h"
43 
44 /* own includes */
45 #include "gizmo_library_intern.h"
46 
51  const bool UNUSED(select),
52  const float color[4])
53 {
54  /* TODO store the Batches inside the GizmoGeomInfo and updated it when geom changes
55  * So we don't need to re-created and discard it every time */
56 
57  GPUVertBuf *vbo;
58  GPUIndexBuf *el;
59  GPUBatch *batch;
60  GPUIndexBufBuilder elb = {0};
61 
62  GPUVertFormat format = {0};
64 
65  /* Elements */
66  GPU_indexbuf_init(&elb, GPU_PRIM_TRIS, info->ntris, info->nverts);
67  for (int i = 0; i < info->ntris; i++) {
68  const ushort *idx = &info->indices[i * 3];
69  GPU_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
70  }
71  el = GPU_indexbuf_build(&elb);
72 
74  GPU_vertbuf_data_alloc(vbo, info->nverts);
75 
76  GPU_vertbuf_attr_fill(vbo, pos_id, info->verts);
77 
80 
81  GPU_batch_uniform_4fv(batch, "color", color);
82 
83  /* We may want to re-visit this, for now disable
84  * since it causes issues leaving the GL state modified. */
85 #if 0
88 #endif
89 
91 
92 #if 0
95 #endif
96 
98 }
99 
101  const float color[4], const float (*verts)[3], uint vert_count, uint pos, uint primitive_type)
102 {
103  immUniformColor4fv(color);
104  immBegin(primitive_type, vert_count);
105  for (int i = 0; i < vert_count; i++) {
106  immVertex3fv(pos, verts[i]);
107  }
108  immEnd();
109 }
unsigned int uint
Definition: BLI_sys_types.h:83
unsigned short ushort
Definition: BLI_sys_types.h:84
#define UNUSED(x)
GPUBatch
Definition: GPU_batch.h:93
void GPU_batch_discard(GPUBatch *)
Definition: gpu_batch.cc:127
void GPU_batch_program_set_builtin(GPUBatch *batch, eGPUBuiltinShader shader_id)
Definition: gpu_batch.cc:299
GPUBatch * GPU_batch_create_ex(GPUPrimType prim, GPUVertBuf *vert, GPUIndexBuf *elem, eGPUBatchFlag owns_flag)
Definition: gpu_batch.cc:60
void GPU_batch_draw(GPUBatch *batch)
Definition: gpu_batch.cc:234
#define GPU_batch_uniform_4fv(batch, name, val)
Definition: GPU_batch.h:142
@ GPU_BATCH_OWNS_INDEX
Definition: GPU_batch.h:54
@ GPU_BATCH_OWNS_VBO
Definition: GPU_batch.h:45
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_TRIS
Definition: GPU_primitive.h:37
@ GPU_SHADER_3D_UNIFORM_COLOR
Definition: GPU_shader.h:200
void GPU_face_culling(eGPUFaceCullTest culling)
Definition: gpu_state.cc:60
@ GPU_CULL_NONE
Definition: GPU_state.h:103
@ GPU_CULL_BACK
Definition: GPU_state.h:105
@ GPU_DEPTH_LESS_EQUAL
Definition: GPU_state.h:81
@ GPU_DEPTH_NONE
Definition: GPU_state.h:78
void GPU_depth_test(eGPUDepthTest test)
Definition: gpu_state.cc:75
#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.
GPUBatch * batch
Definition: drawnode.c:3779
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
format
Definition: logImageCore.h:47
const ushort * indices
const float(* verts)[3]
__forceinline const avxb select(const avxb &m, const avxb &t, const avxb &f)
Definition: util_avxb.h:167