ai_params.h
Go to the documentation of this file.
1 // Copyright 2020 Autodesk, Inc. All rights reserved.
2 //
3 // Use of this software is subject to the terms of the Autodesk license
4 // agreement provided at the time of installation or download, or which
5 // otherwise accompanies this software in either electronic or hard copy form.
6 
12 #pragma once
13 #include "ai_array.h"
14 #include "ai_closure.h"
15 #include "ai_color.h"
16 #include "ai_enum.h"
17 #include "ai_math.h"
18 #include "ai_matrix.h"
19 #include "ai_vector.h"
20 #include "ai_api.h"
21 #include <stdint.h> // uint32_t etc
22 
23 #ifdef _WIN32
24 # ifndef WIN32_LEAN_AND_MEAN
25 # define WIN32_LEAN_AND_MEAN
26 # endif
27 # ifndef VC_EXTRALEAN
28 # define VC_EXTRALEAN
29 # endif
30 # ifndef NOMINMAX
31 # define NOMINMAX
32 # endif
33 // Force an include of windows.h to make sure it can't be included after this header
34 // (thanks to its own internal include guard) and the RGB() macro is not defined again
35 # include <windows.h>
36 # ifdef RGB
37 # undef RGB
38 // The RGB() macro in WinGDI.h returns a COLORREF, which we know to be a DWORD, which
39 // in turn is an unsigned long, see:
40 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx
41 // Let's recreate this as a function instead of as a macro.
42 inline constexpr unsigned long RGB(unsigned long r, unsigned long g, unsigned long b)
43 {
44  return r | g << 8 | b << 16;
45 }
46 # endif
47 #endif
48 
49 // forward declaration
50 struct AtList;
51 struct AtNode;
52 
70 #define AI_TYPE_BYTE 0x00
71 #define AI_TYPE_INT 0x01
72 #define AI_TYPE_UINT 0x02
73 #define AI_TYPE_BOOLEAN 0x03
74 #define AI_TYPE_FLOAT 0x04
75 #define AI_TYPE_RGB 0x05
76 #define AI_TYPE_RGBA 0x06
77 #define AI_TYPE_VECTOR 0x07
78 #define AI_TYPE_VECTOR2 0x09
79 #define AI_TYPE_STRING 0x0A
80 #define AI_TYPE_POINTER 0x0B
81 #define AI_TYPE_NODE 0x0C
82 #define AI_TYPE_ARRAY 0x0D
83 #define AI_TYPE_MATRIX 0x0E
84 #define AI_TYPE_ENUM 0x0F
85 #define AI_TYPE_CLOSURE 0x10
86 #define AI_TYPE_USHORT 0x11
87 #define AI_TYPE_HALF 0x12
88 #define AI_TYPE_UNDEFINED 0xFF
89 #define AI_TYPE_NONE 0xFF
90 /* \}*/
91 
95 #define AI_USERDEF_UNDEFINED 0
96 #define AI_USERDEF_CONSTANT 1
97 #define AI_USERDEF_UNIFORM 2
98 #define AI_USERDEF_VARYING 3
99 #define AI_USERDEF_INDEXED 4
100 /* \}*/
101 
106 {
107 public:
108  AI_DEVICE bool const& BOOL() const{ return *reinterpret_type<bool const*> (&data); }
109  AI_DEVICE uint8_t const& BYTE() const{ return *reinterpret_type<uint8_t const*> (&data); }
110  AI_DEVICE int const& INT() const{ return *reinterpret_type<int const*> (&data); }
111  AI_DEVICE unsigned const& UINT() const{ return *reinterpret_type<unsigned const*> (&data); }
112  AI_DEVICE float const& FLT() const{ return *reinterpret_type<float const*> (&data); }
113  AI_DEVICE AtRGB const& RGB() const{ return *reinterpret_type<AtRGB const*> (&data); }
114  AI_DEVICE AtRGBA const& RGBA() const{ return *reinterpret_type<AtRGBA const*> (&data); }
115  AI_DEVICE AtVector const& VEC() const{ return *reinterpret_type<AtVector const*> (&data); }
116  AI_DEVICE AtVector2 const& VEC2() const{ return *reinterpret_type<AtVector2 const*> (&data); }
117  AI_DEVICE AtString const& STR() const{ return *reinterpret_type<AtString const*> (&data); }
118  AI_DEVICE void* const& PTR() const{ return *reinterpret_type<void* const*> (&data); }
119  AtMatrix* const& pMTX() const{ return *reinterpret_type<AtMatrix* const*> (&data); }
120  AtArray* const& ARRAY() const{ return *reinterpret_type<AtArray* const*> (&data); }
121  AI_DEVICE AtClosureList const& CLOSURE() const{ return *reinterpret_type<AtClosureList const*>(&data); }
122 
123  AI_DEVICE bool & BOOL() { return *reinterpret_type<bool *> (&data); }
124  AI_DEVICE uint8_t & BYTE() { return *reinterpret_type<uint8_t *> (&data); }
125  AI_DEVICE int & INT() { return *reinterpret_type<int *> (&data); }
126  AI_DEVICE unsigned & UINT() { return *reinterpret_type<unsigned *> (&data); }
127  AI_DEVICE float & FLT() { return *reinterpret_type<float *> (&data); }
128  AI_DEVICE AtRGB & RGB() { return *reinterpret_type<AtRGB *> (&data); }
129  AI_DEVICE AtRGBA & RGBA() { return *reinterpret_type<AtRGBA *> (&data); }
130  AI_DEVICE AtVector & VEC() { return *reinterpret_type<AtVector *> (&data); }
131  AI_DEVICE AtVector2 & VEC2() { return *reinterpret_type<AtVector2*> (&data); }
132  AI_DEVICE AtString & STR() { return *reinterpret_type<AtString *> (&data); }
133  AI_DEVICE void* & PTR() { return *reinterpret_type<void* *> (&data); }
134  AtMatrix* & pMTX() { return *reinterpret_type<AtMatrix**> (&data); }
135  AtArray* & ARRAY() { return *reinterpret_type<AtArray* *> (&data); }
136  AI_DEVICE AtClosureList & CLOSURE(){ return *reinterpret_type<AtClosureList*>(&data); }
137 
138 private:
139  // 128 bits of raw data, naturally aligned to 64 bit so it properly works
140  // with pointers. This is big enough to hold up to four floats, as needed
141  // by AtRGBA.
142  uint64_t data[2];
143 };
144 
151 struct AtParamEntry;
152 
157 AI_API AI_PURE AtString AiParamGetName (const AtParamEntry* pentry);
158 AI_API AI_PURE uint8_t AiParamGetType (const AtParamEntry* pentry);
159 AI_API AI_PURE const AtParamValue* AiParamGetDefault (const AtParamEntry* pentry);
160 AI_API AI_PURE AtEnum AiParamGetEnum (const AtParamEntry* pentry);
161 AI_API AI_PURE const char* AiParamGetTypeName(uint8_t type);
162 AI_API AI_DEVICE AI_CONST int AiParamGetTypeSize(uint8_t type);
163 /* \}*/
164 
171 struct AtUserParamEntry;
172 
177 AI_API AI_DEVICE AI_PURE const char* AiUserParamGetName (const AtUserParamEntry* upentry);
178 AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetType (const AtUserParamEntry* upentry);
179 AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetArrayType(const AtUserParamEntry* upentry);
180 AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetCategory (const AtUserParamEntry* upentry);
181 /* \}*/
182 
194 AI_API AI_CONST bool AiParamTypeConvertible(uint8_t dst_type, uint8_t src_type);
195 
221 #define AiParameterByte(n,c) AiNodeParamByte (params,-1,n,c);
222 #define AiParameterInt(n,c) AiNodeParamInt (params,-1,n,c);
223 #define AiParameterUInt(n,c) AiNodeParamUInt (params,-1,n,c);
224 #define AiParameterBool(n,c) AiNodeParamBool (params,-1,n,c);
225 #define AiParameterFlt(n,c) AiNodeParamFlt (params,-1,n,c);
226 #define AiParameterRGB(n,r,g,b) AiNodeParamRGB (params,-1,n,r,g,b);
227 #define AiParameterRGBA(n,r,g,b,a) AiNodeParamRGBA (params,-1,n,r,g,b,a);
228 #define AiParameterVec(n,x,y,z) AiNodeParamVec (params,-1,n,x,y,z);
229 #define AiParameterVec2(n,x,y) AiNodeParamVec2 (params,-1,n,x,y);
230 #define AiParameterStr(n,c) AiNodeParamStr (params,-1,n,c);
231 #define AiParameterPtr(n,c) AiNodeParamPtr (params,-1,n,c);
232 #define AiParameterNode(n,c) AiNodeParamNode (params,-1,n,c);
233 #define AiParameterArray(n,c) AiNodeParamArray (params,-1,n,c);
234 #define AiParameterMtx(n,c) AiNodeParamMtx (params,-1,n,c);
235 #define AiParameterEnum(n,c,e) AiNodeParamEnum (params,-1,n,c,e);
236 #define AiParameterClosure(n) AiNodeParamClosure(params,-1,n);
237 /* \}*/
238 
239 /*\}*/
240 
241 /* for convenience, the macros above call these functions */
242 AI_API void AiNodeParamByte (AtList* params, int varoffset, const char* pname, uint8_t pdefault);
243 AI_API void AiNodeParamInt (AtList* params, int varoffset, const char* pname, int pdefault);
244 AI_API void AiNodeParamUInt (AtList* params, int varoffset, const char* pname, unsigned int pdefault);
245 AI_API void AiNodeParamBool (AtList* params, int varoffset, const char* pname, bool pdefault);
246 AI_API void AiNodeParamFlt (AtList* params, int varoffset, const char* pname, float pdefault);
247 AI_API void AiNodeParamRGB (AtList* params, int varoffset, const char* pname, float r, float g, float b);
248 AI_API void AiNodeParamRGBA (AtList* params, int varoffset, const char* pname, float r, float g, float b, float a);
249 AI_API void AiNodeParamVec (AtList* params, int varoffset, const char* pname, float x, float y, float z);
250 AI_API void AiNodeParamVec2 (AtList* params, int varoffset, const char* pname, float x, float y);
251 AI_API void AiNodeParamStr (AtList* params, int varoffset, const char* pname, const char* pdefault);
252 AI_API void AiNodeParamPtr (AtList* params, int varoffset, const char* pname, void* pdefault);
253 AI_API void AiNodeParamNode (AtList* params, int varoffset, const char* pname, AtNode* pdefault);
254 AI_API void AiNodeParamArray (AtList* params, int varoffset, const char* pname, AtArray* pdefault);
255 AI_API void AiNodeParamMtx (AtList* params, int varoffset, const char* pname, AtMatrix matrix);
256 AI_API void AiNodeParamEnum (AtList* params, int varoffset, const char* pname, int pdefault, AtEnum enum_type);
257 AI_API void AiNodeParamClosure(AtList* params, int varoffset, const char* pname);
RGB color.
Definition: ai_color.h:31
This represents a node in Arnold.
Vector math types, operators and utilities.
AI_API AI_PURE AtEnum AiParamGetEnum(const AtParamEntry *pentry)
Return the enum type of a given enum parameter.
Definition: ai_paramentry.cpp:178
Math operations.
Arnold String allows for fast string comparisons.
Definition: ai_string.h:46
3D point (single precision)
Definition: ai_vector.h:29
AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetArrayType(const AtUserParamEntry *upentry)
Look-up user-declared parameter array-type (int, float, etc...)
Definition: ai_userdefs.cpp:35
AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetType(const AtUserParamEntry *upentry)
Look-up user-declared parameter type (int, float, etc...)
Definition: ai_userdefs.cpp:24
Color types and utilities.
Definition: ai_matrix.h:30
DLL export prefix for API functions (necessary for multi-platform development)
2D point
Definition: ai_vector.h:254
AI_API AI_DEVICE AI_PURE const char * AiUserParamGetName(const AtUserParamEntry *upentry)
Look-up user-declared parameter name.
Definition: ai_userdefs.cpp:12
AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetCategory(const AtUserParamEntry *upentry)
Look-up user-declared parameter category (constant, uniform, varying)
Definition: ai_userdefs.cpp:46
AI_API AI_CONST bool AiParamTypeConvertible(uint8_t dst_type, uint8_t src_type)
Returns whether an AtParamValue of type src_type can be converted to dst_type.
Definition: ai_paramentry.cpp:532
Generic array data type and methods.
AI_API AI_PURE const char * AiParamGetTypeName(uint8_t type)
Return the name of an Arnold data type.
Definition: ai_paramentry.cpp:101
AI_API AI_PURE const AtParamValue * AiParamGetDefault(const AtParamEntry *pentry)
Return the default value of a given parameter.
Definition: ai_paramentry.cpp:162
Actual parameter value for each supported type.
Definition: ai_params.h:105
AI_API AI_DEVICE AI_CONST int AiParamGetTypeSize(uint8_t type)
Return the size of an Arnold data type.
Definition: ai_paramentry.cpp:124
AI_API AI_PURE AtString AiParamGetName(const AtParamEntry *pentry)
Return the name of a given parameter.
Definition: ai_paramentry.cpp:67
RGB color + alpha.
Definition: ai_color.h:266
AI_API AI_PURE uint8_t AiParamGetType(const AtParamEntry *pentry)
Return the type of a given parameter.
Definition: ai_paramentry.cpp:83
Definition: ai_closure.h:84
Enum data type and utility functions.
const char ** AtEnum
String-based enumerated data type.
Definition: ai_enum.h:31
Matrix math type and methods.
Closure type and utilities.

© 2020 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com