Blender  V3.3
draw_attributes.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2022 Blender Foundation. All rights reserved. */
3 
4 #include "draw_attributes.h"
5 
6 /* Return true if the given DRW_AttributeRequest is already in the requests. */
8 {
9  for (int i = 0; i < requests->num_requests; i++) {
10  const DRW_AttributeRequest src_req = requests->requests[i];
11  if (src_req.domain != req.domain) {
12  continue;
13  }
14  if (src_req.layer_index != req.layer_index) {
15  continue;
16  }
17  if (src_req.cd_type != req.cd_type) {
18  continue;
19  }
20  return true;
21  }
22  return false;
23 }
24 
25 static void drw_attributes_merge_requests(const DRW_Attributes *src_requests,
26  DRW_Attributes *dst_requests)
27 {
28  for (int i = 0; i < src_requests->num_requests; i++) {
29  if (dst_requests->num_requests == GPU_MAX_ATTR) {
30  return;
31  }
32 
33  if (drw_attributes_has_request(dst_requests, src_requests->requests[i])) {
34  continue;
35  }
36 
37  dst_requests->requests[dst_requests->num_requests] = src_requests->requests[i];
38  dst_requests->num_requests += 1;
39  }
40 }
41 
43 {
44  memset(attributes, 0, sizeof(DRW_Attributes));
45 }
46 
48  const DRW_Attributes *src,
49  ThreadMutex *render_mutex)
50 {
51  BLI_mutex_lock(render_mutex);
53  BLI_mutex_unlock(render_mutex);
54 }
55 
57 {
58  for (int i = 0; i < b->num_requests; i++) {
59  if (!drw_attributes_has_request(a, b->requests[i])) {
60  return false;
61  }
62  }
63 
64  return true;
65 }
66 
68  const char *name,
69  const eCustomDataType type,
70  const int layer_index,
71  const eAttrDomain domain)
72 {
73  if (attrs->num_requests >= GPU_MAX_ATTR) {
74  return nullptr;
75  }
76 
77  DRW_AttributeRequest *req = &attrs->requests[attrs->num_requests];
78  req->cd_type = type;
79  BLI_strncpy(req->attribute_name, name, sizeof(req->attribute_name));
80  req->layer_index = layer_index;
81  req->domain = domain;
82  attrs->num_requests += 1;
83  return req;
84 }
85 
87  const char *name,
88  int *r_layer_index,
89  eCustomDataType *r_type)
90 {
91  const eCustomDataType possible_attribute_types[8] = {
100  };
101 
102  for (int i = 0; i < ARRAY_SIZE(possible_attribute_types); i++) {
103  const eCustomDataType attr_type = possible_attribute_types[i];
104  int layer_index = CustomData_get_named_layer(custom_data, attr_type, name);
105  if (layer_index == -1) {
106  continue;
107  }
108 
109  *r_layer_index = layer_index;
110  *r_type = attr_type;
111  return true;
112  }
113 
114  return false;
115 }
eAttrDomain
Definition: BKE_attribute.h:25
int CustomData_get_named_layer(const struct CustomData *data, int type, const char *name)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:373
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:378
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:82
#define ARRAY_SIZE(arr)
eCustomDataType
@ CD_PROP_BYTE_COLOR
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_COLOR
@ CD_PROP_INT8
@ CD_PROP_INT32
@ CD_PROP_FLOAT2
@ CD_PROP_BOOL
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
#define GPU_MAX_ATTR
Definition: GPU_shader.h:388
SyclQueue void void * src
void drw_attributes_merge(DRW_Attributes *dst, const DRW_Attributes *src, ThreadMutex *render_mutex)
bool drw_custom_data_match_attribute(const CustomData *custom_data, const char *name, int *r_layer_index, eCustomDataType *r_type)
static void drw_attributes_merge_requests(const DRW_Attributes *src_requests, DRW_Attributes *dst_requests)
DRW_AttributeRequest * drw_attributes_add_request(DRW_Attributes *attrs, const char *name, const eCustomDataType type, const int layer_index, const eAttrDomain domain)
static bool drw_attributes_has_request(const DRW_Attributes *requests, DRW_AttributeRequest req)
bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b)
void drw_attributes_clear(DRW_Attributes *attributes)
Utilities for rendering attributes.
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
eCustomDataType cd_type
DRW_AttributeRequest requests[GPU_MAX_ATTR]