Blender
V4.3
source
blender
gpu
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
16
enum
GPUPrimType
{
17
GPU_PRIM_POINTS
,
18
GPU_PRIM_LINES
,
19
GPU_PRIM_TRIS
,
20
GPU_PRIM_LINE_STRIP
,
21
GPU_PRIM_LINE_LOOP
,
/* GL has this, Vulkan and Metal do not */
22
GPU_PRIM_TRI_STRIP
,
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. */
27
GPU_PRIM_LINES_ADJ
,
28
GPU_PRIM_TRIS_ADJ
,
29
GPU_PRIM_LINE_STRIP_ADJ
,
30
31
GPU_PRIM_NONE
,
32
};
33
34
/* what types of primitives does each shader expect? */
35
enum
GPUPimClass
{
36
GPU_PRIM_CLASS_NONE
= 0,
37
GPU_PRIM_CLASS_POINT
= (1 << 0),
38
GPU_PRIM_CLASS_LINE
= (1 << 1),
39
GPU_PRIM_CLASS_SURFACE
= (1 << 2),
40
GPU_PRIM_CLASS_ANY
=
GPU_PRIM_CLASS_POINT
|
GPU_PRIM_CLASS_LINE
|
GPU_PRIM_CLASS_SURFACE
,
41
};
42
43
inline
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
58
case
GPU_PRIM_LINE_STRIP
:
59
return
vertex_len - 1;
60
61
case
GPU_PRIM_LINE_LOOP
:
62
return
vertex_len;
63
64
case
GPU_PRIM_LINES_ADJ
:
65
BLI_assert
(vertex_len % 4 == 0);
66
return
vertex_len / 4;
67
68
case
GPU_PRIM_LINE_STRIP_ADJ
:
69
return
vertex_len - 2;
70
71
case
GPU_PRIM_TRIS
:
72
BLI_assert
(vertex_len % 3 == 0);
73
return
vertex_len / 3;
74
75
case
GPU_PRIM_TRI_STRIP
:
76
BLI_assert
(vertex_len >= 3);
77
return
vertex_len - 2;
78
79
case
GPU_PRIM_TRI_FAN
:
80
BLI_assert
(vertex_len >= 3);
81
return
vertex_len - 2;
82
83
case
GPU_PRIM_TRIS_ADJ
:
84
BLI_assert
(vertex_len % 6 == 0);
85
return
vertex_len / 6;
86
87
default
:
88
BLI_assert_unreachable
();
89
return
0;
90
}
91
}
92
93
inline
bool
is_restart_compatible
(
GPUPrimType
type)
94
{
95
switch
(type) {
96
case
GPU_PRIM_POINTS
:
97
case
GPU_PRIM_LINES
:
98
case
GPU_PRIM_TRIS
:
99
case
GPU_PRIM_LINES_ADJ
:
100
case
GPU_PRIM_TRIS_ADJ
:
101
case
GPU_PRIM_NONE
:
102
default
: {
103
return
false
;
104
}
105
case
GPU_PRIM_LINE_STRIP
:
106
case
GPU_PRIM_LINE_LOOP
:
107
case
GPU_PRIM_TRI_STRIP
:
108
case
GPU_PRIM_TRI_FAN
:
109
case
GPU_PRIM_LINE_STRIP_ADJ
: {
110
return
true
;
111
}
112
}
113
return
false
;
114
}
115
BLI_assert.h
BLI_assert_unreachable
#define BLI_assert_unreachable()
Definition
BLI_assert.h:97
BLI_assert
#define BLI_assert(a)
Definition
BLI_assert.h:50
uint
unsigned int uint
Definition
BLI_sys_types.h:68
GPU_common.hh
GPUPimClass
GPUPimClass
Definition
GPU_primitive.hh:35
GPU_PRIM_CLASS_NONE
@ GPU_PRIM_CLASS_NONE
Definition
GPU_primitive.hh:36
GPU_PRIM_CLASS_POINT
@ GPU_PRIM_CLASS_POINT
Definition
GPU_primitive.hh:37
GPU_PRIM_CLASS_LINE
@ GPU_PRIM_CLASS_LINE
Definition
GPU_primitive.hh:38
GPU_PRIM_CLASS_SURFACE
@ GPU_PRIM_CLASS_SURFACE
Definition
GPU_primitive.hh:39
GPU_PRIM_CLASS_ANY
@ GPU_PRIM_CLASS_ANY
Definition
GPU_primitive.hh:40
GPUPrimType
GPUPrimType
Definition
GPU_primitive.hh:16
GPU_PRIM_TRI_FAN
@ GPU_PRIM_TRI_FAN
Definition
GPU_primitive.hh:23
GPU_PRIM_LINE_LOOP
@ GPU_PRIM_LINE_LOOP
Definition
GPU_primitive.hh:21
GPU_PRIM_LINE_STRIP_ADJ
@ GPU_PRIM_LINE_STRIP_ADJ
Definition
GPU_primitive.hh:29
GPU_PRIM_TRIS_ADJ
@ GPU_PRIM_TRIS_ADJ
Definition
GPU_primitive.hh:28
GPU_PRIM_NONE
@ GPU_PRIM_NONE
Definition
GPU_primitive.hh:31
GPU_PRIM_LINES
@ GPU_PRIM_LINES
Definition
GPU_primitive.hh:18
GPU_PRIM_POINTS
@ GPU_PRIM_POINTS
Definition
GPU_primitive.hh:17
GPU_PRIM_LINES_ADJ
@ GPU_PRIM_LINES_ADJ
Definition
GPU_primitive.hh:27
GPU_PRIM_LINE_STRIP
@ GPU_PRIM_LINE_STRIP
Definition
GPU_primitive.hh:20
GPU_PRIM_TRI_STRIP
@ GPU_PRIM_TRI_STRIP
Definition
GPU_primitive.hh:22
GPU_PRIM_TRIS
@ GPU_PRIM_TRIS
Definition
GPU_primitive.hh:19
gpu_get_prim_count_from_type
int gpu_get_prim_count_from_type(uint vertex_len, GPUPrimType prim_type)
Definition
GPU_primitive.hh:43
is_restart_compatible
bool is_restart_compatible(GPUPrimType type)
Definition
GPU_primitive.hh:93
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0