Blender V4.3
GPU_primitive.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 by Mike Erwin. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#pragma once
12
13#include "BLI_assert.h"
14#include "GPU_common.hh"
15
21 GPU_PRIM_LINE_LOOP, /* GL has this, Vulkan and Metal do not */
23 GPU_PRIM_TRI_FAN, /* Metal API does not support this. */
24
25 /* Metal API does not support ADJ primitive types but
26 * handled via the geometry-shader-alternative path. */
30
32};
33
34/* what types of primitives does each shader expect? */
42
43inline int gpu_get_prim_count_from_type(uint vertex_len, GPUPrimType prim_type)
44{
45 /* does vertex_len make sense for this primitive type? */
46 if (vertex_len == 0) {
47 return 0;
48 }
49
50 switch (prim_type) {
51 case GPU_PRIM_POINTS:
52 return vertex_len;
53
54 case GPU_PRIM_LINES:
55 BLI_assert(vertex_len % 2 == 0);
56 return vertex_len / 2;
57
59 return vertex_len - 1;
60
62 return vertex_len;
63
65 BLI_assert(vertex_len % 4 == 0);
66 return vertex_len / 4;
67
69 return vertex_len - 2;
70
71 case GPU_PRIM_TRIS:
72 BLI_assert(vertex_len % 3 == 0);
73 return vertex_len / 3;
74
76 BLI_assert(vertex_len >= 3);
77 return vertex_len - 2;
78
80 BLI_assert(vertex_len >= 3);
81 return vertex_len - 2;
82
84 BLI_assert(vertex_len % 6 == 0);
85 return vertex_len / 6;
86
87 default:
89 return 0;
90 }
91}
92
94{
95 switch (type) {
96 case GPU_PRIM_POINTS:
97 case GPU_PRIM_LINES:
98 case GPU_PRIM_TRIS:
101 case GPU_PRIM_NONE:
102 default: {
103 return false;
104 }
108 case GPU_PRIM_TRI_FAN:
110 return true;
111 }
112 }
113 return false;
114}
115
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#define BLI_assert(a)
Definition BLI_assert.h:50
unsigned int uint
GPUPimClass
@ GPU_PRIM_CLASS_NONE
@ GPU_PRIM_CLASS_POINT
@ GPU_PRIM_CLASS_LINE
@ GPU_PRIM_CLASS_SURFACE
@ GPU_PRIM_CLASS_ANY
GPUPrimType
@ GPU_PRIM_TRI_FAN
@ GPU_PRIM_LINE_LOOP
@ GPU_PRIM_LINE_STRIP_ADJ
@ GPU_PRIM_TRIS_ADJ
@ GPU_PRIM_NONE
@ GPU_PRIM_LINES
@ GPU_PRIM_POINTS
@ GPU_PRIM_LINES_ADJ
@ GPU_PRIM_LINE_STRIP
@ GPU_PRIM_TRI_STRIP
@ GPU_PRIM_TRIS
int gpu_get_prim_count_from_type(uint vertex_len, GPUPrimType prim_type)
bool is_restart_compatible(GPUPrimType type)