rs_math.rsh revision 7349547db61d2d458b31c074b902d56d082e5d84
1#ifndef __RS_MATH_RSH__
2#define __RS_MATH_RSH__
3
4#include "rs_cl.rsh"
5#include "rs_core.rsh"
6
7// Allocations
8
9// Return the rs_allocation associated with a bound data
10// pointer.
11extern rs_allocation __attribute__((overloadable))
12    rsGetAllocation(const void *);
13
14// Return the dimensions associated with an allocation.
15extern uint32_t __attribute__((overloadable))
16    rsAllocationGetDimX(rs_allocation);
17extern uint32_t __attribute__((overloadable))
18    rsAllocationGetDimY(rs_allocation);
19extern uint32_t __attribute__((overloadable))
20    rsAllocationGetDimZ(rs_allocation);
21extern uint32_t __attribute__((overloadable))
22    rsAllocationGetDimLOD(rs_allocation);
23extern uint32_t __attribute__((overloadable))
24    rsAllocationGetDimFaces(rs_allocation);
25
26// Extract a single element from an allocation.
27extern const void * __attribute__((overloadable))
28    rsGetElementAt(rs_allocation, uint32_t x);
29extern const void * __attribute__((overloadable))
30    rsGetElementAt(rs_allocation, uint32_t x, uint32_t y);
31extern const void * __attribute__((overloadable))
32    rsGetElementAt(rs_allocation, uint32_t x, uint32_t y, uint32_t z);
33
34
35// Debugging, print to the LOG a description string and a value.
36extern void __attribute__((overloadable))
37    rsDebug(const char *, float);
38extern void __attribute__((overloadable))
39    rsDebug(const char *, float2);
40extern void __attribute__((overloadable))
41    rsDebug(const char *, float3);
42extern void __attribute__((overloadable))
43    rsDebug(const char *, float4);
44extern void __attribute__((overloadable))
45    rsDebug(const char *, int);
46extern void __attribute__((overloadable))
47    rsDebug(const char *, uint);
48extern void __attribute__((overloadable))
49    rsDebug(const char *, const void *);
50#define RS_DEBUG(a) rsDebug(#a, a)
51#define RS_DEBUG_MARKER rsDebug(__FILE__, __LINE__)
52
53// Return a random value between 0 (or min_value) and max_malue.
54extern int __attribute__((overloadable))
55    rsRand(int max_value);
56extern int __attribute__((overloadable))
57    rsRand(int min_value, int max_value);
58extern float __attribute__((overloadable))
59    rsRand(float max_value);
60extern float __attribute__((overloadable))
61    rsRand(float min_value, float max_value);
62
63// return the fractional part of a float
64// min(v - ((int)floor(v)), 0x1.fffffep-1f);
65extern float __attribute__((overloadable))
66    rsFrac(float);
67
68// time
69extern int32_t __attribute__((overloadable))
70    rsSecond(void);
71extern int32_t __attribute__((overloadable))
72    rsMinute(void);
73extern int32_t __attribute__((overloadable))
74    rsHour(void);
75extern int32_t __attribute__((overloadable))
76    rsDay(void);
77extern int32_t __attribute__((overloadable))
78    rsMonth(void);
79extern int32_t __attribute__((overloadable))
80    rsYear(void);
81
82// Return the current system clock in milliseconds
83extern int64_t __attribute__((overloadable))
84    rsUptimeMillis(void);
85
86// Return the current system clock in nanoseconds
87extern int64_t __attribute__((overloadable))
88    rsUptimeNanos(void);
89
90// Return the time in seconds since function was last called in this script.
91extern float __attribute__((overloadable))
92    rsGetDt(void);
93
94// Send a message back to the client.  Will not block and returns true
95// if the message was sendable and false if the fifo was full.
96// A message ID is required.  Data payload is optional.
97extern bool __attribute__((overloadable))
98    rsSendToClient(int cmdID);
99extern bool __attribute__((overloadable))
100    rsSendToClient(int cmdID, const void *data, uint len);
101
102// Send a message back to the client, blocking until the message is queued.
103// A message ID is required.  Data payload is optional.
104extern void __attribute__((overloadable))
105    rsSendToClientBlocking(int cmdID);
106extern void __attribute__((overloadable))
107    rsSendToClientBlocking(int cmdID, const void *data, uint len);
108
109// Script to Script
110typedef struct rs_script_call {
111    uint32_t xStart;
112    uint32_t xEnd;
113    uint32_t yStart;
114    uint32_t yEnd;
115    uint32_t zStart;
116    uint32_t zEnd;
117    uint32_t arrayStart;
118    uint32_t arrayEnd;
119
120} rs_script_call_t;
121
122extern void __attribute__((overloadable))
123    rsForEach(rs_script script, rs_allocation input,
124              rs_allocation output, const void * usrData);
125
126extern void __attribute__((overloadable))
127    rsForEach(rs_script script, rs_allocation input,
128              rs_allocation output, const void * usrData,
129              const rs_script_call_t *);
130
131#endif
132