Blender V4.3
draw_attributes.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_string.h"
6
7#include "BKE_attribute.hh"
8#include "BKE_customdata.hh"
9
10#include "draw_attributes.hh"
11
12namespace blender::draw {
13
14/* Return true if the given DRW_AttributeRequest is already in the requests. */
15static bool drw_attributes_has_request(const DRW_Attributes *requests,
16 const DRW_AttributeRequest &req)
17{
18 for (int i = 0; i < requests->num_requests; i++) {
19 const DRW_AttributeRequest &src_req = requests->requests[i];
20 if (src_req.domain == req.domain && src_req.layer_index == req.layer_index &&
21 src_req.cd_type == req.cd_type)
22 {
23 return true;
24 }
25 }
26 return false;
27}
28
29static void drw_attributes_merge_requests(const DRW_Attributes *src_requests,
30 DRW_Attributes *dst_requests)
31{
32 for (int i = 0; i < src_requests->num_requests; i++) {
33 if (dst_requests->num_requests == GPU_MAX_ATTR) {
34 return;
35 }
36
37 if (drw_attributes_has_request(dst_requests, src_requests->requests[i])) {
38 continue;
39 }
40
41 dst_requests->requests[dst_requests->num_requests] = src_requests->requests[i];
42 dst_requests->num_requests += 1;
43 }
44}
45
47{
48 *attributes = {};
49}
50
51void drw_attributes_merge(DRW_Attributes *dst, const DRW_Attributes *src, std::mutex &render_mutex)
52{
53 if (src->num_requests == 0) {
54 return;
55 }
56 std::lock_guard lock{render_mutex};
58}
59
61{
62 for (int i = 0; i < b->num_requests; i++) {
63 if (!drw_attributes_has_request(a, b->requests[i])) {
64 return false;
65 }
66 }
67
68 return true;
69}
70
72 const char *name,
73 const eCustomDataType type,
74 const int layer_index,
75 const blender::bke::AttrDomain domain)
76{
77 if (attrs->num_requests >= GPU_MAX_ATTR ||
78 drw_attributes_has_request(attrs, {type, layer_index, domain}))
79 {
80 return;
81 }
82
83 DRW_AttributeRequest *req = &attrs->requests[attrs->num_requests];
84 req->cd_type = type;
85 STRNCPY(req->attribute_name, name);
86 req->layer_index = layer_index;
87 req->domain = domain;
88 attrs->num_requests += 1;
89}
90
92 const char *name,
93 int *r_layer_index,
94 eCustomDataType *r_type)
95{
96 const eCustomDataType possible_attribute_types[10] = {
107 };
108
109 for (int i = 0; i < ARRAY_SIZE(possible_attribute_types); i++) {
110 const eCustomDataType attr_type = possible_attribute_types[i];
111 int layer_index = CustomData_get_named_layer(&custom_data, attr_type, name);
112 if (layer_index == -1) {
113 continue;
114 }
115
116 *r_layer_index = layer_index;
117 *r_type = attr_type;
118 return true;
119 }
120
121 return false;
122}
123
124} // namespace blender::draw
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_named_layer(const CustomData *data, eCustomDataType type, blender::StringRef name)
#define STRNCPY(dst, src)
Definition BLI_string.h:593
#define ARRAY_SIZE(arr)
@ CD_PROP_BYTE_COLOR
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_INT32_2D
@ CD_PROP_COLOR
@ CD_PROP_QUATERNION
@ CD_PROP_INT32
@ CD_PROP_FLOAT2
#define GPU_MAX_ATTR
Definition GPU_shader.hh:29
volatile int lock
local_group_size(16, 16) .push_constant(Type b
Utilities for rendering attributes.
void drw_attributes_clear(DRW_Attributes *attributes)
bool drw_custom_data_match_attribute(const CustomData &custom_data, const char *name, int *r_layer_index, eCustomDataType *r_type)
void drw_attributes_merge(DRW_Attributes *dst, const DRW_Attributes *src, std::mutex &render_mutex)
static bool drw_attributes_has_request(const DRW_Attributes *requests, const DRW_AttributeRequest &req)
static void drw_attributes_merge_requests(const DRW_Attributes *src_requests, DRW_Attributes *dst_requests)
void drw_attributes_add_request(DRW_Attributes *attrs, const char *name, const eCustomDataType type, const int layer_index, const blender::bke::AttrDomain domain)
bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b)
DRW_AttributeRequest requests[GPU_MAX_ATTR]