Blender  V2.93
type_callbacks.cc
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 
18 #include "NOD_type_callbacks.hh"
19 
20 namespace blender::nodes {
21 
23 {
24  if (stype.get_cpp_type != nullptr) {
25  return stype.get_cpp_type();
26  }
27  return nullptr;
28 }
29 
30 std::optional<MFDataType> socket_mf_type_get(const bNodeSocketType &stype)
31 {
32  const CPPType *cpp_type = socket_cpp_type_get(stype);
33  if (cpp_type != nullptr) {
34  return MFDataType::ForSingle(*cpp_type);
35  }
36  return {};
37 }
38 
40 {
41  if (!socket_mf_type_get(stype).has_value()) {
42  return false;
43  }
44  if (stype.expand_in_mf_network == nullptr && stype.get_cpp_value == nullptr) {
45  return false;
46  }
47  return true;
48 }
49 
50 bool socket_cpp_value_get(const bNodeSocket &socket, void *r_value)
51 {
52  if (socket.typeinfo->get_cpp_value != nullptr) {
53  socket.typeinfo->get_cpp_value(socket, r_value);
54  return true;
55  }
56  return false;
57 }
58 
60 {
61  bNodeSocket &socket = builder.bsocket();
62  if (socket.typeinfo->expand_in_mf_network != nullptr) {
63  socket.typeinfo->expand_in_mf_network(builder);
64  }
65  else if (socket.typeinfo->get_cpp_value != nullptr) {
66  const CPPType &type = *socket_cpp_type_get(*socket.typeinfo);
67  void *buffer = builder.resource_scope().linear_allocator().allocate(type.size(),
68  type.alignment());
69  socket.typeinfo->get_cpp_value(socket, buffer);
70  builder.set_constant_value(type, buffer);
71  }
72  else {
74  }
75 }
76 
77 } // namespace blender::nodes
#define BLI_assert_unreachable()
Definition: BLI_assert.h:96
_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
void * allocate(const int64_t size, const int64_t alignment)
LinearAllocator & linear_allocator()
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void socket_expand_in_mf_network(SocketMFNetworkBuilder &builder)
std::optional< MFDataType > socket_mf_type_get(const bNodeSocketType &stype)
bool socket_is_mf_data_socket(const bNodeSocketType &stype)
const CPPType * socket_cpp_type_get(const bNodeSocketType &stype)
bool socket_cpp_value_get(const bNodeSocket &socket, void *r_value)
Defines a socket type.
Definition: BKE_node.h:143
SocketGetCPPTypeFunction get_cpp_type
Definition: BKE_node.h:194
SocketExpandInMFNetworkFunction expand_in_mf_network
Definition: BKE_node.h:192
SocketGetCPPValueFunction get_cpp_value
Definition: BKE_node.h:196
struct bNodeSocketType * typeinfo